[gtk/wip/baedert/for-master: 3/3] Ignore gradients with only transparent stops




commit 54d65edf8ec266a41ea78383052b1958d88b7abe
Author: Timm Bäder <mail baedert org>
Date:   Thu Jul 15 17:06:05 2021 +0200

    Ignore gradients with only transparent stops

 gtk/gtkcssimageconic.c  | 24 ++++++++++++++++--------
 gtk/gtkcssimagelinear.c | 10 +++++++++-
 gtk/gtkcssimageradial.c |  8 ++++++++
 3 files changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcssimageconic.c b/gtk/gtkcssimageconic.c
index b046c0df4e..9665121aaa 100644
--- a/gtk/gtkcssimageconic.c
+++ b/gtk/gtkcssimageconic.c
@@ -40,6 +40,7 @@ gtk_css_image_conic_snapshot (GtkCssImage        *image,
   GskColorStop *stops;
   int i, last;
   double offset;
+  gboolean visible = FALSE;
 
   stops = g_newa (GskColorStop, self->n_stops);
 
@@ -48,8 +49,12 @@ gtk_css_image_conic_snapshot (GtkCssImage        *image,
   for (i = 0; i < self->n_stops; i++)
     {
       const GtkCssImageConicColorStop *stop = &self->color_stops[i];
+      const GdkRGBA *stop_color = gtk_css_color_value_get_rgba (stop->color);
       double pos, step;
 
+      if (!visible && !gdk_rgba_is_clear (stop_color))
+        visible = TRUE;
+
       if (stop->offset == NULL)
         {
           if (i == 0)
@@ -81,14 +86,17 @@ gtk_css_image_conic_snapshot (GtkCssImage        *image,
       last = i;
     }
 
-    gtk_snapshot_append_conic_gradient (
-          snapshot,
-          &GRAPHENE_RECT_INIT (0, 0, width, height),
-          &GRAPHENE_POINT_INIT (_gtk_css_position_value_get_x (self->center, width),
-                                _gtk_css_position_value_get_y (self->center, height)),
-          _gtk_css_number_value_get (self->rotation, 360),
-          stops,
-          self->n_stops);
+  if (!visible)
+    return;
+
+  gtk_snapshot_append_conic_gradient (
+        snapshot,
+        &GRAPHENE_RECT_INIT (0, 0, width, height),
+        &GRAPHENE_POINT_INIT (_gtk_css_position_value_get_x (self->center, width),
+                              _gtk_css_position_value_get_y (self->center, height)),
+        _gtk_css_number_value_get (self->rotation, 360),
+        stops,
+        self->n_stops);
 }
 
 static gboolean
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 13f848d945..67d53ec84a 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -147,6 +147,7 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
   double start, end; /* position of first/last point on gradient line - with gradient line being [0, 1] */
   double offset;
   int i, last;
+  gboolean visible = FALSE;
 
   if (linear->side)
     {
@@ -211,8 +212,12 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
   for (i = 0; i < linear->n_stops; i++)
     {
       const GtkCssImageLinearColorStop *stop = &linear->color_stops[i];
+      const GdkRGBA *stop_color = gtk_css_color_value_get_rgba (stop->color);
       double pos, step;
 
+      if (!visible && !gdk_rgba_is_clear (stop_color))
+        visible = TRUE;
+
       if (stop->offset == NULL)
         {
           if (i == 0)
@@ -237,13 +242,16 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
           offset += step;
 
           stops[last].offset = (offset - start) / (end - start);
-          stops[last].color = *gtk_css_color_value_get_rgba (stop->color);
+          stops[last].color = *stop_color;
         }
 
       offset = pos;
       last = i;
     }
 
+  if (!visible)
+    return;
+
   if (linear->repeating)
     {
       gtk_snapshot_append_repeating_linear_gradient (
diff --git a/gtk/gtkcssimageradial.c b/gtk/gtkcssimageradial.c
index 4b36a1e165..0b93a0b9e2 100644
--- a/gtk/gtkcssimageradial.c
+++ b/gtk/gtkcssimageradial.c
@@ -87,6 +87,7 @@ gtk_css_image_radial_snapshot (GtkCssImage *image,
   double r1, r2, r3, r4, r;
   double offset;
   int i, last;
+  gboolean visible = FALSE;
 
   x = _gtk_css_position_value_get_x (radial->position, width);
   y = _gtk_css_position_value_get_y (radial->position, height);
@@ -164,8 +165,12 @@ gtk_css_image_radial_snapshot (GtkCssImage *image,
   for (i = 0; i < radial->n_stops; i++)
     {
       const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
+      const GdkRGBA *stop_color = gtk_css_color_value_get_rgba (stop->color);
       double pos, step;
 
+      if (!visible && !gdk_rgba_is_clear (stop_color))
+        visible = TRUE;
+
       if (stop->offset == NULL)
         {
           if (i == 0)
@@ -194,6 +199,9 @@ gtk_css_image_radial_snapshot (GtkCssImage *image,
       last = i;
     }
 
+  if (!visible)
+    return;
+
  if (radial->repeating)
    gtk_snapshot_append_repeating_radial_gradient (snapshot,
                                                   &GRAPHENE_RECT_INIT (0, 0, width, height),


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