Blame SOURCES/0007-cogl-Expose-cogl_blit_framebuffer.patch

1a3082
From be13d3c844a6623563ae4e74dbb3409baf16fc9c Mon Sep 17 00:00:00 2001
1a3082
From: Pekka Paalanen <pekka.paalanen@collabora.com>
1a3082
Date: Mon, 3 Dec 2018 14:34:41 +0200
1a3082
Subject: [PATCH 07/12] cogl: Expose cogl_blit_framebuffer
1a3082
1a3082
The function will be used in copying from a primary GPU framebuffer to a
1a3082
secondary GPU framebuffer using the primary GPU specifically when the
1a3082
secondary GPU is not render-capable.
1a3082
1a3082
To allow falling back in case glBlitFramebuffer cannot be used, add boolean
1a3082
return value, and GError argument for debugging purposes.
1a3082
1a3082
https://gitlab.gnome.org/GNOME/mutter/merge_requests/615
1a3082
(cherry picked from commit 6061abbf90cd1d62e262ebf3636470d2219e04a7)
1a3082
---
1a3082
 cogl/cogl/cogl-blit.c                | 11 ++---
1a3082
 cogl/cogl/cogl-framebuffer-private.h | 55 -----------------------
1a3082
 cogl/cogl/cogl-framebuffer.c         | 40 +++++++++++------
1a3082
 cogl/cogl/cogl-framebuffer.h         | 66 +++++++++++++++++++++++++++-
1a3082
 4 files changed, 98 insertions(+), 74 deletions(-)
1a3082
1a3082
diff --git a/cogl/cogl/cogl-blit.c b/cogl/cogl/cogl-blit.c
1a3082
index c561b2e45..ae5a8a345 100644
1a3082
--- a/cogl/cogl/cogl-blit.c
1a3082
+++ b/cogl/cogl/cogl-blit.c
1a3082
@@ -207,11 +207,12 @@ _cogl_blit_framebuffer_blit (CoglBlitData *data,
1a3082
                              int width,
1a3082
                              int height)
1a3082
 {
1a3082
-  _cogl_blit_framebuffer (data->src_fb,
1a3082
-                          data->dest_fb,
1a3082
-                          src_x, src_y,
1a3082
-                          dst_x, dst_y,
1a3082
-                          width, height);
1a3082
+  cogl_blit_framebuffer (data->src_fb,
1a3082
+                         data->dest_fb,
1a3082
+                         src_x, src_y,
1a3082
+                         dst_x, dst_y,
1a3082
+                         width, height,
1a3082
+                         NULL);
1a3082
 }
1a3082
 
1a3082
 static void
1a3082
diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h
1a3082
index cb1f87354..7d71fb1dc 100644
1a3082
--- a/cogl/cogl/cogl-framebuffer-private.h
1a3082
+++ b/cogl/cogl/cogl-framebuffer-private.h
1a3082
@@ -367,61 +367,6 @@ void
1a3082
 _cogl_push_framebuffers (CoglFramebuffer *draw_buffer,
1a3082
                          CoglFramebuffer *read_buffer);
1a3082
 
1a3082
-/*
1a3082
- * _cogl_blit_framebuffer:
1a3082
- * @src: The source #CoglFramebuffer
1a3082
- * @dest: The destination #CoglFramebuffer
1a3082
- * @src_x: Source x position
1a3082
- * @src_y: Source y position
1a3082
- * @dst_x: Destination x position
1a3082
- * @dst_y: Destination y position
1a3082
- * @width: Width of region to copy
1a3082
- * @height: Height of region to copy
1a3082
- *
1a3082
- * This blits a region of the color buffer of the source buffer
1a3082
- * to the destination buffer. This function should only be
1a3082
- * called if the COGL_PRIVATE_FEATURE_BLIT_FRAMEBUFFER feature is
1a3082
- * advertised.
1a3082
- *
1a3082
- * The source and destination rectangles are defined in offscreen
1a3082
- * framebuffer orientation. When copying between an offscreen and
1a3082
- * onscreen framebuffers, the image is y-flipped accordingly.
1a3082
- *
1a3082
- * The two buffers must have the same value types (e.g. floating-point,
1a3082
- * unsigned int, signed int, or fixed-point), but color formats do not
1a3082
- * need to match. This limitation comes from OpenGL ES 3.0 definition
1a3082
- * of glBlitFramebuffer.
1a3082
- *
1a3082
- * Note that this function differs a lot from the glBlitFramebuffer
1a3082
- * function provided by the GL_EXT_framebuffer_blit extension. Notably
1a3082
- * it doesn't support having different sizes for the source and
1a3082
- * destination rectangle. This doesn't seem
1a3082
- * like a particularly useful feature. If the application wanted to
1a3082
- * scale the results it may make more sense to draw a primitive
1a3082
- * instead.
1a3082
- *
1a3082
- * The GL function is documented to be affected by the scissor. This
1a3082
- * function therefore ensure that an empty clip stack is flushed
1a3082
- * before performing the blit which means the scissor is effectively
1a3082
- * ignored.
1a3082
- *
1a3082
- * The function also doesn't support specifying the buffers to copy
1a3082
- * and instead only the color buffer is copied. When copying the depth
1a3082
- * or stencil buffers the extension on GLES2.0 only supports copying
1a3082
- * the full buffer which would be awkward to document with this
1a3082
- * API. If we wanted to support that feature it may be better to have
1a3082
- * a separate function to copy the entire buffer for a given mask.
1a3082
- */
1a3082
-void
1a3082
-_cogl_blit_framebuffer (CoglFramebuffer *src,
1a3082
-                        CoglFramebuffer *dest,
1a3082
-                        int src_x,
1a3082
-                        int src_y,
1a3082
-                        int dst_x,
1a3082
-                        int dst_y,
1a3082
-                        int width,
1a3082
-                        int height);
1a3082
-
1a3082
 void
