kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

Blame SOURCES/0005-cogl-Allow-glBlitFramebuffer-between-onscreen-offscr.patch

5525bd
From e4b2234d9918e9d3357ac3c7ca3898599725d3da Mon Sep 17 00:00:00 2001
5525bd
From: Pekka Paalanen <pekka.paalanen@collabora.com>
5525bd
Date: Mon, 6 May 2019 15:08:29 +0300
5525bd
Subject: [PATCH 05/12] cogl: Allow glBlitFramebuffer between
5525bd
 onscreen/offscreen
5525bd
5525bd
Depends on "cogl: Replace ANGLE with GLES3 and NV framebuffer_blit"
5525bd
5525bd
Allow blitting between onscreen and offscreen framebuffers by doing the y-flip
5525bd
as necessary. This was not possible with ANGLE, but now with ANGLE gone,
5525bd
glBlitFramebuffer supports flipping the copied image.
5525bd
5525bd
This will be useful in follow-up work to copy from onscreen primary GPU
5525bd
framebuffer to an offscreen secondary GPU framebuffer.
5525bd
5525bd
https://gitlab.gnome.org/GNOME/mutter/merge_requests/615
5525bd
5525bd
(cherry picked from commit 45289b3d65e308117f1bc8fe6a4c88c1baaacca7)
5525bd
---
5525bd
 cogl/cogl/cogl-framebuffer-private.h      | 14 +++----
5525bd
 cogl/cogl/cogl-framebuffer.c              | 46 ++++++++++++++++++-----
5525bd
 cogl/cogl/driver/gl/cogl-framebuffer-gl.c |  5 +--
5525bd
 3 files changed, 43 insertions(+), 22 deletions(-)
5525bd
5525bd
diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h
5525bd
index b06fbaee1..f68153d8b 100644
5525bd
--- a/cogl/cogl/cogl-framebuffer-private.h
5525bd
+++ b/cogl/cogl/cogl-framebuffer-private.h
5525bd
@@ -381,7 +381,11 @@ _cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
5525bd
  * This blits a region of the color buffer of the source buffer
5525bd
  * to the destination buffer. This function should only be
5525bd
  * called if the COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT feature is
5525bd
- * advertised. The two buffers must both be offscreen.
5525bd
+ * advertised.
5525bd
+ *
5525bd
+ * The source and destination rectangles are defined in offscreen
5525bd
+ * framebuffer orientation. When copying between an offscreen and
5525bd
+ * onscreen framebuffers, the image is y-flipped accordingly.
5525bd
  *
5525bd
  * The two buffers must have the same value types (e.g. floating-point,
5525bd
  * unsigned int, signed int, or fixed-point), but color formats do not
5525bd
@@ -396,14 +400,6 @@ _cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
5525bd
  * scale the results it may make more sense to draw a primitive
5525bd
  * instead.
5525bd
  *
5525bd
- * We can only really support blitting between two offscreen buffers
5525bd
- * for this function on GLES2.0. This is because we effectively render
5525bd
- * upside down to offscreen buffers to maintain Cogl's representation
5525bd
- * of the texture coordinate system where 0,0 is the top left of the
5525bd
- * texture. If we were to blit from an offscreen to an onscreen buffer
5525bd
- * then we would need to mirror the blit along the x-axis but the GLES
5525bd
- * extension does not support this.
5525bd
- *
5525bd
  * The GL function is documented to be affected by the scissor. This
5525bd
  * function therefore ensure that an empty clip stack is flushed
5525bd
  * before performing the blit which means the scissor is effectively
5525bd
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
5525bd
index 0bc225945..90976a611 100644
5525bd
--- a/cogl/cogl/cogl-framebuffer.c
5525bd
+++ b/cogl/cogl/cogl-framebuffer.c
5525bd
@@ -1460,15 +1460,12 @@ _cogl_blit_framebuffer (CoglFramebuffer *src,
5525bd
                         int height)
