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