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> SetupWindowAndGetSurfaceDescriptor(GLFWwindow* window) {
switch (glfwGetPlatform()) {
#if DAWN_PLATFORM_IS(WINDOWS)
case GLFW_PLATFORM_WIN32: {
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
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<wgpu::SurfaceDescriptorFromWaylandSurface> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>();
desc->display = glfwGetWaylandDisplay();
desc->surface = glfwGetWaylandWindow(window);
return std::move(desc);
}
std::unique_ptr<wgpu::SurfaceDescriptorFromWindowsHWND> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
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<wgpu::SurfaceDescriptorFromWaylandSurface> desc =
std::make_unique<wgpu::SurfaceDescriptorFromWaylandSurface>();
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<wgpu::SurfaceDescriptorFromXlibWindow> desc =
std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>();
desc->display = glfwGetX11Display();
desc->window = glfwGetX11Window(window);
return std::move(desc);
}
#endif
default:
return nullptr;
{
std::unique_ptr<wgpu::SurfaceDescriptorFromXlibWindow> desc =
std::make_unique<wgpu::SurfaceDescriptorFromXlibWindow>();
desc->display = glfwGetX11Display();
desc->window = glfwGetX11Window(window);
return std::move(desc);
}
#else
{ return nullptr; }
#endif
#else
return nullptr;
#endif
}
} // namespace utils