5525bd
 {
5525bd
   CoglContext *ctx = src->context;
5525bd
+  int src_x1, src_y1, src_x2, src_y2;
5525bd
+  int dst_x1, dst_y1, dst_x2, dst_y2;
5525bd
 
5525bd
   _COGL_RETURN_IF_FAIL (_cogl_has_private_feature
5525bd
                         (ctx, COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT));
5525bd
 
5525bd
-  /* We can only support blitting between offscreen buffers because
5525bd
-     otherwise we would need to mirror the image and GLES2.0 doesn't
5525bd
-     support this */
5525bd
-  _COGL_RETURN_IF_FAIL (cogl_is_offscreen (src));
5525bd
-  _COGL_RETURN_IF_FAIL (cogl_is_offscreen (dest));
5525bd
   /* The buffers must use the same premult convention */
5525bd
   _COGL_RETURN_IF_FAIL ((src->internal_format & COGL_PREMULT_BIT) ==
5525bd
                         (dest->internal_format & COGL_PREMULT_BIT));
5525bd
@@ -1492,10 +1489,41 @@ _cogl_blit_framebuffer (CoglFramebuffer *src,
5525bd
    * as changed */
5525bd
   ctx->current_draw_buffer_changes |= COGL_FRAMEBUFFER_STATE_CLIP;
5525bd
 
5525bd
-  ctx->glBlitFramebuffer (src_x, src_y,
5525bd
-                          src_x + width, src_y + height,
5525bd
-                          dst_x, dst_y,
5525bd
-                          dst_x + width, dst_y + height,
5525bd
+  /* Offscreens we do the normal way, onscreens need an y-flip. Even if
5525bd
+   * we consider offscreens to be rendered upside-down, the offscreen
5525bd
+   * orientation is in this function's API. */
5525bd
+  if (cogl_is_offscreen (src))
5525bd
+    {
5525bd
+      src_x1 = src_x;
5525bd
+      src_y1 = src_y;
5525bd
+      src_x2 = src_x + width;
5525bd
+      src_y2 = src_y + height;
5525bd
+    }
5525bd
+  else
5525bd
+    {
5525bd
+      src_x1 = src_x;
5525bd
+      src_y1 = cogl_framebuffer_get_height (src) - src_y;
5525bd
+      src_x2 = src_x + width;
5525bd
+      src_y2 = src_y1 - height;
5525bd
+    }
5525bd
+
5525bd
+  if (cogl_is_offscreen (dest))
5525bd
+    {
5525bd
+      dst_x1 = dst_x;
5525bd
+      dst_y1 = dst_y;
5525bd
+      dst_x2 = dst_x + width;
5525bd
+      dst_y2 = dst_y + height;
5525bd
+    }
5525bd
+  else
5525bd
+    {
5525bd
+      dst_x1 = dst_x;
5525bd
+      dst_y1 = cogl_framebuffer_get_height (dest) - dst_y;
5525bd
+      dst_x2 = dst_x + width;
5525bd
+      dst_y2 = dst_y1 - height;
5525bd
+    }
5525bd
+
5525bd
+  ctx->glBlitFramebuffer (src_x1, src_y1, src_x2, src_y2,
5525bd
+                          dst_x1, dst_y1, dst_x2, dst_y2,
5525bd
                           GL_COLOR_BUFFER_BIT,
5525bd
                           GL_NEAREST);
5525bd
 }
5525bd
diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
5525bd
index 5402a7075..83e1d263a 100644
5525bd
--- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
5525bd
+++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
5525bd
@@ -400,12 +400,9 @@ _cogl_framebuffer_gl_flush_state (CoglFramebuffer *draw_buffer,
5525bd
       else
5525bd
         {
5525bd
           /* NB: Currently we only take advantage of binding separate
5525bd
-           * read/write buffers for offscreen framebuffer blit
5525bd
-           * purposes.  */
5525bd
+           * read/write buffers for framebuffer blit purposes. */
5525bd
           _COGL_RETURN_IF_FAIL (_cogl_has_private_feature
5525bd
                                 (ctx, COGL_PRIVATE_FEATURE_OFFSCREEN_BLIT));
5525bd
-          _COGL_RETURN_IF_FAIL (draw_buffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN);
5525bd
-          _COGL_RETURN_IF_FAIL (read_buffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN);
5525bd
 
5525bd
           _cogl_framebuffer_gl_bind (draw_buffer, GL_DRAW_FRAMEBUFFER);
5525bd
           _cogl_framebuffer_gl_bind (read_buffer, GL_READ_FRAMEBUFFER);
5525bd
-- 
5525bd
2.21.0
5525bd