1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "RenderAPI/BsRenderWindow.h" |
6 | #include <X11/extensions/Xrandr.h> |
7 | |
8 | namespace bs |
9 | { |
10 | class LinuxWindow; |
11 | class LinuxRenderWindow; |
12 | |
13 | namespace ct |
14 | { |
15 | class LinuxGLSupport; |
16 | class LinuxContext; |
17 | class LinuxRenderWindow; |
18 | } |
19 | |
20 | /** @addtogroup GL |
21 | * @{ |
22 | */ |
23 | |
24 | /** |
25 | * Render window implementation for Linux. |
26 | * |
27 | * @note Sim thread only. |
28 | */ |
29 | class LinuxRenderWindow : public RenderWindow |
30 | { |
31 | public: |
32 | ~LinuxRenderWindow() { } |
33 | |
34 | /** @copydoc RenderWindow::getCustomAttribute */ |
35 | void getCustomAttribute(const String& name, void* pData) const override; |
36 | |
37 | /** @copydoc RenderWindow::screenToWindowPos */ |
38 | Vector2I screenToWindowPos(const Vector2I& screenPos) const override; |
39 | |
40 | /** @copydoc RenderWindow::windowToScreenPos */ |
41 | Vector2I windowToScreenPos(const Vector2I& windowPos) const override; |
42 | |
43 | /** @copydoc RenderWindow::getCore */ |
44 | SPtr<ct::LinuxRenderWindow> getCore() const; |
45 | |
46 | protected: |
47 | friend class GLRenderWindowManager; |
48 | friend class ct::LinuxGLSupport; |
49 | friend class ct::LinuxRenderWindow; |
50 | |
51 | LinuxRenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, ct::LinuxGLSupport& glSupport); |
52 | |
53 | /** @copydoc RenderWindow::getProperties */ |
54 | const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; } |
55 | |
56 | /** @copydoc RenderWindow::syncProperties */ |
57 | void syncProperties() override; |
58 | |
59 | /** @copydoc RenderWindow::createCore() */ |
60 | SPtr<ct::CoreObject> createCore() const override; |
61 | |
62 | private: |
63 | ct::LinuxGLSupport& mGLSupport; |
64 | RenderWindowProperties mProperties; |
65 | }; |
66 | |
67 | namespace ct |
68 | { |
69 | /** |
70 | * Render window implementation for Linux. |
71 | * |
72 | * @note Core thread only. |
73 | */ |
74 | class LinuxRenderWindow : public RenderWindow |
75 | { |
76 | public: |
77 | LinuxRenderWindow(const RENDER_WINDOW_DESC& desc, UINT32 windowId, LinuxGLSupport &glSupport); |
78 | ~LinuxRenderWindow(); |
79 | |
80 | /** @copydoc RenderWindow::setFullscreen(UINT32, UINT32, float, UINT32) */ |
81 | void setFullscreen(UINT32 width, UINT32 height, float refreshRate = 60.0f, UINT32 monitorIdx = 0) override; |
82 | |
83 | /** @copydoc RenderWindow::setFullscreen(const VideoMode&) */ |
84 | void setFullscreen(const VideoMode& videoMode) override; |
85 | |
86 | /** @copydoc RenderWindow::setWindowed */ |
87 | void setWindowed(UINT32 width, UINT32 height) override; |
88 | |
89 | /** @copydoc RenderWindow::setHidden */ |
90 | void setHidden(bool hidden) override; |
91 | |
92 | /** @copydoc RenderWindow::minimize */ |
93 | void minimize() override; |
94 | |
95 | /** @copydoc RenderWindow::maximize */ |
96 | void maximize() override; |
97 | |
98 | /** @copydoc RenderWindow::restore */ |
99 | void restore() override; |
100 | |
101 | /** @copydoc RenderWindow::move */ |
102 | void move(INT32 left, INT32 top) override; |
103 | |
104 | /** @copydoc RenderWindow::resize */ |
105 | void resize(UINT32 width, UINT32 height) override; |
106 | |
107 | /** @copydoc RenderWindow::setVSync */ |
108 | void setVSync(bool enabled, UINT32 interval = 1) override; |
109 | |
110 | /** |
111 | * Copies the contents of a frame buffer into the pre-allocated buffer. |
112 | * |
113 | * @param[out] dst Previously allocated buffer to read the contents into. Must be of valid size. |
114 | * @param[in] buffer Frame buffer to read the contents from. |
115 | */ |
116 | void copyToMemory(PixelData& dst, FrameBuffer buffer); |
117 | |
118 | /** @copydoc RenderWindow::swapBuffers */ |
119 | void swapBuffers(UINT32 syncMask) override; |
120 | |
121 | /** @copydoc RenderWindow::getCustomAttribute */ |
122 | void getCustomAttribute(const String& name, void* pData) const override; |
123 | |
124 | /** @copydoc RenderWindow::setActive */ |
125 | void setActive(bool state) override; |
126 | |
127 | /** @copydoc RenderWindow::_windowMovedOrResized */ |
128 | void _windowMovedOrResized() override; |
129 | |
130 | /** Returns a lock that can be used for accessing synced properties. */ |
131 | SpinLock& _getPropertiesLock() { return mLock;} |
132 | |
133 | /** Returns the internal X11 window that this object wraps. */ |
134 | LinuxWindow* _getInternal() const { return mWindow; } |
135 | |
136 | protected: |
137 | friend class LinuxGLSupport; |
138 | |
139 | /** Changes the video mode to the specified RandR mode on the specified output device. */ |
140 | void setVideoMode(INT32 screen, RROutput output, RRMode mode); |
141 | |
142 | /** @copydoc CoreObject::initialize */ |
143 | void initialize() override; |
144 | |
145 | /** @copydoc RenderWindow::getProperties */ |
146 | const RenderTargetProperties& getPropertiesInternal() const override { return mProperties; } |
147 | |
148 | /** @copydoc RenderWindow::getSyncedProperties */ |
149 | RenderWindowProperties& getSyncedProperties() override { return mSyncedProperties; } |
150 | |
151 | /** @copydoc RenderWindow::syncProperties */ |
152 | void syncProperties() override; |
153 | |
154 | protected: |
155 | friend class bs::LinuxRenderWindow; |
156 | |
157 | LinuxWindow* mWindow; |
158 | LinuxGLSupport& mGLSupport; |
159 | SPtr<LinuxContext> mContext; |
160 | RenderWindowProperties mProperties; |
161 | RenderWindowProperties mSyncedProperties; |
162 | bool mIsChild; |
163 | bool mShowOnSwap; |
164 | }; |
165 | } |
166 | |
167 | /** @} */ |
168 | } |
169 | |
170 | |