From 481634930cb8d65d35068df0414783d2ccbccd45 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 16 Feb 2022 03:46:29 +0100 Subject: [PATCH] glcontext: Remove leftover function call That call should have been removed way back when. Add a testcase to make sure this keeps working. Fixes #4697 --- gdk/gdkglcontext.c | 6 +-- testsuite/gdk/glcontext.c | 82 +++++++++++++++++++++++++++++++++++++++ testsuite/gdk/meson.build | 1 + 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 testsuite/gdk/glcontext.c diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index d1bc7c57c2..373f2fefd5 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -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 index 0000000000..0bc9148064 --- /dev/null +++ b/testsuite/gdk/glcontext.c @@ -0,0 +1,82 @@ +#include + +#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 (); +} diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build index e3b2e8869a..04c780f3f0 100644 --- a/testsuite/gdk/meson.build +++ b/testsuite/gdk/meson.build @@ -19,6 +19,7 @@ tests = [ { 'name': 'display' }, { 'name': 'displaymanager' }, { 'name': 'encoding' }, + { 'name': 'glcontext' }, { 'name': 'keysyms' }, { 'name': 'memorytexture' }, { 'name': 'pixbuf' }, -- 2.30.2