#include <config.h>
#include "ev-pixbuf-cache.h"
#include "ev-job-scheduler.h"
-#include "ev-mapping.h"
-#include "ev-document-forms.h"
-#include "ev-document-images.h"
-#include "ev-document-annotations.h"
#include "ev-view-private.h"
typedef struct _CacheJobInfo
gboolean page_ready;
/* Region of the page that needs to be drawn */
- GdkRegion *region;
+ cairo_region_t *region;
/* Data we get from rendering */
cairo_surface_t *surface;
gboolean points_set;
cairo_surface_t *selection;
- GdkRegion *selection_region;
+ cairo_region_t *selection_region;
} CacheJobInfo;
struct _EvPixbufCache
* case of twin pages.
*/
int preload_cache_size;
+ guint job_list_len;
+
CacheJobInfo *prev_job;
CacheJobInfo *job_list;
CacheJobInfo *next_job;
pixbuf_cache = EV_PIXBUF_CACHE (object);
- g_free (pixbuf_cache->prev_job);
- g_free (pixbuf_cache->job_list);
- g_free (pixbuf_cache->next_job);
+ if (pixbuf_cache->job_list) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->job_list_len,
+ pixbuf_cache->job_list);
+ pixbuf_cache->job_list = NULL;
+ }
+ if (pixbuf_cache->prev_job) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->preload_cache_size,
+ pixbuf_cache->prev_job);
+ pixbuf_cache->prev_job = NULL;
+ }
+ if (pixbuf_cache->next_job) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->preload_cache_size,
+ pixbuf_cache->next_job);
+ pixbuf_cache->next_job = NULL;
+ }
g_object_unref (pixbuf_cache->model);
job_info->surface = NULL;
}
if (job_info->region) {
- gdk_region_destroy (job_info->region);
+ cairo_region_destroy (job_info->region);
job_info->region = NULL;
}
if (job_info->selection) {
job_info->selection = NULL;
}
if (job_info->selection_region) {
- gdk_region_destroy (job_info->selection_region);
+ cairo_region_destroy (job_info->selection_region);
job_info->selection_region = NULL;
}
job_info->selection = NULL;
}
if (job_info->selection_region) {
- gdk_region_destroy (job_info->selection_region);
+ cairo_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_region = cairo_region_reference (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;
static void
ev_pixbuf_cache_update_range (EvPixbufCache *pixbuf_cache,
gint start_page,
- gint end_page)
+ gint end_page,
+ guint rotation,
+ gdouble scale)
{
CacheJobInfo *new_job_list;
CacheJobInfo *new_prev_job = NULL;
CacheJobInfo *new_next_job = NULL;
gint new_preload_cache_size;
+ guint new_job_list_len;
int i, page;
- gdouble scale = ev_document_model_get_scale (pixbuf_cache->model);
- gint rotation = ev_document_model_get_rotation (pixbuf_cache->model);
new_preload_cache_size = ev_pixbuf_cache_get_preload_size (pixbuf_cache,
start_page,
pixbuf_cache->preload_cache_size == new_preload_cache_size)
return;
- new_job_list = g_new0 (CacheJobInfo, (end_page - start_page) + 1);
+ new_job_list_len = (end_page - start_page) + 1;
+ new_job_list = g_slice_alloc0 (sizeof (CacheJobInfo) * new_job_list_len);
if (new_preload_cache_size > 0) {
- new_prev_job = g_new0 (CacheJobInfo, new_preload_cache_size);
- new_next_job = g_new0 (CacheJobInfo, new_preload_cache_size);
+ new_prev_job = g_slice_alloc0 (sizeof (CacheJobInfo) * new_preload_cache_size);
+ new_next_job = g_slice_alloc0 (sizeof (CacheJobInfo) * new_preload_cache_size);
}
/* We go through each job in the old cache and either clear it or move
page ++;
}
- g_free (pixbuf_cache->job_list);
- g_free (pixbuf_cache->prev_job);
- g_free (pixbuf_cache->next_job);
+ if (pixbuf_cache->job_list) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->job_list_len,
+ pixbuf_cache->job_list);
+ }
+ if (pixbuf_cache->prev_job) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->preload_cache_size,
+ pixbuf_cache->prev_job);
+ }
+ if (pixbuf_cache->next_job) {
+ g_slice_free1 (sizeof (CacheJobInfo) * pixbuf_cache->preload_cache_size,
+ pixbuf_cache->next_job);
+ }
pixbuf_cache->preload_cache_size = new_preload_cache_size;
+ pixbuf_cache->job_list_len = new_job_list_len;
pixbuf_cache->job_list = new_job_list;
pixbuf_cache->prev_job = new_prev_job;
}
static void
-get_selection_colors (GtkWidget *widget, GdkColor **text, GdkColor **base)
+get_selection_colors (GtkWidget *widget, GdkColor *text, GdkColor *base)
{
- GtkStyle *style = gtk_widget_get_style (widget);
-
- if (gtk_widget_has_focus (widget)) {
- *text = &style->text [GTK_STATE_SELECTED];
- *base = &style->base [GTK_STATE_SELECTED];
- } else {
- *text = &style->text [GTK_STATE_ACTIVE];
- *base = &style->base [GTK_STATE_ACTIVE];
- }
+ GtkStyleContext *context = gtk_widget_get_style_context (widget);
+ GtkStateFlags state = 0;
+ GdkRGBA fg, bg;
+
+ state |= gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE;
+
+ gtk_style_context_get_color (context, state, &fg);
+ text->pixel = 0;
+ text->red = CLAMP ((guint) (fg.red * 65535), 0, 65535);
+ text->green = CLAMP ((guint) (fg.green * 65535), 0, 65535);
+ text->blue = CLAMP ((guint) (fg.blue * 65535), 0, 65535);
+
+ gtk_style_context_get_background_color (context, state, &bg);
+ base->pixel = 0;
+ base->red = CLAMP ((guint) (bg.red * 65535), 0, 65535);
+ base->green = CLAMP ((guint) (bg.green * 65535), 0, 65535);
+ base->blue = CLAMP ((guint) (bg.blue * 65535), 0, 65535);
}
static void
-add_job (EvPixbufCache *pixbuf_cache,
- CacheJobInfo *job_info,
- GdkRegion *region,
- gint width,
- gint height,
- gint page,
- gint rotation,
- gfloat scale,
- EvJobPriority priority)
+add_job (EvPixbufCache *pixbuf_cache,
+ CacheJobInfo *job_info,
+ cairo_region_t *region,
+ gint width,
+ gint height,
+ gint page,
+ gint rotation,
+ gfloat scale,
+ EvJobPriority priority)
{
job_info->page_ready = FALSE;
if (job_info->region)
- gdk_region_destroy (job_info->region);
- job_info->region = region ? gdk_region_copy (region) : NULL;
+ cairo_region_destroy (job_info->region);
+ job_info->region = region ? cairo_region_reference (region) : NULL;
job_info->job = ev_job_render_new (pixbuf_cache->document,
page, rotation, scale,
width, height);
if (new_selection_surface_needed (pixbuf_cache, job_info, page, scale)) {
- GdkColor *text, *base;
+ GdkColor text, base;
- gtk_widget_ensure_style (pixbuf_cache->view);
get_selection_colors (pixbuf_cache->view, &text, &base);
ev_job_render_set_selection_info (EV_JOB_RENDER (job_info->job),
&(job_info->target_points),
job_info->selection_style,
- text, base);
+ &text, &base);
}
g_signal_connect (job_info->job, "finished",
ev_pixbuf_cache_set_page_range (EvPixbufCache *pixbuf_cache,
gint start_page,
gint end_page,
- gint rotation,
- gfloat scale,
GList *selection_list)
{
+ gdouble scale = ev_document_model_get_scale (pixbuf_cache->model);
+ gint rotation = ev_document_model_get_rotation (pixbuf_cache->model);
+
g_return_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache));
g_return_if_fail (start_page >= 0 && start_page < ev_document_get_n_pages (pixbuf_cache->document));
/* First, resize the page_range as needed. We cull old pages
* mercilessly. */
- ev_pixbuf_cache_update_range (pixbuf_cache, start_page, end_page);
+ ev_pixbuf_cache_update_range (pixbuf_cache, start_page, end_page, rotation, scale);
/* Then, we update the current jobs to see if any of them are the wrong
* size, we remove them if we need to. */
CacheJobInfo *job_info;
job_info = pixbuf_cache->prev_job + i;
- if (job_info->surface)
+ if (job_info && job_info->surface)
ev_document_misc_invert_surface (job_info->surface);
job_info = pixbuf_cache->next_job + i;
- if (job_info->surface)
+ if (job_info && job_info->surface)
ev_document_misc_invert_surface (job_info->surface);
}
CacheJobInfo *job_info;
job_info = pixbuf_cache->job_list + i;
- if (job_info->surface)
+ if (job_info && job_info->surface)
ev_document_misc_invert_surface (job_info->surface);
}
}
{
int i;
+ if (!pixbuf_cache->job_list)
+ return;
+
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
dispose_cache_job_info (pixbuf_cache->prev_job + i, pixbuf_cache);
dispose_cache_job_info (pixbuf_cache->next_job + i, pixbuf_cache);
{
gint i;
+ if (!pixbuf_cache->job_list)
+ return;
+
/* FIXME: doesn't update running jobs. */
for (i = 0; i < pixbuf_cache->preload_cache_size; i++) {
CacheJobInfo *job_info;
}
cairo_surface_t *
-ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
- gint page,
- gfloat scale,
- GdkRegion **region)
+ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
+ gint page,
+ gfloat scale,
+ cairo_region_t **region)
{
CacheJobInfo *job_info;
*/
if (ev_rect_cmp (&(job_info->target_points), &(job_info->selection_points))) {
EvRectangle *old_points;
- GdkColor *text, *base;
+ GdkColor text, base;
EvRenderContext *rc;
EvPage *ev_page;
g_object_unref (ev_page);
if (job_info->selection_region)
- gdk_region_destroy (job_info->selection_region);
+ cairo_region_destroy (job_info->selection_region);
job_info->selection_region =
ev_selection_get_selection_region (EV_SELECTION (pixbuf_cache->document),
rc, job_info->selection_style,
&(job_info->target_points));
- gtk_widget_ensure_style (pixbuf_cache->view);
-
get_selection_colors (pixbuf_cache->view, &text, &base);
ev_selection_render_selection (EV_SELECTION (pixbuf_cache->document),
&(job_info->target_points),
old_points,
job_info->selection_style,
- text, base);
+ &text, &base);
job_info->selection_points = job_info->target_points;
g_object_unref (rc);
ev_document_doc_mutex_unlock ();
if (!EV_IS_SELECTION (pixbuf_cache->document))
return;
+ if (pixbuf_cache->start_page == -1 || pixbuf_cache->end_page == -1)
+ return;
+
/* 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++) {
g_return_val_if_fail (EV_IS_PIXBUF_CACHE (pixbuf_cache), NULL);
+ if (pixbuf_cache->start_page == -1 || pixbuf_cache->end_page == -1)
+ return NULL;
+
/* 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++) {
selection->page = page;
selection->rect = pixbuf_cache->prev_job[i].selection_points;
if (pixbuf_cache->prev_job[i].selection_region)
- selection->covered_region = gdk_region_copy (pixbuf_cache->prev_job[i].selection_region);
+ selection->covered_region = cairo_region_reference (pixbuf_cache->prev_job[i].selection_region);
retval = g_list_append (retval, selection);
}
selection->page = page;
selection->rect = pixbuf_cache->job_list[i].selection_points;
if (pixbuf_cache->job_list[i].selection_region)
- selection->covered_region = gdk_region_copy (pixbuf_cache->job_list[i].selection_region);
+ selection->covered_region = cairo_region_reference (pixbuf_cache->job_list[i].selection_region);
retval = g_list_append (retval, selection);
}
selection->page = page;
selection->rect = pixbuf_cache->next_job[i].selection_points;
if (pixbuf_cache->next_job[i].selection_region)
- selection->covered_region = gdk_region_copy (pixbuf_cache->next_job[i].selection_region);
+ selection->covered_region = cairo_region_reference (pixbuf_cache->next_job[i].selection_region);
retval = g_list_append (retval, selection);
}
}
void
-ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
- GdkRegion *region,
- gint page,
- gint rotation,
- gdouble scale)
+ev_pixbuf_cache_reload_page (EvPixbufCache *pixbuf_cache,
+ cairo_region_t *region,
+ gint page,
+ gint rotation,
+ gdouble scale)
{
CacheJobInfo *job_info;
gint width, height;