GdkGLContext: Track shared context
This allows us to read it back, but primarily it ensures the shared context wrapper stays alive as long as the context.
This commit is contained in:
		@ -82,6 +82,7 @@
 | 
			
		||||
typedef struct {
 | 
			
		||||
  GdkWindow *window;
 | 
			
		||||
  GdkVisual *visual;
 | 
			
		||||
  GdkGLContext *shared_context;
 | 
			
		||||
 | 
			
		||||
  guint realized : 1;
 | 
			
		||||
  guint use_texture_rectangle : 1;
 | 
			
		||||
@ -93,6 +94,7 @@ enum {
 | 
			
		||||
 | 
			
		||||
  PROP_WINDOW,
 | 
			
		||||
  PROP_VISUAL,
 | 
			
		||||
  PROP_SHARED_CONTEXT,
 | 
			
		||||
 | 
			
		||||
  LAST_PROP
 | 
			
		||||
};
 | 
			
		||||
@ -118,6 +120,7 @@ gdk_gl_context_dispose (GObject *gobject)
 | 
			
		||||
 | 
			
		||||
  g_clear_object (&priv->window);
 | 
			
		||||
  g_clear_object (&priv->visual);
 | 
			
		||||
  g_clear_object (&priv->shared_context);
 | 
			
		||||
 | 
			
		||||
  G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject);
 | 
			
		||||
}
 | 
			
		||||
@ -155,6 +158,15 @@ gdk_gl_context_set_property (GObject      *gobject,
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case PROP_SHARED_CONTEXT:
 | 
			
		||||
      {
 | 
			
		||||
        GdkGLContext *context = g_value_get_object (value);
 | 
			
		||||
 | 
			
		||||
        if (context != NULL)
 | 
			
		||||
          priv->shared_context = g_object_ref (context);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
 | 
			
		||||
    }
 | 
			
		||||
@ -178,6 +190,10 @@ gdk_gl_context_get_property (GObject    *gobject,
 | 
			
		||||
      g_value_set_object (value, priv->visual);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    case PROP_SHARED_CONTEXT:
 | 
			
		||||
      g_value_set_object (value, priv->shared_context);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
 | 
			
		||||
    }
 | 
			
		||||
@ -220,6 +236,22 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
 | 
			
		||||
                         G_PARAM_CONSTRUCT_ONLY |
 | 
			
		||||
                         G_PARAM_STATIC_STRINGS);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * GdkGLContext:shared-context:
 | 
			
		||||
   *
 | 
			
		||||
   * The #GdkGLContext that this context is sharing data with, or #NULL
 | 
			
		||||
   *
 | 
			
		||||
   * Since: 3.16
 | 
			
		||||
   */
 | 
			
		||||
  obj_pspecs[PROP_SHARED_CONTEXT] =
 | 
			
		||||
    g_param_spec_object ("shared-context",
 | 
			
		||||
                         P_("Shared context"),
 | 
			
		||||
                         P_("The GL context this context share data with"),
 | 
			
		||||
                         GDK_TYPE_GL_CONTEXT,
 | 
			
		||||
                         G_PARAM_READWRITE |
 | 
			
		||||
                         G_PARAM_CONSTRUCT_ONLY |
 | 
			
		||||
                         G_PARAM_STATIC_STRINGS);
 | 
			
		||||
 | 
			
		||||
  gobject_class->set_property = gdk_gl_context_set_property;
 | 
			
		||||
  gobject_class->get_property = gdk_gl_context_get_property;
 | 
			
		||||
  gobject_class->dispose = gdk_gl_context_dispose;
 | 
			
		||||
@ -351,6 +383,26 @@ gdk_gl_context_get_window (GdkGLContext *context)
 | 
			
		||||
  return priv->window;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * gdk_gl_context_get_shared_context:
 | 
			
		||||
 * @context: a #GdkGLContext
 | 
			
		||||
 *
 | 
			
		||||
 * Retrieves the #GdkGLContext that this @context share data with.
 | 
			
		||||
 *
 | 
			
		||||
 * Returns: (transfer none): a #GdkGLContext or %NULL
 | 
			
		||||
 *
 | 
			
		||||
 * Since: 3.16
 | 
			
		||||
 */
 | 
			
		||||
GdkGLContext *
 | 
			
		||||
gdk_gl_context_get_shared_context (GdkGLContext *context)
 | 
			
		||||
{
 | 
			
		||||
  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 | 
			
		||||
 | 
			
		||||
  g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
 | 
			
		||||
 | 
			
		||||
  return priv->shared_context;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * gdk_gl_context_clear_current:
 | 
			
		||||
 *
 | 
			
		||||
 | 
			
		||||
@ -364,6 +364,7 @@ gdk_wayland_window_create_gl_context (GdkWindow     *window,
 | 
			
		||||
  context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
 | 
			
		||||
                          "window", window,
 | 
			
		||||
                          "visual", gdk_window_get_visual (window),
 | 
			
		||||
                          "shared-context", share,
 | 
			
		||||
                          NULL);
 | 
			
		||||
 | 
			
		||||
  context->egl_config = config;
 | 
			
		||||
 | 
			
		||||
@ -1124,6 +1124,7 @@ gdk_x11_window_create_gl_context (GdkWindow    *window,
 | 
			
		||||
  context = g_object_new (GDK_TYPE_X11_GL_CONTEXT,
 | 
			
		||||
                          "window", window,
 | 
			
		||||
                          "visual", gdk_visual,
 | 
			
		||||
                          "shared-context", share,
 | 
			
		||||
                          NULL);
 | 
			
		||||
 | 
			
		||||
  context->profile = profile;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user