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



commit f9599b64d0284b64b5ffc23bd022ca0cd736c739
Author: Adam Jackson <ajax redhat com>
Date:   Fri Oct 18 16:44:43 2019 -0400

    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

 cogl/cogl/cogl-context.c                    | 16 ++++++++++++++++
 cogl/cogl/cogl-driver.h                     |  6 ++++++
 cogl/cogl/driver/gl/cogl-util-gl-private.h  |  7 +++++++
 cogl/cogl/driver/gl/gl/cogl-driver-gl.c     | 14 ++++++++++++++
 cogl/cogl/driver/gl/gles/cogl-driver-gles.c |  2 ++
 cogl/cogl/driver/nop/cogl-driver-nop.c      | 14 ++++++++++++++
 6 files changed, 59 insertions(+)
---
diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c
index d28f633b7..2d856e845 100644
--- a/cogl/cogl/cogl-context.c
+++ b/cogl/cogl/cogl-context.c
@@ -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);
diff --git a/cogl/cogl/cogl-driver.h b/cogl/cogl/cogl-driver.h
index 295de92cf..f9b779fa7 100644
--- a/cogl/cogl/cogl-driver.h
+++ b/cogl/cogl/cogl-driver.h
@@ -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
diff --git a/cogl/cogl/driver/gl/cogl-util-gl-private.h b/cogl/cogl/driver/gl/cogl-util-gl-private.h
index a3de93980..e22a29b1f 100644
--- a/cogl/cogl/driver/gl/cogl-util-gl-private.h
+++ b/cogl/cogl/driver/gl/cogl-util-gl-private.h
@@ -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);
 
diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
index df6395ea0..75ffb8d84 100644
--- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
+++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c
@@ -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,
diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
index b3166cd74..a29ac49aa 100644
--- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
+++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c
@@ -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,
diff --git a/cogl/cogl/driver/nop/cogl-driver-nop.c b/cogl/cogl/driver/nop/cogl-driver-nop.c
index a7255a089..4fffd3686 100644
--- a/cogl/cogl/driver/nop/cogl-driver-nop.c
+++ b/cogl/cogl/driver/nop/cogl-driver-nop.c
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]