[gtk/wip/chergert/glproto: 148/526] setup clip rect as part of starting draw




commit 7c61c0d023e5954f518186eaf22b73e49e595c19
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 29 20:19:10 2020 -0800

    setup clip rect as part of starting draw

 gsk/next/gskglprogram.c        | 29 ++++++++++++++++++++---------
 gsk/next/gskglprogramprivate.h |  3 ++-
 gsk/next/gskglrenderjob.c      | 31 +++++++++++++------------------
 3 files changed, 35 insertions(+), 28 deletions(-)
---
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index 68c4933874..916d4ff8a3 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -27,14 +27,15 @@
 
 struct _GskGLProgram
 {
-  GObject               parent_instance;
-  int                   id;
-  char                 *name;
-  GArray               *uniform_locations;
-  GskGLCommandQueue   *command_queue;
-  int                  projection_location;
-  int                  modelview_location;
-  int                  viewport_location;
+  GObject            parent_instance;
+  int                id;
+  char              *name;
+  GArray            *uniform_locations;
+  GskGLCommandQueue *command_queue;
+  int                projection_location;
+  int                modelview_location;
+  int                viewport_location;
+  int                clip_rect_location;
 };
 
 G_DEFINE_TYPE (GskGLProgram, gsk_gl_program, G_TYPE_OBJECT)
@@ -105,6 +106,7 @@ gsk_gl_program_init (GskGLProgram *self)
   self->viewport_location = -1;
   self->projection_location = -1;
   self->modelview_location = -1;
+  self->clip_rect_location = -1;
 }
 
 /**
@@ -159,6 +161,8 @@ gsk_gl_program_add_uniform (GskGLProgram *self,
     self->projection_location = location;
   else if (key == UNIFORM_SHARED_VIEWPORT)
     self->viewport_location = location;
+  else if (key == UNIFORM_SHARED_CLIP_RECT)
+    self->clip_rect_location = location;
 
   return TRUE;
 }
@@ -369,7 +373,8 @@ void
 gsk_gl_program_begin_draw (GskGLProgram            *self,
                            const graphene_rect_t   *viewport,
                            const graphene_matrix_t *projection,
-                           const graphene_matrix_t *modelview)
+                           const graphene_matrix_t *modelview,
+                           const GskRoundedRect    *clip)
 {
   g_assert (GSK_IS_GL_PROGRAM (self));
   g_assert (viewport != NULL);
@@ -395,6 +400,12 @@ gsk_gl_program_begin_draw (GskGLProgram            *self,
                                              self->projection_location,
                                              projection);
 
+  if (clip != NULL && self->clip_rect_location > -1)
+    gsk_gl_command_queue_set_uniform_rounded_rect (self->command_queue,
+                                                   self->id,
+                                                   self->clip_rect_location,
+                                                   clip);
+
   gsk_gl_command_queue_begin_draw (self->command_queue, self->id, viewport);
 }
 
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index e866f79b76..b42d337265 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -91,7 +91,8 @@ void             gsk_gl_program_set_uniform_rounded_rect (GskGLProgram
 void             gsk_gl_program_begin_draw               (GskGLProgram            *self,
                                                           const graphene_rect_t   *viewport,
                                                           const graphene_matrix_t *projection,
-                                                          const graphene_matrix_t *modelview);
+                                                          const graphene_matrix_t *modelview,
+                                                          const GskRoundedRect    *clip);
 void             gsk_gl_program_end_draw                 (GskGLProgram            *self);
 
 G_END_DECLS
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index 5fc0a4c73b..5e5af5b850 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -254,13 +254,13 @@ gsk_gl_render_job_pop_modelview (GskGLRenderJob *job)
     }
 }
 
-static inline GskGLRenderClip *
+static inline GskRoundedRect *
 gsk_gl_render_job_get_clip (GskGLRenderJob *job)
 {
   if (job->clip->len == 0)
     return NULL;
   else
-    return &g_array_index (job->clip, GskGLRenderClip, job->clip->len - 1);
+    return &g_array_index (job->clip, GskGLRenderClip, job->clip->len - 1).rect;
 }
 
 static void
@@ -430,18 +430,21 @@ static gboolean
 gsk_gl_render_job_node_overlaps_clip (GskGLRenderJob *job,
                                       GskRenderNode  *node)
 {
-  GskGLRenderClip *clip;
-  graphene_rect_t transformed_bounds;
+  GskRoundedRect *clip;
 
   g_assert (job != NULL);
   g_assert (node != NULL);
 
-  if (!(clip = gsk_gl_render_job_get_clip (job)))
-    return TRUE;
+  clip = gsk_gl_render_job_get_clip (job);
 
-  gsk_gl_render_job_transform_bounds (job, &node->bounds, &transformed_bounds);
+  if (clip != NULL)
+    {
+      graphene_rect_t transformed_bounds;
+      gsk_gl_render_job_transform_bounds (job, &node->bounds, &transformed_bounds);
+      return rect_intersects (&clip->bounds, &transformed_bounds);
+    }
 
-  return rect_intersects (&clip->rect.bounds, &transformed_bounds);
+  return TRUE;
 }
 
 static void
@@ -537,19 +540,11 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
 
     case GSK_COLOR_NODE:
       {
-        GskGLRenderClip *clip = gsk_gl_render_job_get_clip (job);
-
-        g_assert (modelview != NULL);
-        g_assert (g_str_equal (gsk_gl_program_get_name (job->driver->color), "color"));
-
         gsk_gl_program_begin_draw (job->driver->color,
                                    &job->viewport,
                                    &job->projection,
-                                   &modelview->matrix);
-        if (clip != NULL)
-          gsk_gl_program_set_uniform_rounded_rect (job->driver->color,
-                                                   UNIFORM_SHARED_CLIP_RECT,
-                                                   &clip->rect);
+                                   &modelview->matrix,
+                                   gsk_gl_render_job_get_clip (job));
         gsk_gl_program_set_uniform_color (job->driver->color,
                                           UNIFORM_COLOR_COLOR,
                                           gsk_color_node_get_color (node));


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