[gtk/wip/chergert/glproto: 370/526] flip y when drawing framebuffers from command queue




commit 809eeecb09a63daad9df4be51de45fd3ba0b5330
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 29 13:21:18 2021 -0800

    flip y when drawing framebuffers from command queue
    
    when we are debugging, its a lot nicer to see the offscreen data shown
    in a format that we can reason about without turning the laptop upside
    down.

 gsk/next/gskglcommandqueue.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index f2c2787abd..62cc056036 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -169,10 +169,11 @@ static inline void
 gsk_gl_command_queue_capture_png (GskGLCommandQueue *self,
                                   const char        *filename,
                                   guint              width,
-                                  guint              height)
+                                  guint              height,
+                                  gboolean           flip_y)
 {
   cairo_surface_t *surface;
-  gpointer data;
+  guint8 *data;
   guint stride;
 
   g_assert (GSK_IS_GL_COMMAND_QUEUE (self));
@@ -182,6 +183,20 @@ gsk_gl_command_queue_capture_png (GskGLCommandQueue *self,
   data = g_malloc_n (height, stride);
 
   glReadPixels (0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data);
+
+  if (flip_y)
+    {
+      guint8 *flipped = g_malloc_n (height, stride);
+
+      for (guint i = 0; i < height; i++)
+        memcpy (flipped + (height * stride) - ((i + 1) * stride),
+                data + (stride * i),
+                stride);
+
+      g_free (data);
+      data = flipped;
+    }
+
   surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, width, height, stride);
   cairo_surface_write_to_png (surface, filename);
 
@@ -870,7 +885,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue    *self,
                       batch->any.kind, batch->any.program,
                       batch->any.kind == GSK_GL_COMMAND_KIND_DRAW ? batch->draw.uniform_count : 0,
                       batch->any.kind == GSK_GL_COMMAND_KIND_DRAW ? batch->draw.bind_count : 0);
-          gsk_gl_command_queue_capture_png (self, filename, width, height);
+          gsk_gl_command_queue_capture_png (self, filename, width, height, TRUE);
         }
 #endif
 


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