[gtk/matthiasc/color-profile-rebased: 11/22] gsk: Support flipping gl textures




commit dbc2dfd454be6dff82e70660c0c4233cccf7511c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 8 14:47:45 2022 -0400

    gsk: Support flipping gl textures
    
    Add upside-down flipping to the list of supported
    conversions when handling GL textures.

 gsk/gl/gskglcommandqueueprivate.h |  1 +
 gsk/gl/gskgldriver.c              | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/gsk/gl/gskglcommandqueueprivate.h b/gsk/gl/gskglcommandqueueprivate.h
index a6ffc9f96d..5014806ca0 100644
--- a/gsk/gl/gskglcommandqueueprivate.h
+++ b/gsk/gl/gskglcommandqueueprivate.h
@@ -284,6 +284,7 @@ void                gsk_gl_command_queue_execute              (GskGLCommandQueue
 typedef enum {
   GSK_CONVERSION_LINEARIZE   = 1 << 0,
   GSK_CONVERSION_PREMULTIPLY = 1 << 1,
+  GSK_CONVERSION_FLIP        = 1 << 2,
 } GskConversion;
 
 int                 gsk_gl_command_queue_upload_texture       (GskGLCommandQueue    *self,
diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c
index d631f81f4c..51f367fb61 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -691,17 +691,18 @@ gsk_gl_driver_cache_texture (GskGLDriver         *self,
 }
 
 static void
-draw_offscreen (GskGLCommandQueue *command_queue,
-                float              min_x,
-                float              min_y,
-                float              max_x,
-                float              max_y)
+draw_rect (GskGLCommandQueue *command_queue,
+           float              min_x,
+           float              min_y,
+           float              max_x,
+           float              max_y,
+           gboolean           flip)
 {
   GskGLDrawVertex *vertices = gsk_gl_command_queue_add_vertices (command_queue);
   float min_u = 0;
-  float min_v = 1;
   float max_u = 1;
-  float max_v = 0;
+  float min_v = flip ? 0 : 1;
+  float max_v = flip ? 1 : 0;
   guint16 c = FP16_ZERO;
 
   vertices[0] = (GskGLDrawVertex) { .position = { min_x, min_y }, .uv = { min_u, min_v }, .color = { c, c, 
c, c } };
@@ -778,7 +779,7 @@ gsk_gl_driver_convert_texture (GskGLDriver   *self,
   int prev_fbo;
   GskGLProgram *program;
 
-  if (conversion == (GSK_CONVERSION_LINEARIZE | GSK_CONVERSION_PREMULTIPLY))
+  if ((conversion & (GSK_CONVERSION_LINEARIZE | GSK_CONVERSION_PREMULTIPLY)) == (GSK_CONVERSION_LINEARIZE | 
GSK_CONVERSION_PREMULTIPLY))
     program = self->linearize_premultiply_no_clip;
   else if (conversion & GSK_CONVERSION_LINEARIZE)
     program = self->linearize_no_clip;
@@ -810,7 +811,7 @@ gsk_gl_driver_convert_texture (GskGLDriver   *self,
                                       UNIFORM_SHARED_SOURCE, 0,
                                       GL_TEXTURE_2D, GL_TEXTURE0, texture_id);
 
-  draw_offscreen (self->command_queue, 0, 0, width, height);
+  draw_rect (self->command_queue, 0, 0, width, height, (conversion & GSK_CONVERSION_FLIP) != 0);
 
   gsk_gl_command_queue_end_draw (self->command_queue);
 


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