[gtk/wip/baedert/gl-rework: 150/176] Avoid a few state changes



commit 336227fb73a2f9ac3393d809af952c1cc06d4d3f
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 17 17:15:17 2019 +0100

    Avoid a few state changes
    
    We can't optimize the save/restore calls away in the snapshot code, so
    do it from the caller side.

 gtk/gtkimage.c  | 15 +++++++++++----
 gtk/gtkwidget.c | 15 +++++++++++----
 2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 751ae9de23..8a415750e9 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1136,10 +1136,17 @@ gtk_image_snapshot (GtkWidget   *widget,
       else
         y = CLAMP (baseline - h * gtk_image_get_baseline_align (image), 0, height - ceil (h));
 
-      gtk_snapshot_save (snapshot);
-      gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
-      gdk_paintable_snapshot (GDK_PAINTABLE (priv->icon_helper), snapshot, w, h);
-      gtk_snapshot_restore (snapshot);
+      if (x != 0 || y != 0)
+        {
+          gtk_snapshot_save (snapshot);
+          gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+          gdk_paintable_snapshot (GDK_PAINTABLE (priv->icon_helper), snapshot, w, h);
+          gtk_snapshot_restore (snapshot);
+        }
+      else
+        {
+          gdk_paintable_snapshot (GDK_PAINTABLE (priv->icon_helper), snapshot, w, h);
+        }
     }
 }
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c1bd09842e..0546f5f545 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -13154,12 +13154,19 @@ gtk_widget_snapshot_child (GtkWidget   *widget,
   if (GTK_IS_NATIVE (child))
     return;
 
-  gtk_snapshot_save (snapshot);
-  gtk_snapshot_transform (snapshot, priv->transform);
+  if (priv->transform)
+    {
+      gtk_snapshot_save (snapshot);
+      gtk_snapshot_transform (snapshot, priv->transform);
 
-  gtk_widget_snapshot (child, snapshot);
+      gtk_widget_snapshot (child, snapshot);
 
-  gtk_snapshot_restore (snapshot);
+      gtk_snapshot_restore (snapshot);
+    }
+  else
+    {
+      gtk_widget_snapshot (child, snapshot);
+    }
 }
 
 /**


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