mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-09 17:14:47 -06:00
UI: use atomics for window handle display/surface
This commit is contained in:
parent
e43871fa8a
commit
7d04612d06
@ -7,7 +7,7 @@ MetalLayerHandle::MetalLayerHandle(MTL::Device* device, const Vector2i& size, bo
|
||||
{
|
||||
const auto& windowInfo = (mainWindow ? WindowSystem::GetWindowInfo().window_main : WindowSystem::GetWindowInfo().window_pad);
|
||||
|
||||
m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.surface, m_layerScaleX, m_layerScaleY);
|
||||
m_layer = (CA::MetalLayer*)CreateMetalLayer(windowInfo.surface.load(), m_layerScaleX, m_layerScaleY);
|
||||
m_layer->setDevice(device);
|
||||
m_layer->setDrawableSize(CGSize{(float)size.x * m_layerScaleX, (float)size.y * m_layerScaleY});
|
||||
m_layer->setFramebufferOnly(true);
|
||||
|
||||
@ -53,7 +53,7 @@ public:
|
||||
private:
|
||||
bool HasMonitorChanged()
|
||||
{
|
||||
HWND hWnd = (HWND)WindowSystem::GetWindowInfo().canvas_main.surface;
|
||||
HWND hWnd = (HWND)WindowSystem::GetWindowInfo().canvas_main.surface.load(std::memory_order::relaxed);
|
||||
if (hWnd == 0)
|
||||
return true;
|
||||
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
|
||||
@ -71,7 +71,7 @@ private:
|
||||
|
||||
HRESULT GetAdapterHandleFromHwnd(D3DKMT_HANDLE* phAdapter, UINT* pOutput)
|
||||
{
|
||||
HWND hWnd = (HWND)WindowSystem::GetWindowInfo().canvas_main.surface;
|
||||
HWND hWnd = (HWND)WindowSystem::GetWindowInfo().canvas_main.surface.load(std::memory_order::relaxed);
|
||||
if (hWnd == 0)
|
||||
return E_FAIL;
|
||||
|
||||
|
||||
@ -1633,17 +1633,17 @@ VkSurfaceKHR VulkanRenderer::CreateWaylandSurface(VkInstance instance, wl_displa
|
||||
VkSurfaceKHR VulkanRenderer::CreateFramebufferSurface(VkInstance instance, WindowSystem::WindowHandleInfo& windowInfo)
|
||||
{
|
||||
#if BOOST_OS_WINDOWS
|
||||
return CreateWinSurface(instance, static_cast<HWND>(windowInfo.surface));
|
||||
return CreateWinSurface(instance, static_cast<HWND>(windowInfo.surface.load()));
|
||||
#elif BOOST_OS_LINUX || BOOST_OS_BSD
|
||||
if(windowInfo.backend == WindowSystem::WindowHandleInfo::Backend::X11)
|
||||
return CreateXlibSurface(instance, static_cast<Display*>(windowInfo.display), reinterpret_cast<Window>(windowInfo.surface));
|
||||
#ifdef HAS_WAYLAND
|
||||
if(windowInfo.backend == WindowSystem::WindowHandleInfo::Backend::Wayland)
|
||||
return CreateWaylandSurface(instance, static_cast<wl_display*>(windowInfo.display), static_cast<wl_surface*>(windowInfo.surface));
|
||||
#endif
|
||||
if (windowInfo.backend == WindowSystem::WindowHandleInfo::Backend::X11)
|
||||
return CreateXlibSurface(instance, static_cast<Display*>(windowInfo.display.load()), reinterpret_cast<Window>(windowInfo.surface.load()));
|
||||
#ifdef HAS_WAYLAND
|
||||
if (windowInfo.backend == WindowSystem::WindowHandleInfo::Backend::Wayland)
|
||||
return CreateWaylandSurface(instance, static_cast<wl_display*>(windowInfo.display.load()), static_cast<wl_surface*>(windowInfo.surface.load()));
|
||||
#endif
|
||||
return {};
|
||||
#elif BOOST_OS_MACOS
|
||||
return CreateCocoaSurface(instance, windowInfo.surface);
|
||||
return CreateCocoaSurface(instance, windowInfo.surface.load());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ DirectSoundAPI::DirectSoundAPI(GUID* guid, sint32 samplerate, sint32 channels, s
|
||||
if (DirectSoundCreate8(guid, &m_direct_sound, nullptr) != DS_OK)
|
||||
throw std::runtime_error("can't create directsound device");
|
||||
|
||||
if (FAILED(m_direct_sound->SetCooperativeLevel(static_cast<HWND>(WindowSystem::GetWindowInfo().window_main.surface), DSSCL_PRIORITY)))
|
||||
if (FAILED(m_direct_sound->SetCooperativeLevel(static_cast<HWND>(WindowSystem::GetWindowInfo().window_main.surface.load()), DSSCL_PRIORITY)))
|
||||
throw std::runtime_error("can't set directsound priority");
|
||||
|
||||
DSBUFFERDESC bd{};
|
||||
|
||||
@ -13,8 +13,32 @@ namespace WindowSystem
|
||||
Cocoa,
|
||||
Windows,
|
||||
} backend;
|
||||
void* display = nullptr;
|
||||
void* surface = nullptr;
|
||||
std::atomic<void*> display = nullptr;
|
||||
std::atomic<void*> surface = nullptr;
|
||||
|
||||
WindowHandleInfo() = default;
|
||||
|
||||
WindowHandleInfo(WindowHandleInfo&& other) noexcept
|
||||
: backend(other.backend),
|
||||
display(other.display.exchange(nullptr)),
|
||||
surface(other.surface.exchange(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
WindowHandleInfo(const WindowHandleInfo&) = delete;
|
||||
WindowHandleInfo& operator=(const WindowHandleInfo&) = delete;
|
||||
|
||||
WindowHandleInfo& operator=(WindowHandleInfo&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
backend = other.backend;
|
||||
display.store(other.display.exchange(nullptr));
|
||||
surface.store(other.surface.exchange(nullptr));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
enum struct PlatformKeyCodes : uint32
|
||||
|
||||
@ -112,5 +112,5 @@ WindowSystem::WindowHandleInfo initHandleContextFromWxWidgetsWindow(wxWindow* wx
|
||||
handleInfo.backend = WindowSystem::WindowHandleInfo::Backend::Cocoa;
|
||||
handleInfo.surface = reinterpret_cast<void*>(wxw->GetHandle());
|
||||
#endif
|
||||
return handleInfo;
|
||||
return std::move(handleInfo);
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ void ImGui_UpdateWindowInformation(bool mainWindow)
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
||||
#if BOOST_OS_WINDOWS
|
||||
io.ImeWindowHandle = mainWindow ? windowInfo.window_main.surface : windowInfo.window_pad.surface;
|
||||
io.ImeWindowHandle = mainWindow ? windowInfo.window_main.surface.load(std::memory_order::relaxed) : windowInfo.window_pad.surface.load(std::memory_order::relaxed);
|
||||
#else
|
||||
io.ImeWindowHandle = nullptr;
|
||||
#endif
|
||||
|
||||
@ -105,7 +105,7 @@ bool DirectInputController::connect()
|
||||
return false;
|
||||
}
|
||||
|
||||
HWND hwndMainWindow = static_cast<HWND>(WindowSystem::GetWindowInfo().window_main.surface);
|
||||
HWND hwndMainWindow = static_cast<HWND>(WindowSystem::GetWindowInfo().window_main.surface.load(std::memory_order::relaxed));
|
||||
|
||||
// set access
|
||||
if (FAILED(m_device->SetCooperativeLevel(hwndMainWindow, DISCL_BACKGROUND | DISCL_EXCLUSIVE)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user