[gtk/matthiasc/color-profiles: 103/111] ngl: Refactor a bit
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profiles: 103/111] ngl: Refactor a bit
- Date: Wed, 6 Oct 2021 06:20:01 +0000 (UTC)
commit 72ac0d02887ae07b8e3a3090b0cc2bf7a11fc61b
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 2393c29f75..19e58200a0 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -784,6 +784,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`
@@ -828,8 +873,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)))
{
@@ -855,54 +899,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;
}
}
}
@@ -913,8 +921,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]