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