[gtk/wip/chergert/macos-iosurface: 27/29] gsk/gl: use default_framebuffer in render job




commit 9aea04899bd54321946c0d22be68f2d0cc782d14
Author: Christian Hergert <christian hergert me>
Date:   Thu Feb 10 21:51:15 2022 -0800

    gsk/gl: use default_framebuffer in render job
    
    Now that we have the ability to set a default framebuffer for a
    GdkGLContext, the GskGLRenderer needs to respect that when creating the
    render job.  Furthermore, we need to check against it when applying the
    scissor test.
    
    Generally, 0 is the default framebuffer. But on platforms where we need
    to bind a platform-specific feature to a GL_FRAMEBUFFER, we might have a
    default that is not 0. For example, on macOS we bind an IOSurfaceRef to
    a GL_TEXTURE_RECTANGLE which then is assigned as the backing store for a
    framebuffer we want as the destination. This is different than using
    gsk_gl_renderer_render_texture() in that we don't want to incur an extra
    copy to the destination surface.

 gsk/gl/gskglcommandqueue.c | 18 +++++++++++-------
 gsk/gl/gskglrenderer.c     |  4 +++-
 2 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gsk/gl/gskglcommandqueue.c b/gsk/gl/gskglcommandqueue.c
index 3af8c1eb09..311dd78c6d 100644
--- a/gsk/gl/gskglcommandqueue.c
+++ b/gsk/gl/gskglcommandqueue.c
@@ -675,9 +675,9 @@ gsk_gl_command_queue_split_draw (GskGLCommandQueue *self)
 }
 
 void
-gsk_gl_command_queue_clear (GskGLCommandQueue    *self,
-                             guint                  clear_bits,
-                             const graphene_rect_t *viewport)
+gsk_gl_command_queue_clear (GskGLCommandQueue     *self,
+                            guint                  clear_bits,
+                            const graphene_rect_t *viewport)
 {
   GskGLCommandBatch *batch;
 
@@ -750,11 +750,12 @@ static inline void
 apply_scissor (gboolean              *state,
                guint                  framebuffer,
                const graphene_rect_t *scissor,
-               gboolean               has_scissor)
+               gboolean               has_scissor,
+               guint                  default_framebuffer)
 {
   g_assert (framebuffer != (guint)-1);
 
-  if (framebuffer != 0 || !has_scissor)
+  if (framebuffer != default_framebuffer || !has_scissor)
     {
       if (*state != FALSE)
         {
@@ -953,6 +954,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
   guint width = 0;
   guint height = 0;
   G_GNUC_UNUSED guint n_binds = 0;
+  guint default_framebuffer;
   guint n_fbos = 0;
   G_GNUC_UNUSED guint n_uniforms = 0;
   guint n_programs = 0;
@@ -972,6 +974,8 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
   for (guint i = 0; i < G_N_ELEMENTS (textures); i++)
     textures[i] = -1;
 
+  default_framebuffer = self->context->default_framebuffer;
+
   gsk_gl_command_queue_sort_batches (self);
 
   gsk_gl_command_queue_make_current (self);
@@ -1049,7 +1053,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
         case GSK_GL_COMMAND_KIND_CLEAR:
           if (apply_framebuffer (&framebuffer, batch->clear.framebuffer))
             {
-              apply_scissor (&scissor_state, framebuffer, &scissor_test, has_scissor);
+              apply_scissor (&scissor_state, framebuffer, &scissor_test, has_scissor, default_framebuffer);
               n_fbos++;
             }
 
@@ -1073,7 +1077,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
 
           if (apply_framebuffer (&framebuffer, batch->draw.framebuffer))
             {
-              apply_scissor (&scissor_state, framebuffer, &scissor_test, has_scissor);
+              apply_scissor (&scissor_state, framebuffer, &scissor_test, has_scissor, default_framebuffer);
               n_fbos++;
             }
 
diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c
index 64ba0b6f69..d20c0819e9 100644
--- a/gsk/gl/gskglrenderer.c
+++ b/gsk/gl/gskglrenderer.c
@@ -199,6 +199,7 @@ gsk_gl_renderer_render (GskRenderer          *renderer,
   GskGLRenderJob *job;
   GdkSurface *surface;
   float scale_factor;
+  GLuint framebuffer_id;
 
   g_assert (GSK_IS_GL_RENDERER (renderer));
   g_assert (root != NULL);
@@ -221,7 +222,8 @@ gsk_gl_renderer_render (GskRenderer          *renderer,
   render_region = get_render_region (surface, self->context);
 
   gsk_gl_driver_begin_frame (self->driver, self->command_queue);
-  job = gsk_gl_render_job_new (self->driver, &viewport, scale_factor, render_region, 0);
+  framebuffer_id = self->context->default_framebuffer;
+  job = gsk_gl_render_job_new (self->driver, &viewport, scale_factor, render_region, framebuffer_id);
 #ifdef G_ENABLE_DEBUG
   if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), FALLBACK))
     gsk_gl_render_job_set_debug_fallback (job, TRUE);


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