[gtk/matthiasc/color-profiles: 135/140] ngl: Refactor a bit




commit 906674ed19d25d99c7da9dbc9e7f49281ffa76f4
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 2 00:07:13 2021 -0400

    ngl: Refactor a bit
    
    Break out a convert_texture routine that will
    be reused in the future.

 gsk/ngl/gskngldriver.c | 94 +++++++++++++++++++++++++++-----------------------
 1 file changed, 50 insertions(+), 44 deletions(-)
---
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index 721705ffab..993dad11a8 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -775,6 +775,51 @@ reset_modelview (GskNglProgram *program)
                                     &modelview);
 }
 
+static GskNglTexture *
+gsk_ngl_driver_convert_texture (GskNglDriver *self,
+                                int           texture_id,
+                                int           width,
+                                int           height,
+                                int           format)
+{
+  GskNglRenderTarget *target;
+  int prev_fbo;
+  GskNglProgram *program = self->linearize_no_clip;
+
+  gdk_gl_context_make_current (self->command_queue->context);
+
+  gsk_ngl_driver_create_render_target (self,
+                                       width, height,
+                                       format,
+                                       GL_LINEAR, GL_LINEAR,
+                                       &target);
+
+  prev_fbo = gsk_ngl_command_queue_bind_framebuffer (self->command_queue, target->framebuffer_id);
+  gsk_ngl_command_queue_clear (self->command_queue, 0, &GRAPHENE_RECT_INIT (0, 0, width, height));
+
+  gsk_ngl_command_queue_begin_draw (self->command_queue,
+                                    program->program_info,
+                                    width, height);
+
+  set_projection_for_size (program, width, height);
+  set_viewport_for_size (program, width, height);
+  reset_modelview (program);
+
+  gsk_ngl_program_set_uniform_texture (program,
+                                       UNIFORM_SHARED_SOURCE, 0,
+                                       GL_TEXTURE_2D, GL_TEXTURE0, texture_id);
+
+  draw_offscreen (self->command_queue, 0, 0, width, height);
+
+  gsk_ngl_command_queue_end_draw (self->command_queue);
+
+  gsk_ngl_command_queue_bind_framebuffer (self->command_queue, prev_fbo);
+
+  texture_id = gsk_ngl_driver_release_render_target (self, target, FALSE);
+
+  return g_hash_table_lookup (self->textures, GUINT_TO_POINTER (texture_id));
+}
+
 /**
  * gsk_ngl_driver_load_texture:
  * @self: a `GdkTexture`
@@ -819,8 +864,7 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
   context = self->command_queue->context;
   width = gdk_texture_get_width (texture);
   height = gdk_texture_get_height (texture);
-
-  format = GL_RGBA8;
+  format = gdk_texture_is_hdr (texture) ? GL_RGBA16F : GL_RGBA8;
 
   if ((t = gdk_texture_get_render_data (texture, self)))
     {
@@ -846,54 +890,18 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
             }
           else
             {
-              GskNglRenderTarget *target;
-              guint prev_fbo;
-
               /* The GL texture isn't linear sRGB, so we need to convert
                * it before we can use it. For now, we just assume that it
                * is nonlinear sRGB. Eventually, we should figure out how
                * to convert from other color spaces to linear sRGB
                */
-              gdk_gl_context_make_current (context);
-
-              gsk_ngl_driver_create_render_target (self,
-                                                   width, height,
-                                                   format,
-                                                   min_filter, mag_filter,
-                                                   &target);
-
-              prev_fbo = gsk_ngl_command_queue_bind_framebuffer (self->command_queue, 
target->framebuffer_id);
-              gsk_ngl_command_queue_clear (self->command_queue, 0, &GRAPHENE_RECT_INIT (0, 0, width, 
height));
-
-              gsk_ngl_command_queue_begin_draw (self->command_queue,
-                                                self->linearize_no_clip->program_info,
-                                                width, height);
-
-              set_projection_for_size (self->linearize_no_clip, width, height);
-              set_viewport_for_size (self->linearize_no_clip, width, height);
-              reset_modelview (self->linearize_no_clip);
 
-              gsk_ngl_program_set_uniform_texture (self->linearize_no_clip,
-                                                   UNIFORM_SHARED_SOURCE, 0,
-                                                   GL_TEXTURE_2D, GL_TEXTURE0, gl_texture_id);
-              draw_offscreen (self->command_queue, 0, 0, width, height);
+              t = gsk_ngl_driver_convert_texture (self, gl_texture_id, width, height, format);
 
-              gsk_ngl_command_queue_end_draw (self->command_queue);
+              if (gdk_texture_set_render_data (texture, self, t, (GDestroyNotify)gsk_ngl_texture_destroyed))
+                t->user = texture;
 
-              gsk_ngl_command_queue_bind_framebuffer (self->command_queue, prev_fbo);
-
-              texture_id = gsk_ngl_driver_release_render_target (self, target, FALSE);
-
-              t = gsk_ngl_texture_new (texture_id,
-                                       width, height, format, min_filter, mag_filter,
-                                       self->current_frame_id);
-
-              /* Use gsk_ngl_texture_free() as destroy notify here since we are
-               * not inserting this GskNglTexture into self->textures!
-               */
-              gdk_texture_set_render_data (texture, self, t, (GDestroyNotify)gsk_ngl_texture_free);
-
-              return texture_id;
+              return t->texture_id;
             }
         }
     }
@@ -904,8 +912,6 @@ gsk_ngl_driver_load_texture (GskNglDriver *self,
    * the right context is at work again. */
   gdk_gl_context_make_current (context);
 
-  width = gdk_texture_get_width (texture);
-  height = gdk_texture_get_height (texture);
   texture_id = gsk_ngl_command_queue_upload_texture (self->command_queue,
                                                      downloaded_texture,
                                                      0,


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