1a3082
 _cogl_framebuffer_push_projection (CoglFramebuffer *framebuffer);
1a3082
 
1a3082
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
1a3082
index 5cc4eada4..6d35c6b13 100644
1a3082
--- a/cogl/cogl/cogl-framebuffer.c
1a3082
+++ b/cogl/cogl/cogl-framebuffer.c
1a3082
@@ -1449,26 +1449,38 @@ cogl_framebuffer_read_pixels (CoglFramebuffer *framebuffer,
1a3082
   return ret;
1a3082
 }
1a3082
 
1a3082
-void
1a3082
-_cogl_blit_framebuffer (CoglFramebuffer *src,
1a3082
-                        CoglFramebuffer *dest,
1a3082
-                        int src_x,
1a3082
-                        int src_y,
1a3082
-                        int dst_x,
1a3082
-                        int dst_y,
1a3082
-                        int width,
1a3082
-                        int height)
1a3082
+gboolean
1a3082
+cogl_blit_framebuffer (CoglFramebuffer *src,
1a3082
+                       CoglFramebuffer *dest,
1a3082
+                       int src_x,
1a3082
+                       int src_y,
1a3082
+                       int dst_x,
1a3082
+                       int dst_y,
1a3082
+                       int width,
1a3082
+                       int height,
1a3082
+                       GError **error)
1a3082
 {
1a3082
   CoglContext *ctx = src->context;
1a3082
   int src_x1, src_y1, src_x2, src_y2;
1a3082
   int dst_x1, dst_y1, dst_x2, dst_y2;
1a3082
 
1a3082
-  _COGL_RETURN_IF_FAIL (_cogl_has_private_feature
1a3082
-                        (ctx, COGL_PRIVATE_FEATURE_BLIT_FRAMEBUFFER));
1a3082
+  if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_BLIT_FRAMEBUFFER))
1a3082
+    {
1a3082
+      g_set_error_literal (error, COGL_SYSTEM_ERROR,
1a3082
+                           COGL_SYSTEM_ERROR_UNSUPPORTED,
1a3082
+                           "Cogl BLIT_FRAMEBUFFER is not supported by the system.");
1a3082
+      return FALSE;
1a3082
+    }
1a3082
 
1a3082
   /* The buffers must use the same premult convention */
1a3082
-  _COGL_RETURN_IF_FAIL ((src->internal_format & COGL_PREMULT_BIT) ==
1a3082
-                        (dest->internal_format & COGL_PREMULT_BIT));
1a3082
+  if ((src->internal_format & COGL_PREMULT_BIT) !=
1a3082
+      (dest->internal_format & COGL_PREMULT_BIT))
1a3082
+    {
1a3082
+      g_set_error_literal (error, COGL_SYSTEM_ERROR,
1a3082
+                           COGL_SYSTEM_ERROR_UNSUPPORTED,
1a3082
+                           "cogl_blit_framebuffer premult mismatch.");
1a3082
+      return FALSE;
1a3082
+    }
1a3082
 
1a3082
   /* Make sure the current framebuffers are bound. We explicitly avoid
1a3082
      flushing the clip state so we can bind our own empty state */
1a3082
@@ -1526,6 +1538,8 @@ _cogl_blit_framebuffer (CoglFramebuffer *src,
1a3082
                           dst_x1, dst_y1, dst_x2, dst_y2,
1a3082
                           GL_COLOR_BUFFER_BIT,
1a3082
                           GL_NEAREST);
1a3082
+
1a3082
+  return TRUE;
1a3082
 }
