ngl: Store the shared driver in the display

... instead of some random GL context.
This commit is contained in:
Benjamin Otte 2021-07-05 04:24:43 +02:00
parent e4f0418003
commit dd666e4fe4
3 changed files with 16 additions and 21 deletions

View File

@ -24,6 +24,7 @@
#include "config.h" #include "config.h"
#include <gdk/gdkglcontextprivate.h> #include <gdk/gdkglcontextprivate.h>
#include <gdk/gdkdisplayprivate.h>
#include <gdk/gdktextureprivate.h> #include <gdk/gdktextureprivate.h>
#include <gsk/gskdebugprivate.h> #include <gsk/gskdebugprivate.h>
#include <gsk/gskglshaderprivate.h> #include <gsk/gskglshaderprivate.h>
@ -447,30 +448,34 @@ gsk_ngl_driver_new (GskNglCommandQueue *command_queue,
} }
/** /**
* gsk_ngl_driver_from_shared_context: * gsk_ngl_driver_for_display:
* @context: a shared `GdkGLContext` retrieved with gdk_gl_context_get_shared_context() * @display: A #GdkDisplay that is known to support GL
* @debug_shaders: if debug information for shaders should be displayed * @debug_shaders: if debug information for shaders should be displayed
* @error: location for error information * @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. * contexts for a display so that fewer programs are necessary for driving output.
* *
* Returns: (transfer full): a `GskNglDriver` if successful; otherwise %NULL and * Returns: (transfer full): a `GskNglDriver` if successful; otherwise %NULL and
* @error is set. * @error is set.
*/ */
GskNglDriver * GskNglDriver *
gsk_ngl_driver_from_shared_context (GdkGLContext *context, gsk_ngl_driver_for_display (GdkDisplay *display,
gboolean debug_shaders, gboolean debug_shaders,
GError **error) GError **error)
{ {
GdkGLContext *context;
GskNglCommandQueue *command_queue = NULL; GskNglCommandQueue *command_queue = NULL;
GskNglDriver *driver; 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); return g_object_ref (driver);
context = gdk_display_get_gl_context (display);
g_assert (context);
gdk_gl_context_make_current (context); gdk_gl_context_make_current (context);
/* Initially we create a command queue using the shared context. However, /* 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))) if (!(driver = gsk_ngl_driver_new (command_queue, debug_shaders, error)))
goto failure; goto failure;
g_object_set_data_full (G_OBJECT (context), g_object_set_data_full (G_OBJECT (display),
"GSK_NGL_DRIVER", "GSK_NGL_DRIVER",
g_object_ref (driver), g_object_ref (driver),
g_object_unref); g_object_unref);

View File

@ -136,7 +136,7 @@ struct _GskNglDriver
guint in_frame : 1; guint in_frame : 1;
}; };
GskNglDriver *gsk_ngl_driver_from_shared_context (GdkGLContext *context, GskNglDriver *gsk_ngl_driver_for_display (GdkDisplay *display,
gboolean debug_shaders, gboolean debug_shaders,
GError **error); GError **error);
GskNglCommandQueue *gsk_ngl_driver_create_command_queue (GskNglDriver *self, GskNglCommandQueue *gsk_ngl_driver_create_command_queue (GskNglDriver *self,

View File

@ -86,7 +86,6 @@ gsk_ngl_renderer_realize (GskRenderer *renderer,
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME; G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
GskNglRenderer *self = (GskNglRenderer *)renderer; GskNglRenderer *self = (GskNglRenderer *)renderer;
GdkGLContext *context = NULL; GdkGLContext *context = NULL;
GdkGLContext *shared_context;
GskNglDriver *driver = NULL; GskNglDriver *driver = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
gboolean debug_shaders = FALSE; gboolean debug_shaders = FALSE;
@ -105,21 +104,12 @@ gsk_ngl_renderer_realize (GskRenderer *renderer,
!gdk_gl_context_realize (context, error)) !gdk_gl_context_realize (context, error))
goto failure; 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 #ifdef G_ENABLE_DEBUG
if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SHADERS)) if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SHADERS))
debug_shaders = TRUE; debug_shaders = TRUE;
#endif #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; goto failure;
self->command_queue = gsk_ngl_driver_create_command_queue (driver, context); self->command_queue = gsk_ngl_driver_create_command_queue (driver, context);