2022-07-27 11:25:25 -04:00
|
|
|
#include "BackendBinding.hpp"
|
|
|
|
|
|
2023-05-27 14:57:24 -04:00
|
|
|
#include <memory>
|
|
|
|
|
|
2026-03-30 21:34:03 -06:00
|
|
|
#if !defined(SDL_PLATFORM_MACOS) && !defined(SDL_PLATFORM_IOS) && !defined(SDL_PLATFORM_TVOS)
|
2025-04-04 22:01:52 -06:00
|
|
|
#include <SDL3/SDL_video.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-27 11:25:25 -04:00
|
|
|
namespace aurora::webgpu::utils {
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorCocoa(SDL_Window* window);
|
2023-05-27 11:44:36 -04:00
|
|
|
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptor(SDL_Window* window) {
|
2026-03-30 21:34:03 -06:00
|
|
|
#if defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS)
|
2023-05-27 11:44:36 -04:00
|
|
|
return SetupWindowAndGetSurfaceDescriptorCocoa(window);
|
|
|
|
|
#else
|
2025-04-02 19:57:16 -06:00
|
|
|
const auto props = SDL_GetWindowProperties(window);
|
2026-02-19 23:53:38 -07:00
|
|
|
#if defined(SDL_PLATFORM_ANDROID)
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::SurfaceSourceAndroidNativeWindow> desc =
|
|
|
|
|
std::make_shared<wgpu::SurfaceSourceAndroidNativeWindow>();
|
2026-02-19 23:53:38 -07:00
|
|
|
desc->window = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_ANDROID_WINDOW_POINTER, nullptr);
|
|
|
|
|
return std::move(desc);
|
|
|
|
|
#elif defined(SDL_PLATFORM_WIN32)
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::SurfaceSourceWindowsHWND> desc = std::make_shared<wgpu::SurfaceSourceWindowsHWND>();
|
2025-04-03 21:03:08 -06:00
|
|
|
desc->hwnd = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);
|
|
|
|
|
desc->hinstance = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER, nullptr);
|
2023-05-27 14:57:24 -04:00
|
|
|
return std::move(desc);
|
2025-04-02 19:57:16 -06:00
|
|
|
#elif defined(SDL_PLATFORM_LINUX)
|
2025-04-03 21:03:08 -06:00
|
|
|
const char* driver = SDL_GetCurrentVideoDriver();
|
|
|
|
|
if (SDL_strcmp(driver, "wayland") == 0) {
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::SurfaceSourceWaylandSurface> desc = std::make_shared<wgpu::SurfaceSourceWaylandSurface>();
|
2025-04-03 00:12:22 -06:00
|
|
|
desc->display = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr);
|
|
|
|
|
desc->surface = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, nullptr);
|
2023-05-27 14:57:24 -04:00
|
|
|
return std::move(desc);
|
|
|
|
|
}
|
2025-04-03 21:03:08 -06:00
|
|
|
if (SDL_strcmp(driver, "x11") == 0) {
|
2026-03-16 17:09:25 +01:00
|
|
|
std::shared_ptr<wgpu::SurfaceSourceXlibWindow> desc = std::make_shared<wgpu::SurfaceSourceXlibWindow>();
|
2025-04-03 00:12:22 -06:00
|
|
|
desc->display = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr);
|
|
|
|
|
desc->window = SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
|
2023-05-27 14:57:24 -04:00
|
|
|
return std::move(desc);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return nullptr;
|
|
|
|
|
#endif
|
2022-07-27 11:25:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace aurora::webgpu::utils
|