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.
This commit is contained in:
Chun-wei Fan 2022-01-18 10:41:28 +08:00
parent 38c17c1f79
commit 6f2848c311
3 changed files with 40 additions and 64 deletions

View File

@ -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;
if (gdk_display_init_egl (display,
EGL_PLATFORM_ANGLE_ANGLE,
init_gl_hdc,
TRUE,
error))
is_egl = TRUE;
}
#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 (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);
}
/**

View File

@ -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;

View File

@ -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);