[gtk+/wip/simple-draw4: 11/20] GtkWindow: Move cairo_save/restore from marshaller



commit 5fc83197dd6755e5f5ce07a48fc3b092142e1606
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Apr 25 14:00:18 2013 +0200

    GtkWindow: Move cairo_save/restore from marshaller
    
    We do the save/restore when emitting ::draw rather than in a custom
    marshaller, as this saves an extra stack frame, which is helpfull now
    that we do painting fully recursive. This is also likely to save a few
    cycles.

 gtk/gtkwidget.c |   70 ++++++------------------------------------------------
 1 files changed, 8 insertions(+), 62 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index a8498ed..5a84fa5 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -956,64 +956,6 @@ child_property_notify_dispatcher (GObject     *object,
   GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
 }
 
-/* We guard against the draw signal callbacks modifying the state of the
- * cairo context by surounding it with save/restore.
- * Maybe we should also cairo_new_path() just to be sure?
- */
-static void
-gtk_widget_draw_marshaller (GClosure     *closure,
-                            GValue       *return_value,
-                            guint         n_param_values,
-                            const GValue *param_values,
-                            gpointer      invocation_hint,
-                            gpointer      marshal_data)
-{
-  cairo_t *cr = g_value_get_boxed (&param_values[1]);
-
-  cairo_save (cr);
-
-  _gtk_marshal_BOOLEAN__BOXED (closure,
-                               return_value,
-                               n_param_values,
-                               param_values,
-                               invocation_hint,
-                               marshal_data);
-
-
-  cairo_restore (cr);
-}
-
-static void
-gtk_widget_draw_marshallerv (GClosure     *closure,
-                            GValue       *return_value,
-                            gpointer      instance,
-                            va_list       args,
-                            gpointer      marshal_data,
-                            int           n_params,
-                            GType        *param_types)
-{
-  cairo_t *cr;
-  va_list args_copy;
-
-  G_VA_COPY (args_copy, args);
-  cr = va_arg (args_copy, gpointer);
-
-  cairo_save (cr);
-
-  _gtk_marshal_BOOLEAN__BOXEDv (closure,
-                               return_value,
-                               instance,
-                               args,
-                               marshal_data,
-                               n_params,
-                               param_types);
-
-
-  cairo_restore (cr);
-
-  va_end (args_copy);
-}
-
 static void
 gtk_widget_class_init (GtkWidgetClass *klass)
 {
@@ -1949,12 +1891,12 @@ gtk_widget_class_init (GtkWidgetClass *klass)
                   G_TYPE_FROM_CLASS (gobject_class),
                   G_SIGNAL_RUN_LAST,
                   G_STRUCT_OFFSET (GtkWidgetClass, draw),
-                   _gtk_boolean_handled_accumulator, NULL,
-                   gtk_widget_draw_marshaller,
+                  _gtk_boolean_handled_accumulator, NULL,
+                 _gtk_marshal_BOOLEAN__BOXED,
                   G_TYPE_BOOLEAN, 1,
-                  CAIRO_GOBJECT_TYPE_CONTEXT);
+                  CAIRO_GOBJECT_TYPE_CONTEXT | G_SIGNAL_TYPE_STATIC_SCOPE);
   g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
-                              gtk_widget_draw_marshallerv);
+                             _gtk_marshal_BOOLEAN__BOXEDv);
 
   /**
    * GtkWidget::mnemonic-activate:
@@ -6380,10 +6322,14 @@ _gtk_widget_draw_internal (GtkWidget *widget,
     {
       gboolean result;
 
+      cairo_save (cr);
+
       g_signal_emit (widget, widget_signals[DRAW],
                      0, cr,
                      &result);
 
+      cairo_restore (cr);
+
 #ifdef G_ENABLE_DEBUG
       if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_BASELINES))
        {


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