[gtk/wip/baedert/for-master: 38/39] gl renderer: Fall back to cairo if gradients use too many stops




commit 627883a78f4c5dfe810b52b7850bb5102ae76067
Author: Timm Bäder <mail baedert org>
Date:   Mon Sep 21 21:19:19 2020 +0200

    gl renderer: Fall back to cairo if gradients use too many stops

 gsk/gl/gskglrenderer.c         | 80 +++++++++++++++++++++++++-----------------
 gsk/gl/gskglrenderops.c        |  4 +--
 gsk/gl/gskglrenderopsprivate.h |  6 ++--
 3 files changed, 53 insertions(+), 37 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 5c033c52c9..501daeb45c 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -1175,21 +1175,29 @@ render_linear_gradient_node (GskGLRenderer   *self,
                              GskRenderNode   *node,
                              RenderOpBuilder *builder)
 {
-  const int n_color_stops = MIN (8, gsk_linear_gradient_node_get_n_color_stops (node));
-  const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node, NULL);
-  const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
-  const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
-
-  ops_set_program (builder, &self->programs->linear_gradient_program);
-  ops_set_linear_gradient (builder,
-                           n_color_stops,
-                           stops,
-                           builder->dx + start->x,
-                           builder->dy + start->y,
-                           builder->dx + end->x,
-                           builder->dy + end->y);
+  const int n_color_stops = gsk_linear_gradient_node_get_n_color_stops (node);
 
-  load_vertex_data (ops_draw (builder, NULL), node, builder);
+  if (n_color_stops < GL_MAX_GRADIENT_STOPS)
+    {
+      const GskColorStop *stops = gsk_linear_gradient_node_peek_color_stops (node, NULL);
+      const graphene_point_t *start = gsk_linear_gradient_node_peek_start (node);
+      const graphene_point_t *end = gsk_linear_gradient_node_peek_end (node);
+
+      ops_set_program (builder, &self->programs->linear_gradient_program);
+      ops_set_linear_gradient (builder,
+                               n_color_stops,
+                               stops,
+                               builder->dx + start->x,
+                               builder->dy + start->y,
+                               builder->dx + end->x,
+                               builder->dy + end->y);
+
+      load_vertex_data (ops_draw (builder, NULL), node, builder);
+    }
+  else
+    {
+      render_fallback_node (self, node, builder);
+    }
 }
 
 static inline void
@@ -1197,25 +1205,33 @@ render_radial_gradient_node (GskGLRenderer   *self,
                              GskRenderNode   *node,
                              RenderOpBuilder *builder)
 {
-  const int n_color_stops = MIN (8, gsk_radial_gradient_node_get_n_color_stops (node));
-  const GskColorStop *stops = gsk_radial_gradient_node_peek_color_stops (node, NULL);
-  const graphene_point_t *center = gsk_radial_gradient_node_peek_center (node);
-  const float start = gsk_radial_gradient_node_get_start (node);
-  const float end = gsk_radial_gradient_node_get_end (node);
-  const float hradius = gsk_radial_gradient_node_get_hradius (node);
-  const float vradius = gsk_radial_gradient_node_get_vradius (node);
-
-  ops_set_program (builder, &self->programs->radial_gradient_program);
-  ops_set_radial_gradient (builder,
-                           n_color_stops,
-                           stops,
-                           builder->dx + center->x,
-                           builder->dy + center->y,
-                           start, end,
-                           hradius * builder->scale_x,
-                           vradius * builder->scale_y);
+  const int n_color_stops = gsk_radial_gradient_node_get_n_color_stops (node);
 
-  load_vertex_data (ops_draw (builder, NULL), node, builder);
+  if (n_color_stops < GL_MAX_GRADIENT_STOPS)
+    {
+      const GskColorStop *stops = gsk_radial_gradient_node_peek_color_stops (node, NULL);
+      const graphene_point_t *center = gsk_radial_gradient_node_peek_center (node);
+      const float start = gsk_radial_gradient_node_get_start (node);
+      const float end = gsk_radial_gradient_node_get_end (node);
+      const float hradius = gsk_radial_gradient_node_get_hradius (node);
+      const float vradius = gsk_radial_gradient_node_get_vradius (node);
+
+      ops_set_program (builder, &self->programs->radial_gradient_program);
+      ops_set_radial_gradient (builder,
+                               n_color_stops,
+                               stops,
+                               builder->dx + center->x,
+                               builder->dy + center->y,
+                               start, end,
+                               hradius * builder->scale_x,
+                               vradius * builder->scale_y);
+
+      load_vertex_data (ops_draw (builder, NULL), node, builder);
+    }
+  else
+    {
+      render_fallback_node (self, node, builder);
+    }
 }
 
 static inline gboolean
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index 7713f294eb..c3ffce648d 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -909,7 +909,7 @@ ops_set_linear_gradient (RenderOpBuilder     *self,
 {
   ProgramState *current_program_state = get_current_program_state (self);
   OpLinearGradient *op;
-  const guint real_n_color_stops = MIN (MAX_GRADIENT_STOPS, n_color_stops);
+  const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
 
   g_assert (current_program_state);
 
@@ -972,7 +972,7 @@ ops_set_radial_gradient (RenderOpBuilder    *self,
                          float               hradius,
                          float               vradius)
 {
-  const guint real_n_color_stops = MIN (MAX_GRADIENT_STOPS, n_color_stops);
+  const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
   OpRadialGradient *op;
 
   /* TODO: State tracking? */
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index a6c6d0f232..b4eafea543 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -14,7 +14,7 @@
 
 #define GL_N_VERTICES 6
 #define GL_N_PROGRAMS 14
-#define MAX_GRADIENT_STOPS 8
+#define GL_MAX_GRADIENT_STOPS 8
 
 typedef struct
 {
@@ -147,13 +147,13 @@ typedef struct
     } unblurred_outset_shadow;
     struct {
       int n_color_stops;
-      GskColorStop color_stops[MAX_GRADIENT_STOPS];
+      GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
       float start_point[2];
       float end_point[2];
     } linear_gradient;
     struct {
       int n_color_stops;
-      GskColorStop color_stops[MAX_GRADIENT_STOPS];
+      GskColorStop color_stops[GL_MAX_GRADIENT_STOPS];
       float center[2];
       float start;
       float end;


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