[gtk/wip.win32.fixes] WIP: GDK-Win32: Port to common EGL handling code
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip.win32.fixes] WIP: GDK-Win32: Port to common EGL handling code
- Date: Thu, 7 Oct 2021 09:04:37 +0000 (UTC)
commit 3e156a923ab65348111001295589718b2a383d66
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Thu Oct 7 17:04:09 2021 +0800
WIP: GDK-Win32: Port to common EGL handling code
gdk/win32/gdkdisplay-win32.c | 60 +++++------
gdk/win32/gdkdisplay-win32.h | 8 --
gdk/win32/gdkglcontext-win32-egl.c | 207 +++++--------------------------------
gdk/win32/gdkglcontext-win32-wgl.c | 3 -
gdk/win32/gdksurface-win32.c | 12 +--
5 files changed, 63 insertions(+), 227 deletions(-)
---
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index e89e35bb14..d98ccdadae 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -645,14 +645,6 @@ gdk_win32_display_dispose (GObject *object)
{
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (object);
-#ifdef HAVE_EGL
- if (display_win32->egl_disp != EGL_NO_DISPLAY)
- {
- eglTerminate (display_win32->egl_disp);
- display_win32->egl_disp = EGL_NO_DISPLAY;
- }
-#endif
-
if (display_win32->hwnd != NULL)
{
if (display_win32->dummy_context_wgl.hglrc != NULL)
@@ -1146,23 +1138,47 @@ gdk_win32_display_get_setting (GdkDisplay *display,
return _gdk_win32_get_setting (name, value);
}
+#ifndef EGL_PLATFORM_ANGLE_ANGLE
+#define EGL_PLATFORM_ANGLE_ANGLE 0x3202
+#endif
+
static gboolean
gdk_win32_display_init_gl_backend (GdkDisplay *display,
GError **error)
{
gboolean result = FALSE;
+ GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
+
+ if (display_win32->dummy_context_wgl.hdc == NULL)
+ display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
/* No env vars set, do the regular GL initialization, first WGL and then EGL,
* as WGL is the more tried-and-tested configuration.
*/
- result = gdk_win32_display_init_wgl (display, error);
+#ifdef HAVE_EGL
+ result = gdk_display_init_egl (display,
+ EGL_PLATFORM_ANGLE_ANGLE,
+ display_win32->dummy_context_wgl.hdc,
+ FALSE,
+ error);
+#endif
+
+ if (!result)
+ {
+ g_clear_error (error);
+ result = gdk_win32_display_init_wgl (display, error);
+ }
#ifdef HAVE_EGL
if (!result)
{
g_clear_error (error);
- result = gdk_win32_display_init_egl (display, error);
+ result = gdk_display_init_egl (display,
+ EGL_PLATFORM_ANGLE_ANGLE,
+ display_win32->dummy_context_wgl.hdc,
+ TRUE,
+ error);
}
#endif
@@ -1179,17 +1195,17 @@ gdk_win32_display_init_gl (GdkDisplay *display,
if (!gdk_win32_display_init_gl_backend (display, error))
return NULL;
+ if (display_win32->wgl_pixel_format != 0)
+ gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL, "display", display, NULL);
#ifdef HAVE_EGL
- if (display_win32->egl_disp)
+ else if (gdk_display_get_egl_display (display))
gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL, "display", display, NULL);
- else
#endif
- if (display_win32->wgl_pixel_format != 0)
- gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL, "display", display, NULL);
g_return_val_if_fail (gl_context != NULL, NULL);
return gl_context;
+
}
/**
@@ -1203,23 +1219,9 @@ gdk_win32_display_init_gl (GdkDisplay *display,
gpointer
gdk_win32_display_get_egl_display (GdkDisplay *display)
{
-#ifdef HAVE_EGL
- GdkWin32Display *display_win32;
-#endif
-
g_return_val_if_fail (GDK_IS_WIN32_DISPLAY (display), NULL);
-#ifdef HAVE_EGL
- display_win32 = GDK_WIN32_DISPLAY (display);
-
- if (display_win32->wgl_pixel_format != 0)
- return NULL;
-
- return display_win32->egl_disp;
-#else
- /* no EGL support */
- return NULL;
-#endif
+ return gdk_display_get_egl_display (display);
}
static void
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index d8d3d121e6..22532cf39a 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -135,14 +135,6 @@ struct _GdkWin32Display
int wgl_pixel_format;
guint gl_version;
-#ifdef HAVE_EGL
- /* EGL (Angle) Items */
- guint egl_version;
- EGLDisplay egl_disp;
- EGLConfig egl_config;
- HDC hdc_egl_temp;
-#endif
-
GListModel *monitors;
guint hasWglARBCreateContext : 1;
diff --git a/gdk/win32/gdkglcontext-win32-egl.c b/gdk/win32/gdkglcontext-win32-egl.c
index 2f62e8c45a..1c82b921b4 100644
--- a/gdk/win32/gdkglcontext-win32-egl.c
+++ b/gdk/win32/gdkglcontext-win32-egl.c
@@ -58,21 +58,20 @@ gdk_win32_gl_context_egl_dispose (GObject *gobject)
{
GdkGLContext *context = GDK_GL_CONTEXT (gobject);
GdkWin32GLContextEGL *context_egl = GDK_WIN32_GL_CONTEXT_EGL (gobject);
- GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (gdk_gl_context_get_display (context));
+ GdkDisplay *display = gdk_gl_context_get_display (context);
GdkSurface *surface = gdk_gl_context_get_surface (context);
- if (display_win32 != NULL)
- {
- if (eglGetCurrentContext () == context_egl->egl_context)
- eglMakeCurrent(display_win32->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE,
- EGL_NO_CONTEXT);
+ if (eglGetCurrentContext () == context_egl->egl_context)
+ eglMakeCurrent(gdk_display_get_egl_display (display),
+ EGL_NO_SURFACE,
+ EGL_NO_SURFACE,
+ EGL_NO_CONTEXT);
- GDK_NOTE (OPENGL, g_message ("Destroying EGL (ANGLE) context"));
+ GDK_NOTE (OPENGL, g_message ("Destroying EGL (ANGLE) context"));
- eglDestroyContext (display_win32->egl_disp,
- context_egl->egl_context);
- context_egl->egl_context = EGL_NO_CONTEXT;
- }
+ eglDestroyContext (gdk_display_get_egl_display (display),
+ context_egl->egl_context);
+ context_egl->egl_context = EGL_NO_CONTEXT;
G_OBJECT_CLASS (gdk_win32_gl_context_egl_parent_class)->dispose (gobject);
}
@@ -109,7 +108,7 @@ gdk_win32_gl_context_egl_end_frame (GdkDrawContext *draw_context,
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
GdkWin32GLContextEGL *context_egl = GDK_WIN32_GL_CONTEXT_EGL (context);
GdkSurface *surface = gdk_gl_context_get_surface (context);
- GdkWin32Display *display_win32 = (GDK_WIN32_DISPLAY (gdk_gl_context_get_display (context)));
+ GdkDisplay *display = gdk_gl_context_get_display (context);
cairo_rectangle_int_t whole_window;
EGLSurface egl_surface;
@@ -122,7 +121,7 @@ gdk_win32_gl_context_egl_end_frame (GdkDrawContext *draw_context,
gdk_surface_get_height (surface)
};
- egl_surface = gdk_win32_surface_get_egl_surface (surface, display_win32->egl_config, FALSE);
+ egl_surface = gdk_surface_get_egl_surface (surface);
if (is_egl_force_redraw (surface))
{
@@ -135,7 +134,7 @@ gdk_win32_gl_context_egl_end_frame (GdkDrawContext *draw_context,
reset_egl_force_redraw (surface);
}
- eglSwapBuffers (display_win32->egl_disp, egl_surface);
+ eglSwapBuffers (gdk_display_get_egl_display (display), egl_surface);
}
#ifndef EGL_PLATFORM_ANGLE_ANGLE
@@ -150,103 +149,6 @@ gdk_win32_gl_context_egl_end_frame (GdkDrawContext *draw_context,
#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208
#endif
-static EGLDisplay
-gdk_win32_get_egl_display (GdkWin32Display *display)
-{
- EGLDisplay disp;
-
- if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
- {
- PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay = (void *) eglGetProcAddress
("eglGetPlatformDisplayEXT");
- if (getPlatformDisplay)
- {
- EGLint disp_attr[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
EGL_NONE};
-
- disp = getPlatformDisplay (EGL_PLATFORM_ANGLE_ANGLE, display->hdc_egl_temp, disp_attr);
-
- if (disp != EGL_NO_DISPLAY)
- return disp;
- }
- }
-
- return eglGetDisplay (display->hdc_egl_temp);
-}
-
-#define MAX_EGL_ATTRS 30
-
-static gboolean
-find_eglconfig_for_window (GdkWin32Display *display,
- EGLConfig *egl_config_out,
- EGLint *min_swap_interval_out,
- GError **error)
-{
- EGLint attrs[MAX_EGL_ATTRS];
- EGLint count;
- EGLConfig *configs, chosen_config;
-
- int i = 0;
-
- EGLDisplay egl_disp = display->egl_disp;
-
- attrs[i++] = EGL_CONFORMANT;
- attrs[i++] = EGL_OPENGL_ES2_BIT;
- attrs[i++] = EGL_SURFACE_TYPE;
- attrs[i++] = EGL_WINDOW_BIT;
-
- attrs[i++] = EGL_COLOR_BUFFER_TYPE;
- attrs[i++] = EGL_RGB_BUFFER;
-
- attrs[i++] = EGL_RED_SIZE;
- attrs[i++] = 1;
- attrs[i++] = EGL_GREEN_SIZE;
- attrs[i++] = 1;
- attrs[i++] = EGL_BLUE_SIZE;
- attrs[i++] = 1;
- attrs[i++] = EGL_ALPHA_SIZE;
- attrs[i++] = 1;
-
- attrs[i++] = EGL_NONE;
- g_assert (i < MAX_EGL_ATTRS);
-
- if (!eglChooseConfig (display->egl_disp, attrs, NULL, 0, &count) || count < 1)
- {
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_UNSUPPORTED_FORMAT,
- _("No available configurations for the given pixel format"));
- return FALSE;
- }
-
- configs = g_new (EGLConfig, count);
-
- if (!eglChooseConfig (display->egl_disp, attrs, configs, count, &count) || count < 1)
- {
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_UNSUPPORTED_FORMAT,
- _("No available configurations for the given pixel format"));
- return FALSE;
- }
-
- /* Pick first valid configuration i guess? */
- chosen_config = configs[0];
-
- if (!eglGetConfigAttrib (display->egl_disp, chosen_config,
- EGL_MIN_SWAP_INTERVAL, min_swap_interval_out))
- {
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_NOT_AVAILABLE,
- "Could not retrieve the minimum swap interval");
- g_free (configs);
- return FALSE;
- }
-
- if (egl_config_out != NULL)
- *egl_config_out = chosen_config;
-
- g_free (configs);
-
- return TRUE;
-}
-
#ifdef G_ENABLE_DEBUG
static int
@@ -306,67 +208,6 @@ describe_egl_config (EGLDisplay dpy,
}
#endif
-gboolean
-gdk_win32_display_init_egl (GdkDisplay *display,
- GError **error)
-{
- GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
- int best_idx = 0;
- EGLDisplay egl_disp;
-
- if (!gdk_gl_backend_can_be_used (GDK_GL_EGL, error))
- return FALSE;
-
- if (display_win32->egl_disp != EGL_NO_DISPLAY)
- return TRUE;
-
- egl_disp = gdk_win32_get_egl_display (display_win32);
-
- if (egl_disp == EGL_NO_DISPLAY)
- return FALSE;
-
- if (!eglInitialize (egl_disp, NULL, NULL))
- {
- eglTerminate (egl_disp);
- egl_disp = EGL_NO_DISPLAY;
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_NOT_AVAILABLE,
- _("No GL implementation is available"));
- return FALSE;
- }
-
- display_win32->egl_disp = egl_disp;
- display_win32->egl_version = epoxy_egl_version (egl_disp);
-
- eglBindAPI (EGL_OPENGL_ES_API);
-
- display_win32->hasEglSurfacelessContext =
- epoxy_has_egl_extension (egl_disp, "EGL_KHR_surfaceless_context");
-
-
- GDK_DISPLAY_NOTE (display, OPENGL, {
- char *ext = describe_extensions (display_win32->egl_disp);
- char *cfg = describe_egl_config (display_win32->egl_disp,
- display_win32->egl_config);
- g_message ("EGL found\n"
- " - Version: %s\n"
- " - Vendor: %s\n"
- " - Client API: %s\n"
- " - Extensions:\n"
- "\t%s\n"
- " - Config: %s",
- eglQueryString (display_win32->egl_disp, EGL_VERSION),
- eglQueryString (display_win32->egl_disp, EGL_VENDOR),
- eglQueryString (display_win32->egl_disp, EGL_CLIENT_APIS),
- ext, cfg);
- g_free (ext);
- g_free (cfg);
- });
-
- return find_eglconfig_for_window (display_win32, &display_win32->egl_config,
- &display_win32->egl_min_swap_interval, error);
-}
-
#define N_EGL_ATTRS 16
static EGLContext
@@ -424,7 +265,8 @@ gdk_win32_gl_context_egl_realize (GdkGLContext *context,
GdkSurface *surface = gdk_gl_context_get_surface (context);
GdkWin32Surface *impl = GDK_WIN32_SURFACE (surface);
GdkDisplay *display = gdk_gl_context_get_display (context);
- GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
+ EGLDisplay egl_display = gdk_display_get_egl_display (display);
+ EGLConfig egl_config = gdk_display_get_egl_config (display);
GdkGLContext *share = gdk_display_get_gl_context (display);
gdk_gl_context_get_required_version (context, &major, &minor);
@@ -455,8 +297,8 @@ gdk_win32_gl_context_egl_realize (GdkGLContext *context,
compat_bit ? "yes" : "no",
legacy_bit ? "yes" : "no"));
- ctx = create_egl_context (display_win32->egl_disp,
- display_win32->egl_config,
+ ctx = create_egl_context (egl_display,
+ egl_config,
share,
flags,
major,
@@ -489,9 +331,10 @@ gdk_win32_gl_context_egl_clear_current (GdkGLContext *context)
{
GdkDisplay *display = gdk_gl_context_get_display (context);
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
+ EGLDisplay egl_display = gdk_display_get_egl_display (display);
- if (display_win32->egl_disp != EGL_NO_DISPLAY)
- return eglMakeCurrent (display_win32->egl_disp,
+ if (egl_display != EGL_NO_DISPLAY)
+ return eglMakeCurrent (egl_display,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT);
@@ -506,6 +349,8 @@ gdk_win32_gl_context_egl_make_current (GdkGLContext *context,
GdkWin32GLContextEGL *context_egl = GDK_WIN32_GL_CONTEXT_EGL (context);
GdkDisplay *display = gdk_gl_context_get_display (context);
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
+ EGLDisplay egl_display = gdk_display_get_egl_display (display);
+ EGLConfig egl_config = gdk_display_get_egl_config (display);
GdkSurface *surface;
gboolean do_frame_sync = FALSE;
@@ -515,23 +360,23 @@ gdk_win32_gl_context_egl_make_current (GdkGLContext *context,
surface = gdk_gl_context_get_surface (context);
if (!surfaceless)
- egl_surface = gdk_win32_surface_get_egl_surface (surface, display_win32->egl_config, FALSE);
+ egl_surface = gdk_surface_get_egl_surface (surface);
else
{
if (display_win32->hasEglSurfacelessContext)
egl_surface = EGL_NO_SURFACE;
else
- egl_surface = gdk_win32_surface_get_egl_surface (surface, display_win32->egl_config, TRUE);
+ egl_surface = gdk_surface_get_egl_surface (surface);
}
- if (!eglMakeCurrent (display_win32->egl_disp,
+ if (!eglMakeCurrent (egl_display,
egl_surface,
egl_surface,
context_egl->egl_context))
return FALSE;
if (display_win32->egl_min_swap_interval == 0)
- eglSwapInterval (display_win32->egl_disp, 0);
+ eglSwapInterval (egl_display, 0);
else
g_debug ("Can't disable GL swap interval");
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index ea5f377966..a731a00704 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -226,9 +226,6 @@ gdk_init_dummy_wgl_context (GdkWin32Display *display_win32)
gboolean set_pixel_format_result = FALSE;
int best_idx = 0;
- if (display_win32->dummy_context_wgl.hdc == NULL)
- display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
-
memset (&pfd, 0, sizeof (PIXELFORMATDESCRIPTOR));
best_idx = get_wgl_pfd (display_win32->dummy_context_wgl.hdc, &pfd, NULL);
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index 72a794beab..082162824d 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -690,17 +690,17 @@ gdk_win32_surface_destroy (GdkSurface *window,
}
#ifdef HAVE_EGL
- GdkWin32Display *display = GDK_WIN32_DISPLAY (gdk_surface_get_display (window));
+ GdkDisplay *display = gdk_surface_get_display (window);
/* Get rid of any EGLSurfaces that we might have created */
if (surface->egl_surface != EGL_NO_SURFACE)
{
- eglDestroySurface (display->egl_disp, surface->egl_surface);
+ eglDestroySurface (gdk_display_get_egl_display (display), surface->egl_surface);
surface->egl_surface = EGL_NO_SURFACE;
}
if (surface->egl_dummy_surface != EGL_NO_SURFACE)
{
- eglDestroySurface (display->egl_disp, surface->egl_dummy_surface);
+ eglDestroySurface (gdk_display_get_egl_display (display), surface->egl_dummy_surface);
surface->egl_dummy_surface = EGL_NO_SURFACE;
}
#endif
@@ -5105,15 +5105,15 @@ gdk_win32_surface_get_egl_surface (GdkSurface *surface,
EGLConfig config,
gboolean is_dummy)
{
- GdkWin32Display *display = GDK_WIN32_DISPLAY (gdk_surface_get_display (surface));
GdkWin32Surface *impl = GDK_WIN32_SURFACE (surface);
+ GdkDisplay *display = gdk_surface_get_display (surface);
if (is_dummy)
{
if (impl->egl_dummy_surface == EGL_NO_SURFACE)
{
EGLint attribs[] = {EGL_WIDTH, 1, EGL_WIDTH, 1, EGL_NONE};
- impl->egl_dummy_surface = eglCreatePbufferSurface (display->egl_disp,
+ impl->egl_dummy_surface = eglCreatePbufferSurface (gdk_display_get_egl_display (display),
config,
attribs);
}
@@ -5122,7 +5122,7 @@ gdk_win32_surface_get_egl_surface (GdkSurface *surface,
else
{
if (impl->egl_surface == EGL_NO_SURFACE)
- impl->egl_surface = eglCreateWindowSurface (display->egl_disp,
+ impl->egl_surface = eglCreateWindowSurface (gdk_display_get_egl_display (display),
config,
GDK_SURFACE_HWND (surface),
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]