glcontext: Add gdk_gl_context_get_api()
authorBenjamin Otte <otte@redhat.com>
Thu, 7 Oct 2021 21:03:45 +0000 (23:03 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 8 Oct 2021 01:31:07 +0000 (03:31 +0200)
This is mostly for inspector.

Not sure if we also want to deprecate gdk_gl_context_get_use_es() in
favor of this function.

gdk/gdkglcontext.c
gdk/gdkglcontext.h

index dfbbc109cdf782a2b9408a7e276d07173aefa102..ecd9ed76152f1ddbd787a073a0c0a993cba0e9eb 100644 (file)
@@ -124,6 +124,7 @@ enum {
   PROP_0,
 
   PROP_ALLOWED_APIS,
+  PROP_API,
   PROP_SHARED_CONTEXT,
 
   LAST_PROP
@@ -235,6 +236,10 @@ gdk_gl_context_get_property (GObject    *object,
       g_value_set_flags (value, priv->allowed_apis);
       break;
 
+    case PROP_API:
+      g_value_set_flags (value, priv->api);
+      break;
+
     case PROP_SHARED_CONTEXT:
       g_value_set_object (value, NULL);
       break;
@@ -761,6 +766,23 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
                         G_PARAM_STATIC_STRINGS |
                         G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GdkGLContext:api: (attributes org.gtk.Property.get=gdk_gl_context_get_api)
+   *
+   * The API currently in use.
+   *
+   * Since: 4.6
+   */
+  properties[PROP_API] =
+    g_param_spec_flags ("api",
+                        P_("API"),
+                        P_("The API currently in use"),
+                        GDK_TYPE_GL_API,
+                        0,
+                        G_PARAM_READABLE |
+                        G_PARAM_STATIC_STRINGS |
+                        G_PARAM_EXPLICIT_NOTIFY);
+
   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;
@@ -1234,6 +1256,28 @@ gdk_gl_context_get_allowed_apis (GdkGLContext *self)
   return priv->allowed_apis;
 }
 
+/**
+ * gdk_gl_context_get_api: (attributes org.gtk.Method.get_property=api)
+ * @self: a GL context
+ *
+ * Gets the API currently in use.
+ *
+ * If the renderer has not been realized yet, 0 is returned.
+ *
+ * Returns: the currently used API
+ *
+ * Since: 4.6
+ **/
+GdkGLAPI
+gdk_gl_context_get_api (GdkGLContext *self)
+{
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
+
+  g_return_val_if_fail (GDK_IS_GL_CONTEXT (self), 0);
+
+  return priv->api;
+}
+
 gboolean
 gdk_gl_context_is_api_allowed (GdkGLContext  *self,
                                GdkGLAPI       api,
@@ -1438,6 +1482,9 @@ gdk_gl_context_realize (GdkGLContext  *context,
 
   priv->api = GDK_GL_CONTEXT_GET_CLASS (context)->realize (context, error);
 
+  if (priv->api)
+    g_object_notify_by_pspec (G_OBJECT (context), properties[PROP_API]);
+
   return priv->api;
 }
 
index 7e8e0d1e3624bec56336d85077ea621149e9a0aa..5201f93cb12ec04655996b4289c60a3d4d7b4016 100644 (file)
@@ -95,6 +95,8 @@ void                    gdk_gl_context_set_allowed_apis         (GdkGLContext  *
                                                                  GdkGLAPI       apis);
 GDK_AVAILABLE_IN_4_6
 GdkGLAPI                gdk_gl_context_get_allowed_apis         (GdkGLContext  *self);
+GDK_AVAILABLE_IN_4_6
+GdkGLAPI                gdk_gl_context_get_api                  (GdkGLContext  *self);
 GDK_DEPRECATED_IN_4_6_FOR(gdk_gl_context_set_allowed_apis)
 void                    gdk_gl_context_set_use_es               (GdkGLContext  *context,
                                                                  int            use_es);