Skip to content
Permalink
Browse files

EogScrollView: Implement simple two-pass filtering

Show the filtered image only after a short time.
This should improve the UI's responsiveness quite a bit.

https://bugzilla.gnome.org/show_bug.cgi?id=665897

origin commit:
https://gitlab.gnome.org/GNOME/eog/commit/88c4f54
https://gitlab.gnome.org/GNOME/eog/commit/8169e0a
  • Loading branch information...
Felix Riemann authored and raveit65 committed Feb 15, 2016
1 parent 7f38bf6 commit 7eec54c388ac5f628514c4d60bcf0c4661955dfe
Showing with 65 additions and 4 deletions.
  1. +65 −4 src/eom-scroll-view.c
@@ -148,6 +148,10 @@ struct _EomScrollViewPrivate {
GdkRGBA *override_bg_color;

cairo_surface_t *background_surface;

/* Two-pass filtering */
GSource *hq_redraw_timeout_source;
gboolean force_unfiltered;
};

static void scroll_by (EomScrollView *view, int xofs, int yofs);
@@ -1183,6 +1187,45 @@ eom_scroll_view_focus_out_event (GtkWidget *widget,
return FALSE;
}

static gboolean _hq_redraw_cb (gpointer user_data)
{
EomScrollViewPrivate *priv = EOM_SCROLL_VIEW (user_data)->priv;

priv->force_unfiltered = FALSE;
gtk_widget_queue_draw (GTK_WIDGET (priv->display));

priv->hq_redraw_timeout_source = NULL;
return G_SOURCE_REMOVE;
}

static void
_clear_hq_redraw_timeout (EomScrollView *view)
{
EomScrollViewPrivate *priv = view->priv;

if (priv->hq_redraw_timeout_source != NULL) {
g_source_unref (priv->hq_redraw_timeout_source);
g_source_destroy (priv->hq_redraw_timeout_source);
}

priv->hq_redraw_timeout_source = NULL;
}

static void
_set_hq_redraw_timeout (EomScrollView *view)
{
GSource *source;

_clear_hq_redraw_timeout (view);

source = g_timeout_source_new (200);
g_source_set_callback (source, &_hq_redraw_cb, view, NULL);

g_source_attach (source, NULL);

view->priv->hq_redraw_timeout_source = source;
}

static gboolean
display_draw (GtkWidget *widget, cairo_t *cr, gpointer data)
{
@@ -1308,13 +1351,29 @@ display_draw (GtkWidget *widget, cairo_t *cr, gpointer data)
} else
#endif /* HAVE_RSVG */
{
cairo_filter_t interp_type;

if(!DOUBLE_EQUAL(priv->zoom, 1.0) && priv->force_unfiltered)
{
interp_type = CAIRO_FILTER_NEAREST;
_set_hq_redraw_timeout(view);
}
else
{
if (is_zoomed_in (view))
interp_type = priv->interp_type_in;
else
interp_type = priv->interp_type_out;

_clear_hq_redraw_timeout (view);
priv->force_unfiltered = TRUE;
}
cairo_scale (cr, priv->zoom, priv->zoom);
cairo_set_source_surface (cr, priv->surface, xofs/priv->zoom, yofs/priv->zoom);
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
if (is_zoomed_in (view))
cairo_pattern_set_filter (cairo_get_source (cr), priv->interp_type_in);
else if (is_zoomed_out (view))
cairo_pattern_set_filter (cairo_get_source (cr), priv->interp_type_out);
if (is_zoomed_in (view) || is_zoomed_out (view))
cairo_pattern_set_filter (cairo_get_source (cr), interp_type);

cairo_paint (cr);
}

@@ -1880,6 +1939,8 @@ eom_scroll_view_dispose (GObject *object)
view = EOM_SCROLL_VIEW (object);
priv = view->priv;

_clear_hq_redraw_timeout (view);

if (priv->idle_id != 0) {
g_source_remove (priv->idle_id);
priv->idle_id = 0;

0 comments on commit 7eec54c

Please sign in to comment.
You can’t perform that action at this time.