[gtk/gles-windows-arm64] GDK/Win32: Force GLES if running on ARM64
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gles-windows-arm64] GDK/Win32: Force GLES if running on ARM64
- Date: Tue, 7 Jul 2020 08:56:42 +0000 (UTC)
commit 98996aa60bbc1233b63fdc7254d80a4d62a648ba
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Tue May 7 00:09:03 2019 -0700
GDK/Win32: Force GLES if running on ARM64
If GLES support is enabled on Windows, force GLES mode if we are running
on a ARM64 version of Windows (i.e. Windows 10 for ARM).
This is required as ARM64 versions of Windows only provide a software
implementation of OpenGL 1.1/1.2, which is not enough for our purposes.
Thus, we could make instead use the GLES support provided via Google's
libANGLE (which emulates OpenGL/ES 3 with Direct3D 9/11), so that we
can run GtkGLArea programs under OpenGL/ES in ARM64 versions of Windows.
Note that eventually we could update the libepoxy build files for Windows
to not check nor enable WGL when building for ARM64 Windows, as the WGL
items do not work, although they do build.
gdk/win32/gdkdisplay-win32.c | 39 +++++++++++++++++++++++++++++++++++++++
gdk/win32/gdkdisplay-win32.h | 11 +++++++++++
gdk/win32/gdkglcontext-win32.c | 4 +++-
3 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index 5c18ba689e..c2b572b402 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -37,6 +37,10 @@
#include "gdkwin32langnotification.h"
+#ifndef IMAGE_FILE_MACHINE_ARM64
+# define IMAGE_FILE_MACHINE_ARM64 0xAA64
+#endif
+
static int debug_indent = 0;
static GdkMonitor *
@@ -1034,6 +1038,40 @@ _gdk_win32_enable_hidpi (GdkWin32Display *display)
}
}
+static void
+_gdk_win32_check_on_arm64 (GdkWin32Display *display)
+{
+ static gsize checked = 0;
+
+ if (g_once_init_enter (&checked))
+ {
+ HMODULE kernel32 = LoadLibraryW (L"kernel32.dll");
+
+ if (kernel32 != NULL)
+ {
+ display->cpu_funcs.isWow64Process2 =
+ (funcIsWow64Process2) GetProcAddress (kernel32, "IsWow64Process2");
+
+ if (display->cpu_funcs.isWow64Process2 != NULL)
+ {
+ USHORT proc_cpu = 0;
+ USHORT native_cpu = 0;
+
+ display->cpu_funcs.isWow64Process2 (GetCurrentProcess (),
+ &proc_cpu,
+ &native_cpu);
+
+ if (native_cpu == IMAGE_FILE_MACHINE_ARM64)
+ display->running_on_arm64 = TRUE;
+ }
+
+ FreeLibrary (kernel32);
+ }
+
+ g_once_init_leave (&checked, 1);
+ }
+}
+
static void
gdk_win32_display_init (GdkWin32Display *display)
{
@@ -1042,6 +1080,7 @@ gdk_win32_display_init (GdkWin32Display *display)
display->monitors = g_ptr_array_new_with_free_func (g_object_unref);
_gdk_win32_enable_hidpi (display);
+ _gdk_win32_check_on_arm64 (display);
/* if we have DPI awareness, set up fixed scale if set */
if (display->dpi_aware_type != PROCESS_DPI_UNAWARE &&
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index ad8db96f0f..3089f4dea0 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -60,6 +60,13 @@ typedef struct _GdkWin32User32DPIFuncs
funcIsProcessDPIAware isDpiAwareFunc;
} GdkWin32User32DPIFuncs;
+/* Detect running architecture */
+typedef BOOL (WINAPI *funcIsWow64Process2) (HANDLE, USHORT *, USHORT *);
+typedef struct _GdkWin32KernelCPUFuncs
+{
+ funcIsWow64Process2 isWow64Process2;
+} GdkWin32KernelCPUFuncs;
+
struct _GdkWin32Display
{
GdkDisplay display;
@@ -109,6 +116,10 @@ struct _GdkWin32Display
GdkWin32ShcoreFuncs shcore_funcs;
GdkWin32User32DPIFuncs user32_dpi_funcs;
+
+ /* Running CPU items */
+ guint running_on_arm64 : 1;
+ GdkWin32KernelCPUFuncs cpu_funcs;
};
struct _GdkWin32DisplayClass
diff --git a/gdk/win32/gdkglcontext-win32.c b/gdk/win32/gdkglcontext-win32.c
index 26a8b02a6a..0782c9a59a 100644
--- a/gdk/win32/gdkglcontext-win32.c
+++ b/gdk/win32/gdkglcontext-win32.c
@@ -577,7 +577,9 @@ _gdk_win32_display_init_gl (GdkDisplay *display,
#ifdef GDK_WIN32_ENABLE_EGL
EGLDisplay egl_disp;
- disable_wgl = (_gdk_gl_flags & GDK_GL_GLES) != 0;
+
+ disable_wgl = ((_gdk_gl_flags & GDK_GL_GLES) != 0) ||
+ display_win32->running_on_arm64;
#endif
if (display_win32->have_wgl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]