Don't store surface for invisible and uncached pages

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2013-07-27 16:25:20 +02:00
parent f98514d5ed
commit b5237680f2
5 changed files with 43 additions and 6 deletions

View file

@ -106,6 +106,12 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
} }
} else { } else {
zathura_page_set_visibility(page, false); zathura_page_set_visibility(page, false);
/* if the page is not visible and not cached, but still has a surface, we
* need to get rid of the surface */
if (zathura_page_widget_have_surface(ZATHURA_PAGE(page_widget)) == true &&
zathura_page_cache_is_cached(zathura, zathura_page_get_index(page)) == false) {
zathura_page_widget_update_surface(ZATHURA_PAGE(page_widget), NULL);
}
girara_list_t* results = NULL; girara_list_t* results = NULL;
g_object_get(page_widget, "search-results", &results, NULL); g_object_get(page_widget, "search-results", &results, NULL);

View file

@ -506,11 +506,16 @@ zathura_page_widget_update_surface(ZathuraPage* widget, cairo_surface_t* surface
mutex_lock(&(priv->lock)); mutex_lock(&(priv->lock));
if (priv->surface != NULL) { if (priv->surface != NULL) {
cairo_surface_destroy(priv->surface); cairo_surface_destroy(priv->surface);
priv->surface = NULL;
} }
priv->render_requested = false; priv->render_requested = false;
priv->surface = surface; if (surface != NULL) {
if (priv->surface != NULL) { /* if we're not visible or not cached, we don't care about the surface */
cairo_surface_reference(surface); if (zathura_page_get_visibility(priv->page) == true ||
zathura_page_cache_is_cached(priv->zathura, zathura_page_get_index(priv->page)) == true) {
priv->surface = surface;
cairo_surface_reference(surface);
}
} }
mutex_unlock(&(priv->lock)); mutex_unlock(&(priv->lock));
/* force a redraw here */ /* force a redraw here */
@ -876,3 +881,12 @@ zathura_page_widget_update_view_time(ZathuraPage* widget)
priv->last_view = g_get_real_time(); priv->last_view = g_get_real_time();
} }
} }
bool
zathura_page_widget_have_surface(ZathuraPage* widget)
{
g_return_val_if_fail(ZATHURA_IS_PAGE(widget) == TRUE, false);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
return priv->surface != NULL;
}

View file

@ -88,4 +88,12 @@ zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int i
*/ */
void zathura_page_widget_update_view_time(ZathuraPage* widget); void zathura_page_widget_update_view_time(ZathuraPage* widget);
/**
* Check if we have a surface.
*
* @param widget the widget
* @returns true if the widget has a surface, false otherwise
*/
bool zathura_page_widget_have_surface(ZathuraPage* widget);
#endif #endif

View file

@ -54,7 +54,6 @@ typedef struct position_set_delayed_s {
} position_set_delayed_t; } position_set_delayed_t;
static gboolean document_info_open(gpointer data); static gboolean document_info_open(gpointer data);
static bool zathura_page_cache_is_cached(zathura_t* zathura, unsigned int page_index);
static ssize_t zathura_page_cache_lru_invalidate(zathura_t* zathura); static ssize_t zathura_page_cache_lru_invalidate(zathura_t* zathura);
static void zathura_page_cache_invalidate_all(zathura_t* zathura); static void zathura_page_cache_invalidate_all(zathura_t* zathura);
static bool zathura_page_cache_is_full(zathura_t* zathura, bool* result); static bool zathura_page_cache_is_full(zathura_t* zathura, bool* result);
@ -1364,7 +1363,7 @@ zathura_jumplist_save(zathura_t* zathura)
} }
} }
static bool bool
zathura_page_cache_is_cached(zathura_t* zathura, unsigned int page_index) zathura_page_cache_is_cached(zathura_t* zathura, unsigned int page_index)
{ {
g_return_val_if_fail(zathura != NULL, false); g_return_val_if_fail(zathura != NULL, false);
@ -1452,7 +1451,7 @@ zathura_page_cache_add(zathura_t* zathura, unsigned int page_index)
g_return_if_fail(page != NULL); g_return_if_fail(page != NULL);
if (zathura_page_cache_is_cached(zathura, page_index)) { if (zathura_page_cache_is_cached(zathura, page_index) == true) {
return; return;
} }

View file

@ -421,4 +421,14 @@ bool zathura_jumplist_load(zathura_t* zathura, const char* file);
*/ */
void zathura_page_cache_add(zathura_t* zathura, unsigned int page_index); void zathura_page_cache_add(zathura_t* zathura, unsigned int page_index);
/**
* Checks if the given page is cached
*
* @param zathura The zathura session
* @param page_index The index of the page that may be cached
*
* @return true if page is cached otherwise false
*/
bool zathura_page_cache_is_cached(zathura_t* zathura, unsigned int page_index);
#endif // ZATHURA_H #endif // ZATHURA_H