[gtk/wip.win32.fixes: 21/23] GDK/Win32: Re-enable libANGLE GLES to work




commit bfce3251b77fbea0b1a87bc22810bc52ace2dfb8
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Mar 25 17:59:28 2022 +0800

    GDK/Win32: Re-enable libANGLE GLES to work
    
    For libANGLE on Windows, it only supports GLES but not proper desktop GL,
    so check whether we are using a libANGLE EGL implementation and enforce
    that we only allow the GLES API set if so before we realize the context.

 gdk/win32/gdkdisplay-win32.c       | 36 ++++++++++++++++++++++++------------
 gdk/win32/gdkdisplay-win32.h       |  1 +
 gdk/win32/gdkglcontext-win32-egl.c | 16 ++++++++++++++++
 3 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index a544bf3827..2c9951bbd5 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -1181,6 +1181,7 @@ gdk_win32_display_init_gl (GdkDisplay  *display,
 {
   GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
   HDC init_gl_hdc = NULL;
+  GdkGLContext *ctx = NULL;
 
   if (display_win32->dummy_context_wgl.hdc == NULL)
     display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
@@ -1205,39 +1206,50 @@ gdk_win32_display_init_gl (GdkDisplay  *display,
                                 FALSE,
                                 error))
         {
-          return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
-                               "display", display,
-                               NULL);
+          ctx = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
+                              "display", display,
+                              NULL);
         }
       else
         g_clear_error (error);
     }
 #endif
 
-  if (gdk_win32_display_init_wgl (display, error))
+  if (ctx == NULL && gdk_win32_display_init_wgl (display, error))
     {
-      return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL,
-                           "display", display,
-                           NULL);
+      ctx = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL,
+                          "display", display,
+                          NULL);
     }
 
 #ifdef HAVE_EGL
   g_clear_error (error);
 
-  if (gdk_display_init_egl (display,
+  if (ctx == NULL &&
+      gdk_display_init_egl (display,
                             EGL_PLATFORM_ANGLE_ANGLE,
                             init_gl_hdc,
                             TRUE,
                             error))
     {
-      return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
-                           "display", display,
-                           NULL);
+      ctx = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
+                          "display", display,
+                          NULL);
 
     }
+
+  if (ctx != NULL && GDK_IS_WIN32_GL_CONTEXT_EGL (ctx))
+    {
+      EGLDisplay egl_disp = gdk_display_get_egl_display (display);
+      const char *angle_str = "ANGLE ";
+
+      display_win32->is_angle = strncmp (angle_str,
+                                         eglQueryString (egl_disp, EGL_VENDOR),
+                                         strlen (angle_str));
+    }
 #endif
 
-  return NULL;
+  return ctx;
 }
 
 /**
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index 19f11e5f9f..fde060b3e7 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -139,6 +139,7 @@ struct _GdkWin32Display
   guint hasEglKHRCreateContext : 1;
   guint hasEglSurfacelessContext : 1;
   EGLint egl_min_swap_interval;
+  guint is_angle : 1;
 #endif
 
   /* HiDPI Items */
diff --git a/gdk/win32/gdkglcontext-win32-egl.c b/gdk/win32/gdkglcontext-win32-egl.c
index e953bd9e13..761eae1802 100644
--- a/gdk/win32/gdkglcontext-win32-egl.c
+++ b/gdk/win32/gdkglcontext-win32-egl.c
@@ -124,6 +124,21 @@ gdk_win32_gl_context_egl_begin_frame (GdkDrawContext *draw_context,
   GDK_DRAW_CONTEXT_CLASS (gdk_win32_gl_context_egl_parent_class)->begin_frame (draw_context, 
prefers_high_depth, update_area);
 }
 
+static GdkGLAPI
+gdk_win32_gl_context_egl_realize (GdkGLContext *context,
+                                  GError **error)
+{
+  GdkDisplay *display =
+    gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
+  GdkGLContextClass *klass =
+    GDK_GL_CONTEXT_CLASS (gdk_win32_gl_context_egl_parent_class);
+
+  if (GDK_WIN32_DISPLAY (display)->is_angle)
+    gdk_gl_context_set_allowed_apis (context, GDK_GL_API_GLES);
+
+  return klass->realize (context, error);
+}
+
 static void
 gdk_win32_gl_context_egl_class_init (GdkWin32GLContextClass *klass)
 {
@@ -131,6 +146,7 @@ gdk_win32_gl_context_egl_class_init (GdkWin32GLContextClass *klass)
   GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS(klass);
 
   context_class->backend_type = GDK_GL_EGL;
+  context_class->realize = gdk_win32_gl_context_egl_realize;
 
   draw_context_class->begin_frame = gdk_win32_gl_context_egl_begin_frame;
   draw_context_class->end_frame = gdk_win32_gl_context_egl_end_frame;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]