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.
This commit is contained in:
Chun-wei Fan
2019-05-07 00:09:03 -07:00
parent b8b966ef80
commit 98996aa60b
3 changed files with 53 additions and 1 deletions

View File

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

View File

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

View File

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