[gtk/wip/baedert/for-master] gl renderer: Proper state tracking for color matrix ops



commit 284a7997f5db01a9ac341b22a25d8a1c3bd4e63c
Author: Timm Bäder <mail baedert org>
Date:   Fri Dec 18 18:28:17 2020 +0100

    gl renderer: Proper state tracking for color matrix ops

 gsk/gl/gskglrenderer.c  | 10 ++++++----
 gsk/gl/gskglrenderops.c | 28 ++++++++++++++--------------
 gsk/gl/opbuffer.h       |  3 ++-
 3 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index a1b9fbed2c..b0df8db050 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -2856,10 +2856,12 @@ static inline void
 apply_color_matrix_op (const Program       *program,
                        const OpColorMatrix *op)
 {
-  float mat[16];
-  OP_PRINT (" -> Color Matrix");
-  graphene_matrix_to_float (op->matrix, mat);
-  glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
+  if (op->matrix.send)
+    {
+      float mat[16];
+      graphene_matrix_to_float (op->matrix.value, mat);
+      glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
+    }
 
   if (op->offset.send)
     {
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index be7eff6fba..d7639162ad 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -533,30 +533,30 @@ ops_set_color_matrix (RenderOpBuilder         *builder,
                       const graphene_vec4_t   *offset)
 {
   ProgramState *current_program_state = get_current_program_state (builder);
+  const bool offset_equal = graphene_vec4_equal (offset, &current_program_state->color_matrix.offset);
+  const bool matrix_equal = graphene_matrix_equal_fast (matrix,
+                                                        &current_program_state->color_matrix.matrix);
   OpColorMatrix *op;
-  bool offset_equal;
 
-  offset_equal = memcmp (offset,
-                         &current_program_state->color_matrix.offset,
-                         sizeof (graphene_vec4_t)) == 0;
-
-  if (memcmp (matrix,
-              &current_program_state->color_matrix.matrix,
-              sizeof (graphene_matrix_t)) == 0 &&
-      offset_equal)
+  if (offset_equal && matrix_equal)
     return;
 
-  current_program_state->color_matrix.matrix = *matrix;
-
   op = ops_begin (builder, OP_CHANGE_COLOR_MATRIX);
-  op->matrix = matrix;
+
+  if (!matrix_equal)
+    {
+      current_program_state->color_matrix.matrix = *matrix;
+      op->matrix.value = matrix;
+      op->matrix.send = TRUE;
+    }
+  else
+    op->matrix.send = FALSE;
 
   if (!offset_equal)
     {
+      current_program_state->color_matrix.offset = *offset;
       op->offset.value = offset;
       op->offset.send = TRUE;
-
-      current_program_state->color_matrix.offset = *offset;
     }
   else
     op->offset.send = FALSE;
diff --git a/gsk/gl/opbuffer.h b/gsk/gl/opbuffer.h
index 08f48b7c5f..db9b5c9425 100644
--- a/gsk/gl/opbuffer.h
+++ b/gsk/gl/opbuffer.h
@@ -53,6 +53,7 @@ typedef struct { GskRoundedRect value; guint send: 1; guint send_corners: 1; } R
 typedef struct { const GdkRGBA *value; guint send: 1; } RGBAUniformValue;
 typedef struct { const graphene_vec4_t *value; guint send: 1; } Vec4UniformValue;
 typedef struct { const GskColorStop *value; guint send: 1; } ColorStopUniformValue;
+typedef struct { const graphene_matrix_t *value; guint send: 1; } MatrixUniformValue;
 
 /* OpNode are allocated within OpBuffer.pos, but we keep
  * a secondary index into the locations of that buffer
@@ -167,7 +168,7 @@ typedef struct
 
 typedef struct
 {
-  const graphene_matrix_t *matrix;
+  MatrixUniformValue matrix;
   Vec4UniformValue offset;
 } OpColorMatrix;
 


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