[gtk+] container: Avoid duplicate calls to should_propagate



commit a768798f2b520b3a385b51f704f76b30020d617a
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 28 22:45:11 2015 -0400

    container: Avoid duplicate calls to should_propagate
    
    We were calling gtk_container_should_propagate_draw
    twice for each child. We can avoid this by splitting
    out an gtk_container_propagate_draw_internal function.

 gtk/gtkcontainer.c |   89 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index c0614f5..af1c741 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -378,6 +378,9 @@ static void    gtk_container_buildable_custom_finished (GtkBuildable *buildable,
 static gboolean gtk_container_should_propagate_draw (GtkContainer   *container,
                                                      GtkWidget      *child,
                                                      cairo_t        *cr);
+static void gtk_container_propagate_draw_internal (GtkContainer *container,
+                                                   GtkWidget    *child,
+                                                   cairo_t      *cr);
 
 /* --- variables --- */
 static GQuark                vadjustment_key_id;
@@ -3660,8 +3663,7 @@ gtk_container_draw (GtkWidget *widget,
   for (i = 0; i < child_infos->len; i++)
     {
       child_info = &g_array_index (child_infos, ChildOrderInfo, i);
-      gtk_container_propagate_draw (container,
-                                    child_info->child, cr);
+      gtk_container_propagate_draw_internal (container, child_info->child, cr);
     }
 
   g_array_free (child_infos, TRUE);
@@ -3744,49 +3746,15 @@ gtk_container_should_propagate_draw (GtkContainer   *container,
   return TRUE;
 }
 
-
-/**
- * gtk_container_propagate_draw:
- * @container: a #GtkContainer
- * @child: a child of @container
- * @cr: Cairo context as passed to the container. If you want to use @cr
- *   in container’s draw function, consider using cairo_save() and
- *   cairo_restore() before calling this function.
- *
- * When a container receives a call to the draw function, it must send
- * synthetic #GtkWidget::draw calls to all children that don’t have their
- * own #GdkWindows. This function provides a convenient way of doing this.
- * A container, when it receives a call to its #GtkWidget::draw function,
- * calls gtk_container_propagate_draw() once for each child, passing in
- * the @cr the container received.
- *
- * gtk_container_propagate_draw() takes care of translating the origin of @cr,
- * and deciding whether the draw needs to be sent to the child. It is a
- * convenient and optimized way of getting the same effect as calling
- * gtk_widget_draw() on the child directly.
- *
- * In most cases, a container can simply either inherit the
- * #GtkWidget::draw implementation from #GtkContainer, or do some drawing
- * and then chain to the ::draw implementation from #GtkContainer.
- **/
-void
-gtk_container_propagate_draw (GtkContainer   *container,
-                              GtkWidget      *child,
-                              cairo_t        *cr)
+static void
+gtk_container_propagate_draw_internal (GtkContainer *container,
+                                       GtkWidget    *child,
+                                       cairo_t      *cr)
 {
   GtkAllocation allocation;
   GdkWindow *window, *w;
   int x, y;
 
-  g_return_if_fail (GTK_IS_CONTAINER (container));
-  g_return_if_fail (GTK_IS_WIDGET (child));
-  g_return_if_fail (cr != NULL);
-
-  g_assert (_gtk_widget_get_parent (child) == GTK_WIDGET (container));
-
-  if (!gtk_container_should_propagate_draw (container, child, cr))
-    return;
-
   /* translate coordinates. Ugly business, that. */
   if (!_gtk_widget_get_has_window (GTK_WIDGET (container)))
     {
@@ -3831,6 +3799,47 @@ gtk_container_propagate_draw (GtkContainer   *container,
   cairo_restore (cr);
 }
 
+/**
+ * gtk_container_propagate_draw:
+ * @container: a #GtkContainer
+ * @child: a child of @container
+ * @cr: Cairo context as passed to the container. If you want to use @cr
+ *   in container’s draw function, consider using cairo_save() and
+ *   cairo_restore() before calling this function.
+ *
+ * When a container receives a call to the draw function, it must send
+ * synthetic #GtkWidget::draw calls to all children that don’t have their
+ * own #GdkWindows. This function provides a convenient way of doing this.
+ * A container, when it receives a call to its #GtkWidget::draw function,
+ * calls gtk_container_propagate_draw() once for each child, passing in
+ * the @cr the container received.
+ *
+ * gtk_container_propagate_draw() takes care of translating the origin of @cr,
+ * and deciding whether the draw needs to be sent to the child. It is a
+ * convenient and optimized way of getting the same effect as calling
+ * gtk_widget_draw() on the child directly.
+ *
+ * In most cases, a container can simply either inherit the
+ * #GtkWidget::draw implementation from #GtkContainer, or do some drawing
+ * and then chain to the ::draw implementation from #GtkContainer.
+ **/
+void
+gtk_container_propagate_draw (GtkContainer *container,
+                              GtkWidget    *child,
+                              cairo_t      *cr)
+{
+  g_return_if_fail (GTK_IS_CONTAINER (container));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (cr != NULL);
+
+  g_assert (_gtk_widget_get_parent (child) == GTK_WIDGET (container));
+
+  if (!gtk_container_should_propagate_draw (container, child, cr))
+    return;
+
+  gtk_container_propagate_draw_internal (container, child, cr);
+}
+
 gboolean
 _gtk_container_get_reallocate_redraws (GtkContainer *container)
 {


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