1a3082
 
1a3082
 void
1a3082
diff --git a/cogl/cogl/cogl-framebuffer.h b/cogl/cogl/cogl-framebuffer.h
1a3082
index 48a77e1ed..230a78627 100644
1a3082
--- a/cogl/cogl/cogl-framebuffer.h
1a3082
+++ b/cogl/cogl/cogl-framebuffer.h
1a3082
@@ -3,7 +3,8 @@
1a3082
  *
1a3082
  * A Low Level GPU Graphics and Utilities API
1a3082
  *
1a3082
- * Copyright (C) 2011 Intel Corporation.
1a3082
+ * Copyright (C) 2007,2008,2009,2011 Intel Corporation.
1a3082
+ * Copyright (C) 2019 DisplayLink (UK) Ltd.
1a3082
  *
1a3082
  * Permission is hereby granted, free of charge, to any person
1a3082
  * obtaining a copy of this software and associated documentation
1a3082
@@ -1846,6 +1847,69 @@ typedef enum /*< prefix=COGL_FRAMEBUFFER_ERROR >*/
1a3082
 gboolean
1a3082
 cogl_is_framebuffer (void *object);
1a3082
 
1a3082
+/**
1a3082
+ * cogl_blit_framebuffer:
1a3082
+ * @src: The source #CoglFramebuffer
1a3082
+ * @dest: The destination #CoglFramebuffer
1a3082
+ * @src_x: Source x position
1a3082
+ * @src_y: Source y position
1a3082
+ * @dst_x: Destination x position
1a3082
+ * @dst_y: Destination y position
1a3082
+ * @width: Width of region to copy
1a3082
+ * @height: Height of region to copy
1a3082
+ * @error: optional error object
1a3082
+ *
1a3082
+ * @return FALSE for an immediately detected error, TRUE otherwise.
1a3082
+ *
1a3082
+ * This blits a region of the color buffer of the source buffer
1a3082
+ * to the destination buffer. This function should only be
1a3082
+ * called if the COGL_PRIVATE_FEATURE_BLIT_FRAMEBUFFER feature is
1a3082
+ * advertised.
1a3082
+ *
1a3082
+ * The source and destination rectangles are defined in offscreen
1a3082
+ * framebuffer orientation. When copying between an offscreen and
1a3082
+ * onscreen framebuffers, the image is y-flipped accordingly.
1a3082
+ *
1a3082
+ * The two buffers must have the same value types (e.g. floating-point,
1a3082
+ * unsigned int, signed int, or fixed-point), but color formats do not
1a3082
+ * need to match. This limitation comes from OpenGL ES 3.0 definition
1a3082
+ * of glBlitFramebuffer.
1a3082
+ *
1a3082
+ * Note that this function differs a lot from the glBlitFramebuffer
1a3082
+ * function provided by the GL_EXT_framebuffer_blit extension. Notably
1a3082
+ * it doesn't support having different sizes for the source and
1a3082
+ * destination rectangle. This doesn't seem
1a3082
+ * like a particularly useful feature. If the application wanted to
1a3082
+ * scale the results it may make more sense to draw a primitive
1a3082
+ * instead.
1a3082
+ *
1a3082
+ * The GL function is documented to be affected by the scissor. This
1a3082
+ * function therefore ensure that an empty clip stack is flushed
1a3082
+ * before performing the blit which means the scissor is effectively
1a3082
+ * ignored.
1a3082
+ *
1a3082
+ * The function also doesn't support specifying the buffers to copy
1a3082
+ * and instead only the color buffer is copied. When copying the depth
1a3082
+ * or stencil buffers the extension on GLES2.0 only supports copying
1a3082
+ * the full buffer which would be awkward to document with this
1a3082
+ * API. If we wanted to support that feature it may be better to have
1a3082
+ * a separate function to copy the entire buffer for a given mask.
1a3082
+ *
1a3082
+ * The @c error argument is optional, it can be NULL. If it is not NULL
1a3082
+ * and this function returns FALSE, an error object with a code from
1a3082
+ * COGL_SYSTEM_ERROR will be created.
1a3082
+ */
1a3082
+gboolean
1a3082
+cogl_blit_framebuffer (CoglFramebuffer *src,
1a3082
+                       CoglFramebuffer *dest,
1a3082
+                       int src_x,
1a3082
+                       int src_y,
1a3082
+                       int dst_x,
1a3082
+                       int dst_y,
1a3082
+                       int width,
1a3082
+                       int height,
1a3082
+                       GError **error);
1a3082
+
1a3082
 G_END_DECLS
1a3082
 
1a3082
 #endif /* __COGL_FRAMEBUFFER_H */
1a3082
-- 
1a3082
2.21.0
1a3082