[gtk/wip/baedert/transforms6: 7/18] widget: Only push a transform if we need to



commit 435fb64e3983b4df11196c6a8e6a0497e708adda
Author: Timm Bäder <mail baedert org>
Date:   Thu Nov 29 09:49:16 2018 +0100

    widget: Only push a transform if we need to

 gtk/gtkwidget.c        | 12 ++++++++++--
 gtk/gtkwidgetprivate.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 8895a90511..de96adf080 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2887,6 +2887,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
     }
 
   graphene_matrix_init_identity (&priv->transform);
+  priv->has_transform = FALSE;
 
   /* this will be set to TRUE if the widget gets a child or if the
    * expand flag is set on the widget, but until one of those happen
@@ -4312,6 +4313,7 @@ gtk_widget_size_allocate_transformed (GtkWidget               *widget,
   priv->allocation = real_allocation;
   priv->allocated_baseline = baseline;
   priv->transform = final_transform;
+  priv->has_transform = !graphene_matrix_is_identity (&final_transform);
 
   if (!alloc_needed && !size_changed && !baseline_changed)
     {
@@ -13472,9 +13474,13 @@ gtk_widget_snapshot_child (GtkWidget   *widget,
   g_return_if_fail (_gtk_widget_get_parent (child) == widget);
   g_return_if_fail (snapshot != NULL);
 
-  gtk_snapshot_push_transform (snapshot, &priv->transform);
+  if (priv->has_transform)
+    gtk_snapshot_push_transform (snapshot, &priv->transform);
+
   gtk_widget_snapshot (child, snapshot);
-  gtk_snapshot_pop (snapshot);
+
+  if (priv->has_transform)
+    gtk_snapshot_pop (snapshot);
 }
 
 /**
@@ -13714,6 +13720,8 @@ gtk_widget_set_transform (GtkWidget               *widget,
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
 
+  priv->has_transform = !graphene_matrix_is_identity (transform);
+
   graphene_matrix_init_from_matrix (&priv->transform, transform);
 }
 
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index ec45b27205..9b172f46aa 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -145,6 +145,7 @@ struct _GtkWidgetPrivate
 
   graphene_matrix_t allocated_transform;
   graphene_matrix_t transform;
+  guint has_transform : 1;
 
   /* The widget's requested sizes */
   SizeRequestCache requests;


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