summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2022-01-18 10:41:28 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2022-01-19 11:56:32 +0800
commit6f2848c311fd06f8bf33bb755bc1cf665ffe0bc3 (patch)
tree1bcdb552324f2fd47bf1b159b22ab16c20859b56
parent38c17c1f796a394d0cf559712ac7a78409c4ea8b (diff)
downloadgtk+-6f2848c311fd06f8bf33bb755bc1cf665ffe0bc3.tar.gz
Cleanup "GDK/Win32: Try to fix initializing GLES contexts"
As per Benjamin's suggestions, cleanup the previous implementation on initializing the GLES context on Windows, so that we use more items that are already in GDK proper and integrate two functions into one.
-rw-r--r--gdk/win32/gdkdisplay-win32.c93
-rw-r--r--gdk/win32/gdkdisplay-win32.h8
-rw-r--r--gdk/win32/gdkglcontext-win32-wgl.c5
3 files changed, 41 insertions, 65 deletions
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index 14de69ff7b..aee962bd80 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -1175,17 +1175,19 @@ gdk_win32_display_get_setting (GdkDisplay *display,
#define EGL_PLATFORM_ANGLE_ANGLE 0x3202
#endif
-static gboolean
-gdk_win32_display_init_gl_backend (GdkDisplay *display,
- GError **error)
+static GdkGLContext *
+gdk_win32_display_init_gl (GdkDisplay *display,
+ GError **error)
{
- gboolean result = FALSE;
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
- GdkWin32GLType gl_type = GDK_WIN32_GL_TYPE_NONE;
+ HDC init_gl_hdc = NULL;
+ gboolean is_egl = FALSE;
if (display_win32->dummy_context_wgl.hdc == NULL)
display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
+ init_gl_hdc = display_win32->dummy_context_wgl.hdc;
+
/*
* No env vars set, do the regular GL initialization, first WGL and then EGL,
* as WGL is the more tried-and-tested configuration.
@@ -1193,78 +1195,63 @@ gdk_win32_display_init_gl_backend (GdkDisplay *display,
#ifdef HAVE_EGL
/*
- * Disable defaulting to EGL for now, since shaders need to be fixed for
- * usage against libANGLE EGL. EGL is used more as a compatibility layer
+ * Disable defaulting to EGL as EGL is used more as a compatibility layer
* on Windows rather than being a native citizen on Windows
*/
if (GDK_DEBUG_CHECK (GL_EGL) || GDK_DEBUG_CHECK (GL_GLES))
{
- result = gdk_display_init_egl (display,
- EGL_PLATFORM_ANGLE_ANGLE,
- display_win32->dummy_context_wgl.hdc,
- FALSE,
- error);
-
- if (result)
- gl_type = GDK_WIN32_GL_TYPE_EGL;
+ if (gdk_display_init_egl (display,
+ EGL_PLATFORM_ANGLE_ANGLE,
+ init_gl_hdc,
+ FALSE,
+ error))
+ is_egl = TRUE;
}
#endif
- if (!result)
+ if (!is_egl)
{
g_clear_error (error);
- result = gdk_win32_display_init_wgl (display, error);
- if (result)
- gl_type = GDK_WIN32_GL_TYPE_WGL;
+ if (gdk_win32_display_init_wgl (display, error))
+ {
+ gdk_gl_backend_use (GDK_GL_WGL);
+ return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL,
+ "display", display,
+ NULL);
+ }
}
-
#ifdef HAVE_EGL
- if (!result)
+ if (!is_egl)
{
g_clear_error (error);
- result = gdk_display_init_egl (display,
- EGL_PLATFORM_ANGLE_ANGLE,
- display_win32->dummy_context_wgl.hdc,
- TRUE,
- error);
-
- if (result)
- gl_type = GDK_WIN32_GL_TYPE_EGL;
- }
-#endif
- display_win32->gl_type = gl_type;
- return result;
-}
-
-static GdkGLContext *
-gdk_win32_display_init_gl (GdkDisplay *display,
- GError **error)
-{
- GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
- GdkGLContext *gl_context = NULL;
-
- if (!gdk_win32_display_init_gl_backend (display, error))
- return NULL;
+ if (gdk_display_init_egl (display,
+ EGL_PLATFORM_ANGLE_ANGLE,
+ init_gl_hdc,
+ TRUE,
+ error))
+ is_egl = TRUE;
+ }
- if (display_win32->gl_type == GDK_WIN32_GL_TYPE_WGL)
- gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL, "display", display, NULL);
-#ifdef HAVE_EGL
- else if (display_win32->gl_type == GDK_WIN32_GL_TYPE_EGL)
+ if (is_egl)
{
- gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL, "display", display, NULL);
+ GdkGLContext *gl_context = NULL;
- /* We want to use a GLES 3.0+ context */
+ /* We want to use a GLES 3.0+ context for libANGLE GLES */
+ gdk_gl_backend_use (GDK_GL_EGL);
+ gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
+ "display", display,
+ NULL);
gdk_gl_context_set_allowed_apis (gl_context, GDK_GL_API_GLES);
gdk_gl_context_set_required_version (gl_context, 3, 0);
+
+ return gl_context;
}
#endif
- g_return_val_if_fail (gl_context != NULL, NULL);
-
- return gl_context;
+ g_return_val_if_reached (NULL);
}
/**
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index 88757e03e0..19f11e5f9f 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -105,13 +105,6 @@ typedef enum {
GDK_WIN32_TABLET_INPUT_API_WINPOINTER
} GdkWin32TabletInputAPI;
-typedef enum
-{
- GDK_WIN32_GL_TYPE_NONE,
- GDK_WIN32_GL_TYPE_WGL,
- GDK_WIN32_GL_TYPE_EGL,
-} GdkWin32GLType;
-
typedef struct
{
HDC hdc;
@@ -132,7 +125,6 @@ struct _GdkWin32Display
/* WGL/OpenGL Items */
GdkWin32GLDummyContextWGL dummy_context_wgl;
- GdkWin32GLType gl_type;
guint gl_version;
GListModel *monitors;
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index 9a90ccffc6..231f2a6a01 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -258,9 +258,6 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
if (!gdk_gl_backend_can_be_used (GDK_GL_WGL, error))
return FALSE;
- if (display_win32->gl_type == GDK_WIN32_GL_TYPE_WGL)
- return TRUE;
-
/* acquire and cache dummy Window (HWND & HDC) and
* dummy GL Context, it is used to query functions
* and used for other stuff as well
@@ -724,7 +721,7 @@ gdk_win32_display_get_wgl_version (GdkDisplay *display,
if (!GDK_IS_WIN32_DISPLAY (display))
return FALSE;
- if (!gdk_win32_display_init_wgl (display, NULL))
+ if (!gdk_gl_backend_can_be_used (GDK_GL_WGL, NULL))
return FALSE;
display_win32 = GDK_WIN32_DISPLAY (display);