Skip to content

Commit e76a18d

Browse files
Piiitclefebvre
authored andcommitted
Fixes "Having selected text leads to high cpu load" (#140)
Fixes #70 This patch is based on: https://git.gnome.org/browse/evince/commit/?id=1987f04ea36329b1bd61d053a19d9e341e0454ce author Sebastian Keller <sebastian-keller@gmx.de> 2015-09-22 21:25:34 (GMT) libview: Save/restore context when getting colors for a different state Getting colors for a state different from the current state of the corresponding widget without saving the context might trigger an invalidation and a redraw. Because this was happening from the draw function this resulted in a redraw loop and constant high CPU usage. This could be triggered by selecting text or searching. https://bugzilla.gnome.org/show_bug.cgi?id=755442
1 parent a185d0a commit e76a18d

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

libdocument/ev-document-misc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ ev_document_misc_paint_one_page (cairo_t *cr,
144144
GtkStateFlags state = gtk_widget_get_state_flags (widget);
145145
GdkRGBA fg, bg, shade_bg;
146146

147+
gtk_style_context_save (context);
147148
gtk_style_context_get_background_color (context, state, &bg);
148149
gtk_style_context_get_color (context, state, &fg);
149150
gtk_style_context_get_color (context, state, &shade_bg);
151+
gtk_style_context_restore (context);
150152
shade_bg.alpha *= 0.5;
151153

152154
gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);

libview/ev-pixbuf-cache.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ get_selection_colors (GtkWidget *widget, GdkColor *text, GdkColor *base)
633633

634634
state |= gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE;
635635

636+
gtk_style_context_save (context);
637+
636638
gtk_style_context_get_color (context, state, &fg);
637639
text->pixel = 0;
638640
text->red = CLAMP ((guint) (fg.red * 65535), 0, 65535);
@@ -644,6 +646,8 @@ get_selection_colors (GtkWidget *widget, GdkColor *text, GdkColor *base)
644646
base->red = CLAMP ((guint) (bg.red * 65535), 0, 65535);
645647
base->green = CLAMP ((guint) (bg.green * 65535), 0, 65535);
646648
base->blue = CLAMP ((guint) (bg.blue * 65535), 0, 65535);
649+
650+
gtk_style_context_restore (context);
647651
}
648652

649653
static void

libview/ev-view.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4284,7 +4284,9 @@ draw_rubberband (EvView *view,
42844284
GdkRGBA color;
42854285

42864286
context = gtk_widget_get_style_context (GTK_WIDGET (view));
4287+
gtk_style_context_save (context);
42874288
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color);
4289+
gtk_style_context_restore (context);
42884290

42894291
cairo_save (cr);
42904292
cairo_set_source_rgba (cr, color.red, color.green, color.blue, alpha);

0 commit comments

Comments
 (0)