Sort requests based on last view time again

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2013-08-30 17:50:34 +02:00
parent 8d53833d81
commit 07005886f8
3 changed files with 106 additions and 66 deletions

View file

@ -506,7 +506,7 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
/* render real page */
if (priv->render_requested == false) {
priv->render_requested = true;
zathura_render_request(priv->render_request);
zathura_render_request(priv->render_request, priv->last_view);
}
}
mutex_unlock(&(priv->lock));

104
render.c
View file

@ -21,7 +21,6 @@ static void zathura_renderer_finalize(GObject* object);
static void zathura_render_request_finalize(GObject* object);
static void render_job(void* data, void* user_data);
static bool render(ZathuraRenderRequest* request, ZathuraRenderer* renderer);
static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data);
static void color2double(const GdkColor* col, double* v);
@ -50,6 +49,7 @@ typedef struct request_private_s {
zathura_page_t* page;
bool requested;
bool aborted;
gint64 last_view_time;
} request_private_t;
#define GET_PRIVATE(obj) \
@ -298,7 +298,7 @@ zathura_renderer_stop(ZathuraRenderer* renderer)
/* ZathuraRenderRequest methods */
void
zathura_render_request(ZathuraRenderRequest* request)
zathura_render_request(ZathuraRenderRequest* request, gint64 last_view_time)
{
g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request));
@ -307,6 +307,7 @@ zathura_render_request(ZathuraRenderRequest* request)
if (request_priv->requested == false) {
request_priv->requested = true;
request_priv->aborted = false;
request_priv->last_view_time = last_view_time;
g_thread_pool_push(priv->pool, request, NULL);
}
@ -326,26 +327,34 @@ zathura_render_request_abort(ZathuraRenderRequest* request)
/* render job */
static void
render_job(void* data, void* user_data)
typedef struct emit_completed_signal_s
{
ZathuraRenderRequest* request = data;
ZathuraRenderer* renderer = user_data;
g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request));
g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
ZathuraRenderer* renderer;
ZathuraRenderRequest* request;
cairo_surface_t* surface;
} emit_completed_signal_t;
private_t* priv = GET_PRIVATE(renderer);
request_private_t* request_priv = REQUEST_GET_PRIVATE(request);
if (priv->about_to_close == true || request_priv->aborted == true) {
/* back out early */
request_priv->requested = false;
return;
}
static gboolean
emit_completed_signal(void* data)
{
emit_completed_signal_t* ecs = data;
private_t* priv = GET_PRIVATE(ecs->renderer);
request_private_t* request_priv = REQUEST_GET_PRIVATE(ecs->request);
girara_debug("Rendering page %d ...", zathura_page_get_index(request_priv->page) + 1);
if (render(request, renderer) != true) {
girara_error("Rendering failed (page %d)\n", zathura_page_get_index(request_priv->page) + 1);
if (priv->about_to_close == false && request_priv->aborted == false) {
/* emit the signal */
g_signal_emit(ecs->request, request_signals[REQUEST_COMPLETED], 0, ecs->surface);
}
/* mark the request as done */
request_priv->requested = false;
/* clean up the data */
cairo_surface_destroy(ecs->surface);
g_object_unref(ecs->renderer);
g_object_unref(ecs->request);
g_free(ecs);
return FALSE;
}
static void
@ -400,36 +409,6 @@ colorumax(const double* h, double l, double l1, double l2)
return fmin(u, v);
}
typedef struct emit_completed_signal_s
{
ZathuraRenderer* renderer;
ZathuraRenderRequest* request;
cairo_surface_t* surface;
} emit_completed_signal_t;
static gboolean
emit_completed_signal(void* data)
{
emit_completed_signal_t* ecs = data;
private_t* priv = GET_PRIVATE(ecs->renderer);
request_private_t* request_priv = REQUEST_GET_PRIVATE(ecs->request);
if (priv->about_to_close == false && request_priv->aborted == false) {
/* emit the signal */
g_signal_emit(ecs->request, request_signals[REQUEST_COMPLETED], 0, ecs->surface);
}
/* mark the request as done */
request_priv->requested = false;
/* clean up the data */
cairo_surface_destroy(ecs->surface);
g_object_unref(ecs->renderer);
g_object_unref(ecs->request);
g_free(ecs);
return FALSE;
}
static void
recolor(private_t* priv, unsigned int page_width, unsigned int page_height,
cairo_surface_t* surface)
@ -583,6 +562,29 @@ render(ZathuraRenderRequest* request, ZathuraRenderer* renderer)
return true;
}
static void
render_job(void* data, void* user_data)
{
ZathuraRenderRequest* request = data;
ZathuraRenderer* renderer = user_data;
g_return_if_fail(ZATHURA_IS_RENDER_REQUEST(request));
g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
private_t* priv = GET_PRIVATE(renderer);
request_private_t* request_priv = REQUEST_GET_PRIVATE(request);
if (priv->about_to_close == true || request_priv->aborted == true) {
/* back out early */
request_priv->requested = false;
return;
}
girara_debug("Rendering page %d ...", zathura_page_get_index(request_priv->page) + 1);
if (render(request, renderer) != true) {
girara_error("Rendering failed (page %d)\n", zathura_page_get_index(request_priv->page) + 1);
}
}
void
render_all(zathura_t* zathura)
{
@ -615,10 +617,8 @@ render_thread_sort(gconstpointer a, gconstpointer b, gpointer UNUSED(data))
request_private_t* priv_a = REQUEST_GET_PRIVATE(request_a);
request_private_t* priv_b = REQUEST_GET_PRIVATE(request_b);
if (priv_a->aborted == priv_b->aborted) {
unsigned int page_a_index = zathura_page_get_index(priv_a->page);
unsigned int page_b_index = zathura_page_get_index(priv_b->page);
return page_a_index < page_b_index ? -1 :
(page_a_index > page_b_index ? 1 : 0);
return priv_a->last_view_time < priv_b->last_view_time ? -1 :
(priv_a->last_view_time > priv_b->last_view_time ? 1 : 0);
}
/* sort aborted entries earlier so that the are thrown out of the queue */

View file

@ -41,44 +41,82 @@ struct zathura_renderer_class_s
*/
GType zathura_renderer_get_type(void);
/**
* Create a page view widget.
* @param zathura the zathura instance
* @param page the page to be displayed
* @return a page view widget
* Create a renderer.
* @return a renderer object
*/
ZathuraRenderer* zathura_renderer_new(void);
/**
* Return whether recoloring is enabled.
* @param renderer a renderer object
* @returns true if recoloring is enabled, false otherwise
*/
bool zathura_renderer_recolor_enabled(ZathuraRenderer* renderer);
/**
* Enable/disable recoloring.
* @param renderer a renderer object
* @param enable wheter to enable or disable recoloring
*/
void zathura_renderer_enable_recolor(ZathuraRenderer* renderer, bool enable);
/**
* Return whether hue should be preserved while recoloring.
* @param renderer a renderer object
* @returns true if hue should be preserved, false otherwise
*/
bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer);
/**
* Enable/disable preservation of hue while recoloring.
* @param renderer a renderer object
* @param enable wheter to enable or disable hue preservation
*/
void zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer,
bool enable);
/**
* Set light and dark colors for recoloring.
* @param renderer a renderer object
* @param light light color
* @param dark dark color
*/
void zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer,
const GdkColor* light, const GdkColor* dark);
/**
* Set light and dark colors for recoloring.
* @param renderer a renderer object
* @param light light color
* @param dark dark color
*/
void zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer,
const char* light, const char* dark);
/**
* Get light and dark colors for recoloring.
* @param renderer a renderer object
* @param light light color
* @param dark dark color
*/
void zathura_renderer_get_recolor_colors(ZathuraRenderer* renderer,
GdkColor* light, GdkColor* dark);
/**
* Stop rendering.
* @param renderer a render object
*/
void zathura_renderer_stop(ZathuraRenderer* renderer);
/**
* Lock the render thread. This is useful if you want to render on your own (e.g
* for printing).
*
* @param render_thread The render thread object.
* @param renderer renderer object
*/
void zathura_renderer_lock(ZathuraRenderer* renderer);
/**
* Unlock the render thread.
*
* @param render_thread The render thread object.
* @param renderer renderer object.
*/
void zathura_renderer_unlock(ZathuraRenderer* renderer);
typedef struct zathura_render_request_s ZathuraRenderRequest;
typedef struct zathura_render_request_class_s ZathuraRenderRequestClass;
@ -109,15 +147,15 @@ struct zathura_render_request_class_s
ZathuraRenderRequestClass))
/**
* Returns the type of the renderer.
* Returns the type of the render request.
* @return the type
*/
GType zathura_page_render_info_get_type(void);
/**
* Create a page view widget.
* @param zathura the zathura instance
* Create a render request object
* @param renderer a renderer object
* @param page the page to be displayed
* @return a page view widget
* @returns render request object
*/
ZathuraRenderRequest* zathura_render_request_new(ZathuraRenderer* renderer,
zathura_page_t* page);
@ -127,8 +165,10 @@ ZathuraRenderRequest* zathura_render_request_new(ZathuraRenderer* renderer,
* that should be rendered.
*
* @param request request object of the page that should be renderer
* @param last_view_time last view time of the page
*/
void zathura_render_request(ZathuraRenderRequest* request);
void zathura_render_request(ZathuraRenderRequest* request,
gint64 last_view_time);
/**
* Abort an existing render request.