[gtk/wip/otte/glcontext: 7/7] glcontext: Add gdk_gl_context_get_api()




commit e974a0412ff2f4bb0382407b939a2c14fdff19ee
Author: Benjamin Otte <otte redhat com>
Date:   Thu Oct 7 23:03:45 2021 +0200

    glcontext: Add gdk_gl_context_get_api()
    
    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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 gdk/gdkglcontext.h |  2 ++
 2 files changed, 49 insertions(+)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index dfbbc109cd..ecd9ed7615 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -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;
 }
 
diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h
index 7e8e0d1e36..5201f93cb1 100644
--- a/gdk/gdkglcontext.h
+++ b/gdk/gdkglcontext.h
@@ -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);


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