[gnome-photos] image-view, preview-view: Remove overhead when drawing the background



commit b81579f161ddf6e35c0455c790e6f0dcdb171f9a
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Oct 11 15:56:51 2018 +0200

    image-view, preview-view: Remove overhead when drawing the background
    
    The draw-background originated in gegl-gtk. Any use of a signal implies
    taking a global lock in glib/gobject/gsignal.c, which is better avoided
    in code paths aiming to achieve 60 frames per second.
    
    (Emitting a signal is even worse than just checking if there's a
    pending handler. It involves marshalling the arguments through GValue
    and a lot of extra code over and above taking the lock. Just avoiding
    that much yields visible performance improvements. [1,2,3])
    
    Therefore, it's better to get rid of it, and have ImageView draw its
    own background. It's also more idiomatic in GTK+ 3.x.
    
    [1] https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153
    [2] https://gitlab.gnome.org/GNOME/gtk/commit/cdd951e927ad3793
    [3] https://gitlab.gnome.org/GNOME/gtk/commit/68e50d20a7f765b3

 src/photos-image-view.c   | 28 ++++++++++++----------------
 src/photos-preview-view.c | 21 ---------------------
 2 files changed, 12 insertions(+), 37 deletions(-)
---
diff --git a/src/photos-image-view.c b/src/photos-image-view.c
index 5fc72291..dade2a24 100644
--- a/src/photos-image-view.c
+++ b/src/photos-image-view.c
@@ -77,7 +77,6 @@ enum
 
 enum
 {
-  DRAW_BACKGROUND,
   DRAW_OVERLAY,
   LAST_SIGNAL
 };
@@ -608,6 +607,10 @@ photos_image_view_draw (GtkWidget *widget, cairo_t *cr)
 {
   PhotosImageView *self = PHOTOS_IMAGE_VIEW (widget);
   GdkRectangle rect;
+  GtkStateFlags flags;
+  GtkStyleContext *context;
+  gint height;
+  gint width;
 
   if (self->node == NULL)
     goto out;
@@ -615,9 +618,14 @@ photos_image_view_draw (GtkWidget *widget, cairo_t *cr)
   if (!gdk_cairo_get_clip_rectangle (cr, &rect))
     goto out;
 
-  cairo_save (cr);
-  g_signal_emit (self, signals[DRAW_BACKGROUND], 0, cr, &rect);
-  cairo_restore(cr);
+  context = gtk_widget_get_style_context (widget);
+  flags = gtk_widget_get_state_flags (widget);
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, flags);
+  height = gtk_widget_get_allocated_height (widget);
+  width = gtk_widget_get_allocated_width (widget);
+  gtk_render_background (context, cr, 0, 0, width, height);
+  gtk_style_context_restore (context);
 
   cairo_save (cr);
   photos_image_view_draw_node (self, cr, &rect);
@@ -995,18 +1003,6 @@ photos_image_view_class_init (PhotosImageViewClass *class)
                                                         1.0,
                                                         G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE));
 
-  signals[DRAW_BACKGROUND] = g_signal_new ("draw-background",
-                                           G_TYPE_FROM_CLASS (class),
-                                           G_SIGNAL_RUN_LAST,
-                                           0,
-                                           NULL, /* accumulator */
-                                           NULL, /* accu_data */
-                                           _photos_marshal_VOID__BOXED_BOXED,
-                                           G_TYPE_NONE,
-                                           2,
-                                           CAIRO_GOBJECT_TYPE_CONTEXT,
-                                           GDK_TYPE_RECTANGLE);
-
   signals[DRAW_OVERLAY] = g_signal_new ("draw-overlay",
                                         G_TYPE_FROM_CLASS (class),
                                         G_SIGNAL_RUN_LAST,
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 117e81a2..b169746f 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -220,26 +220,6 @@ photos_preview_view_button_release_event (GtkWidget *widget, GdkEvent *event, gp
 }
 
 
-static void
-photos_preview_view_draw_background (PhotosPreviewView *self, cairo_t *cr, GdkRectangle *rect, gpointer 
user_data)
-{
-  GtkStyleContext *context;
-  GtkStateFlags flags;
-  GtkWidget *view = GTK_WIDGET (user_data);
-  gint height;
-  gint width;
-
-  context = gtk_widget_get_style_context (view);
-  flags = gtk_widget_get_state_flags (view);
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, flags);
-  height = gtk_widget_get_allocated_height (view);
-  width = gtk_widget_get_allocated_width (view);
-  gtk_render_background (context, cr, 0, 0, width, height);
-  gtk_style_context_restore (context);
-}
-
-
 static void
 photos_preview_view_draw_overlay (PhotosPreviewView *self, cairo_t *cr, GdkRectangle *rect, gpointer 
user_data)
 {
@@ -520,7 +500,6 @@ photos_preview_view_create_view_with_container (PhotosPreviewView *self)
   gtk_container_add (GTK_CONTAINER (sw), view);
   g_signal_connect (view, "button-press-event", G_CALLBACK (photos_preview_view_button_press_event), self);
   g_signal_connect (view, "button-release-event", G_CALLBACK (photos_preview_view_button_release_event), 
self);
-  g_signal_connect_swapped (view, "draw-background", G_CALLBACK (photos_preview_view_draw_background), self);
   g_signal_connect_swapped (view, "draw-overlay", G_CALLBACK (photos_preview_view_draw_overlay), self);
   g_signal_connect (view, "motion-notify-event", G_CALLBACK (photos_preview_view_motion_notify_event), self);
   g_signal_connect (view, "notify::best-fit", G_CALLBACK (photos_preview_view_notify_best_fit), self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]