[gtk+] Optimize away trivial opacities



commit 9c391e7a9f6b5baca8ad8e6ecd57a17bf5e2ba37
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Oct 19 12:01:02 2017 +0200

    Optimize away trivial opacities
    
    No need to go color matrix on an opacity of 0 or 1.

 gtk/gtksnapshot.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 2f72614..4413667 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -288,11 +288,22 @@ gtk_snapshot_collect_opacity (GtkSnapshot      *snapshot,
   if (node == NULL)
     return NULL;
 
-  opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity);
-  if (name)
-    gsk_render_node_set_name (opacity_node, name);
-
-  gsk_render_node_unref (node);
+  if (state->data.opacity.opacity == 1.0)
+    {
+      opacity_node = node;
+    }
+  else if (state->data.opacity.opacity == 0.0)
+    {
+      gsk_render_node_unref (node);
+      opacity_node = NULL;
+    }
+  else
+    {
+      opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity);
+      if (name)
+        gsk_render_node_set_name (opacity_node, name);
+      gsk_render_node_unref (node);
+    }
 
   return opacity_node;
 }
@@ -324,7 +335,7 @@ gtk_snapshot_push_opacity (GtkSnapshot *snapshot,
                                    current_state->translate_x,
                                    current_state->translate_y,
                                    gtk_snapshot_collect_opacity);
-  state->data.opacity.opacity = opacity;
+  state->data.opacity.opacity = CLAMP (opacity, 0.0, 1.0);
 }
 
 static GskRenderNode *


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