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




commit 531ae7614ed330f1a90e0aea30cfe0231cdaf4ee
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  | 28 +++++++++++++++++++---------
 gtk/gtkcssimagelinear.c | 12 +++++++++++-
 gtk/gtkcssimageradial.c | 12 +++++++++++-
 3 files changed, 41 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssimageconic.c b/gtk/gtkcssimageconic.c
index b046c0df4e..15795cf822 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);
 
@@ -69,26 +70,35 @@ gtk_css_image_conic_snapshot (GtkCssImage        *image,
       step = (pos - offset) / (i - last);
       for (last = last + 1; last <= i; last++)
         {
+          const GdkRGBA *stop_color;
+
           stop = &self->color_stops[last];
+          stop_color = gtk_css_color_value_get_rgba (stop->color);
+
+          if (!visible && !gdk_rgba_is_clear (stop_color))
+            visible = TRUE;
 
           offset += step;
 
           stops[last].offset = offset;
-          stops[last].color = *gtk_css_color_value_get_rgba (stop->color);
+          stops[last].color = *stop_color;
         }
 
       offset = pos;
       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..e93c9fa91b 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)
     {
@@ -232,18 +233,27 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
       step = (pos - offset) / (i - last);
       for (last = last + 1; last <= i; last++)
         {
+          const GdkRGBA *stop_color;
+
           stop = &linear->color_stops[last];
+          stop_color = gtk_css_color_value_get_rgba (stop->color);
+
+          if (!visible && !gdk_rgba_is_clear (stop_color))
+            visible = TRUE;
 
           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..98b93cf556 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);
@@ -182,18 +183,27 @@ gtk_css_image_radial_snapshot (GtkCssImage *image,
       step = (pos - offset) / (i - last);
       for (last = last + 1; last <= i; last++)
         {
+          const GdkRGBA *stop_color;
+
           stop = &radial->color_stops[last];
+          stop_color = gtk_css_color_value_get_rgba (stop->color);
+
+          if (!visible && !gdk_rgba_is_clear (stop_color))
+            visible = TRUE;
 
           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 (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]