diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 48f444a594..697eb2ffa3 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -79,6 +79,7 @@ #include typedef struct { + GdkDisplay *display; GdkWindow *window; GdkGLContext *shared_context; GdkGLProfile profile; @@ -91,6 +92,7 @@ typedef struct { enum { PROP_0, + PROP_DISPLAY, PROP_WINDOW, PROP_PROFILE, PROP_SHARED_CONTEXT, @@ -117,6 +119,7 @@ gdk_gl_context_dispose (GObject *gobject) if (current == context) g_private_replace (&thread_current_context, NULL); + g_clear_object (&priv->display); g_clear_object (&priv->window); g_clear_object (&priv->shared_context); @@ -133,6 +136,20 @@ gdk_gl_context_set_property (GObject *gobject, switch (prop_id) { + case PROP_DISPLAY: + { + GdkDisplay *display = g_value_get_object (value); + + if (display) + g_object_ref (display); + + if (priv->display) + g_object_unref (priv->display); + + priv->display = display; + } + break; + case PROP_WINDOW: { GdkWindow *window = g_value_get_object (value); @@ -175,6 +192,10 @@ gdk_gl_context_get_property (GObject *gobject, switch (prop_id) { + case PROP_DISPLAY: + g_value_set_object (value, priv->display); + break; + case PROP_WINDOW: g_value_set_object (value, priv->window); break; @@ -197,6 +218,22 @@ gdk_gl_context_class_init (GdkGLContextClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + /** + * GdkGLContext:display: + * + * The #GdkWindow the gl context is bound to. + * + * Since: 3.16 + */ + obj_pspecs[PROP_DISPLAY] = + g_param_spec_object ("display", + P_("Display"), + P_("The GDK display the context is from"), + GDK_TYPE_DISPLAY, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + /** * GdkGLContext:window: * @@ -329,7 +366,7 @@ gdk_gl_context_make_current (GdkGLContext *context) if (current == context) return; - if (gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), context)) + if (gdk_display_make_gl_context_current (priv->display, context)) { g_private_replace (&thread_current_context, g_object_ref (context)); if (!priv->realized) @@ -337,6 +374,26 @@ gdk_gl_context_make_current (GdkGLContext *context) } } +/** + * gdk_gl_context_get_display: + * @context: a #GdkGLContext + * + * Retrieves the #GdkDisplay the @context is created for + * + * Returns: (transfer none): a #GdkDisplay or %NULL + * + * Since: 3.16 + */ +GdkDisplay * +gdk_gl_context_get_display (GdkGLContext *context) +{ + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL); + + return priv->display; +} + /** * gdk_gl_context_get_window: * @context: a #GdkGLContext @@ -417,7 +474,7 @@ gdk_gl_context_clear_current (void) { GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (current); - if (gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), NULL)) + if (gdk_display_make_gl_context_current (priv->display, NULL)) g_private_replace (&thread_current_context, NULL); } } diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h index e78e9b44b7..be71ae4382 100644 --- a/gdk/gdkglcontext.h +++ b/gdk/gdkglcontext.h @@ -42,6 +42,8 @@ GQuark gdk_gl_error_quark (void); GDK_AVAILABLE_IN_3_16 GType gdk_gl_context_get_type (void) G_GNUC_CONST; +GDK_AVAILABLE_IN_3_16 +GdkDisplay * gdk_gl_context_get_display (GdkGLContext *context); GDK_AVAILABLE_IN_3_16 GdkWindow * gdk_gl_context_get_window (GdkGLContext *context); GDK_AVAILABLE_IN_3_16 diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c index 4c80a802de..04d9094793 100644 --- a/gdk/wayland/gdkglcontext-wayland.c +++ b/gdk/wayland/gdkglcontext-wayland.c @@ -365,6 +365,7 @@ gdk_wayland_window_create_gl_context (GdkWindow *window, g_print ("Created EGL context[%p]\n", ctx)); context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT, + "display", display, "window", window, "profile", profile, "shared-context", share, diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c index 4315bfd7aa..2542b01cc2 100644 --- a/gdk/x11/gdkglcontext-x11.c +++ b/gdk/x11/gdkglcontext-x11.c @@ -206,7 +206,7 @@ gdk_x11_gl_context_end_frame (GdkGLContext *context, { GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context); GdkWindow *window = gdk_gl_context_get_window (context); - GdkDisplay *display = gdk_window_get_display (window); + GdkDisplay *display = gdk_gl_context_get_display (context); Display *dpy = gdk_x11_display_get_xdisplay (display); GdkX11Display *display_x11 = GDK_X11_DISPLAY (display); DrawableInfo *info; @@ -503,8 +503,7 @@ gdk_x11_gl_context_dispose (GObject *gobject) if (context_x11->glx_context != NULL) { GdkGLContext *context = GDK_GL_CONTEXT (gobject); - GdkWindow *window = gdk_gl_context_get_window (context); - GdkDisplay *display = gdk_window_get_display (window); + GdkDisplay *display = gdk_gl_context_get_display (context); Display *dpy = gdk_x11_display_get_xdisplay (display); if (glXGetCurrentContext () == context_x11->glx_context) @@ -1119,6 +1118,7 @@ gdk_x11_window_create_gl_context (GdkWindow *window, is_direct ? "direct" : "indirect")); context = g_object_new (GDK_TYPE_X11_GL_CONTEXT, + "display", display, "window", window, "profile", profile, "shared-context", share,