[gtk/wip/chergert/glproto: 545/920] setup modelview stack




commit 265d70ad337fe1e540005e50ba273c4a6e61a880
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 19 14:48:12 2020 -0800

    setup modelview stack

 gsk/next/gskglrenderjob.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
---
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index e0d8393cfa..f32477d123 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -55,6 +55,14 @@ typedef struct _GskGLRenderModelview
   guint         n_repeated;
 } GskGLRenderModelview;
 
+static void
+gsk_gl_render_modelview_clear (gpointer data)
+{
+  GskGLRenderModelview *modelview = data;
+
+  g_clear_pointer (&modelview->transform, gsk_transform_unref);
+}
+
 static void
 init_projection_matrix (graphene_matrix_t     *projection,
                         const graphene_rect_t *viewport,
@@ -72,6 +80,55 @@ init_projection_matrix (graphene_matrix_t     *projection,
     graphene_matrix_scale (projection, 1, -1, 1);
 }
 
+static void
+gsk_gl_render_job_push_modelview (GskGLRenderJob *job,
+                                  GskTransform   *transform)
+{
+  GskGLRenderModelview modelview = { transform, 0 };
+
+  g_assert (job != NULL);
+  g_assert (job->modelview != NULL);
+  g_assert (transform != NULL || job->modelview->len > 0);
+
+  if G_LIKELY (job->modelview->len > 0)
+    {
+      GskGLRenderModelview *last;
+
+      last = &g_array_index (job->modelview,
+                             GskGLRenderModelview,
+                             job->modelview->len - 1);
+
+      if (transform == NULL || gsk_transform_equal (transform, last->transform))
+        {
+          last->n_repeated++;
+          return;
+        }
+    }
+
+  g_assert (transform != NULL);
+
+  g_array_append_val (job->modelview, modelview);
+}
+
+static void
+gsk_gl_render_job_pop_modelview (GskGLRenderJob *job)
+{
+  GskGLRenderModelview *modelview;
+
+  g_assert (job != NULL);
+  g_assert (job->modelview != NULL);
+  g_assert (job->modelview->len > 0);
+
+  modelview = &g_array_index (job->modelview,
+                              GskGLRenderModelview,
+                              job->modelview->len - 1);
+
+  if (modelview->n_repeated == 0)
+    job->modelview->len--;
+  else
+    modelview->n_repeated--;
+}
+
 GskGLRenderJob *
 gsk_gl_render_job_new (GskNextDriver         *driver,
                        GskRenderNode         *root,
@@ -91,7 +148,6 @@ gsk_gl_render_job_new (GskNextDriver         *driver,
   job = g_slice_new0 (GskGLRenderJob);
   job->driver = g_object_ref (driver);
   job->root = gsk_render_node_ref (root);
-  job->modelview = g_array_new (FALSE, FALSE, sizeof (GskGLRenderModelview));
   job->clip = g_array_new (FALSE, FALSE, sizeof (GskGLRenderClip));
   job->framebuffer = framebuffer;
   job->scale_factor = scale_factor;
@@ -99,6 +155,12 @@ gsk_gl_render_job_new (GskNextDriver         *driver,
   job->region = region ? cairo_region_copy (region) : NULL;
   job->flip_y = !!flip_y;
 
+  init_projection_matrix (&job->projection, viewport, flip_y);
+
+  job->modelview = g_array_new (FALSE, FALSE, sizeof (GskGLRenderModelview));
+  g_array_set_clear_func (job->modelview, gsk_gl_render_modelview_clear);
+  gsk_gl_render_job_push_modelview (job, gsk_transform_scale (NULL, scale_factor, scale_factor));
+
   return job;
 }
 


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