[gtk/wip/otte/gleanup: 40/53] ngl: Store the shared driver in the display




commit 5dc6391d08ca1bb8acf0b8b68d325492ffa15e60
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jul 5 04:24:43 2021 +0200

    ngl: Store the shared driver in the display
    
    ... instead of some random GL context.

 gsk/ngl/gskngldriver.c        | 23 ++++++++++++++---------
 gsk/ngl/gskngldriverprivate.h |  2 +-
 gsk/ngl/gsknglrenderer.c      | 12 +-----------
 3 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/gsk/ngl/gskngldriver.c b/gsk/ngl/gskngldriver.c
index ec7cdf7bb7..32862047d8 100644
--- a/gsk/ngl/gskngldriver.c
+++ b/gsk/ngl/gskngldriver.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include <gdk/gdkglcontextprivate.h>
+#include <gdk/gdkdisplayprivate.h>
 #include <gdk/gdktextureprivate.h>
 #include <gsk/gskdebugprivate.h>
 #include <gsk/gskglshaderprivate.h>
@@ -447,30 +448,34 @@ gsk_ngl_driver_new (GskNglCommandQueue  *command_queue,
 }
 
 /**
- * gsk_ngl_driver_from_shared_context:
- * @context: a shared `GdkGLContext` retrieved with gdk_gl_context_get_shared_context()
+ * gsk_ngl_driver_for_display:
+ * @display: A #GdkDisplay that is known to support GL
  * @debug_shaders: if debug information for shaders should be displayed
  * @error: location for error information
  *
- * Retrieves a driver for a shared context. Generally this is shared across all GL
+ * Retrieves a driver for a shared display. Generally this is shared across all GL
  * contexts for a display so that fewer programs are necessary for driving output.
  *
  * Returns: (transfer full): a `GskNglDriver` if successful; otherwise %NULL and
  *   @error is set.
  */
 GskNglDriver *
-gsk_ngl_driver_from_shared_context (GdkGLContext  *context,
-                                    gboolean       debug_shaders,
-                                    GError       **error)
+gsk_ngl_driver_for_display (GdkDisplay  *display,
+                            gboolean     debug_shaders,
+                            GError     **error)
 {
+  GdkGLContext *context;
   GskNglCommandQueue *command_queue = NULL;
   GskNglDriver *driver;
 
-  g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
+  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
 
-  if ((driver = g_object_get_data (G_OBJECT (context), "GSK_NGL_DRIVER")))
+  if ((driver = g_object_get_data (G_OBJECT (display), "GSK_NGL_DRIVER")))
     return g_object_ref (driver);
 
+  context = gdk_display_get_gl_context (display);
+  g_assert (context);
+
   gdk_gl_context_make_current (context);
 
   /* Initially we create a command queue using the shared context. However,
@@ -484,7 +489,7 @@ gsk_ngl_driver_from_shared_context (GdkGLContext  *context,
   if (!(driver = gsk_ngl_driver_new (command_queue, debug_shaders, error)))
     goto failure;
 
-  g_object_set_data_full (G_OBJECT (context),
+  g_object_set_data_full (G_OBJECT (display),
                           "GSK_NGL_DRIVER",
                           g_object_ref (driver),
                           g_object_unref);
diff --git a/gsk/ngl/gskngldriverprivate.h b/gsk/ngl/gskngldriverprivate.h
index b0b5f7f550..b5b5e60600 100644
--- a/gsk/ngl/gskngldriverprivate.h
+++ b/gsk/ngl/gskngldriverprivate.h
@@ -136,7 +136,7 @@ struct _GskNglDriver
   guint in_frame : 1;
 };
 
-GskNglDriver       *gsk_ngl_driver_from_shared_context    (GdkGLContext         *context,
+GskNglDriver       *gsk_ngl_driver_for_display            (GdkDisplay           *display,
                                                            gboolean              debug_shaders,
                                                            GError              **error);
 GskNglCommandQueue *gsk_ngl_driver_create_command_queue   (GskNglDriver         *self,
diff --git a/gsk/ngl/gsknglrenderer.c b/gsk/ngl/gsknglrenderer.c
index c84f112047..fa393c11cf 100644
--- a/gsk/ngl/gsknglrenderer.c
+++ b/gsk/ngl/gsknglrenderer.c
@@ -86,7 +86,6 @@ gsk_ngl_renderer_realize (GskRenderer  *renderer,
   G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
   GskNglRenderer *self = (GskNglRenderer *)renderer;
   GdkGLContext *context = NULL;
-  GdkGLContext *shared_context;
   GskNglDriver *driver = NULL;
   gboolean ret = FALSE;
   gboolean debug_shaders = FALSE;
@@ -105,21 +104,12 @@ gsk_ngl_renderer_realize (GskRenderer  *renderer,
       !gdk_gl_context_realize (context, error))
     goto failure;
 
-  if (!(shared_context = gdk_display_get_gl_context (gdk_surface_get_display (surface))))
-    {
-      g_set_error (error,
-                   GDK_GL_ERROR,
-                   GDK_GL_ERROR_NOT_AVAILABLE,
-                   "Failed to locate shared GL context for driver");
-      goto failure;
-    }
-
 #ifdef G_ENABLE_DEBUG
   if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SHADERS))
     debug_shaders = TRUE;
 #endif
 
-  if (!(driver = gsk_ngl_driver_from_shared_context (shared_context, debug_shaders, error)))
+  if (!(driver = gsk_ngl_driver_for_display (gdk_surface_get_display (surface), debug_shaders, error)))
     goto failure;
 
   self->command_queue = gsk_ngl_driver_create_command_queue (driver, context);


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