From 8271419222dfbc8ab8890bca2316485480f60794 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 1 Jun 2012 20:56:55 +0200 Subject: [PATCH] Render pages for printing in render thread. This needs some looking in the render thread. --- page-widget.c | 2 +- print.c | 2 +- render.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ render.h | 4 +++- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/page-widget.c b/page-widget.c index d52e14d..34c903e 100644 --- a/page-widget.c +++ b/page-widget.c @@ -452,7 +452,7 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) } /* render real page */ - render_page(priv->zathura->sync.render_thread, priv->page); + render_page(priv->zathura->sync.render_thread, priv->page, false, NULL); } g_static_mutex_unlock(&(priv->lock)); return FALSE; diff --git a/print.c b/print.c index 247352b..35d5e16 100644 --- a/print.c +++ b/print.c @@ -93,5 +93,5 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* return; } - zathura_page_render(page, cairo, true); + render_page(zathura->sync.render_thread, page, true, cairo); } diff --git a/render.c b/render.c index a709f64..ed93b6e 100644 --- a/render.c +++ b/render.c @@ -22,17 +22,38 @@ struct render_thread_s GThreadPool* pool; /**< Pool of threads */ }; +typedef struct job_s +{ + zathura_page_t* page; + bool printing; + cairo_t* target; + GMutex* mutex; + GCond* cond; +} job_t; + static void render_job(void* data, void* user_data) { - zathura_page_t* page = data; + job_t* job = data; zathura_t* zathura = user_data; - if (page == NULL || zathura == NULL) { + if (job == NULL || zathura == NULL || job->page == NULL) { return; } - if (render(zathura, page) != true) { - girara_error("Rendering failed (page %d)\n", zathura_page_get_index(page)); + if (job->printing == false) { + girara_debug("Rendering page %d", zathura_page_get_index(job->page)); + if (render(zathura, job->page) != true) { + girara_error("Rendering failed (page %d)\n", zathura_page_get_index(job->page)); + } + g_free(data); + } else if (job->target != NULL) { + girara_debug("Rendering page %d for printing", zathura_page_get_index(job->page)); + g_mutex_lock(job->mutex); + if (zathura_page_render(job->page, job->target, true) != ZATHURA_ERROR_OK) { + girara_error("Rendering failed (page %d)\n", zathura_page_get_index(job->page)); + } + g_cond_signal(job->cond); + g_mutex_unlock(job->mutex); } } @@ -72,13 +93,30 @@ render_free(render_thread_t* render_thread) } bool -render_page(render_thread_t* render_thread, zathura_page_t* page) +render_page(render_thread_t* render_thread, zathura_page_t* page, bool printing, cairo_t* target) { if (render_thread == NULL || page == NULL || render_thread->pool == NULL) { return false; } - g_thread_pool_push(render_thread->pool, page, NULL); + job_t* job = g_malloc0(sizeof(job_t)); + job->page = page; + job->printing = printing; + job->target = target; + if (printing == true) { + job->mutex = g_mutex_new(); + job->cond = g_cond_new(); + g_mutex_lock(job->mutex); + } + g_thread_pool_push(render_thread->pool, job, NULL); + if (printing == true) { + g_cond_wait(job->cond, job->mutex); + g_mutex_unlock(job->mutex); + g_cond_free(job->cond); + g_mutex_free(job->mutex); + g_free(job); + } + return true; } diff --git a/render.h b/render.h index 435ef83..901b6ce 100644 --- a/render.h +++ b/render.h @@ -31,9 +31,11 @@ void render_free(render_thread_t* render_thread); * * @param render_thread The render thread object * @param page The page that should be rendered + * @param printing Render the page for printing. + * @param target Rendering target in case we're rendering for printing. * @return true if no error occured */ -bool render_page(render_thread_t* render_thread, zathura_page_t* page); +bool render_page(render_thread_t* render_thread, zathura_page_t* page, bool printing, cairo_t* target); /** * This function is used to unmark all pages as not rendered. This should