[gtk+/wip/baedert/gl: 65/86] gl renderer: Keep track of border program state



commit c11dbbe2b25172fe9df45410a40c9150984d13e9
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 5 08:38:42 2017 +0100

    gl renderer: Keep track of border program state

 gsk/gl/gskglrenderer.c         |   25 +++++++++++----------
 gsk/gl/gskglrenderops.c        |   47 ++++++++++++++++++++++++++++++++++++++++
 gsk/gl/gskglrenderopsprivate.h |   16 ++++++++++++-
 3 files changed, 74 insertions(+), 14 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 9eea015..a844a19 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -340,7 +340,6 @@ render_border_node (GskGLRenderer   *self,
   graphene_rect_t transformed_clip;
   graphene_rect_t intersection;
   GskRoundedRect child_clip;
-  RenderOp op;
   struct {
     float w;
     float h;
@@ -379,12 +378,7 @@ render_border_node (GskGLRenderer   *self,
 
       prev_clip = ops_set_clip (builder, &child_clip);
 
-      op.op = OP_CHANGE_BORDER;
-      op.border.widths[0] = widths[0];
-      op.border.widths[1] = widths[1];
-      op.border.widths[2] = widths[2];
-      op.border.widths[3] = widths[3];
-      ops_add (builder, &op);
+      ops_set_border (builder, widths);
     }
   else
     {
@@ -392,7 +386,7 @@ render_border_node (GskGLRenderer   *self,
     }
 
   /* Top */
-  ops_set_color (builder, &colors[0]);
+  ops_set_border_color (builder, &colors[0]);
   ops_draw (builder, (const GskQuadVertex[6]) {
     { { min_x,              min_y              }, { 0, 1 }, }, /* Upper left */
     { { min_x + sizes[0].w, min_y + sizes[0].h }, { 0, 0 }, }, /* Lower left */
@@ -404,7 +398,7 @@ render_border_node (GskGLRenderer   *self,
   });
 
   /* Right */
-  ops_set_color (builder, &colors[1]);
+  ops_set_border_color (builder, &colors[1]);
   ops_draw (builder, (const GskQuadVertex[6]) {
     { { max_x - sizes[1].w, min_y + sizes[1].h }, { 0, 1 }, }, /* Upper left */
     { { max_x - sizes[2].w, max_y - sizes[2].h }, { 0, 0 }, }, /* Lower left */
@@ -416,7 +410,7 @@ render_border_node (GskGLRenderer   *self,
   });
 
   /* Bottom */
-  ops_set_color (builder, &colors[2]);
+  ops_set_border_color (builder, &colors[2]);
   ops_draw (builder, (const GskQuadVertex[6]) {
     { { min_x + sizes[3].w, max_y - sizes[3].h }, { 0, 1 }, }, /* Upper left */
     { { min_x,              max_y              }, { 0, 0 }, }, /* Lower left */
@@ -428,7 +422,7 @@ render_border_node (GskGLRenderer   *self,
   });
 
   /* Left */
-  ops_set_color (builder, &colors[3]);
+  ops_set_border_color (builder, &colors[3]);
   ops_draw (builder, (const GskQuadVertex[6]) {
     { { min_x,              min_y              }, { 0, 1 }, }, /* Upper left */
     { { min_x,              max_y              }, { 0, 0 }, }, /* Lower left */
@@ -1537,13 +1531,20 @@ gsk_gl_renderer_render_ops (GskGLRenderer *self,
         case OP_CHANGE_COLOR:
           OP_PRINT (" -> Color: (%f, %f, %f, %f)", op->color.red, op->color.green, op->color.blue, 
op->color.alpha);
           g_assert (program == &self->color_program || program == &self->coloring_program ||
-                    program == &self->shadow_program || program == &self->border_program);
+                    program == &self->shadow_program);
           /* TODO: We use color.color_location here and this is right for all three of the programs above,
            *       but that's just a coincidence. */
           glUniform4f (program->color.color_location,
                        op->color.red, op->color.green, op->color.blue, op->color.alpha);
           break;
 
+        case OP_CHANGE_BORDER_COLOR:
+          OP_PRINT (" -> Border color (%f, %f, %f, %f)",
+                    op->border.color[0], op->border.color[1], op->border.color[2], op->border.color[3]);
+          g_assert (program == &self->border_program);
+          glUniform4fv (program->border.color_location, 1, op->border.color);
+          break;
+
         case OP_CHANGE_CLIP:
           OP_PRINT (" -> Clip (%f, %f, %f, %f) (%f, %f, %f, %f), (%f, %f, %f, %f)",
                     op->clip.bounds.origin.x, op->clip.bounds.origin.y,
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index 998b12a..0b5a7dc 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -1,5 +1,14 @@
 #include "gskglrenderopsprivate.h"
 
+static inline void
+rgba_to_float (const GdkRGBA *c,
+               float         *f)
+{
+  f[0] = c->red;
+  f[1] = c->green;
+  f[2] = c->blue;
+  f[3] = c->alpha;
+}
 
 void
 ops_set_program (RenderOpBuilder *builder,
@@ -276,6 +285,44 @@ ops_set_color_matrix (RenderOpBuilder         *builder,
 }
 
 void
+ops_set_border (RenderOpBuilder *builder,
+                const float     *widths)
+{
+  RenderOp op;
+
+  if (memcmp (&builder->program_state[builder->current_program->index].border.widths,
+              widths, sizeof (float) * 4) == 0)
+    return;
+
+  memcpy (&builder->program_state[builder->current_program->index].border.widths,
+          widths, sizeof (float) * 4);
+
+  op.op = OP_CHANGE_BORDER;
+  op.border.widths[0] = widths[0];
+  op.border.widths[1] = widths[1];
+  op.border.widths[2] = widths[2];
+  op.border.widths[3] = widths[3];
+  g_array_append_val (builder->render_ops, op);
+}
+
+void
+ops_set_border_color (RenderOpBuilder *builder,
+                      const GdkRGBA   *color)
+{
+  RenderOp op;
+  op.op = OP_CHANGE_BORDER_COLOR;
+  rgba_to_float (color, op.border.color);
+
+  if (memcmp (&op.border.color, &builder->program_state[builder->current_program->index].border.color,
+              sizeof (float) * 4) == 0)
+    return;
+
+  rgba_to_float (color, builder->program_state[builder->current_program->index].border.color);
+
+  g_array_append_val (builder->render_ops, op);
+}
+
+void
 ops_draw (RenderOpBuilder     *builder,
           const GskQuadVertex  vertex_data[GL_N_VERTICES])
 {
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index a383993..7e35373 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -30,8 +30,9 @@ enum {
   OP_CHANGE_INSET_SHADOW    =  14,
   OP_CHANGE_OUTSET_SHADOW   =  15,
   OP_CHANGE_BORDER          =  16,
-  OP_CLEAR                  =  17,
-  OP_DRAW                   =  18,
+  OP_CHANGE_BORDER_COLOR    =  17,
+  OP_CLEAR                  =  18,
+  OP_DRAW                   =  19,
 };
 
 typedef struct
@@ -159,6 +160,7 @@ typedef struct
     } shadow;
     struct {
       float widths[4];
+      float color[4];
     } border;
   };
 } RenderOp;
@@ -179,6 +181,10 @@ typedef struct
         graphene_matrix_t matrix;
         graphene_vec4_t offset;
       } color_matrix;
+      struct {
+        float widths[4];
+        float color[4];
+      } border;
     };
   } program_state[GL_N_PROGRAMS];
 
@@ -230,6 +236,12 @@ void              ops_set_color_matrix   (RenderOpBuilder         *builder,
                                           const graphene_matrix_t *matrix,
                                           const graphene_vec4_t   *offset);
 
+void              ops_set_border         (RenderOpBuilder         *builder,
+                                          const float             *widths);
+
+void              ops_set_border_color   (RenderOpBuilder         *builder,
+                                          const GdkRGBA           *color);
+
 void              ops_draw               (RenderOpBuilder        *builder,
                                           const GskQuadVertex     vertex_data[GL_N_VERTICES]);
 


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