BsWin32RenderWindow.cpp 18 KB

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