[gtk/wip.win32.fixes: 7/23] glcontext: Make the creation of EGL context more obvious
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip.win32.fixes: 7/23] glcontext: Make the creation of EGL context more obvious
- Date: Wed, 1 Jun 2022 02:26:59 +0000 (UTC)
commit d06c74707baa3641194ca2105d87a2f9125dd05c
Author: Pablo Correa Gómez <ablocorrea hotmail com>
Date: Fri May 6 16:40:13 2022 +0200
glcontext: Make the creation of EGL context more obvious
By splitting it into its own function it becomes more that the
EGL code is a shared implementation.
gdk/gdkglcontext.c | 292 +++++++++++++++++++++++++++--------------------------
1 file changed, 149 insertions(+), 143 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index e58c0e57dc..8796221331 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -259,178 +259,185 @@ gdk_gl_context_get_property (GObject *object,
#define N_EGL_ATTRS 16
static GdkGLAPI
-gdk_gl_context_real_realize (GdkGLContext *context,
- GError **error)
+gdk_gl_context_realize_egl (GdkGLContext *context,
+ GError **error)
{
-#ifdef HAVE_EGL
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkDisplay *display = gdk_gl_context_get_display (context);
EGLDisplay egl_display = gdk_display_get_egl_display (display);
- if (egl_display)
- {
- EGLConfig egl_config;
- GdkGLContext *share = gdk_display_get_gl_context (display);
- GdkGLContextPrivate *share_priv = gdk_gl_context_get_instance_private (share);
- EGLContext ctx;
- EGLint context_attribs[N_EGL_ATTRS];
- int major, minor, flags;
- gboolean debug_bit, forward_bit, legacy_bit;
- GdkGLAPI api;
- int i = 0;
- G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
-
- if (share != NULL)
- gdk_gl_context_get_required_version (share, &major, &minor);
- else
- gdk_gl_context_get_required_version (context, &major, &minor);
+ EGLConfig egl_config;
+ GdkGLContext *share = gdk_display_get_gl_context (display);
+ GdkGLContextPrivate *share_priv = gdk_gl_context_get_instance_private (share);
+ EGLContext ctx;
+ EGLint context_attribs[N_EGL_ATTRS];
+ int major, minor, flags;
+ gboolean debug_bit, forward_bit, legacy_bit;
+ GdkGLAPI api;
+ int i = 0;
+ G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
- debug_bit = gdk_gl_context_get_debug_enabled (context);
- forward_bit = gdk_gl_context_get_forward_compatible (context);
- legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
- (share != NULL && gdk_gl_context_is_legacy (share));
+ if (share != NULL)
+ gdk_gl_context_get_required_version (share, &major, &minor);
+ else
+ gdk_gl_context_get_required_version (context, &major, &minor);
- if (display->have_egl_no_config_context)
- egl_config = NULL;
- else
- egl_config = gdk_display_get_egl_config (display);
+ debug_bit = gdk_gl_context_get_debug_enabled (context);
+ forward_bit = gdk_gl_context_get_forward_compatible (context);
+ legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
+ (share != NULL && gdk_gl_context_is_legacy (share));
- flags = 0;
+ if (display->have_egl_no_config_context)
+ egl_config = NULL;
+ else
+ egl_config = gdk_display_get_egl_config (display);
- if (debug_bit)
- flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
- if (forward_bit)
- flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
+ flags = 0;
- if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) &&
- eglBindAPI (EGL_OPENGL_API))
- {
- /* We want a core profile, unless in legacy mode */
- context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
- context_attribs[i++] = legacy_bit
- ? EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR
- : EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
-
- /* Specify the version */
- context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
- context_attribs[i++] = legacy_bit ? 3 : major;
- context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
- context_attribs[i++] = legacy_bit ? 0 : minor;
- api = GDK_GL_API_GL;
- }
- else if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) &&
- eglBindAPI (EGL_OPENGL_ES_API))
- {
- context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
- if (major == 3)
- context_attribs[i++] = 3;
- else
- context_attribs[i++] = 2;
- api = GDK_GL_API_GLES;
- }
+ if (debug_bit)
+ flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
+ if (forward_bit)
+ flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
+
+ if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) &&
+ eglBindAPI (EGL_OPENGL_API))
+ {
+ /* We want a core profile, unless in legacy mode */
+ context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
+ context_attribs[i++] = legacy_bit
+ ? EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR
+ : EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
+
+ /* Specify the version */
+ context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
+ context_attribs[i++] = legacy_bit ? 3 : major;
+ context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
+ context_attribs[i++] = legacy_bit ? 0 : minor;
+ api = GDK_GL_API_GL;
+ }
+ else if (gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) &&
+ eglBindAPI (EGL_OPENGL_ES_API))
+ {
+ context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
+ if (major == 3)
+ context_attribs[i++] = 3;
else
- {
- g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
- _("The EGL implementation does not support any allowed APIs"));
- return 0;
- }
+ context_attribs[i++] = 2;
+ api = GDK_GL_API_GLES;
+ }
+ else
+ {
+ g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+ _("The EGL implementation does not support any allowed APIs"));
+ return 0;
+ }
- /* Specify the flags */
+ /* Specify the flags */
+ context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
+ context_attribs[i++] = flags;
+
+ context_attribs[i++] = EGL_NONE;
+ g_assert (i < N_EGL_ATTRS);
+
+ GDK_DISPLAY_NOTE (display, OPENGL,
+ g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)",
+ major, minor,
+ debug_bit ? "yes" : "no",
+ forward_bit ? "yes" : "no",
+ legacy_bit ? "yes" : "no",
+ api == GDK_GL_API_GLES ? "yes" : "no"));
+
+ ctx = eglCreateContext (egl_display,
+ egl_config,
+ share != NULL ? share_priv->egl_context
+ : EGL_NO_CONTEXT,
+ context_attribs);
+
+ /* If context creation failed without the ES bit, let's try again with it */
+ if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) && eglBindAPI
(EGL_OPENGL_ES_API))
+ {
+ i = 0;
+ context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
+ context_attribs[i++] = 2;
+ context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
+ context_attribs[i++] = 0;
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
- context_attribs[i++] = flags;
-
+ context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
context_attribs[i++] = EGL_NONE;
g_assert (i < N_EGL_ATTRS);
+ legacy_bit = FALSE;
+ api = GDK_GL_API_GLES;
+
GDK_DISPLAY_NOTE (display, OPENGL,
- g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)",
- major, minor,
- debug_bit ? "yes" : "no",
- forward_bit ? "yes" : "no",
- legacy_bit ? "yes" : "no",
- api == GDK_GL_API_GLES ? "yes" : "no"));
+ g_message ("eglCreateContext failed, switching to OpenGL ES"));
+ ctx = eglCreateContext (egl_display,
+ egl_config,
+ share != NULL ? share_priv->egl_context
+ : EGL_NO_CONTEXT,
+ context_attribs);
+ }
+
+ /* If context creation failed without the legacy bit, let's try again with it */
+ if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) && eglBindAPI
(EGL_OPENGL_API))
+ {
+ i = 0;
+ context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
+ context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
+ context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
+ context_attribs[i++] = 3;
+ context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
+ context_attribs[i++] = 0;
+ context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
+ context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
+ context_attribs[i++] = EGL_NONE;
+ g_assert (i < N_EGL_ATTRS);
+ legacy_bit = TRUE;
+ api = GDK_GL_API_GL;
+
+ GDK_DISPLAY_NOTE (display, OPENGL,
+ g_message ("eglCreateContext failed, switching to legacy"));
ctx = eglCreateContext (egl_display,
egl_config,
share != NULL ? share_priv->egl_context
- : EGL_NO_CONTEXT,
+ : EGL_NO_CONTEXT,
context_attribs);
+ }
- /* If context creation failed without the ES bit, let's try again with it */
- if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GLES, NULL) && eglBindAPI
(EGL_OPENGL_ES_API))
- {
- i = 0;
- context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
- context_attribs[i++] = 2;
- context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
- context_attribs[i++] = 0;
- context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
- context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
- context_attribs[i++] = EGL_NONE;
- g_assert (i < N_EGL_ATTRS);
-
- legacy_bit = FALSE;
- api = GDK_GL_API_GLES;
-
- GDK_DISPLAY_NOTE (display, OPENGL,
- g_message ("eglCreateContext failed, switching to OpenGL ES"));
- ctx = eglCreateContext (egl_display,
- egl_config,
- share != NULL ? share_priv->egl_context
- : EGL_NO_CONTEXT,
- context_attribs);
- }
+ if (ctx == NULL)
+ {
+ g_set_error_literal (error, GDK_GL_ERROR,
+ GDK_GL_ERROR_NOT_AVAILABLE,
+ _("Unable to create a GL context"));
+ return 0;
+ }
- /* If context creation failed without the legacy bit, let's try again with it */
- if (ctx == NULL && gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, NULL) && eglBindAPI
(EGL_OPENGL_API))
- {
- i = 0;
- context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
- context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
- context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
- context_attribs[i++] = 3;
- context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
- context_attribs[i++] = 0;
- context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
- context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
- context_attribs[i++] = EGL_NONE;
- g_assert (i < N_EGL_ATTRS);
-
- legacy_bit = TRUE;
- api = GDK_GL_API_GL;
-
- GDK_DISPLAY_NOTE (display, OPENGL,
- g_message ("eglCreateContext failed, switching to legacy"));
- ctx = eglCreateContext (egl_display,
- egl_config,
- share != NULL ? share_priv->egl_context
- : EGL_NO_CONTEXT,
- context_attribs);
- }
+ GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Created EGL context[%p]", ctx));
- if (ctx == NULL)
- {
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_NOT_AVAILABLE,
- _("Unable to create a GL context"));
- return 0;
- }
+ priv->egl_context = ctx;
- GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Created EGL context[%p]", ctx));
+ gdk_gl_context_set_is_legacy (context, legacy_bit);
- priv->egl_context = ctx;
+ if (epoxy_has_egl_extension (egl_display, "EGL_KHR_swap_buffers_with_damage"))
+ priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageKHR");
+ else if (epoxy_has_egl_extension (egl_display, "EGL_EXT_swap_buffers_with_damage"))
+ priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageEXT");
- gdk_gl_context_set_is_legacy (context, legacy_bit);
+ gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
- if (epoxy_has_egl_extension (egl_display, "EGL_KHR_swap_buffers_with_damage"))
- priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageKHR");
- else if (epoxy_has_egl_extension (egl_display, "EGL_EXT_swap_buffers_with_damage"))
- priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageEXT");
+ return api;
+}
- gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
+static GdkGLAPI
+gdk_gl_context_default_realize (GdkGLContext *context,
+ GError **error)
+{
+#ifdef HAVE_EGL
+ GdkDisplay *display = gdk_gl_context_get_display (context);
- return api;
- }
+ if (gdk_display_get_egl_display (display))
+ return gdk_gl_context_realize_egl (context, error);
#endif
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
@@ -667,7 +674,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
- klass->realize = gdk_gl_context_real_realize;
+ klass->realize = gdk_gl_context_default_realize;
klass->get_damage = gdk_gl_context_real_get_damage;
klass->is_shared = gdk_gl_context_real_is_shared;
klass->make_current = gdk_gl_context_real_make_current;
@@ -1845,4 +1852,3 @@ gdk_gl_backend_use (GdkGLBackend backend_type)
g_assert (the_gl_backend_type == backend_type);
}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]