BsRenderWindow.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include "BsRenderWindow.h"
  2. #include "BsCoreThread.h"
  3. #include "BsRenderWindowManager.h"
  4. #include "BsViewport.h"
  5. #include "BsPlatform.h"
  6. #include "BsFrameAlloc.h"
  7. namespace BansheeEngine
  8. {
  9. RenderWindowProperties::RenderWindowProperties(const RENDER_WINDOW_DESC& desc)
  10. {
  11. mWidth = desc.videoMode.getWidth();
  12. mHeight = desc.videoMode.getHeight();
  13. mHwGamma = desc.gamma;
  14. mVSync = desc.vsync;
  15. mVSyncInterval = desc.vsyncInterval;
  16. mMultisampleCount = desc.multisampleCount;
  17. mLeft = desc.left;
  18. mTop = desc.top;
  19. mIsFullScreen = desc.fullscreen;
  20. mHidden = desc.hidden;
  21. mIsModal = desc.modal;
  22. mIsWindow = true;
  23. mRequiresTextureFlipping = false;
  24. }
  25. RenderWindowCore::RenderWindowCore(const RENDER_WINDOW_DESC& desc)
  26. :mDesc(desc)
  27. {
  28. }
  29. RenderWindowCore::~RenderWindowCore()
  30. {
  31. Platform::resetNonClientAreas(*this);
  32. RenderWindowCoreManager::instance().windowDestroyed(this);
  33. }
  34. void RenderWindowCore::setHidden(bool hidden)
  35. {
  36. THROW_IF_NOT_CORE_THREAD;
  37. }
  38. void RenderWindowCore::setActive(bool state)
  39. {
  40. THROW_IF_NOT_CORE_THREAD;
  41. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  42. props.mActive = state;
  43. RenderWindowManager::instance().notifyPropertiesDirty(this);
  44. }
  45. void RenderWindowCore::syncToCore(const CoreSyncData& data)
  46. {
  47. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  48. props = data.getData<RenderWindowProperties>();
  49. }
  50. void RenderWindowCore::_windowMovedOrResized()
  51. {
  52. THROW_IF_NOT_CORE_THREAD;
  53. RenderWindowManager::instance().notifyMovedOrResized(this);
  54. }
  55. void RenderWindowCore::_windowFocusReceived()
  56. {
  57. THROW_IF_NOT_CORE_THREAD;
  58. RenderWindowProperties& properties = const_cast<RenderWindowProperties&>(getProperties());
  59. properties.mHasFocus = true;
  60. RenderWindowManager::instance().notifyFocusReceived(this);
  61. }
  62. void RenderWindowCore::_windowFocusLost()
  63. {
  64. THROW_IF_NOT_CORE_THREAD;
  65. RenderWindowProperties& properties = const_cast<RenderWindowProperties&>(getProperties());
  66. properties.mHasFocus = false;
  67. RenderWindowManager::instance().notifyFocusLost(this);
  68. }
  69. void RenderWindowCore::_notifyMaximized()
  70. {
  71. THROW_IF_NOT_CORE_THREAD;
  72. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  73. props.mIsMaximized = true;
  74. RenderWindowManager::instance().notifyPropertiesDirty(this);
  75. }
  76. void RenderWindowCore::_notifyMinimized()
  77. {
  78. THROW_IF_NOT_CORE_THREAD;
  79. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  80. props.mIsMaximized = false;
  81. RenderWindowManager::instance().notifyPropertiesDirty(this);
  82. }
  83. void RenderWindowCore::_notifyRestored()
  84. {
  85. THROW_IF_NOT_CORE_THREAD;
  86. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  87. props.mIsMaximized = false;
  88. RenderWindowManager::instance().notifyPropertiesDirty(this);
  89. }
  90. const RenderWindowProperties& RenderWindowCore::getProperties() const
  91. {
  92. return static_cast<const RenderWindowProperties&>(getPropertiesInternal());
  93. }
  94. void RenderWindow::destroy()
  95. {
  96. RenderWindowManager::instance().notifyWindowDestroyed(this);
  97. RenderTarget::destroy();
  98. }
  99. RenderWindow::RenderWindow(const RENDER_WINDOW_DESC& desc)
  100. :mDesc(desc)
  101. {
  102. }
  103. void RenderWindow::resize(CoreAccessor& accessor, UINT32 width, UINT32 height)
  104. {
  105. std::function<void(SPtr<RenderWindowCore>, UINT32, UINT32)> resizeFunc =
  106. [](SPtr<RenderWindowCore> renderWindow, UINT32 width, UINT32 height)
  107. {
  108. renderWindow->resize(width, height);
  109. };
  110. accessor.queueCommand(std::bind(resizeFunc, getCore(), width, height));
  111. }
  112. void RenderWindow::move(CoreAccessor& accessor, INT32 left, INT32 top)
  113. {
  114. std::function<void(SPtr<RenderWindowCore>, INT32, INT32)> moveFunc =
  115. [](SPtr<RenderWindowCore> renderWindow, INT32 left, INT32 top)
  116. {
  117. renderWindow->move(left, top);
  118. };
  119. accessor.queueCommand(std::bind(moveFunc, getCore(), left, top));
  120. }
  121. void RenderWindow::hide(CoreAccessor& accessor)
  122. {
  123. std::function<void(SPtr<RenderWindowCore>)> hideFunc =
  124. [](SPtr<RenderWindowCore> renderWindow)
  125. {
  126. renderWindow->setHidden(true);
  127. };
  128. accessor.queueCommand(std::bind(hideFunc, getCore()));
  129. }
  130. void RenderWindow::show(CoreAccessor& accessor)
  131. {
  132. std::function<void(SPtr<RenderWindowCore>)> showFunc =
  133. [](SPtr<RenderWindowCore> renderWindow)
  134. {
  135. renderWindow->setHidden(false);
  136. };
  137. accessor.queueCommand(std::bind(showFunc, getCore()));
  138. }
  139. void RenderWindow::minimize(CoreAccessor& accessor)
  140. {
  141. std::function<void(SPtr<RenderWindowCore>)> minimizeFunc =
  142. [](SPtr<RenderWindowCore> renderWindow)
  143. {
  144. renderWindow->minimize();
  145. };
  146. accessor.queueCommand(std::bind(minimizeFunc, getCore()));
  147. }
  148. void RenderWindow::maximize(CoreAccessor& accessor)
  149. {
  150. std::function<void(SPtr<RenderWindowCore>)> maximizeFunc =
  151. [](SPtr<RenderWindowCore> renderWindow)
  152. {
  153. renderWindow->maximize();
  154. };
  155. accessor.queueCommand(std::bind(maximizeFunc, getCore()));
  156. }
  157. void RenderWindow::restore(CoreAccessor& accessor)
  158. {
  159. std::function<void(SPtr<RenderWindowCore>)> restoreFunc =
  160. [](SPtr<RenderWindowCore> renderWindow)
  161. {
  162. renderWindow->restore();
  163. };
  164. accessor.queueCommand(std::bind(restoreFunc, getCore()));
  165. }
  166. void RenderWindow::setFullscreen(CoreAccessor& accessor, UINT32 width, UINT32 height,
  167. float refreshRate, UINT32 monitorIdx)
  168. {
  169. std::function<void(SPtr<RenderWindowCore>, UINT32, UINT32, float, UINT32)> fullscreenFunc =
  170. [](SPtr<RenderWindowCore> renderWindow, UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
  171. {
  172. renderWindow->setFullscreen(width, height, refreshRate, monitorIdx);
  173. };
  174. accessor.queueCommand(std::bind(fullscreenFunc, getCore(), width, height, refreshRate, monitorIdx));
  175. }
  176. void RenderWindow::setFullscreen(CoreAccessor& accessor, const VideoMode& mode)
  177. {
  178. std::function<void(SPtr<RenderWindowCore>, const VideoMode&)> fullscreenFunc =
  179. [](SPtr<RenderWindowCore> renderWindow, const VideoMode& mode)
  180. {
  181. renderWindow->setFullscreen(mode);
  182. };
  183. accessor.queueCommand(std::bind(fullscreenFunc, getCore(), std::cref(mode)));
  184. }
  185. void RenderWindow::setWindowed(CoreAccessor& accessor, UINT32 width, UINT32 height)
  186. {
  187. std::function<void(SPtr<RenderWindowCore>, UINT32, UINT32)> windowedFunc =
  188. [](SPtr<RenderWindowCore> renderWindow, UINT32 width, UINT32 height)
  189. {
  190. renderWindow->setWindowed(width, height);
  191. };
  192. accessor.queueCommand(std::bind(windowedFunc, getCore(), width, height));
  193. }
  194. SPtr<RenderWindowCore> RenderWindow::getCore() const
  195. {
  196. return std::static_pointer_cast<RenderWindowCore>(mCoreSpecific);
  197. }
  198. SPtr<CoreObjectCore> RenderWindow::createCore() const
  199. {
  200. RENDER_WINDOW_DESC desc = mDesc;
  201. return RenderWindowCoreManager::instance().createInternal(desc);
  202. }
  203. RenderWindowPtr RenderWindow::create(RENDER_WINDOW_DESC& desc, RenderWindowPtr parentWindow)
  204. {
  205. return RenderWindowManager::instance().create(desc, parentWindow);
  206. }
  207. CoreSyncData RenderWindow::syncToCore(FrameAlloc* allocator)
  208. {
  209. UINT32 size = sizeof(RenderWindowProperties);
  210. UINT8* buffer = allocator->alloc(size);
  211. RenderWindowProperties& props = const_cast<RenderWindowProperties&>(getProperties());
  212. memcpy(buffer, &props, size);
  213. return CoreSyncData(buffer, size);
  214. }
  215. const RenderWindowProperties& RenderWindow::getProperties() const
  216. {
  217. return static_cast<const RenderWindowProperties&>(getPropertiesInternal());
  218. }
  219. }