From e76db0f16514f0f7df88339e96697a0a24819162 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Wed, 1 Sep 2021 08:54:13 -0700 Subject: [PATCH] meson, egl: Support building for the Windows platform Add a stub EGL driver for Windows Fix compiler issues in egl/main Ensure Windows build produces libEGL.dll Default EGL to enabled for Windows when building a Gallium driver Reviewed-by: Eric Engestrom Reviewed By: Bill Kristiansen Acked-by: Roland Scheidegger Part-of: --- meson.build | 19 +++++++++++++------ src/egl/drivers/wgl/egl_wgl.c | 27 +++++++++++++++++++++++++++ src/egl/main/eglcurrent.c | 1 + src/egl/main/egldisplay.c | 5 +++++ src/egl/main/egldisplay.h | 1 + src/egl/main/eglglobals.c | 4 +++- src/egl/main/egllog.c | 1 - src/egl/meson.build | 9 +++++++++ 8 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/egl/drivers/wgl/egl_wgl.c diff --git a/meson.build b/meson.build index e2a909e1d8f..ac343b6b018 100644 --- a/meson.build +++ b/meson.build @@ -435,18 +435,19 @@ elif _egl == 'false' endif if _egl == 'auto' with_egl = ( - not ['darwin', 'windows'].contains(host_machine.system()) and - with_dri and with_shared_glapi + host_machine.system() != 'darwin' and + (with_platform_windows or with_dri) and + with_shared_glapi ) elif _egl == 'enabled' - if not with_dri and not with_platform_haiku - error('EGL requires dri') + if not with_dri and not with_platform_haiku and not with_platform_windows + error('EGL requires dri, haiku, or windows') elif not with_shared_glapi error('EGL requires shared-glapi') elif not ['disabled', 'dri'].contains(with_glx) error('EGL requires dri, but a GLX is being built without dri') - elif ['darwin', 'windows'].contains(host_machine.system()) - error('EGL is not available on Windows or MacOS') + elif host_machine.system() == 'darwin' + error('EGL is not available on MacOS') endif with_egl = true else @@ -913,6 +914,9 @@ endif if with_gbm and not with_platform_android pre_args += '-DHAVE_DRM_PLATFORM' endif +if with_platform_windows + pre_args += '-DHAVE_WINDOWS_PLATFORM' +endif with_android_stub = get_option('android-stub') if with_android_stub and not with_platform_android @@ -2188,6 +2192,9 @@ if with_egl if with_dri3 egl_drivers += 'builtin:egl_dri3' endif + if with_platform_windows + egl_drivers += 'builtin:wgl' + endif lines += 'EGL drivers: ' + ' '.join(egl_drivers) endif if with_egl or with_any_vk diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c new file mode 100644 index 00000000000..226c89d4af5 --- /dev/null +++ b/src/egl/drivers/wgl/egl_wgl.c @@ -0,0 +1,27 @@ +/* + * Copyright © Microsoft Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +struct _egl_driver _eglDriver; + diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index 11277d3e4c0..27b09fc4623 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -33,6 +33,7 @@ #include "c99_compat.h" #include "c11/threads.h" #include "util/u_thread.h" +#include "util/u_string.h" #include "egllog.h" #include "eglcurrent.h" diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 765618f0dd0..aa0c2d3a332 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -35,7 +35,11 @@ #include #include #include +#ifdef _WIN32 +#include +#else #include +#endif #include #include "c11/threads.h" #include "util/macros.h" @@ -77,6 +81,7 @@ static const struct { { _EGL_PLATFORM_HAIKU, "haiku" }, { _EGL_PLATFORM_SURFACELESS, "surfaceless" }, { _EGL_PLATFORM_DEVICE, "device" }, + { _EGL_PLATFORM_WINDOWS, "windows" }, }; diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 4d2afbc712e..66fb5b946e5 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -52,6 +52,7 @@ enum _egl_platform_type { _EGL_PLATFORM_HAIKU, _EGL_PLATFORM_SURFACELESS, _EGL_PLATFORM_DEVICE, + _EGL_PLATFORM_WINDOWS, _EGL_NUM_PLATFORMS, _EGL_INVALID_PLATFORM = -1 diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index e0e9044a924..8d815967f90 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -39,6 +39,7 @@ #include "egldisplay.h" #include "util/macros.h" +#include "util/os_misc.h" #ifdef HAVE_MINCORE #include @@ -137,7 +138,8 @@ EGLBoolean _eglPointerIsDereferencable(void *p) { uintptr_t addr = (uintptr_t) p; - const long page_size = getpagesize(); + uint64_t page_size = 0; + os_get_page_size(&page_size); #ifdef HAVE_MINCORE unsigned char valid = 0; diff --git a/src/egl/main/egllog.c b/src/egl/main/egllog.c index 6a91952577f..984dd5b1939 100644 --- a/src/egl/main/egllog.c +++ b/src/egl/main/egllog.c @@ -39,7 +39,6 @@ #include #include #include -#include #include "c11/threads.h" #include "util/macros.h" #include "util/u_string.h" diff --git a/src/egl/meson.build b/src/egl/meson.build index ab8f4e1fdbe..96bf322b8dc 100644 --- a/src/egl/meson.build +++ b/src/egl/meson.build @@ -140,6 +140,11 @@ elif with_platform_haiku files_egl += files('drivers/haiku/egl_haiku.cpp') link_for_egl += libgl deps_for_egl += cpp.find_library('be') +elif with_platform_windows + c_args_for_egl += [ + '-DEGLAPI=', '-DPUBLIC=' + ] + files_egl += files('drivers/wgl/egl_wgl.c') endif if cc.has_function('mincore') @@ -149,9 +154,11 @@ endif if not with_glvnd egl_lib_name = 'EGL' + get_option('egl-lib-suffix') egl_lib_version = '1.0.0' + egl_lib_soversion = host_machine.system() == 'windows' ? '' : '1' else egl_lib_name = 'EGL_@0@'.format(glvnd_vendor_name) egl_lib_version = '0.0.0' + egl_lib_soversion = '0' deps_for_egl += dep_glvnd files_egl += [g_egldispatchstubs_h, g_egldispatchstubs_c] files_egl += files('main/eglglvnd.c', 'main/egldispatchstubs.c') @@ -181,6 +188,8 @@ libegl = shared_library( dependencies : [deps_for_egl, dep_dl, dep_libdrm, dep_clock, dep_thread, idep_mesautil], install : true, version : egl_lib_version, + soversion : egl_lib_soversion, + name_prefix : 'lib', # even on windows ) if not with_glvnd