From f02e0916837d1a789db99797d572399bd603e7fb Mon Sep 17 00:00:00 2001 From: James Price Date: Fri, 10 Jun 2022 00:13:13 +0000 Subject: [PATCH] Remove requirement for glfw 3.4 Only try to use `glfwGetPlatform()` to distinguish X11 and Wayland if GLFW 3.4 is present. This fixes the build with older GLFW versions. Change-Id: Ia986933eeb3f049336bcd06c71b326f92a1da284 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93262 Commit-Queue: James Price Kokoro: Kokoro Reviewed-by: Kai Ninomiya --- src/dawn/utils/GLFWUtils.cpp | 59 +++++++++++++++++------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/dawn/utils/GLFWUtils.cpp b/src/dawn/utils/GLFWUtils.cpp index 74e8c73f5d..3ba577f72c 100644 --- a/src/dawn/utils/GLFWUtils.cpp +++ b/src/dawn/utils/GLFWUtils.cpp @@ -67,41 +67,38 @@ wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance, GLFWwindow* std::unique_ptr SetupWindowAndGetSurfaceDescriptorCocoa(GLFWwindow* window); std::unique_ptr SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window) { - switch (glfwGetPlatform()) { #if DAWN_PLATFORM_IS(WINDOWS) - case GLFW_PLATFORM_WIN32: { - std::unique_ptr desc = - std::make_unique(); - desc->hwnd = glfwGetWin32Window(window); - desc->hinstance = GetModuleHandle(nullptr); - return std::move(desc); - } -#endif -#if defined(DAWN_ENABLE_BACKEND_METAL) - case GLFW_PLATFORM_COCOA: - return SetupWindowAndGetSurfaceDescriptorCocoa(window); -#endif -#if defined(DAWN_USE_WAYLAND) - case GLFW_PLATFORM_WAYLAND: { - std::unique_ptr desc = - std::make_unique(); - desc->display = glfwGetWaylandDisplay(); - desc->surface = glfwGetWaylandWindow(window); - return std::move(desc); - } + std::unique_ptr desc = + std::make_unique(); + desc->hwnd = glfwGetWin32Window(window); + desc->hinstance = GetModuleHandle(nullptr); + return std::move(desc); +#elif defined(DAWN_ENABLE_BACKEND_METAL) + return SetupWindowAndGetSurfaceDescriptorCocoa(window); +#elif defined(DAWN_USE_WAYLAND) || defined(DAWN_USE_X11) +#if defined(GLFW_PLATFORM_WAYLAND) && defined(DAWN_USE_WAYLAND) + if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) { + std::unique_ptr desc = + std::make_unique(); + desc->display = glfwGetWaylandDisplay(); + desc->surface = glfwGetWaylandWindow(window); + return std::move(desc); + } else // NOLINT(readability/braces) #endif #if defined(DAWN_USE_X11) - case GLFW_PLATFORM_X11: { - std::unique_ptr desc = - std::make_unique(); - desc->display = glfwGetX11Display(); - desc->window = glfwGetX11Window(window); - return std::move(desc); - } -#endif - default: - return nullptr; + { + std::unique_ptr desc = + std::make_unique(); + desc->display = glfwGetX11Display(); + desc->window = glfwGetX11Window(window); + return std::move(desc); } +#else + { return nullptr; } +#endif +#else + return nullptr; +#endif } } // namespace utils