]> www.fi.muni.cz Git - evince.git/blobdiff - libview/ev-pixbuf-cache.c
[libview] Move get_dual_even_left from EvPageCache to EvView
[evince.git] / libview / ev-pixbuf-cache.c
index d7d89f70d9d3f5b6f9dce47dd6f2b35532934072..763ec047365d271698b62bc13ddeb325ce2d2779 100644 (file)
@@ -2,11 +2,10 @@
 #include "ev-pixbuf-cache.h"
 #include "ev-job-scheduler.h"
 #include "ev-page-cache.h"
-#include "ev-document-images.h"
+#include "ev-mapping.h"
 #include "ev-document-forms.h"
-#include "ev-document-links.h"
-#include "ev-image.h"
-#include "ev-form-field.h"
+#include "ev-document-images.h"
+#include "ev-document-annotations.h"
 
 typedef struct _CacheJobInfo
 {
@@ -22,6 +21,7 @@ typedef struct _CacheJobInfo
        GList *link_mapping;
        GList *image_mapping;
        GList *form_field_mapping;
+       GList *annots_mapping;
        GdkRegion *text_mapping;
        
        /* Selection data. 
@@ -97,8 +97,8 @@ static gboolean      new_selection_surface_needed(EvPixbufCache      *pixbuf_cac
 /* These are used for iterating through the prev and next arrays */
 #define FIRST_VISIBLE_PREV(pixbuf_cache) \
        (MAX (0, pixbuf_cache->preload_cache_size - pixbuf_cache->start_page))
-#define VISIBLE_NEXT_LEN(pixbuf_cache, page_cache) \
-       (MIN(pixbuf_cache->preload_cache_size, ev_page_cache_get_n_pages (page_cache) - (1 + pixbuf_cache->end_page)))
+#define VISIBLE_NEXT_LEN(pixbuf_cache) \
+       (MIN(pixbuf_cache->preload_cache_size, ev_document_get_n_pages (pixbuf_cache->document) - (1 + pixbuf_cache->end_page)))
 #define PAGE_CACHE_LEN(pixbuf_cache) \
        ((pixbuf_cache->end_page - pixbuf_cache->start_page) + 1)
 
@@ -177,17 +177,21 @@ dispose_cache_job_info (CacheJobInfo *job_info,
                job_info->region = NULL;
        }
        if (job_info->link_mapping) {
-               ev_link_mapping_free (job_info->link_mapping);
+               ev_mapping_list_free (job_info->link_mapping, g_object_unref);
                job_info->link_mapping = NULL;
        }
        if (job_info->image_mapping) {
-               ev_image_mapping_free (job_info->image_mapping);
+               ev_mapping_list_free (job_info->image_mapping, g_object_unref);
                job_info->image_mapping = NULL;
        }
        if (job_info->form_field_mapping) {
-               ev_form_field_mapping_free (job_info->form_field_mapping);
+               ev_mapping_list_free (job_info->form_field_mapping, g_object_unref);
                job_info->form_field_mapping = NULL;
        }
+       if (job_info->annots_mapping) {
+               ev_mapping_list_free (job_info->annots_mapping, g_object_unref);
+               job_info->annots_mapping = NULL;
+       }
        if (job_info->text_mapping) {
                gdk_region_destroy (job_info->text_mapping);
                job_info->text_mapping = NULL;
@@ -373,6 +377,7 @@ move_one_job (CacheJobInfo  *job_info,
        job_info->link_mapping = NULL;
        job_info->image_mapping = NULL;
        job_info->form_field_mapping = NULL;
+       job_info->annots_mapping = NULL;
 
        if (new_priority != priority && target_page->job) {
                ev_job_scheduler_update_job (target_page->job, new_priority);
@@ -387,15 +392,12 @@ ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
        CacheJobInfo *new_job_list;
        CacheJobInfo *new_prev_job;
        CacheJobInfo *new_next_job;
-       EvPageCache *page_cache;
        int i, page;
 
        if (pixbuf_cache->start_page == start_page &&
            pixbuf_cache->end_page == end_page)
                return;
 
-       page_cache = ev_page_cache_get (pixbuf_cache->document);
-
        new_job_list = g_new0 (CacheJobInfo, (end_page - start_page) + 1);
        new_prev_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
        new_next_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
@@ -427,7 +429,7 @@ ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
        }
 
        for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
-               if (page >= ev_page_cache_get_n_pages (page_cache)) {
+               if (page >= ev_document_get_n_pages (pixbuf_cache->document)) {
                        dispose_cache_job_info (pixbuf_cache->next_job + i, pixbuf_cache);
                } else {
                        move_one_job (pixbuf_cache->next_job + i,
@@ -511,22 +513,28 @@ copy_job_to_job_info (EvJobRender   *job_render,
        
        if (job_render->flags & EV_RENDER_INCLUDE_LINKS) {
                if (job_info->link_mapping)
-                       ev_link_mapping_free (job_info->link_mapping);
+                       ev_mapping_list_free (job_info->link_mapping, g_object_unref);
                job_info->link_mapping = job_render->link_mapping;
        }
 
        if (job_render->flags & EV_RENDER_INCLUDE_IMAGES) {
                if (job_info->image_mapping)
-                       ev_image_mapping_free (job_info->image_mapping);
+                       ev_mapping_list_free (job_info->image_mapping, g_object_unref);
                job_info->image_mapping = job_render->image_mapping;
        }
 
        if (job_render->flags & EV_RENDER_INCLUDE_FORMS) {
                if (job_info->form_field_mapping)
-                       ev_form_field_mapping_free (job_info->form_field_mapping);
+                       ev_mapping_list_free (job_info->form_field_mapping, g_object_unref);
                job_info->form_field_mapping = job_render->form_field_mapping;
        }
 
+       if (job_render->flags & EV_RENDER_INCLUDE_ANNOTS) {
+               if (job_info->annots_mapping)
+                       ev_mapping_list_free (job_info->annots_mapping, g_object_unref);
+               job_info->annots_mapping = job_render->annots_mapping;
+       }
+
        if (job_render->flags & EV_RENDER_INCLUDE_TEXT) {
                if (job_info->text_mapping)
                        gdk_region_destroy (job_info->text_mapping);
@@ -609,7 +617,6 @@ get_selection_colors (GtkWidget *widget, GdkColor **text, GdkColor **base)
 static void
 add_job (EvPixbufCache *pixbuf_cache,
         CacheJobInfo  *job_info,
-        EvPageCache   *page_cache,
         GdkRegion     *region,
         gint           width,
         gint           height,
@@ -633,6 +640,8 @@ add_job (EvPixbufCache *pixbuf_cache,
                flags |= EV_RENDER_INCLUDE_IMAGES;
        if (job_info->form_field_mapping == NULL)
                flags |= EV_RENDER_INCLUDE_FORMS;
+       if (job_info->annots_mapping == NULL)
+               flags |= EV_RENDER_INCLUDE_ANNOTS;
        if (job_info->text_mapping == NULL)
                flags |= EV_RENDER_INCLUDE_TEXT;
 
@@ -683,7 +692,7 @@ add_job_if_needed (EvPixbufCache *pixbuf_cache,
            cairo_image_surface_get_height (job_info->surface) == height)
                return;
 
-       add_job (pixbuf_cache, job_info, page_cache, NULL,
+       add_job (pixbuf_cache, job_info, NULL,
                 width, height, page, rotation, scale,
                 priority);
 }
@@ -718,7 +727,7 @@ ev_pixbuf_cache_add_jobs_if_needed (EvPixbufCache *pixbuf_cache,
                                   EV_JOB_PRIORITY_LOW);
        }
 
-       for (i = 0; i < VISIBLE_NEXT_LEN(pixbuf_cache, page_cache); i++) {
+       for (i = 0; i < VISIBLE_NEXT_LEN(pixbuf_cache); i++) {
                job_info = (pixbuf_cache->next_job + i);
                page = pixbuf_cache->end_page + 1 + i;
 
@@ -737,14 +746,10 @@ ev_pixbuf_cache_set_page_range (EvPixbufCache  *pixbuf_cache,
                                gfloat          scale,
                                GList          *selection_list)
 {
-       EvPageCache *page_cache;
-
        g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
 
-       page_cache = ev_page_cache_get (pixbuf_cache->document);
-
-       g_return_if_fail (start_page >= 0 && start_page < ev_page_cache_get_n_pages (page_cache));
-       g_return_if_fail (end_page >= 0 && end_page < ev_page_cache_get_n_pages (page_cache));
+       g_return_if_fail (start_page >= 0 && start_page < ev_document_get_n_pages (pixbuf_cache->document));
+       g_return_if_fail (end_page >= 0 && end_page < ev_document_get_n_pages (pixbuf_cache->document));
        g_return_if_fail (end_page >= start_page);
 
        /* First, resize the page_range as needed.  We cull old pages
@@ -849,6 +854,28 @@ ev_pixbuf_cache_get_form_field_mapping (EvPixbufCache *pixbuf_cache,
        return job_info->form_field_mapping;
 }
 
+GList *
+ev_pixbuf_cache_get_annots_mapping (EvPixbufCache *pixbuf_cache,
+                                   gint           page)
+{
+       CacheJobInfo *job_info;
+
+       if (!EV_IS_DOCUMENT_ANNOTATIONS (pixbuf_cache->document))
+               return NULL;
+
+       job_info = find_job_cache (pixbuf_cache, page);
+       if (job_info == NULL)
+               return NULL;
+
+       /* We don't need to wait for the idle to handle the callback */
+       if (job_info->job &&
+          EV_JOB (job_info->job)->finished) {
+               copy_job_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
+       }
+
+       return job_info->annots_mapping;
+}
+
 static gboolean
 new_selection_surface_needed (EvPixbufCache *pixbuf_cache,
                              CacheJobInfo  *job_info,
@@ -1078,7 +1105,6 @@ void
 ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
                                    GList         *selection_list)
 {
-       EvPageCache *page_cache;
        EvViewSelection *selection;
        GList *list = selection_list;
        int page;
@@ -1089,8 +1115,6 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
        if (!EV_IS_SELECTION (pixbuf_cache->document))
                return;
 
-       page_cache = ev_page_cache_get (pixbuf_cache->document);
-
        /* We check each area to see what needs updating, and what needs freeing; */
        page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
        for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
@@ -1136,7 +1160,7 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
        }
 
        for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
-               if (page >= ev_page_cache_get_n_pages (page_cache))
+               if (page >= ev_document_get_n_pages (pixbuf_cache->document))
                        break;
 
                selection = NULL;
@@ -1163,7 +1187,6 @@ ev_pixbuf_cache_set_selection_list (EvPixbufCache *pixbuf_cache,
 GList *
 ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
 {
-       EvPageCache *page_cache;
        EvViewSelection *selection;
        GList *retval = NULL;
        int page;
@@ -1171,8 +1194,6 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
 
        g_return_val_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache), NULL);
 
-       page_cache = ev_page_cache_get (pixbuf_cache->document);
-
        /* We check each area to see what needs updating, and what needs freeing; */
        page = pixbuf_cache->start_page - pixbuf_cache->preload_cache_size;
        for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
@@ -1208,7 +1229,7 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
        }
 
        for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
-               if (page >= ev_page_cache_get_n_pages (page_cache))
+               if (page >= ev_document_get_n_pages (pixbuf_cache->document))
                        break;
 
                if (pixbuf_cache->next_job[i].selection_points.x1 != -1) {
@@ -1226,7 +1247,7 @@ ev_pixbuf_cache_get_selection_list (EvPixbufCache *pixbuf_cache)
        return retval;
 }
 
-void           
+void
 ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
                             GdkRegion     *region,
                             gint           page,
@@ -1234,18 +1255,17 @@ ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
                             gdouble        scale)
 {
        CacheJobInfo *job_info;
-        EvPageCache *page_cache;
         gint width, height;
 
        job_info = find_job_cache (pixbuf_cache, page);
        if (job_info == NULL)
                return;
-       
-        page_cache = ev_page_cache_get (pixbuf_cache->document);
-       ev_page_cache_get_size (page_cache, page, rotation, scale,
+
+       ev_page_cache_get_size (ev_page_cache_get (pixbuf_cache->document),
+                               page, rotation, scale,
                                &width, &height);
 
-        add_job (pixbuf_cache, job_info, page_cache, region,
+        add_job (pixbuf_cache, job_info, region,
                 width, height, page, rotation, scale,
                 EV_JOB_PRIORITY_URGENT);
 }