glcontext: Remove leftover function call
authorBenjamin Otte <otte@redhat.com>
Wed, 16 Feb 2022 02:46:29 +0000 (03:46 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 16 Feb 2022 02:48:15 +0000 (03:48 +0100)
That call should have been removed way back when.

Add a testcase to make sure this keeps working.

Fixes #4697

gdk/gdkglcontext.c
testsuite/gdk/glcontext.c [new file with mode: 0644]
testsuite/gdk/meson.build

index d1bc7c57c226f097bfe32e525d0ec62ccba7c60b..373f2fefd504e4089db1d2597d9a9ef1a8a5ce20 100644 (file)
@@ -279,11 +279,7 @@ gdk_gl_context_real_realize (GdkGLContext  *context,
       G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
 
       if (share != NULL)
-        {
-          gdk_gl_context_get_required_version (share, &major, &minor);
-          gdk_gl_context_set_allowed_apis (context,
-                                           gdk_gl_context_get_allowed_apis (share));
-        }
+        gdk_gl_context_get_required_version (share, &major, &minor);
       else
         gdk_gl_context_get_required_version (context, &major, &minor);
 
diff --git a/testsuite/gdk/glcontext.c b/testsuite/gdk/glcontext.c
new file mode 100644 (file)
index 0000000..0bc9148
--- /dev/null
@@ -0,0 +1,82 @@
+#include <gtk/gtk.h>
+
+#define ALL_APIS (GDK_GL_API_GL | GDK_GL_API_GLES)
+
+static GdkGLAPI
+is_unique (GdkGLAPI api)
+{
+  return (api & (api - 1)) == 0;
+}
+
+static void
+test_allowed_backends (gconstpointer data)
+{
+  GdkGLAPI allowed = GPOINTER_TO_SIZE (data);
+  GdkGLAPI not_allowed = (~allowed) & ALL_APIS;
+  GdkGLAPI api, random_apis;
+  GdkDisplay *display = gdk_display_get_default ();
+  GdkGLContext *context;
+  GError *error = NULL;
+
+  display = gdk_display_get_default ();
+  if (!gdk_display_prepare_gl (display, &error))
+    {
+      g_test_message ("no GL support: %s", error->message);
+      g_test_skip ("no GL support");
+      g_clear_error (&error);
+      return;
+    }
+
+  context = gdk_display_create_gl_context (display, &error);
+  g_assert (context);
+  g_assert_no_error (error);
+  g_assert_cmpint (gdk_gl_context_get_api (context), ==, 0);
+  g_assert_cmpint (gdk_gl_context_get_allowed_apis (context), ==, ALL_APIS);
+
+  gdk_gl_context_set_allowed_apis (context, allowed);
+  g_assert_cmpint (gdk_gl_context_get_allowed_apis (context), ==, allowed);
+  g_assert_cmpint (gdk_gl_context_get_api (context), ==, 0);
+
+  if (!gdk_gl_context_realize (context, &error))
+    {
+      g_assert_cmpint (gdk_gl_context_get_api (context), ==, 0);
+
+      if (not_allowed && g_error_matches (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE))
+        {
+          g_clear_error (&error);
+          g_object_unref (context);
+          return;
+        }
+      g_assert_no_error (error);
+    }
+
+  g_assert_no_error (error);
+
+  g_assert_cmpint (gdk_gl_context_get_allowed_apis (context), ==, allowed);
+
+  api = gdk_gl_context_get_api (context);
+  g_assert_cmpint (api, !=, 0);
+  g_assert_true (is_unique (api));
+  g_assert_cmpint (api & allowed, ==, api);
+  g_assert_cmpint (api & not_allowed, ==, 0);
+
+  random_apis = g_random_int_range (0, ALL_APIS + 1);
+  gdk_gl_context_set_allowed_apis (context, random_apis);
+  g_assert_cmpint (gdk_gl_context_get_allowed_apis (context), ==, random_apis);
+  g_assert_cmpint (gdk_gl_context_get_api (context), ==, api);
+
+  g_object_unref (context);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_data_func ("/allowed-apis/none", GSIZE_TO_POINTER (0), test_allowed_backends);
+  g_test_add_data_func ("/allowed-apis/gl", GSIZE_TO_POINTER (GDK_GL_API_GL), test_allowed_backends);
+  g_test_add_data_func ("/allowed-apis/gles", GSIZE_TO_POINTER (GDK_GL_API_GLES), test_allowed_backends);
+  g_test_add_data_func ("/allowed-apis/all", GSIZE_TO_POINTER (GDK_GL_API_GL | GDK_GL_API_GLES), test_allowed_backends);
+
+  return g_test_run ();
+}
index e3b2e8869a3a162f78bc7ea649b47471be7ae33b..04c780f3f0c5f9ec5b42e06c6d07bfbbcb083630 100644 (file)
@@ -19,6 +19,7 @@ tests = [
   { 'name': 'display' },
   { 'name': 'displaymanager' },
   { 'name': 'encoding' },
+  { 'name': 'glcontext' },
   { 'name': 'keysyms' },
   { 'name': 'memorytexture' },
   { 'name': 'pixbuf' },