From dc63d908b8a79c77a6ab9520d9aa7e87e9f89038 Mon Sep 17 00:00:00 2001 From: mafiesto4 Date: Tue, 9 Feb 2021 19:54:46 +0100 Subject: [PATCH] Fix resizing and maximizing window on Linux --- .../Vulkan/GPUSwapChainVulkan.cpp | 4 ++++ .../Engine/Platform/Linux/LinuxPlatform.cpp | 2 +- Source/Engine/Platform/Linux/LinuxWindow.cpp | 24 ++++++++++++++----- Source/Engine/Platform/Linux/LinuxWindow.h | 1 + 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp index f4ad69c80..8a8e38461 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/GPUSwapChainVulkan.cpp @@ -51,6 +51,10 @@ void GPUSwapChainVulkan::ReleaseBackBuffer() void GPUSwapChainVulkan::OnReleaseGPU() { + GPUDeviceLock lock(_device); + + _device->WaitForGPU(); + ReleaseBackBuffer(); // Release data diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 34c4b0a1f..e594e8e75 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -1714,7 +1714,7 @@ void LinuxPlatform::Tick() window = WindowsManager::GetByNativePtr((void*)event.xclient.window); if (window) { - window->CheckForWindowResize(); + window->OnConfigureNotify(&event.xconfigure); } break; case PropertyNotify: diff --git a/Source/Engine/Platform/Linux/LinuxWindow.cpp b/Source/Engine/Platform/Linux/LinuxWindow.cpp index 42f9f17a8..bad1c8132 100644 --- a/Source/Engine/Platform/Linux/LinuxWindow.cpp +++ b/Source/Engine/Platform/Linux/LinuxWindow.cpp @@ -451,16 +451,17 @@ void LinuxWindow::CheckForWindowResize() LINUX_WINDOW_PROLOG; - // Cache client size + // Get client size X11::XWindowAttributes xwa; X11::XGetWindowAttributes(display, window, &xwa); - int32 width = xwa.width; - int32 height = xwa.height; - _clientSize = Vector2(static_cast(width), static_cast(height)); + const int32 width = xwa.width; + const int32 height = xwa.height; + const Vector2 clientSize((float)width, (float)height); // Check if window size has been changed - if (width > 0 && height > 0 && (_swapChain == nullptr || width != _swapChain->GetWidth() || height != _swapChain->GetHeight())) - { + if (clientSize != _clientSize && width > 0 && height > 0) + { + _clientSize = clientSize; OnResize(width, height); } } @@ -580,6 +581,17 @@ void LinuxWindow::OnLeaveNotify(void* event) Input::Mouse->OnMouseLeave(this); } +void LinuxWindow::OnConfigureNotify(void* event) +{ + auto configureEvent = (X11::XConfigureEvent*)event; + const Vector2 clientSize((float)configureEvent->width, (float)configureEvent->height); + if (clientSize != _clientSize) + { + _clientSize = clientSize; + OnResize(configureEvent->width, configureEvent->height); + } +} + void LinuxWindow::Maximize(bool enable) { LINUX_WINDOW_PROLOG; diff --git a/Source/Engine/Platform/Linux/LinuxWindow.h b/Source/Engine/Platform/Linux/LinuxWindow.h index 00c7bd89e..22755874f 100644 --- a/Source/Engine/Platform/Linux/LinuxWindow.h +++ b/Source/Engine/Platform/Linux/LinuxWindow.h @@ -56,6 +56,7 @@ public: void OnButtonRelease(void* event); void OnMotionNotify(void* event); void OnLeaveNotify(void* event); + void OnConfigureNotify(void* event); private: