From b5237680f28d585fecf1c6d23bc7ec044e623ae1 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 27 Jul 2013 16:25:20 +0200 Subject: [PATCH] Don't store surface for invisible and uncached pages Signed-off-by: Sebastian Ramacher --- callbacks.c | 6 ++++++ page-widget.c | 20 +++++++++++++++++--- page-widget.h | 8 ++++++++ zathura.c | 5 ++--- zathura.h | 10 ++++++++++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/callbacks.c b/callbacks.c index 0d9a549..1c49df0 100644 --- a/callbacks.c +++ b/callbacks.c @@ -106,6 +106,12 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi } } else { 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; g_object_get(page_widget, "search-results", &results, NULL); diff --git a/page-widget.c b/page-widget.c index 75694a6..adf69da 100644 --- a/page-widget.c +++ b/page-widget.c @@ -506,11 +506,16 @@ zathura_page_widget_update_surface(ZathuraPage* widget, cairo_surface_t* surface mutex_lock(&(priv->lock)); if (priv->surface != NULL) { cairo_surface_destroy(priv->surface); + priv->surface = NULL; } priv->render_requested = false; - priv->surface = surface; - if (priv->surface != NULL) { - cairo_surface_reference(surface); + if (surface != NULL) { + /* if we're not visible or not cached, we don't care about the 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)); /* force a redraw here */ @@ -876,3 +881,12 @@ zathura_page_widget_update_view_time(ZathuraPage* widget) 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; +} + diff --git a/page-widget.h b/page-widget.h index 5609e78..b9a1c38 100644 --- a/page-widget.h +++ b/page-widget.h @@ -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); +/** + * 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 diff --git a/zathura.c b/zathura.c index 4bf53a6..5506c2c 100644 --- a/zathura.c +++ b/zathura.c @@ -54,7 +54,6 @@ typedef struct position_set_delayed_s { } position_set_delayed_t; 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 void zathura_page_cache_invalidate_all(zathura_t* zathura); 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) { 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); - if (zathura_page_cache_is_cached(zathura, page_index)) { + if (zathura_page_cache_is_cached(zathura, page_index) == true) { return; } diff --git a/zathura.h b/zathura.h index cafbc34..13df384 100644 --- a/zathura.h +++ b/zathura.h @@ -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); +/** + * 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