[gtk+] GdkGLContext: Add display property



commit 6fbc439fd79949fac2733107972785cef285ea71
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Nov 3 13:20:55 2014 +0100

    GdkGLContext: Add display property
    
    We need to use this in the code path where we make the context
    non-current during destroy, because at that point the window
    could be destroyed and gdk_window_get_display() would return
    NULL.

 gdk/gdkglcontext.c                 |   61 ++++++++++++++++++++++++++++++++++-
 gdk/gdkglcontext.h                 |    2 +
 gdk/wayland/gdkglcontext-wayland.c |    1 +
 gdk/x11/gdkglcontext-x11.c         |    6 ++--
 4 files changed, 65 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 48f444a..697eb2f 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -79,6 +79,7 @@
 #include <epoxy/gl.h>
 
 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;
@@ -198,6 +219,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:
    *
    * The #GdkWindow the gl context is bound to.
@@ -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)
@@ -338,6 +375,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 e78e9b4..be71ae4 100644
--- a/gdk/gdkglcontext.h
+++ b/gdk/gdkglcontext.h
@@ -43,6 +43,8 @@ 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
 GdkGLProfile            gdk_gl_context_get_profile      (GdkGLContext *context);
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 4c80a80..04d9094 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 4315bfd..2542b01 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,


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