summaryrefslogtreecommitdiff
path: root/libview/ev-pixbuf-cache.c
diff options
context:
space:
mode:
authorJason Crain <[email protected]>2013-06-15 10:43:08 -0500
committerraveit65 <[email protected]>2017-09-06 18:25:34 +0200
commitd758271a60f8d081d1a0701b48d68981dcad9804 (patch)
tree69fad9b6afab351b7a7dbf358cec0226be8e5c12 /libview/ev-pixbuf-cache.c
parentb062ae0ca9eeb927a111a92bb9d41f3a77630f71 (diff)
downloadatril-d758271a60f8d081d1a0701b48d68981dcad9804.tar.bz2
atril-d758271a60f8d081d1a0701b48d68981dcad9804.tar.xz
libview: Draw selection highlight from region
Allows a fallback for backends which can implement get_selection_region but not render_selection. Changes ev-pixbuf-cache so a redraw is only done when the scale changes. https://bugzilla.gnome.org/show_bug.cgi?id=669022 origin commit: https://git.gnome.org/browse/evince/commit/?h=gnome-3-10&id=9e89fb1
Diffstat (limited to 'libview/ev-pixbuf-cache.c')
-rw-r--r--libview/ev-pixbuf-cache.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/libview/ev-pixbuf-cache.c b/libview/ev-pixbuf-cache.c
index 506d1316..4c890030 100644
--- a/libview/ev-pixbuf-cache.c
+++ b/libview/ev-pixbuf-cache.c
@@ -27,6 +27,7 @@ typedef struct _CacheJobInfo
cairo_surface_t *selection;
cairo_region_t *selection_region;
+ gdouble selection_scale;
} CacheJobInfo;
struct _EvPixbufCache
@@ -287,6 +288,7 @@ copy_job_to_job_info (EvJobRender *job_render,
job_info->selection_points = job_render->selection_points;
job_info->selection_region = cairo_region_reference (job_render->selection_region);
job_info->selection = cairo_surface_reference (job_render->selection);
+ job_info->selection_scale = job_render->scale;
set_device_scale_on_surface (job_info->selection, job_info->device_scale);
g_assert (job_info->selection_points.x1 >= 0);
job_info->points_set = TRUE;
@@ -632,21 +634,17 @@ ev_pixbuf_cache_clear_job_sizes (EvPixbufCache *pixbuf_cache,
}
static void
-get_selection_colors (GtkWidget *widget, GdkColor *text, GdkColor *base)
+get_selection_colors (EvView *view, GdkColor *text, GdkColor *base)
{
- GtkStyleContext *context = gtk_widget_get_style_context (widget);
- GtkStateFlags state = 0;
- GdkRGBA fg, bg;
+ GdkRGBA fg, bg;
- state |= gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE;
+ _ev_view_get_selection_colors (view, &bg, &fg);
- 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);
@@ -679,7 +677,8 @@ add_job (EvPixbufCache *pixbuf_cache,
if (new_selection_surface_needed (pixbuf_cache, job_info, page, scale)) {
GdkColor text, base;
- get_selection_colors (pixbuf_cache->view, &text, &base);
+
+ get_selection_colors (EV_VIEW (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,
@@ -864,24 +863,8 @@ new_selection_surface_needed (EvPixbufCache *pixbuf_cache,
gint page,
gfloat scale)
{
- if (job_info->selection) {
- gint width, height;
- gint selection_width, selection_height;
-
- _get_page_size_for_scale_and_rotation (pixbuf_cache->document,
- page, scale, 0,
- &width, &height);
-
- selection_width = cairo_image_surface_get_width (job_info->selection);
- selection_height = cairo_image_surface_get_height (job_info->selection);
-
- if (width != selection_width || height != selection_height)
- return TRUE;
- } else {
- if (job_info->points_set)
- return TRUE;
- }
-
+ if (job_info->selection || job_info->points_set)
+ return job_info->selection_scale != scale;
return FALSE;
}
@@ -936,12 +919,14 @@ ev_pixbuf_cache_style_changed (EvPixbufCache *pixbuf_cache)
if (job_info->selection) {
cairo_surface_destroy (job_info->selection);
job_info->selection = NULL;
+ job_info->selection_points.x1 = -1;
}
job_info = pixbuf_cache->next_job + i;
if (job_info->selection) {
cairo_surface_destroy (job_info->selection);
job_info->selection = NULL;
+ job_info->selection_points.x1 = -1;
}
}
@@ -952,6 +937,7 @@ ev_pixbuf_cache_style_changed (EvPixbufCache *pixbuf_cache)
if (job_info->selection) {
cairo_surface_destroy (job_info->selection);
job_info->selection = NULL;
+ job_info->selection_points.x1 = -1;
}
}
}
@@ -979,8 +965,11 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
/* If we have a running job, we just return what we have under the
* assumption that it'll be updated later and we can scale it as need
* be */
- if (job_info->job && EV_JOB_RENDER (job_info->job)->include_selection)
+ if (job_info->job && EV_JOB_RENDER (job_info->job)->include_selection) {
+ if (region)
+ *region = job_info->selection_region;
return job_info->selection;
+ }
/* Now, lets see if we need to resize the image. If we do, we clear the
* old one. */
@@ -1003,7 +992,6 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
g_assert (job_info->selection == NULL);
old_points = NULL;
} else {
- g_assert (job_info->selection != NULL);
old_points = &(job_info->selection_points);
}
@@ -1018,7 +1006,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
rc, job_info->selection_style,
&(job_info->target_points));
- get_selection_colors (pixbuf_cache->view, &text, &base);
+ get_selection_colors (EV_VIEW (pixbuf_cache->view), &text, &base);
ev_selection_render_selection (EV_SELECTION (pixbuf_cache->document),
rc, &(job_info->selection),
@@ -1028,6 +1016,7 @@ ev_pixbuf_cache_get_selection_surface (EvPixbufCache *pixbuf_cache,
&text, &base);
set_device_scale_on_surface (job_info->selection, job_info->device_scale);
job_info->selection_points = job_info->target_points;
+ job_info->selection_scale = scale;
g_object_unref (rc);
ev_document_doc_mutex_unlock ();
}