Commit f9599b64 authored by Adam Jackson's avatar Adam Jackson 🥃 Committed by Georges Basile Stavracas Neto

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.

GNOME/mutter!973
parent a46fd334
......@@ -104,6 +104,12 @@ _cogl_context_get_winsys (CoglContext *context)
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
* constructor that could throw an exception but looking at standard
* practices with several high level OO languages including python, C++,
......@@ -207,6 +213,13 @@ cogl_context_new (CoglDisplay *display,
return NULL;
}
if (!context->driver_vtable->context_init (context, error))
{
cogl_object_unref (display);
g_free (context);
return NULL;
}
context->attribute_name_states_hash =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
context->attribute_name_index_map = NULL;
......@@ -393,6 +406,7 @@ static void
_cogl_context_free (CoglContext *context)
{
const CoglWinsysVtable *winsys = _cogl_context_get_winsys (context);
const CoglDriverVtable *driver = _cogl_context_get_driver (context);
winsys->context_deinit (context);
......@@ -474,6 +488,8 @@ _cogl_context_free (CoglContext *context)
g_byte_array_free (context->buffer_map_fallback_array, TRUE);
driver->context_deinit (context);
cogl_object_unref (context->display);
g_free (context);
......
......@@ -40,6 +40,12 @@ typedef struct _CoglDriverVtable 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
* so can be ignored by non-OpenGL drivers. */
gboolean
......
......@@ -76,6 +76,13 @@ _cogl_gl_error_to_string (GLenum error_code);
#endif /* COGL_GL_DEBUG */
gboolean
_cogl_driver_gl_context_init (CoglContext *context,
GError **error);
void
_cogl_driver_gl_context_deinit (CoglContext *context);
GLenum
_cogl_gl_util_get_error (CoglContext *ctx);
......
......@@ -43,6 +43,18 @@
#include "driver/gl/cogl-clip-stack-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
_cogl_driver_pixel_format_from_gl_internal (CoglContext *context,
GLenum gl_int_format,
......@@ -499,6 +511,8 @@ _cogl_driver_update_features (CoglContext *ctx,
const CoglDriverVtable
_cogl_driver_gl =
{
_cogl_driver_gl_context_init,
_cogl_driver_gl_context_deinit,
_cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features,
......
......@@ -378,6 +378,8 @@ _cogl_driver_texture_2d_is_get_data_supported (CoglTexture2D *tex_2d)
const CoglDriverVtable
_cogl_driver_gles =
{
_cogl_driver_gl_context_init,
_cogl_driver_gl_context_deinit,
_cogl_driver_pixel_format_from_gl_internal,
_cogl_driver_pixel_format_to_gl,
_cogl_driver_update_features,
......
......@@ -52,9 +52,23 @@ _cogl_driver_update_features (CoglContext *ctx,
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
_cogl_driver_nop =
{
_cogl_driver_nop_context_init,
_cogl_driver_nop_context_deinit,
NULL, /* pixel_format_from_gl_internal */
NULL, /* pixel_format_to_gl */
_cogl_driver_update_features,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment