]> www.fi.muni.cz Git - evince.git/commitdiff
Add page_ready signal to notify that page is ready as soon as possible
authorCarlos Garcia Campos <carlosgc@gnome.org>
Thu, 26 Jul 2007 17:19:49 +0000 (17:19 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Thu, 26 Jul 2007 17:19:49 +0000 (17:19 +0000)
2007-07-26  Carlos Garcia Campos  <carlosgc@gnome.org>
* shell/ev-pixbuf-cache.c: (job_page_ready_cb), (job_finished_cb),
(copy_job_page_and_selection_to_job_info), (copy_job_to_job_info),
(add_job), (ev_pixbuf_cache_get_surface),
(ev_pixbuf_cache_get_link_mapping),
(ev_pixbuf_cache_get_image_mapping),
(ev_pixbuf_cache_get_form_field_mapping),
(ev_pixbuf_cache_get_text_mapping):
* shell/ev-jobs.[ch]: (ev_job_render_class_init),
(notify_page_ready), (ev_job_render_page_ready),
(ev_job_render_run):
Add page_ready signal to notify that page is ready as soon as
possible even if other page elements like links, forms, images or
text mapping are not ready yet.

svn path=/trunk/; revision=2581

ChangeLog
shell/ev-jobs.c
shell/ev-jobs.h
shell/ev-pixbuf-cache.c

index 648b16add603d865c8df06c690e2762723891b3b..1869dd0b49dd8e47aa1a34112b9ac912b3d6ab99 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-07-26  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-pixbuf-cache.c: (job_page_ready_cb), (job_finished_cb),
+       (copy_job_page_and_selection_to_job_info), (copy_job_to_job_info),
+       (add_job), (ev_pixbuf_cache_get_surface),
+       (ev_pixbuf_cache_get_link_mapping),
+       (ev_pixbuf_cache_get_image_mapping),
+       (ev_pixbuf_cache_get_form_field_mapping),
+       (ev_pixbuf_cache_get_text_mapping):
+       * shell/ev-jobs.[ch]: (ev_job_render_class_init),
+       (notify_page_ready), (ev_job_render_page_ready),
+       (ev_job_render_run):
+
+       Add page_ready signal to notify that page is ready as soon as
+       possible even if other page elements like links, forms, images or
+       text mapping are not ready yet.
+       
 2007-07-26  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/dvi-document.c: (dvi_document_file_exporter_begin),
index d61185c0c90b07851cd33cd7d51458c7a2081461..d5d45f2206670703ee4cde012e875bb4f88df439 100644 (file)
@@ -32,13 +32,18 @@ static void ev_job_load_class_init  (EvJobLoadClass      *class);
 static void ev_job_print_init           (EvJobPrint          *job);
 static void ev_job_print_class_init     (EvJobPrintClass     *class);
 
-enum
-{
+enum {
        FINISHED,
        LAST_SIGNAL
 };
 
+enum {
+       PAGE_READY,
+       RENDER_LAST_SIGNAL
+};
+
 static guint job_signals[LAST_SIGNAL] = { 0 };
+static guint job_render_signals[RENDER_LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (EvJob, ev_job, G_TYPE_OBJECT)
 G_DEFINE_TYPE (EvJobLinks, ev_job_links, EV_TYPE_JOB)
@@ -152,6 +157,15 @@ ev_job_render_class_init (EvJobRenderClass *class)
 
        oclass = G_OBJECT_CLASS (class);
 
+       job_render_signals [PAGE_READY] =
+               g_signal_new ("page-ready",
+                             EV_TYPE_JOB_RENDER,
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (EvJobRenderClass, page_ready),
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
        oclass->dispose = ev_job_render_dispose;
 }
 
@@ -316,6 +330,21 @@ render_finished_cb (EvDocument      *document,
        ev_job_finished (EV_JOB (job));
 }
 
+static gboolean
+notify_page_ready (EvJobRender *job)
+{
+       g_signal_emit (job, job_render_signals[PAGE_READY], 0);
+
+       return FALSE;
+}
+
+static void
+ev_job_render_page_ready (EvJobRender *job)
+{
+       job->page_ready = TRUE;
+       g_idle_add ((GSourceFunc)notify_page_ready, job);
+}
+
 void
 ev_job_render_run (EvJobRender *job)
 {
@@ -333,23 +362,6 @@ ev_job_render_run (EvJobRender *job)
                ev_document_fc_mutex_lock ();
                
                job->surface = ev_document_render (EV_JOB (job)->document, job->rc);
-
-               if (job->include_links && EV_IS_DOCUMENT_LINKS (EV_JOB (job)->document))
-                       job->link_mapping =
-                               ev_document_links_get_links (EV_DOCUMENT_LINKS (EV_JOB (job)->document),
-                                                            job->rc->page);
-               if (job->include_images && EV_IS_DOCUMENT_IMAGES (EV_JOB (job)->document))
-                       job->image_mapping =
-                               ev_document_images_get_images (EV_DOCUMENT_IMAGES (EV_JOB (job)->document),
-                                                              job->rc->page);
-               if (job->include_forms && EV_IS_DOCUMENT_FORMS (EV_JOB (job)->document))
-                       job->form_field_mapping =
-                               ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (EV_JOB(job)->document),
-                                                                  job->rc->page);
-               if (job->include_text && EV_IS_SELECTION (EV_JOB (job)->document))
-                       job->text_mapping =
-                               ev_selection_get_selection_map (EV_SELECTION (EV_JOB (job)->document),
-                                                               job->rc);
                if (job->include_selection && EV_IS_SELECTION (EV_JOB (job)->document)) {
                        ev_selection_render_selection (EV_SELECTION (EV_JOB (job)->document),
                                                       job->rc,
@@ -362,8 +374,27 @@ ev_job_render_run (EvJobRender *job)
                                                                   job->rc,
                                                                   &(job->selection_points));
                }
+
+               ev_job_render_page_ready (job);
                
                ev_document_fc_mutex_unlock ();
+               
+               if (job->include_text && EV_IS_SELECTION (EV_JOB (job)->document))
+                       job->text_mapping =
+                               ev_selection_get_selection_map (EV_SELECTION (EV_JOB (job)->document),
+                                                               job->rc);
+               if (job->include_links && EV_IS_DOCUMENT_LINKS (EV_JOB (job)->document))
+                       job->link_mapping =
+                               ev_document_links_get_links (EV_DOCUMENT_LINKS (EV_JOB (job)->document),
+                                                            job->rc->page);
+               if (job->include_forms && EV_IS_DOCUMENT_FORMS (EV_JOB (job)->document))
+                       job->form_field_mapping =
+                               ev_document_forms_get_form_fields (EV_DOCUMENT_FORMS (EV_JOB(job)->document),
+                                                                  job->rc->page);
+               if (job->include_images && EV_IS_DOCUMENT_IMAGES (EV_JOB (job)->document))
+                       job->image_mapping =
+                               ev_document_images_get_images (EV_DOCUMENT_IMAGES (EV_JOB (job)->document),
+                                                              job->rc->page);
                EV_JOB (job)->finished = TRUE;
        }
 
index 052319898c7c0223eb755f214252b616a332dc69..c0a4036fe9e49570f0d239ed84b3b656089ed9e7 100644 (file)
@@ -119,6 +119,7 @@ struct _EvJobRender
        EvJob parent;
 
        EvRenderContext *rc;
+       gboolean page_ready;
        gint target_width;
        gint target_height;
        cairo_surface_t *surface;
@@ -144,6 +145,8 @@ struct _EvJobRender
 struct _EvJobRenderClass
 {
        EvJobClass parent_class;
+
+       void    (* page_ready) (EvJobRender *job);
 };
 
 struct _EvJobThumbnail
index 4516f75df71f94755d212a1b7b3aa5d37ce77031..951decb26ceacb005cbe7294f073bb2f7d405462 100644 (file)
@@ -11,6 +11,7 @@ typedef struct _CacheJobInfo
 {
        EvJob *job;
        EvRenderContext *rc;
+       gboolean page_ready;
 
        /* Region of the page that needs to be drawn */
        GdkRegion *region; 
@@ -73,6 +74,8 @@ static void          ev_pixbuf_cache_init       (EvPixbufCache      *pixbuf_cach
 static void          ev_pixbuf_cache_class_init (EvPixbufCacheClass *pixbuf_cache);
 static void          ev_pixbuf_cache_finalize   (GObject            *object);
 static void          ev_pixbuf_cache_dispose    (GObject            *object);
+static void          job_page_ready_cb          (EvJob              *job,
+                                                EvPixbufCache      *pixbuf_cache);
 static void          job_finished_cb            (EvJob              *job,
                                                 EvPixbufCache      *pixbuf_cache);
 static CacheJobInfo *find_job_cache             (EvPixbufCache      *pixbuf_cache,
@@ -80,6 +83,9 @@ static CacheJobInfo *find_job_cache             (EvPixbufCache      *pixbuf_cach
 static void          copy_job_to_job_info       (EvJobRender        *job_render,
                                                 CacheJobInfo       *job_info,
                                                 EvPixbufCache      *pixbuf_cache);
+static void          copy_job_page_and_selection_to_job_info (EvJobRender        *job_render,
+                                                             CacheJobInfo       *job_info,
+                                                             EvPixbufCache      *pixbuf_cache);
 static gboolean      new_selection_surface_needed(EvPixbufCache      *pixbuf_cache,
                                                  CacheJobInfo       *job_info,
                                                  gint                page,
@@ -150,6 +156,9 @@ dispose_cache_job_info (CacheJobInfo *job_info,
        if (job_info == NULL)
                return;
        if (job_info->job) {
+               g_signal_handlers_disconnect_by_func (job_info->job,
+                                                     G_CALLBACK (job_page_ready_cb),
+                                                     data);
                g_signal_handlers_disconnect_by_func (job_info->job,
                                                      G_CALLBACK (job_finished_cb),
                                                      data);
@@ -232,6 +241,26 @@ ev_pixbuf_cache_new (GtkWidget  *view,
        return pixbuf_cache;
 }
 
+static void
+job_page_ready_cb (EvJob         *job,
+                  EvPixbufCache *pixbuf_cache)
+{
+       CacheJobInfo *job_info;
+       EvJobRender *job_render = EV_JOB_RENDER (job);
+
+       /* If the job is outside of our interest, we silently discard it */
+       if ((job_render->rc->page < (pixbuf_cache->start_page - pixbuf_cache->preload_cache_size)) ||
+           (job_render->rc->page > (pixbuf_cache->end_page + pixbuf_cache->preload_cache_size))) {
+               g_object_unref (job);
+               return;
+       }
+
+       job_info = find_job_cache (pixbuf_cache, job_render->rc->page);
+
+       copy_job_page_and_selection_to_job_info (job_render, job_info, pixbuf_cache);
+       g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
+}
+
 static void
 job_finished_cb (EvJob         *job,
                 EvPixbufCache *pixbuf_cache)
@@ -245,11 +274,9 @@ job_finished_cb (EvJob         *job,
                g_object_unref (job);
                return;
        }
-       
-       job_info = find_job_cache (pixbuf_cache, job_render->rc->page);
 
+       job_info = find_job_cache (pixbuf_cache, job_render->rc->page);
        copy_job_to_job_info (job_render, job_info, pixbuf_cache);
-       g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
 }
 
 /* This checks a job to see if the job would generate the right sized pixbuf
@@ -419,13 +446,10 @@ ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
 }
 
 static void
-copy_job_to_job_info (EvJobRender   *job_render,
-                     CacheJobInfo  *job_info,
-                     EvPixbufCache *pixbuf_cache)
+copy_job_page_and_selection_to_job_info (EvJobRender   *job_render,
+                                        CacheJobInfo  *job_info,
+                                        EvPixbufCache *pixbuf_cache)
 {
-
-       job_info->points_set = FALSE;
-
        if (job_info->surface) {
                cairo_surface_destroy (job_info->surface);
        }
@@ -436,6 +460,38 @@ copy_job_to_job_info (EvJobRender   *job_render,
        }
        job_info->rc = g_object_ref (job_render->rc);
 
+       job_info->points_set = FALSE;
+       if (job_render->include_selection) {
+               if (job_info->selection) {
+                       cairo_surface_destroy (job_info->selection);
+                       job_info->selection = NULL;
+               }
+               if (job_info->selection_region) {
+                       gdk_region_destroy (job_info->selection_region);
+                       job_info->selection_region = NULL;
+               }
+               
+               job_info->selection_points = job_render->selection_points;
+               job_info->selection_region = gdk_region_copy (job_render->selection_region);
+               job_info->selection = cairo_surface_reference (job_render->selection);
+               g_assert (job_info->selection_points.x1 >= 0);
+               job_info->points_set = TRUE;
+       }
+
+       if (job_info->job) {
+               g_signal_handlers_disconnect_by_func (job_info->job,
+                                                     G_CALLBACK (job_page_ready_cb),
+                                                     pixbuf_cache);
+       }
+
+       job_info->page_ready = TRUE;
+}
+
+static void
+copy_job_to_job_info (EvJobRender   *job_render,
+                     CacheJobInfo  *job_info,
+                     EvPixbufCache *pixbuf_cache)
+{
        if (job_render->include_links) {
                if (job_info->link_mapping)
                        ev_link_mapping_free (job_info->link_mapping);
@@ -460,23 +516,6 @@ copy_job_to_job_info (EvJobRender   *job_render,
                job_info->text_mapping = job_render->text_mapping;
        }
 
-       if (job_render->include_selection) {
-               if (job_info->selection) {
-                       cairo_surface_destroy (job_info->selection);
-                       job_info->selection = NULL;
-               }
-               if (job_info->selection_region) {
-                       gdk_region_destroy (job_info->selection_region);
-                       job_info->selection_region = NULL;
-               }
-               
-               job_info->selection_points = job_render->selection_points;
-               job_info->selection_region = gdk_region_copy (job_render->selection_region);
-               job_info->selection = cairo_surface_reference (job_render->selection);
-               g_assert (job_info->selection_points.x1 >= 0);
-               job_info->points_set = TRUE;
-       }
-
        if (job_info->job) {
                g_signal_handlers_disconnect_by_func (job_info->job,
                                                      G_CALLBACK (job_finished_cb),
@@ -571,6 +610,8 @@ add_job (EvPixbufCache *pixbuf_cache,
        gboolean include_images = TRUE;
        gboolean include_forms = FALSE;
        GdkColor *text, *base;
+
+       job_info->page_ready = FALSE;
        
        if (job_info->rc == NULL) {
                job_info->rc = ev_render_context_new (rotation, page, scale);
@@ -612,7 +653,10 @@ add_job (EvPixbufCache *pixbuf_cache,
                                           include_text,
                                           include_selection);
        ev_job_queue_add_job (job_info->job, priority);
-       g_signal_connect (job_info->job, "finished",
+       g_signal_connect (G_OBJECT (job_info->job), "page-ready",
+                         G_CALLBACK (job_page_ready_cb),
+                         pixbuf_cache);
+       g_signal_connect (G_OBJECT (job_info->job), "finished",
                          G_CALLBACK (job_finished_cb),
                          pixbuf_cache);
 }
@@ -729,10 +773,13 @@ ev_pixbuf_cache_get_surface (EvPixbufCache *pixbuf_cache,
        if (job_info == NULL)
                return NULL;
 
+       if (job_info->page_ready)
+               return job_info->surface;
+       
        /* 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);
+           EV_JOB_RENDER (job_info->job)->page_ready) {
+               copy_job_page_and_selection_to_job_info (EV_JOB_RENDER (job_info->job), job_info, pixbuf_cache);
                g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
        }
 
@@ -753,7 +800,6 @@ ev_pixbuf_cache_get_link_mapping (EvPixbufCache *pixbuf_cache,
        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);
-               g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
        }
 
        return job_info->link_mapping;
@@ -776,7 +822,6 @@ ev_pixbuf_cache_get_image_mapping (EvPixbufCache *pixbuf_cache,
        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);
-               g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
        }
 
        return job_info->image_mapping;
@@ -799,7 +844,6 @@ ev_pixbuf_cache_get_form_field_mapping (EvPixbufCache *pixbuf_cache,
        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);
-               g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
        }
        
        return job_info->form_field_mapping;
@@ -863,7 +907,6 @@ ev_pixbuf_cache_get_text_mapping (EvPixbufCache *pixbuf_cache,
        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);
-               g_signal_emit (pixbuf_cache, signals[JOB_FINISHED], 0, job_info->region);
        }
        
        return job_info->text_mapping;