[gtk/wip/chergert/glproto: 562/920] use shorts for WxH of viewport within batch




commit 238cbcbb8ac454a0b2e040205664fe007f305113
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 26 10:49:03 2020 -0800

    use shorts for WxH of viewport within batch

 gsk/next/gskglcommandqueue.c        | 47 +++++++++++++++++++++++++------------
 gsk/next/gskglcommandqueueprivate.h |  8 +++----
 gsk/next/gskglprogram.c             | 16 ++++++++++---
 gsk/next/gskglprogramprivate.h      |  3 ++-
 gsk/next/gskglrenderjob.c           |  5 ++--
 5 files changed, 53 insertions(+), 26 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index 8d56ffe9ef..9ddd377187 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -23,6 +23,7 @@
 #include <gdk/gdkglcontextprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <epoxy/gl.h>
+#include <string.h>
 
 #include "gskglattachmentstateprivate.h"
 #include "gskglbufferprivate.h"
@@ -206,6 +207,14 @@ typedef struct _GskGLCommandBatch
    */
   int next_batch_index;
 
+  /* The viewport size of the batch. We check this as we process
+   * batches to determine if we need to resize the viewport.
+   */
+  struct {
+    guint16 width;
+    guint16 height;
+  } viewport;
+
   /* A GskGLCommandKind indicating what the batch will do */
   guint kind : 8;
 
@@ -231,7 +240,7 @@ typedef struct _GskGLCommandBatch
   };
 } GskGLCommandBatch;
 
-G_STATIC_ASSERT (sizeof (GskGLCommandBatch) == 32);
+G_STATIC_ASSERT (sizeof (GskGLCommandBatch) == 40);
 
 G_DEFINE_TYPE (GskGLCommandQueue, gsk_gl_command_queue, G_TYPE_OBJECT)
 
@@ -320,13 +329,15 @@ gsk_gl_command_queue_new (GdkGLContext *context)
 }
 
 void
-gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
-                                 guint              program)
+gsk_gl_command_queue_begin_draw (GskGLCommandQueue     *self,
+                                 guint                  program,
+                                 const graphene_rect_t *viewport)
 {
   GskGLCommandBatch *batch;
 
   g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
   g_return_if_fail (self->in_draw == FALSE);
+  g_return_if_fail (viewport != NULL);
 
   g_array_set_size (self->batches, self->batches->len + 1);
 
@@ -334,6 +345,8 @@ gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
   batch->kind = GSK_GL_COMMAND_KIND_DRAW;
   batch->program = program;
   batch->next_batch_index = -1;
+  batch->viewport.width = viewport->size.width;
+  batch->viewport.height = viewport->size.height;
   batch->draw.framebuffer = 0;
   batch->draw.uniform_count = 0;
   batch->draw.uniform_offset = self->batch_uniforms->len;
@@ -444,8 +457,9 @@ gsk_gl_command_queue_add_vertices (GskGLCommandQueue     *self,
 }
 
 void
-gsk_gl_command_queue_clear (GskGLCommandQueue *self,
-                            guint              clear_bits)
+gsk_gl_command_queue_clear (GskGLCommandQueue     *self,
+                            guint                  clear_bits,
+                            const graphene_rect_t *viewport)
 {
   GskGLCommandBatch *batch;
 
@@ -460,6 +474,8 @@ gsk_gl_command_queue_clear (GskGLCommandQueue *self,
 
   batch = &g_array_index (self->batches, GskGLCommandBatch, self->batches->len - 1);
   batch->kind = GSK_GL_COMMAND_KIND_CLEAR;
+  batch->viewport.width = viewport->size.width;
+  batch->viewport.height = viewport->size.height;
   batch->clear.bits = clear_bits;
   batch->clear.framebuffer = self->attachments->fbo.id;
   batch->next_batch_index = -1;
@@ -853,9 +869,12 @@ apply_uniform (GskGLUniformState      *state,
 void
 gsk_gl_command_queue_execute (GskGLCommandQueue *self)
 {
+  graphene_rect_t viewport = GRAPHENE_RECT_INIT (0, 0, 0, 0);
   GLuint framebuffer = 0;
   GLuint vao_id;
   int next_batch_index;
+  guint16 width = 0;
+  guint16 height = 0;
 
   g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
   g_return_if_fail (self->in_draw == FALSE);
@@ -908,6 +927,10 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self)
               glBindFramebuffer (GL_FRAMEBUFFER, framebuffer);
             }
 
+          if (width != batch->viewport.width ||
+              height != batch->viewport.height)
+            glViewport (0, 0, batch->viewport.width, batch->viewport.height);
+
           glClear (batch->clear.bits);
           break;
 
@@ -926,6 +949,10 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self)
               glBindFramebuffer (GL_FRAMEBUFFER, framebuffer);
             }
 
+          if (width != batch->viewport.width ||
+              height != batch->viewport.height)
+            glViewport (0, 0, batch->viewport.width, batch->viewport.height);
+
           if (batch->draw.bind_count > 0)
             {
               for (guint i = 0; i < batch->draw.bind_count; i++)
@@ -1023,16 +1050,6 @@ gsk_gl_command_queue_end_frame (GskGLCommandQueue *self)
   self->autorelease_textures->len = 0;
 }
 
-void
-gsk_gl_command_queue_change_viewport (GskGLCommandQueue     *self,
-                                      const graphene_rect_t *viewport)
-{
-  g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
-  g_return_if_fail (viewport != NULL);
-
-  
-}
-
 gboolean
 gsk_gl_command_queue_create_render_target (GskGLCommandQueue *self,
                                            int                width,
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 1a5ccae8e2..34784089ab 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -35,8 +35,6 @@ void               gsk_gl_command_queue_make_current             (GskGLCommandQu
 void               gsk_gl_command_queue_begin_frame              (GskGLCommandQueue        *self);
 void               gsk_gl_command_queue_end_frame                (GskGLCommandQueue        *self);
 void               gsk_gl_command_queue_execute                  (GskGLCommandQueue        *self);
-void               gsk_gl_command_queue_change_viewport          (GskGLCommandQueue        *self,
-                                                                  const graphene_rect_t    *viewport);
 guint              gsk_gl_command_queue_upload_texture           (GskGLCommandQueue        *self,
                                                                   GdkTexture               *texture,
                                                                   GError                  **error);
@@ -56,7 +54,8 @@ void               gsk_gl_command_queue_delete_program           (GskGLCommandQu
 void               gsk_gl_command_queue_bind_framebuffer         (GskGLCommandQueue        *self,
                                                                   guint                     framebuffer);
 void               gsk_gl_command_queue_clear                    (GskGLCommandQueue        *self,
-                                                                  guint                     clear_bits);
+                                                                  guint                     clear_bits,
+                                                                  const graphene_rect_t    *viewport);
 void               gsk_gl_command_queue_set_uniform1i            (GskGLCommandQueue        *self,
                                                                   guint                     program,
                                                                   guint                     location,
@@ -142,7 +141,8 @@ void               gsk_gl_command_queue_autorelease_framebuffer  (GskGLCommandQu
 void               gsk_gl_command_queue_autorelease_texture      (GskGLCommandQueue        *self,
                                                                   guint                     texture_id);
 void               gsk_gl_command_queue_begin_draw               (GskGLCommandQueue        *self,
-                                                                  guint                     program);
+                                                                  guint                     program,
+                                                                  const graphene_rect_t    *viewport);
 void               gsk_gl_command_queue_end_draw                 (GskGLCommandQueue        *self);
 GskGLDrawVertex   *gsk_gl_command_queue_add_vertices             (GskGLCommandQueue        *self,
                                                                   const GskGLDrawVertex     
vertices[GSK_GL_N_VERTICES]);
diff --git a/gsk/next/gskglprogram.c b/gsk/next/gskglprogram.c
index 9a6b4bbac4..0f1a6af5ed 100644
--- a/gsk/next/gskglprogram.c
+++ b/gsk/next/gskglprogram.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include "gskglcommandqueueprivate.h"
+#include "gskgldriverprivate.h"
 #include "gskglprogramprivate.h"
 #include "gskgluniformstateprivate.h"
 
@@ -323,11 +324,20 @@ gsk_gl_program_set_uniform_rounded_rect (GskGLProgram         *self,
 }
 
 void
-gsk_gl_program_begin_draw (GskGLProgram *self)
+gsk_gl_program_begin_draw (GskGLProgram          *self,
+                           const graphene_rect_t *viewport)
 {
   g_assert (GSK_IS_GL_PROGRAM (self));
+  g_assert (viewport != NULL);
 
-  return gsk_gl_command_queue_begin_draw (self->command_queue, self->id);
+  gsk_gl_command_queue_set_uniform4f (self->command_queue,
+                                      self->id,
+                                      get_uniform_location (self, UNIFORM_SHARED_VIEWPORT),
+                                      viewport->origin.x,
+                                      viewport->origin.y,
+                                      viewport->size.width,
+                                      viewport->size.height);
+  gsk_gl_command_queue_begin_draw (self->command_queue, self->id, viewport);
 }
 
 void
@@ -335,5 +345,5 @@ gsk_gl_program_end_draw (GskGLProgram *self)
 {
   g_assert (GSK_IS_GL_PROGRAM (self));
 
-  return gsk_gl_command_queue_end_draw (self->command_queue);
+  gsk_gl_command_queue_end_draw (self->command_queue);
 }
diff --git a/gsk/next/gskglprogramprivate.h b/gsk/next/gskglprogramprivate.h
index a8d047c214..b717102c7b 100644
--- a/gsk/next/gskglprogramprivate.h
+++ b/gsk/next/gskglprogramprivate.h
@@ -83,7 +83,8 @@ void             gsk_gl_program_set_uniform_texture      (GskGLProgram
 void             gsk_gl_program_set_uniform_rounded_rect (GskGLProgram          *self,
                                                           guint                  key,
                                                           const GskRoundedRect  *rounded_rect);
-void             gsk_gl_program_begin_draw               (GskGLProgram          *self);
+void             gsk_gl_program_begin_draw               (GskGLProgram          *self,
+                                                          const graphene_rect_t *viewport);
 void             gsk_gl_program_end_draw                 (GskGLProgram          *self);
 
 G_END_DECLS
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index d30edff90b..24c38f3a7f 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -534,7 +534,7 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
       /* TODO: determine how we want to update mv/projection */
       /* TODO: and how about change_viewport()? */
 
-      gsk_gl_program_begin_draw (program);
+      gsk_gl_program_begin_draw (program, &job->viewport);
       gsk_gl_program_set_uniform_color (program,
                                         UNIFORM_COLOR_COLOR,
                                         gsk_color_node_get_color (node));
@@ -590,8 +590,7 @@ gsk_gl_render_job_render (GskGLRenderJob *job,
   gsk_next_driver_begin_frame (job->driver);
 
   gsk_gl_command_queue_bind_framebuffer (job->command_queue, job->framebuffer);
-  gsk_gl_command_queue_change_viewport (job->command_queue, &job->viewport);
-  gsk_gl_command_queue_clear (job->command_queue, 0);
+  gsk_gl_command_queue_clear (job->command_queue, 0, &job->viewport);
 
   gdk_gl_context_push_debug_group (context, "Building command queue");
   gsk_gl_render_job_visit_node (job, root);


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