summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntia Puentes <[email protected]>2013-06-28 12:55:59 +0200
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commit99936ea8e6c0857835a2283ac992716b92598bfa (patch)
tree8ef823502798cc6115789dad1cb2646c4e3567f8
parent24f9aab02d59b31114ee26b490a586501b35b986 (diff)
downloadatril-99936ea8e6c0857835a2283ac992716b92598bfa.tar.bz2
atril-99936ea8e6c0857835a2283ac992716b92598bfa.tar.xz
libview: Pre-cache some prev/next pages to the current page range.
https://bugzilla.gnome.org/show_bug.cgi?id=702767 origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=ac3800a
-rw-r--r--libview/ev-page-cache.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/libview/ev-page-cache.c b/libview/ev-page-cache.c
index 4deef21f..d24382b1 100644
--- a/libview/ev-page-cache.c
+++ b/libview/ev-page-cache.c
@@ -74,6 +74,7 @@ struct _EvPageCacheClass {
EV_PAGE_DATA_INCLUDE_FORMS | \
EV_PAGE_DATA_INCLUDE_ANNOTS)
+#define PRE_CACHE_SIZE 1
static void job_page_data_finished_cb (EvJob *job,
EvPageCache *cache);
@@ -303,41 +304,66 @@ job_page_data_cancelled_cb (EvJob *job,
data->job = NULL;
}
+static void
+ev_page_cache_schedule_job_if_needed (EvPageCache *cache,
+ gint page)
+{
+ EvPageCacheData *data = &cache->page_list[page];
+ EvJobPageDataFlags flags;
+
+ if (data->flags == cache->flags && !data->dirty && (data->done || data->job))
+ return;
+
+ if (data->job)
+ ev_job_cancel (data->job);
+
+ flags = ev_page_cache_get_flags_for_data (cache, data);
+
+ data->flags = cache->flags;
+ data->job = ev_job_page_data_new (cache->document, page, flags);
+ g_signal_connect (data->job, "finished",
+ G_CALLBACK (job_page_data_finished_cb),
+ cache);
+ g_signal_connect (data->job, "cancelled",
+ G_CALLBACK (job_page_data_cancelled_cb),
+ data);
+ ev_job_scheduler_push_job (data->job, EV_JOB_PRIORITY_NONE);
+
+}
+
void
ev_page_cache_set_page_range (EvPageCache *cache,
gint start,
gint end)
{
gint i;
+ gint pages_to_pre_cache;
if (cache->flags == EV_PAGE_DATA_INCLUDE_NONE)
return;
+ for (i = start; i <= end; i++)
+ ev_page_cache_schedule_job_if_needed (cache, i);
+
cache->start_page = start;
cache->end_page = end;
- for (i = start; i <= end; i++) {
- EvPageCacheData *data = &cache->page_list[i];
- EvJobPageDataFlags flags;
-
- if (data->flags == cache->flags && !data->dirty && (data->done || data->job))
- continue;
-
- if (data->job)
- ev_job_cancel (data->job);
-
- flags = ev_page_cache_get_flags_for_data (cache, data);
-
- data->flags = cache->flags;
- data->job = ev_job_page_data_new (cache->document, i, flags);
- g_signal_connect (data->job, "finished",
- G_CALLBACK (job_page_data_finished_cb),
- cache);
- g_signal_connect (data->job, "cancelled",
- G_CALLBACK (job_page_data_cancelled_cb),
- data);
- ev_job_scheduler_push_job (data->job, EV_JOB_PRIORITY_NONE);
- }
+ i = 1;
+ pages_to_pre_cache = PRE_CACHE_SIZE * 2;
+ while ((start - i > 0) || (end + i < cache->n_pages)) {
+ if (end + i < cache->n_pages) {
+ ev_page_cache_schedule_job_if_needed (cache, end + i);
+ if (--pages_to_pre_cache == 0)
+ break;
+ }
+
+ if (start - i > 0) {
+ ev_page_cache_schedule_job_if_needed (cache, start - i);
+ if (--pages_to_pre_cache == 0)
+ break;
+ }
+ i++;
+ }
}
EvJobPageDataFlags