BsWin32RenderWindow.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Win32/BsWin32RenderWindow.h"
  4. #include "Private/Win32/BsWin32Platform.h"
  5. #include "Private/Win32/BsWin32Window.h"
  6. #include "Win32/BsWin32VideoModeInfo.h"
  7. #include "Corethread/BsCoreThread.h"
  8. #include "Profiling/BsRenderStats.h"
  9. #include "Managers/BsRenderWindowManager.h"
  10. #include "BsVulkanRenderAPI.h"
  11. #include "BsVulkanDevice.h"
  12. #include "BsVulkanSwapChain.h"
  13. #include "BsVulkanDevice.h"
  14. #include "BsVulkanCommandBuffer.h"
  15. #include "Managers/BsVulkanCommandBufferManager.h"
  16. #include "BsVulkanQueue.h"
  17. #include "Math/BsMath.h"
  18. namespace bs
  19. {
  20. Win32RenderWindow::Win32RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId)
  21. : RenderWindow(desc, windowId), mProperties(desc)
  22. { }
  23. void Win32RenderWindow::getCustomAttribute(const String& name, void* pData) const
  24. {
  25. if (name == "WINDOW")
  26. {
  27. UINT64 *pHwnd = (UINT64*)pData;
  28. *pHwnd = (UINT64)getHWnd();
  29. return;
  30. }
  31. }
  32. Vector2I Win32RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
  33. {
  34. POINT pos;
  35. pos.x = screenPos.x;
  36. pos.y = screenPos.y;
  37. ScreenToClient(getHWnd(), &pos);
  38. return Vector2I(pos.x, pos.y);
  39. }
  40. Vector2I Win32RenderWindow::windowToScreenPos(const Vector2I& windowPos) const
  41. {
  42. POINT pos;
  43. pos.x = windowPos.x;
  44. pos.y = windowPos.y;
  45. ClientToScreen(getHWnd(), &pos);
  46. return Vector2I(pos.x, pos.y);
  47. }
  48. SPtr<ct::Win32RenderWindow> Win32RenderWindow::getCore() const
  49. {
  50. return std::static_pointer_cast<ct::Win32RenderWindow>(mCoreSpecific);
  51. }
  52. HWND Win32RenderWindow::getHWnd() const
  53. {
  54. blockUntilCoreInitialized();
  55. return getCore()->_getWindowHandle();
  56. }
  57. void Win32RenderWindow::syncProperties()
  58. {
  59. ScopedSpinLock lock(getCore()->mLock);
  60. mProperties = getCore()->mSyncedProperties;
  61. }
  62. SPtr<ct::CoreObject> Win32RenderWindow::createCore() const
  63. {
  64. ct::VulkanRenderAPI& rapi = static_cast<ct::VulkanRenderAPI&>(ct::RenderAPI::instance());
  65. RENDER_WINDOW_DESC desc = mDesc;
  66. SPtr<ct::CoreObject> coreObj = bs_shared_ptr_new<ct::Win32RenderWindow>(desc, mWindowId, rapi);
  67. coreObj->_setThisPtr(coreObj);
  68. return coreObj;
  69. }
  70. namespace ct
  71. {
  72. Win32RenderWindow::Win32RenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, VulkanRenderAPI& renderAPI)
  73. : RenderWindow(desc, windowId), mProperties(desc), mSyncedProperties(desc), mWindow(nullptr), mIsChild(false)
  74. , mShowOnSwap(false), mDisplayFrequency(0), mRenderAPI(renderAPI), mRequiresNewBackBuffer(true)
  75. { }
  76. Win32RenderWindow::~Win32RenderWindow()
  77. {
  78. SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
  79. presentDevice->waitIdle();
  80. if (mWindow != nullptr)
  81. {
  82. bs_delete(mWindow);
  83. mWindow = nullptr;
  84. }
  85. mSwapChain = nullptr;
  86. vkDestroySurfaceKHR(mRenderAPI._getInstance(), mSurface, gVulkanAllocator);
  87. Platform::resetNonClientAreas(*this);
  88. }
  89. void Win32RenderWindow::initialize()
  90. {
  91. RenderWindowProperties& props = mProperties;
  92. // Create a window
  93. WINDOW_DESC windowDesc;
  94. windowDesc.showTitleBar = mDesc.showTitleBar;
  95. windowDesc.showBorder = mDesc.showBorder;
  96. windowDesc.allowResize = mDesc.allowResize;
  97. windowDesc.enableDoubleClick = true;
  98. windowDesc.fullscreen = mDesc.fullscreen;
  99. windowDesc.width = mDesc.videoMode.getWidth();
  100. windowDesc.height = mDesc.videoMode.getHeight();
  101. windowDesc.hidden = mDesc.hidden || mDesc.hideUntilSwap;
  102. windowDesc.left = mDesc.left;
  103. windowDesc.top = mDesc.top;
  104. windowDesc.outerDimensions = false;
  105. windowDesc.title = mDesc.title;
  106. windowDesc.toolWindow = mDesc.toolWindow;
  107. windowDesc.creationParams = this;
  108. windowDesc.modal = mDesc.modal;
  109. windowDesc.wndProc = &Win32Platform::_win32WndProc;
  110. #ifdef BS_STATIC_LIB
  111. windowDesc.module = GetModuleHandle(NULL);
  112. #else
  113. windowDesc.module = GetModuleHandle("BansheeVulkanRenderAPI.dll");
  114. #endif
  115. NameValuePairList::const_iterator opt;
  116. opt = mDesc.platformSpecific.find("parentWindowHandle");
  117. if (opt != mDesc.platformSpecific.end())
  118. windowDesc.parent = (HWND)parseUINT64(opt->second);
  119. opt = mDesc.platformSpecific.find("externalWindowHandle");
  120. if (opt != mDesc.platformSpecific.end())
  121. windowDesc.external = (HWND)parseUINT64(opt->second);
  122. const Win32VideoModeInfo& videoModeInfo = static_cast<const Win32VideoModeInfo&>(RenderAPI::instance().getVideoModeInfo());
  123. UINT32 numOutputs = videoModeInfo.getNumOutputs();
  124. if (numOutputs > 0)
  125. {
  126. UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
  127. const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
  128. windowDesc.monitor = outputInfo.getMonitorHandle();
  129. }
  130. // Must be set before creating a window, since wndProc will call ShowWindow if needed after creation
  131. if (!windowDesc.external)
  132. {
  133. mShowOnSwap = mDesc.hideUntilSwap;
  134. props.isHidden = mDesc.hideUntilSwap || mDesc.hidden;
  135. }
  136. mWindow = bs_new<Win32Window>(windowDesc);
  137. mIsChild = windowDesc.parent != nullptr;
  138. mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
  139. // Update local properties
  140. props.isFullScreen = mDesc.fullscreen && !mIsChild;
  141. props.width = mWindow->getWidth();
  142. props.height = mWindow->getHeight();
  143. props.top = mWindow->getTop();
  144. props.left = mWindow->getLeft();
  145. props.hwGamma = mDesc.gamma;
  146. props.multisampleCount = 1;
  147. // Create Vulkan surface
  148. VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
  149. surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
  150. surfaceCreateInfo.pNext = nullptr;
  151. surfaceCreateInfo.flags = 0;
  152. surfaceCreateInfo.hwnd = mWindow->getHWnd();
  153. surfaceCreateInfo.hinstance = windowDesc.module;
  154. VkInstance instance = mRenderAPI._getInstance();
  155. VkResult result = vkCreateWin32SurfaceKHR(instance, &surfaceCreateInfo, gVulkanAllocator, &mSurface);
  156. assert(result == VK_SUCCESS);
  157. SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
  158. VkPhysicalDevice physicalDevice = presentDevice->getPhysical();
  159. mPresentQueueFamily = presentDevice->getQueueFamily(GQT_GRAPHICS);
  160. VkBool32 supportsPresent;
  161. vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, mPresentQueueFamily, mSurface, &supportsPresent);
  162. if(!supportsPresent)
  163. {
  164. // Note: Not supporting present only queues at the moment
  165. // Note: Also present device can only return one family of graphics queue, while there could be more (some of
  166. // which support present)
  167. BS_EXCEPT(RenderingAPIException, "Cannot find a graphics queue that also supports present operations.");
  168. }
  169. SurfaceFormat format = presentDevice->getSurfaceFormat(mSurface, mDesc.gamma);
  170. mColorFormat = format.colorFormat;
  171. mColorSpace = format.colorSpace;
  172. mDepthFormat = format.depthFormat;
  173. // Create swap chain
  174. mSwapChain = bs_shared_ptr_new<VulkanSwapChain>();
  175. mSwapChain->rebuild(presentDevice, mSurface, props.width, props.height, props.vsync, mColorFormat, mColorSpace,
  176. mDesc.depthBuffer, mDepthFormat);
  177. // Make the window full screen if required
  178. if (!windowDesc.external)
  179. {
  180. if (props.isFullScreen)
  181. {
  182. DEVMODE displayDeviceMode;
  183. memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
  184. displayDeviceMode.dmSize = sizeof(DEVMODE);
  185. displayDeviceMode.dmBitsPerPel = 32;
  186. displayDeviceMode.dmPelsWidth = props.width;
  187. displayDeviceMode.dmPelsHeight = props.height;
  188. displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
  189. if (mDisplayFrequency)
  190. {
  191. displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
  192. displayDeviceMode.dmFields |= DM_DISPLAYFREQUENCY;
  193. if (ChangeDisplaySettingsEx(NULL, &displayDeviceMode, NULL, CDS_FULLSCREEN | CDS_TEST, NULL) != DISP_CHANGE_SUCCESSFUL)
  194. {
  195. BS_EXCEPT(RenderingAPIException, "ChangeDisplaySettings with user display frequency failed.");
  196. }
  197. }
  198. if (ChangeDisplaySettingsEx(NULL, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
  199. {
  200. BS_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed.");
  201. }
  202. }
  203. }
  204. {
  205. ScopedSpinLock lock(mLock);
  206. mSyncedProperties = props;
  207. }
  208. bs::RenderWindowManager::instance().notifySyncDataDirty(this);
  209. RenderWindow::initialize();
  210. }
  211. void Win32RenderWindow::acquireBackBuffer()
  212. {
  213. // We haven't presented the current back buffer yet, so just use that one
  214. if (!mRequiresNewBackBuffer)
  215. return;
  216. mSwapChain->acquireBackBuffer();
  217. mRequiresNewBackBuffer = false;
  218. }
  219. void Win32RenderWindow::swapBuffers(UINT32 syncMask)
  220. {
  221. THROW_IF_NOT_CORE_THREAD;
  222. if (mShowOnSwap)
  223. setHidden(false);
  224. // Get a command buffer on which we'll submit
  225. SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
  226. // Assuming present queue is always graphics
  227. assert(presentDevice->getQueueFamily(GQT_GRAPHICS) == mPresentQueueFamily);
  228. // Find an appropriate queue to execute on
  229. VulkanQueue* queue = presentDevice->getQueue(GQT_GRAPHICS, 0);
  230. UINT32 queueMask = presentDevice->getQueueMask(GQT_GRAPHICS, 0);
  231. // Ignore myself
  232. syncMask &= ~queueMask;
  233. UINT32 deviceIdx = presentDevice->getIndex();
  234. VulkanCommandBufferManager& cbm = static_cast<VulkanCommandBufferManager&>(CommandBufferManager::instance());
  235. UINT32 numSemaphores;
  236. cbm.getSyncSemaphores(deviceIdx, syncMask, mSemaphoresTemp, numSemaphores);
  237. // Wait on present (i.e. until the back buffer becomes available), if we haven't already done so
  238. const SwapChainSurface& surface = mSwapChain->getBackBuffer();
  239. if(surface.needsWait)
  240. {
  241. mSemaphoresTemp[numSemaphores] = mSwapChain->getBackBuffer().sync;
  242. numSemaphores++;
  243. mSwapChain->notifyBackBufferWaitIssued();
  244. }
  245. queue->present(mSwapChain.get(), mSemaphoresTemp, numSemaphores);
  246. mRequiresNewBackBuffer = true;
  247. }
  248. void Win32RenderWindow::move(INT32 left, INT32 top)
  249. {
  250. THROW_IF_NOT_CORE_THREAD;
  251. RenderWindowProperties& props = mProperties;
  252. if (!props.isFullScreen)
  253. {
  254. mWindow->move(left, top);
  255. props.top = mWindow->getTop();
  256. props.left = mWindow->getLeft();
  257. {
  258. ScopedSpinLock lock(mLock);
  259. mSyncedProperties.top = props.top;
  260. mSyncedProperties.left = props.left;
  261. }
  262. bs::RenderWindowManager::instance().notifySyncDataDirty(this);
  263. }
  264. }
  265. void Win32RenderWindow::resize(UINT32 width, UINT32 height)
  266. {
  267. THROW_IF_NOT_CORE_THREAD;
  268. RenderWindowProperties& props = mProperties;
  269. if (!props.isFullScreen)
  270. {
  271. mWindow->resize(width, height);
  272. props.width = mWindow->getWidth();
  273. props.height = mWindow->getHeight();
  274. {
  275. ScopedSpinLock lock(mLock);
  276. mSyncedProperties.width = props.width;
  277. mSyncedProperties.height = props.height;
  278. }
  279. bs::RenderWindowManager::instance().notifySyncDataDirty(this);
  280. }
  281. }
  282. void Win32RenderWindow::setActive(bool state)
  283. {
  284. THROW_IF_NOT_CORE_THREAD;
  285. mWindow->setActive(state);
  286. RenderWindow::setActive(state);
  287. }
  288. void Win32RenderWindow::setHidden(bool hidden)
  289. {
  290. THROW_IF_NOT_CORE_THREAD;
  291. mShowOnSwap = false;
  292. mWindow->setHidden(hidden);
  293. RenderWindow::setHidden(hidden);
  294. }
  295. void Win32RenderWindow::minimize()
  296. {
  297. THROW_IF_NOT_CORE_THREAD;
  298. mWindow->minimize();
  299. }
  300. void Win32RenderWindow::maximize()
  301. {
  302. THROW_IF_NOT_CORE_THREAD;
  303. mWindow->maximize();
  304. }
  305. void Win32RenderWindow::restore()
  306. {
  307. THROW_IF_NOT_CORE_THREAD;
  308. mWindow->restore();
  309. }
  310. void Win32RenderWindow::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
  311. {
  312. THROW_IF_NOT_CORE_THREAD;
  313. if (mIsChild)
  314. return;
  315. const Win32VideoModeInfo& videoModeInfo = static_cast<const Win32VideoModeInfo&>(RenderAPI::instance().getVideoModeInfo());
  316. UINT32 numOutputs = videoModeInfo.getNumOutputs();
  317. if (numOutputs == 0)
  318. return;
  319. RenderWindowProperties& props = mProperties;
  320. UINT32 actualMonitorIdx = std::min(monitorIdx, numOutputs - 1);
  321. const Win32VideoOutputInfo& outputInfo = static_cast<const Win32VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
  322. mDisplayFrequency = Math::roundToInt(refreshRate);
  323. props.isFullScreen = true;
  324. DEVMODE displayDeviceMode;
  325. memset(&displayDeviceMode, 0, sizeof(displayDeviceMode));
  326. displayDeviceMode.dmSize = sizeof(DEVMODE);
  327. displayDeviceMode.dmBitsPerPel = 32;
  328. displayDeviceMode.dmPelsWidth = width;
  329. displayDeviceMode.dmPelsHeight = height;
  330. displayDeviceMode.dmDisplayFrequency = mDisplayFrequency;
  331. displayDeviceMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
  332. HMONITOR hMonitor = outputInfo.getMonitorHandle();
  333. MONITORINFOEX monitorInfo;
  334. memset(&monitorInfo, 0, sizeof(MONITORINFOEX));
  335. monitorInfo.cbSize = sizeof(MONITORINFOEX);
  336. GetMonitorInfo(hMonitor, &monitorInfo);
  337. if (ChangeDisplaySettingsEx(monitorInfo.szDevice, &displayDeviceMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL)
  338. {
  339. BS_EXCEPT(RenderingAPIException, "ChangeDisplaySettings failed");
  340. }
  341. props.top = monitorInfo.rcMonitor.top;
  342. props.left = monitorInfo.rcMonitor.left;
  343. props.width = width;
  344. props.height = height;
  345. SetWindowLong(mWindow->getHWnd(), GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  346. SetWindowLong(mWindow->getHWnd(), GWL_EXSTYLE, 0);
  347. SetWindowPos(mWindow->getHWnd(), HWND_TOP, props.left, props.top, width, height, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
  348. }
  349. void Win32RenderWindow::setFullscreen(const VideoMode& mode)
  350. {
  351. THROW_IF_NOT_CORE_THREAD;
  352. setFullscreen(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getOutputIdx());
  353. }
  354. void Win32RenderWindow::setWindowed(UINT32 width, UINT32 height)
  355. {
  356. THROW_IF_NOT_CORE_THREAD;
  357. RenderWindowProperties& props = mProperties;
  358. if (!props.isFullScreen)
  359. return;
  360. props.isFullScreen = false;
  361. props.width = width;
  362. props.height = height;
  363. // Drop out of fullscreen
  364. ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
  365. UINT32 winWidth = width;
  366. UINT32 winHeight = height;
  367. RECT rect;
  368. SetRect(&rect, 0, 0, winWidth, winHeight);
  369. AdjustWindowRect(&rect, mWindow->getStyle(), false);
  370. winWidth = rect.right - rect.left;
  371. winHeight = rect.bottom - rect.top;
  372. // Deal with centering when switching down to smaller resolution
  373. HMONITOR hMonitor = MonitorFromWindow(mWindow->getHWnd(), MONITOR_DEFAULTTONEAREST);
  374. MONITORINFO monitorInfo;
  375. memset(&monitorInfo, 0, sizeof(MONITORINFO));
  376. monitorInfo.cbSize = sizeof(MONITORINFO);
  377. GetMonitorInfo(hMonitor, &monitorInfo);
  378. LONG screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
  379. LONG screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
  380. INT32 left = screenw > INT32(winWidth) ? ((screenw - INT32(winWidth)) / 2) : 0;
  381. INT32 top = screenh > INT32(winHeight) ? ((screenh - INT32(winHeight)) / 2) : 0;
  382. SetWindowLong(mWindow->getHWnd(), GWL_STYLE, mWindow->getStyle() | WS_VISIBLE);
  383. SetWindowLong(mWindow->getHWnd(), GWL_EXSTYLE, mWindow->getStyleEx());
  384. SetWindowPos(mWindow->getHWnd(), HWND_NOTOPMOST, left, top, winWidth, winHeight,
  385. SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
  386. {
  387. ScopedSpinLock lock(mLock);
  388. mSyncedProperties.width = props.width;
  389. mSyncedProperties.height = props.height;
  390. }
  391. bs::RenderWindowManager::instance().notifySyncDataDirty(this);
  392. }
  393. void Win32RenderWindow::setVSync(bool enabled, UINT32 interval)
  394. {
  395. // Rebuild swap chain
  396. //// Need to make sure nothing is using the swap buffer before we re-create it
  397. // Note: Optionally I can detect exactly on which queues (if any) are the swap chain images used on, and only wait
  398. // on those
  399. SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
  400. presentDevice->waitIdle();
  401. mSwapChain->rebuild(presentDevice, mSurface, mProperties.width, mProperties.height, enabled, mColorFormat, mColorSpace,
  402. mDesc.depthBuffer, mDepthFormat);
  403. mProperties.vsync = enabled;
  404. mProperties.vsyncInterval = interval;
  405. {
  406. ScopedSpinLock lock(mLock);
  407. mSyncedProperties.vsync = enabled;
  408. mSyncedProperties.vsyncInterval = interval;
  409. }
  410. bs::RenderWindowManager::instance().notifySyncDataDirty(this);
  411. }
  412. HWND Win32RenderWindow::_getWindowHandle() const
  413. {
  414. return mWindow->getHWnd();
  415. }
  416. void Win32RenderWindow::getCustomAttribute(const String& name, void* data) const
  417. {
  418. if (name == "FB")
  419. {
  420. VulkanFramebuffer** fb = (VulkanFramebuffer**)data;
  421. *fb = mSwapChain->getBackBuffer().framebuffer;
  422. return;
  423. }
  424. if(name == "SC")
  425. {
  426. VulkanSwapChain** sc = (VulkanSwapChain**)data;
  427. *sc = mSwapChain.get();
  428. return;
  429. }
  430. if(name == "WINDOW")
  431. {
  432. UINT64 *pWnd = (UINT64*)data;
  433. *pWnd = (UINT64)mWindow->getHWnd();
  434. return;
  435. }
  436. RenderWindow::getCustomAttribute(name, data);
  437. }
  438. void Win32RenderWindow::_windowMovedOrResized()
  439. {
  440. THROW_IF_NOT_CORE_THREAD;
  441. if (!mWindow)
  442. return;
  443. mWindow->_windowMovedOrResized();
  444. RenderWindowProperties& props = mProperties;
  445. if (!props.isFullScreen) // Fullscreen is handled directly by this object
  446. {
  447. props.top = mWindow->getTop();
  448. props.left = mWindow->getLeft();
  449. props.width = mWindow->getWidth();
  450. props.height = mWindow->getHeight();
  451. }
  452. // Resize swap chain
  453. //// Need to make sure nothing is using the swap buffer before we re-create it
  454. // Note: Optionally I can detect exactly on which queues (if any) are the swap chain images used on, and only wait
  455. // on those
  456. SPtr<VulkanDevice> presentDevice = mRenderAPI._getPresentDevice();
  457. presentDevice->waitIdle();
  458. mSwapChain->rebuild(presentDevice, mSurface, props.width, props.height, props.vsync, mColorFormat, mColorSpace,
  459. mDesc.depthBuffer, mDepthFormat);
  460. }
  461. void Win32RenderWindow::syncProperties()
  462. {
  463. ScopedSpinLock lock(mLock);
  464. mProperties = mSyncedProperties;
  465. }
  466. }
  467. }