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)
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;
}
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)
{
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,
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;
}
{
EvJob *job;
EvRenderContext *rc;
+ gboolean page_ready;
/* Region of the page that needs to be drawn */
GdkRegion *region;
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,
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,
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);
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)
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
}
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);
}
}
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);
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),
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);
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);
}
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);
}
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;
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;
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;
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;