From fdf0bd56495fce0bc9bcd49d026df40b67f94226 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 22:59:59 +0200 Subject: [PATCH] Save surface temporary in page_t --- document.c | 1 + document.h | 1 + render.c | 27 ++++++++++++++++----------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/document.c b/document.c index 8802593..6525711 100644 --- a/document.c +++ b/document.c @@ -386,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->rendered = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); + page->surface = NULL; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); diff --git a/document.h b/document.h index 2536958..56a3e90 100644 --- a/document.h +++ b/document.h @@ -150,6 +150,7 @@ struct zathura_page_s GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ + cairo_surface_t* surface; /** Cairo surface */ }; /** diff --git a/render.c b/render.c index 967f7b9..3be9558 100644 --- a/render.c +++ b/render.c @@ -176,10 +176,7 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ - cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); - cairo_set_source_surface(cairo, surface, 0, 0); - cairo_paint(cairo); - cairo_destroy(cairo); + page->surface = surface; zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); @@ -209,22 +206,30 @@ gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { zathura_page_t* page = data; + if (page == NULL) { + return FALSE; + } + g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); if (cairo == NULL) { - girara_error("Could not create blank page"); + girara_error("Could not retreive cairo object"); g_static_mutex_unlock(&(page->lock)); - return false; + return FALSE; } - cairo_set_source_rgb(cairo, 0, 0, 0); - cairo_rectangle(cairo, 0, 0, page->width, page->height); - cairo_fill(cairo); - cairo_destroy(cairo); + if (page->surface == NULL) { + cairo_set_source_surface(cairo, page->surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + + cairo_surface_destroy(page->surface); + page->surface = NULL; + } g_static_mutex_unlock(&(page->lock)); - return true; + return TRUE; }