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




commit 2b99f80e55087f445dbb881cf6ea0f028dd56290
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 4257166aec..98f93ad3d4 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -686,17 +686,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[4] = { FP16_ZERO, FP16_ZERO, FP16_ZERO, FP16_ZERO };
 
   vertices[0] = (GskGLDrawVertex) { .position = { min_x, min_y }, .uv = { min_u, min_v }, .color = { c[0], 
c[1], c[2
@@ -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]