[gtk/wip/chergert/glproto] gskrendernode: Cache angle in conic gradients



commit b0be5bbfdd8f2189038991c479e4adb52dd64a44
Author: Fabio Lagalla <lagfabio amazon com>
Date:   Tue Jan 26 16:15:12 2021 +0100

    gskrendernode: Cache angle in conic gradients

 gsk/gl/gskglrenderer.c         | 13 +++----------
 gsk/gl/gskglrenderops.c        |  4 ++--
 gsk/gl/gskglrenderopsprivate.h |  2 +-
 gsk/gl/opbuffer.h              |  2 +-
 gsk/gskrendernode.h            |  2 ++
 gsk/gskrendernodeimpl.c        | 27 +++++++++++++++++++++++++++
 6 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index b18f8e9efc..febb1b45ee 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -1512,7 +1512,7 @@ render_conic_gradient_node (GskGLRenderer   *self,
     {
       const GskColorStop *stops = gsk_conic_gradient_node_get_color_stops (node, NULL);
       const graphene_point_t *center = gsk_conic_gradient_node_get_center (node);
-      const float rotation = gsk_conic_gradient_node_get_rotation (node);
+      const float angle = gsk_conic_gradient_node_get_angle (node);
 
       ops_set_program (builder, &self->programs->conic_gradient_program);
       ops_set_conic_gradient (builder,
@@ -1520,7 +1520,7 @@ render_conic_gradient_node (GskGLRenderer   *self,
                               stops,
                               builder->dx + center->x,
                               builder->dy + center->y,
-                              rotation);
+                              angle);
 
       load_vertex_data (ops_draw (builder, NULL), &node->bounds, builder);
     }
@@ -3091,7 +3091,6 @@ static inline void
 apply_conic_gradient_op (const Program         *program,
                          const OpConicGradient *op)
 {
-  float angle;
   float bias;
   float scale;
 
@@ -3104,14 +3103,8 @@ apply_conic_gradient_op (const Program         *program,
                   op->n_color_stops.value * 5,
                   (float *)op->color_stops.value);
 
-  angle = 90.0f - op->rotation;
-  angle = M_PI * angle / 180.0f;
-  angle = fmodf (angle, 2.0f * M_PI);
-  if (angle < 0.0f)
-    angle += 2.0f * M_PI;
-
   scale = 0.5f * M_1_PI;
-  bias = angle * scale + 2.0f;
+  bias = op->angle * scale + 2.0f;
   glUniform4f (program->conic_gradient.geometry_location, op->center[0], op->center[1], scale, bias);
 }
 
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index f5c6ab6e62..36f7e37e35 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -957,7 +957,7 @@ ops_set_conic_gradient (RenderOpBuilder    *self,
                         const GskColorStop *color_stops,
                         float               center_x,
                         float               center_y,
-                        float               rotation)
+                        float               angle)
 {
   const guint real_n_color_stops = MIN (GL_MAX_GRADIENT_STOPS, n_color_stops);
   OpConicGradient *op;
@@ -971,6 +971,6 @@ ops_set_conic_gradient (RenderOpBuilder    *self,
   op->color_stops.send = true;
   op->center[0] = center_x;
   op->center[1] = center_y;
-  op->rotation = rotation;
+  op->angle = angle;
 }
 
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 20af58fda5..b23060014b 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -337,7 +337,7 @@ void              ops_set_conic_gradient  (RenderOpBuilder        *self,
                                            const GskColorStop     *color_stops,
                                            float                   center_x,
                                            float                   center_y,
-                                           float                   rotation);
+                                           float                   angle);
 
 GskQuadVertex *   ops_draw               (RenderOpBuilder        *builder,
                                           const GskQuadVertex     vertex_data[GL_N_VERTICES]);
diff --git a/gsk/gl/opbuffer.h b/gsk/gl/opbuffer.h
index e13e8ab2e4..ea954249c5 100644
--- a/gsk/gl/opbuffer.h
+++ b/gsk/gl/opbuffer.h
@@ -165,7 +165,7 @@ typedef struct
   ColorStopUniformValue color_stops;
   IntUniformValue n_color_stops;
   float center[2];
-  float rotation;
+  float angle;
 } OpConicGradient;
 
 typedef struct
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 99af00286f..5ae6bf2f89 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -257,6 +257,8 @@ const graphene_point_t * gsk_conic_gradient_node_get_center         (GskRenderNo
 GDK_AVAILABLE_IN_ALL
 float                    gsk_conic_gradient_node_get_rotation       (GskRenderNode            *node);
 GDK_AVAILABLE_IN_ALL
+float                    gsk_conic_gradient_node_get_angle          (GskRenderNode            *node);
+GDK_AVAILABLE_IN_ALL
 gsize                    gsk_conic_gradient_node_get_n_color_stops  (GskRenderNode            *node);
 GDK_AVAILABLE_IN_ALL
 const GskColorStop *     gsk_conic_gradient_node_get_color_stops    (GskRenderNode            *node,
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index fb6c659baf..f932c38185 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -782,6 +782,7 @@ struct _GskConicGradientNode
 
   graphene_point_t center;
   float rotation;
+  float angle;
 
   gsize n_stops;
   GskColorStop *stops;
@@ -1023,6 +1024,12 @@ gsk_conic_gradient_node_new (const graphene_rect_t  *bounds,
   self->stops = g_malloc_n (n_color_stops, sizeof (GskColorStop));
   memcpy (self->stops, color_stops, n_color_stops * sizeof (GskColorStop));
 
+  self->angle = 90.f - self->rotation;
+  self->angle = G_PI * self->angle / 180.f;
+  self->angle = fmodf (self->angle, 2.f * G_PI);
+  if (self->angle < 0.f)
+    self->angle += 2.f * G_PI;
+
   return node;
 }
 
@@ -1095,6 +1102,26 @@ gsk_conic_gradient_node_get_rotation (GskRenderNode *node)
   return self->rotation;
 }
 
+/**
+ * gsk_conic_gradient_node_get_angle:
+ * @node: (type GskConicGradientNode): a #GskRenderNode for a conic gradient
+ *
+ * Retrieves the angle for the gradient in radians, normalized in [0, 2 * PI]
+ *
+ * The angle is starting at the top and going clockwise, as expressed
+ * in the css specification:
+ * angle = 90 - gsk_conic_gradient_node_get_rotation()
+ *
+ * Returns: the angle for the gradient
+ */
+float
+gsk_conic_gradient_node_get_angle (GskRenderNode *node)
+{
+  GskConicGradientNode *self = (GskConicGradientNode *) node;
+
+  return self->angle;
+}
+
 /*** GSK_BORDER_NODE ***/
 
 /**


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