[mutter] cogl/framebuffer/gl: Move OpenGL driver fields to private struct
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] cogl/framebuffer/gl: Move OpenGL driver fields to private struct
- Date: Fri, 16 Oct 2020 16:25:59 +0000 (UTC)
commit 209b78afd8834bd5c9e91a778bfc31bef6f33d39
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Mon Oct 12 23:29:11 2020 +0200
cogl/framebuffer/gl: Move OpenGL driver fields to private struct
It's driver specific, so it shouldn't be kept in the generic data
structure.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
cogl/cogl/cogl-framebuffer-private.h | 15 +++++--
cogl/cogl/cogl-framebuffer.c | 24 ++++++++++-
cogl/cogl/driver/gl/cogl-framebuffer-gl.c | 67 ++++++++++++++++++++++---------
3 files changed, 81 insertions(+), 25 deletions(-)
---
diff --git a/cogl/cogl/cogl-framebuffer-private.h b/cogl/cogl/cogl-framebuffer-private.h
index 49df3055ad..4250897a6a 100644
--- a/cogl/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl/cogl-framebuffer-private.h
@@ -173,16 +173,15 @@ struct _CoglFramebuffer
int clear_clip_y1;
gboolean clear_clip_dirty;
- /* driver specific */
- gboolean dirty_bitmasks;
- CoglFramebufferBits bits;
-
int samples_per_pixel;
/* Whether the depth buffer was enabled for this framebuffer,
* usually means it needs to be cleared before being reused next.
*/
gboolean depth_buffer_clear_needed;
+
+ gpointer driver_private;
+ GDestroyNotify driver_private_destroy;
};
typedef enum
@@ -398,4 +397,12 @@ _cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
COGL_EXPORT int
_cogl_framebuffer_get_stencil_bits (CoglFramebuffer *framebuffer);
+gpointer
+cogl_framebuffer_get_driver_private (CoglFramebuffer *framebuffer);
+
+void
+cogl_framebuffer_set_driver_private (CoglFramebuffer *framebuffer,
+ gpointer driver_private,
+ GDestroyNotify desrtoy_notify);
+
#endif /* __COGL_FRAMEBUFFER_PRIVATE_H */
diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c
index 8a984972bb..32b0240cdb 100644
--- a/cogl/cogl/cogl-framebuffer.c
+++ b/cogl/cogl/cogl-framebuffer.c
@@ -118,8 +118,6 @@ _cogl_framebuffer_init (CoglFramebuffer *framebuffer,
framebuffer->modelview_stack = cogl_matrix_stack_new (ctx);
framebuffer->projection_stack = cogl_matrix_stack_new (ctx);
- framebuffer->dirty_bitmasks = TRUE;
-
framebuffer->samples_per_pixel = 0;
framebuffer->clip_stack = NULL;
@@ -192,6 +190,11 @@ _cogl_framebuffer_free (CoglFramebuffer *framebuffer)
ctx->current_draw_buffer = NULL;
if (ctx->current_read_buffer == framebuffer)
ctx->current_read_buffer = NULL;
+
+ if (framebuffer->driver_private_destroy)
+ framebuffer->driver_private_destroy (framebuffer->driver_private);
+ framebuffer->driver_private_destroy = NULL;
+ framebuffer->driver_private = NULL;
}
const CoglWinsysVtable *
@@ -2280,3 +2283,20 @@ cogl_framebuffer_draw_textured_rectangles (CoglFramebuffer *framebuffer,
rects,
n_rectangles);
}
+
+gpointer
+cogl_framebuffer_get_driver_private (CoglFramebuffer *framebuffer)
+{
+ return framebuffer->driver_private;
+}
+
+void
+cogl_framebuffer_set_driver_private (CoglFramebuffer *framebuffer,
+ gpointer driver_private,
+ GDestroyNotify destroy_notify)
+{
+ g_warn_if_fail (!framebuffer->driver_private);
+
+ framebuffer->driver_private = driver_private;
+ framebuffer->driver_private_destroy = destroy_notify;
+}
diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
index 520beaf17e..82a6af4cf9 100644
--- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -126,6 +126,11 @@
#define GL_STENCIL 0x1802
#endif
+typedef struct _CoglFramebufferGl
+{
+ gboolean dirty_bitmasks;
+ CoglFramebufferBits bits;
+} CoglFramebufferGl;
static void
_cogl_framebuffer_gl_flush_viewport_state (CoglFramebuffer *framebuffer)
@@ -921,12 +926,33 @@ _cogl_framebuffer_gl_clear (CoglFramebuffer *framebuffer,
GE (ctx, glClear (gl_buffers));
}
+static CoglFramebufferGl *
+ensure_framebuffer_gl (CoglFramebuffer *framebuffer)
+{
+ CoglFramebufferGl *framebuffer_gl;
+
+ framebuffer_gl = cogl_framebuffer_get_driver_private (framebuffer);
+ if (!framebuffer_gl)
+ {
+ framebuffer_gl = g_new0 (CoglFramebufferGl, 1);
+ cogl_framebuffer_set_driver_private (framebuffer,
+ framebuffer_gl,
+ g_free);
+ framebuffer_gl->dirty_bitmasks = TRUE;
+ }
+
+ return framebuffer_gl;
+}
+
static inline void
_cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
{
CoglContext *ctx = framebuffer->context;
+ CoglFramebufferGl *framebuffer_gl;
- if (G_LIKELY (!framebuffer->dirty_bitmasks))
+ framebuffer_gl = ensure_framebuffer_gl (framebuffer);
+
+ if (!framebuffer_gl->dirty_bitmasks)
return;
cogl_framebuffer_allocate (framebuffer, NULL);
@@ -970,7 +996,7 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
for (i = 0; i < G_N_ELEMENTS (params); i++)
{
int *value =
- (int *) ((uint8_t *) &framebuffer->bits + params[i].offset);
+ (int *) ((uint8_t *) &framebuffer_gl->bits + params[i].offset);
GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
params[i].attachment,
params[i].pname,
@@ -980,12 +1006,12 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
else
#endif /* HAVE_COGL_GL */
{
- GE( ctx, glGetIntegerv (GL_RED_BITS, &framebuffer->bits.red) );
- GE( ctx, glGetIntegerv (GL_GREEN_BITS, &framebuffer->bits.green) );
- GE( ctx, glGetIntegerv (GL_BLUE_BITS, &framebuffer->bits.blue) );
- GE( ctx, glGetIntegerv (GL_ALPHA_BITS, &framebuffer->bits.alpha) );
- GE( ctx, glGetIntegerv (GL_DEPTH_BITS, &framebuffer->bits.depth) );
- GE( ctx, glGetIntegerv (GL_STENCIL_BITS, &framebuffer->bits.stencil) );
+ GE( ctx, glGetIntegerv (GL_RED_BITS, &framebuffer_gl->bits.red) );
+ GE( ctx, glGetIntegerv (GL_GREEN_BITS, &framebuffer_gl->bits.green) );
+ GE( ctx, glGetIntegerv (GL_BLUE_BITS, &framebuffer_gl->bits.blue) );
+ GE( ctx, glGetIntegerv (GL_ALPHA_BITS, &framebuffer_gl->bits.alpha) );
+ GE( ctx, glGetIntegerv (GL_DEPTH_BITS, &framebuffer_gl->bits.depth) );
+ GE( ctx, glGetIntegerv (GL_STENCIL_BITS, &framebuffer_gl->bits.stencil) );
}
/* If we don't have alpha textures then the alpha bits are actually
@@ -994,8 +1020,8 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN &&
framebuffer->internal_format == COGL_PIXEL_FORMAT_A_8)
{
- framebuffer->bits.alpha = framebuffer->bits.red;
- framebuffer->bits.red = 0;
+ framebuffer_gl->bits.alpha = framebuffer_gl->bits.red;
+ framebuffer_gl->bits.red = 0;
}
COGL_NOTE (OFFSCREEN,
@@ -1004,25 +1030,28 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN
? "offscreen"
: "onscreen",
- framebuffer->bits.red,
- framebuffer->bits.blue,
- framebuffer->bits.green,
- framebuffer->bits.alpha,
- framebuffer->bits.depth,
- framebuffer->bits.stencil);
-
- framebuffer->dirty_bitmasks = FALSE;
+ framebuffer_gl->bits.red,
+ framebuffer_gl->bits.blue,
+ framebuffer_gl->bits.green,
+ framebuffer_gl->bits.alpha,
+ framebuffer_gl->bits.depth,
+ framebuffer_gl->bits.stencil);
+
+ framebuffer_gl->dirty_bitmasks = FALSE;
}
void
_cogl_framebuffer_gl_query_bits (CoglFramebuffer *framebuffer,
CoglFramebufferBits *bits)
{
+ CoglFramebufferGl *framebuffer_gl;
+
_cogl_framebuffer_init_bits (framebuffer);
/* TODO: cache these in some driver specific location not
* directly as part of CoglFramebuffer. */
- *bits = framebuffer->bits;
+ framebuffer_gl = ensure_framebuffer_gl (framebuffer);
+ *bits = framebuffer_gl->bits;
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]