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 <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
James Price 2022-06-10 00:13:13 +00:00 committed by Dawn LUCI CQ
parent d45b920aed
commit f02e091683
1 changed files with 28 additions and 31 deletions

View File

@ -67,41 +67,38 @@ wgpu::Surface CreateSurfaceForWindow(const wgpu::Instance& instance, GLFWwindow*
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(GLFWwindow* window); std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(GLFWwindow* window);
std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window) { std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window) {
switch (glfwGetPlatform()) {
#if DAWN_PLATFORM_IS(WINDOWS) #if DAWN_PLATFORM_IS(WINDOWS)
case GLFW_PLATFORM_WIN32: { std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc = std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>(); desc->hwnd = glfwGetWin32Window(window);
desc->hwnd = glfwGetWin32Window(window); desc->hinstance = GetModuleHandle(nullptr);
desc->hinstance = GetModuleHandle(nullptr); return std::move(desc);
return std::move(desc); #elif defined(DAWN_ENABLE_BACKEND_METAL)
} return SetupWindowAndGetSurfaceDescriptorCocoa(window);
#endif #elif defined(DAWN_USE_WAYLAND) || defined(DAWN_USE_X11)
#if defined(DAWN_ENABLE_BACKEND_METAL) #if defined(GLFW_PLATFORM_WAYLAND) && defined(DAWN_USE_WAYLAND)
case GLFW_PLATFORM_COCOA: if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
return SetupWindowAndGetSurfaceDescriptorCocoa(window); std::unique_ptr<wgpu::SurfaceDescriptorFromWaylandSurface> desc =
#endif std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>();
#if defined(DAWN_USE_WAYLAND) desc->display = glfwGetWaylandDisplay();
case GLFW_PLATFORM_WAYLAND: { desc->surface = glfwGetWaylandWindow(window);
std::unique_ptr<wgpu::SurfaceDescriptorFromWaylandSurface> desc = return std::move(desc);
std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>(); } else // NOLINT(readability/braces)
desc->display = glfwGetWaylandDisplay();
desc->surface = glfwGetWaylandWindow(window);
return std::move(desc);
}
#endif #endif
#if defined(DAWN_USE_X11) #if defined(DAWN_USE_X11)
case GLFW_PLATFORM_X11: { {
std::unique_ptr<wgpu::SurfaceDescriptorFromXlibWindow> desc = std::unique_ptr<wgpu::SurfaceDescriptorFromXlibWindow> desc =
std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>(); std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>();
desc->display = glfwGetX11Display(); desc->display = glfwGetX11Display();
desc->window = glfwGetX11Window(window); desc->window = glfwGetX11Window(window);
return std::move(desc); return std::move(desc);
}
#endif
default:
return nullptr;
} }
#else
{ return nullptr; }
#endif
#else
return nullptr;
#endif
} }
} // namespace utils } // namespace utils