cogl: Add context_{,de}init hooks to CoglDriverVtable

There's quite a bit of CoglContext that properly belongs to the driver.
Add some hooks to allow the context to create/destroy such state. We
don't have driver-private storage in the CoglContext yet, though we
probably should.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/973
This commit is contained in:
Adam Jackson 2019-10-18 16:44:43 -04:00 committed by Georges Basile Stavracas Neto
parent a46fd33460
commit f9599b64d0
6 changed files with 59 additions and 0 deletions

View File

@ -104,6 +104,12 @@ _cogl_context_get_winsys (CoglContext *context)
return context->display->renderer->winsys_vtable; return context->display->renderer->winsys_vtable;
} }
static const CoglDriverVtable *
_cogl_context_get_driver (CoglContext *context)
{
return context->driver_vtable;
}
/* For reference: There was some deliberation over whether to have a /* For reference: There was some deliberation over whether to have a
* constructor that could throw an exception but looking at standard * constructor that could throw an exception but looking at standard
* practices with several high level OO languages including python, C++, * practices with several high level OO languages including python, C++,
@ -207,6 +213,13 @@ cogl_context_new (CoglDisplay *display,
return NULL; return NULL;
} }
if (!context->driver_vtable->context_init (context, error))
{
cogl_object_unref (display);
g_free (context);
return NULL;
}
context->attribute_name_states_hash = context->attribute_name_states_hash =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
context->attribute_name_index_map = NULL; context->attribute_name_index_map = NULL;
@ -393,6 +406,7 @@ static void
_cogl_context_free (CoglContext *context) _cogl_context_free (CoglContext *context)
{ {
const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context); const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
const CoglDriverVtable *driver = _cogl_context_get_driver (context);
winsys->context_deinit (context); winsys->context_deinit (context);
@ -474,6 +488,8 @@ _cogl_context_free (CoglContext *context)
g_byte_array_free (context->buffer_map_fallback_array, TRUE); g_byte_array_free (context->buffer_map_fallback_array, TRUE);
driver->context_deinit (context);
cogl_object_unref (context->display); cogl_object_unref (context->display);
g_free (context); g_free (context);

View File

@ -40,6 +40,12 @@ typedef struct _CoglDriverVtable CoglDriverVtable;
struct _CoglDriverVtable struct _CoglDriverVtable
{ {
gboolean
(* context_init) (CoglContext *context, GError **error);
void
(* context_deinit) (CoglContext *context);
/* TODO: factor this out since this is OpenGL specific and /* TODO: factor this out since this is OpenGL specific and
* so can be ignored by non-OpenGL drivers. */ * so can be ignored by non-OpenGL drivers. */
gboolean gboolean

View File

@ -76,6 +76,13 @@ _cogl_gl_error_to_string (GLenum error_code);
#endif /* COGL_GL_DEBUG */ #endif /* COGL_GL_DEBUG */
gboolean
_cogl_driver_gl_context_init (CoglContext *context,
GError **error);
void
_cogl_driver_gl_context_deinit (CoglContext *context);
GLenum GLenum
_cogl_gl_util_get_error (CoglContext *ctx); _cogl_gl_util_get_error (CoglContext *ctx);

View File

@ -43,6 +43,18 @@
#include "driver/gl/cogl-clip-stack-gl-private.h" #include "driver/gl/cogl-clip-stack-gl-private.h"
#include "driver/gl/cogl-buffer-gl-private.h" #include "driver/gl/cogl-buffer-gl-private.h"
gboolean
_cogl_driver_gl_context_init (CoglContext *context,
GError **error)
{
return TRUE;
}
void
_cogl_driver_gl_context_deinit (CoglContext *context)
{
}
static gboolean static gboolean
_cogl_driver_pixel_format_from_gl_internal (CoglContext *context, _cogl_driver_pixel_format_from_gl_internal (CoglContext *context,
GLenum gl_int_format, GLenum gl_int_format,
@ -499,6 +511,8 @@ _cogl_driver_update_features (CoglContext *ctx,
const CoglDriverVtable const CoglDriverVtable
_cogl_driver_gl = _cogl_driver_gl =
{ {
_cogl_driver_gl_context_init,
_cogl_driver_gl_context_deinit,
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features, _cogl_driver_update_features,

View File

@ -378,6 +378,8 @@ _cogl_driver_texture_2d_is_get_data_supported (CoglTexture2D *tex_2d)
const CoglDriverVtable const CoglDriverVtable
_cogl_driver_gles = _cogl_driver_gles =
{ {
_cogl_driver_gl_context_init,
_cogl_driver_gl_context_deinit,
_cogl_driver_pixel_format_from_gl_internal, _cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl, _cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features, _cogl_driver_update_features,

View File

@ -52,9 +52,23 @@ _cogl_driver_update_features (CoglContext *ctx,
return TRUE; return TRUE;
} }
static gboolean
_cogl_driver_nop_context_init( CoglContext *context,
GError **error)
{
return TRUE;
}
static void
_cogl_driver_nop_context_deinit (CoglContext *context)
{
}
const CoglDriverVtable const CoglDriverVtable
_cogl_driver_nop = _cogl_driver_nop =
{ {
_cogl_driver_nop_context_init,
_cogl_driver_nop_context_deinit,
NULL, /* pixel_format_from_gl_internal */ NULL, /* pixel_format_from_gl_internal */
NULL, /* pixel_format_to_gl */ NULL, /* pixel_format_to_gl */
_cogl_driver_update_features, _cogl_driver_update_features,