Changeset View
Standalone View
composite.h
Show All 32 Lines | |||||
33 | class Client; | 33 | class Client; | ||
34 | class CompositorSelectionOwner; | 34 | class CompositorSelectionOwner; | ||
35 | class Scene; | 35 | class Scene; | ||
36 | 36 | | |||
37 | class KWIN_EXPORT Compositor : public QObject | 37 | class KWIN_EXPORT Compositor : public QObject | ||
38 | { | 38 | { | ||
39 | Q_OBJECT | 39 | Q_OBJECT | ||
40 | public: | 40 | public: | ||
41 | enum SuspendReason { | | |||
42 | NoReasonSuspend = 0, | | |||
43 | UserSuspend = 1 << 0, | | |||
44 | BlockRuleSuspend = 1 << 1, | | |||
45 | ScriptSuspend = 1 << 2, | | |||
46 | AllReasonSuspend = 0xff | | |||
47 | }; | | |||
48 | Q_DECLARE_FLAGS(SuspendReasons, SuspendReason) | | |||
49 | | ||||
50 | enum class State { | 41 | enum class State { | ||
51 | On = 0, | 42 | On = 0, | ||
52 | Off, | 43 | Off, | ||
53 | Starting, | 44 | Starting, | ||
54 | Stopping | 45 | Stopping | ||
55 | }; | 46 | }; | ||
56 | 47 | | |||
57 | ~Compositor() override; | 48 | ~Compositor() override; | ||
49 | static Compositor* self(); | ||||
zzag: "For pointers or references, use a single space before '*' or '&', but not after"
(there are… | |||||
On function return values I prefer to put the asterisks without space next to the return type since it specifies the return type and not the function. If there are no counter arguments to that and you want to make a rule out of it we can discuss that at KWin sprint. romangg: On function return values I prefer to put the asterisks without space next to the return type… | |||||
As a "WebKit coding style"-head, I agree that putting a whitespace before a pointer doesn't make sense because it's part of the type, but we follow Kdelibs/Frameworks coding style, which dictates that a whitespace has to be put before pointers or references. It doesn't matter whether it's a function or a template argument, you have to put a whitespace. Similar story with clang-format. If we run it, the asterisk will be aligned to right. Please notice that I didn't "invent" or "make out" this rule. zzag: As a "WebKit coding style"-head, I agree that putting a whitespace before a pointer doesn't… | |||||
KWin doesn't follow Kdelibs/Frameworks coding style per se since it's not part of frameworks. Let's discuss this at KWin sprint. romangg: KWin doesn't follow Kdelibs/Frameworks coding style per se since it's not part of frameworks. | |||||
zzag: Nope, it does, see HACKING.md. | |||||
We should change what this file says then. As said, let's discuss this at KWin sprint. romangg: We should change what this file says then. As said, let's discuss this at KWin sprint. | |||||
I don't see any reason why we should switch the coding style. KWin's been following the kdelibs coding style since 2009 or since when Martin reformatted the code.
Okay, but as I said, I don't see any reason to switch. Pointer alignment based on context is pretty weak because from time to time one should ask himself how a pointer/reference has to be aligned. People will also get it wrong. Heck, we have issues even with aligning pointers and references always to right. Another disadvantage of the proposed pointer alignment scheme is that it's quite exotic and rare. Think of it as our current zzag: I don't see any reason why we should switch the coding style. KWin's been following the kdelibs… | |||||
58 | 50 | | |||
59 | // when adding repaints caused by a window, you probably want to use | 51 | // when adding repaints caused by a window, you probably want to use | ||
60 | // either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint() | 52 | // either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint() | ||
61 | void addRepaint(const QRect& r); | 53 | void addRepaint(const QRect& r); | ||
62 | void addRepaint(const QRegion& r); | 54 | void addRepaint(const QRegion& r); | ||
63 | void addRepaint(int x, int y, int w, int h); | 55 | void addRepaint(int x, int y, int w, int h); | ||
64 | void addRepaintFull(); | 56 | void addRepaintFull(); | ||
65 | 57 | | |||
Show All 10 Lines | |||||
76 | void aboutToSwapBuffers(); | 68 | void aboutToSwapBuffers(); | ||
77 | 69 | | |||
78 | /** | 70 | /** | ||
79 | * Notifies the compositor that a pending buffer swap has completed. | 71 | * Notifies the compositor that a pending buffer swap has completed. | ||
80 | **/ | 72 | **/ | ||
81 | void bufferSwapComplete(); | 73 | void bufferSwapComplete(); | ||
82 | 74 | | |||
83 | /** | 75 | /** | ||
84 | * @brief Suspends the Compositor if it is currently active. | | |||
85 | * | | |||
86 | * Note: it is possible that the Compositor is not able to suspend. Use isActive to check | | |||
87 | * whether the Compositor has been suspended. | | |||
88 | * | | |||
89 | * @return void | | |||
90 | * @see resume | | |||
91 | * @see isActive | | |||
92 | **/ | | |||
93 | Q_INVOKABLE void suspend(Compositor::SuspendReason reason); | | |||
94 | | ||||
95 | /** | | |||
96 | * @brief Resumes the Compositor if it is currently suspended. | | |||
97 | * | | |||
98 | * Note: it is possible that the Compositor cannot be resumed, that is there might be Clients | | |||
99 | * blocking the usage of Compositing or the Scene might be broken. Use isActive to check | | |||
100 | * whether the Compositor has been resumed. Also check isCompositingPossible and | | |||
101 | * isOpenGLBroken. | | |||
102 | * | | |||
103 | * Note: The starting of the Compositor can require some time and is partially done threaded. | | |||
104 | * After this method returns the setup may not have been completed. | | |||
105 | * | | |||
106 | * @return void | | |||
107 | * @see suspend | | |||
108 | * @see isActive | | |||
109 | * @see isCompositingPossible | | |||
110 | * @see isOpenGLBroken | | |||
111 | **/ | | |||
112 | Q_INVOKABLE void resume(Compositor::SuspendReason reason); | | |||
113 | | ||||
114 | /** | | |||
115 | * Toggles compositing, that is if the Compositor is suspended it will be resumed | 76 | * Toggles compositing, that is if the Compositor is suspended it will be resumed | ||
116 | * and if the Compositor is active it will be suspended. | 77 | * and if the Compositor is active it will be suspended. | ||
117 | * Invoked by keybinding (shortcut default: Shift + Alt + F12). | 78 | * Invoked by keybinding (shortcut default: Shift + Alt + F12). | ||
118 | **/ | 79 | **/ | ||
119 | void toggleCompositing(); | 80 | virtual void toggleCompositing() = 0; | ||
120 | 81 | | |||
121 | /** | 82 | /** | ||
122 | * Re-initializes the Compositor completely. | 83 | * Re-initializes the Compositor completely. | ||
123 | * Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing | 84 | * Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing | ||
124 | **/ | 85 | **/ | ||
125 | void reinitialize(); | 86 | virtual void reinitialize(); | ||
126 | 87 | | |||
127 | /** | 88 | /** | ||
128 | * Whether the Compositor is active. That is a Scene is present and the Compositor is | 89 | * Whether the Compositor is active. That is a Scene is present and the Compositor is | ||
129 | * not shutting down itself. | 90 | * not shutting down itself. | ||
130 | **/ | 91 | **/ | ||
131 | bool isActive(); | 92 | bool isActive(); | ||
132 | int xrrRefreshRate() const { | 93 | virtual int refreshRate() const = 0; | ||
133 | return m_xrrRefreshRate; | | |||
134 | } | | |||
135 | 94 | | |||
136 | bool hasScene() const { | 95 | bool hasScene() const { | ||
137 | return m_scene != NULL; | 96 | return m_scene != NULL; | ||
138 | } | 97 | } | ||
98 | Scene *scene() const { | ||||
99 | return m_scene; | ||||
100 | } | ||||
139 | 101 | | |||
140 | /** | 102 | /** | ||
141 | * Checks whether @p w is the Scene's overlay window. | 103 | * Checks whether @p w is the Scene's overlay window. | ||
142 | **/ | 104 | **/ | ||
143 | bool checkForOverlayWindow(WId w) const; | 105 | virtual bool checkForOverlayWindow(WId w) const = 0; | ||
144 | /** | | |||
145 | * @returns Whether the Scene's Overlay X Window is visible. | | |||
146 | **/ | | |||
147 | bool isOverlayWindowVisible() const; | | |||
148 | | ||||
149 | Scene *scene() { | | |||
150 | return m_scene; | | |||
151 | } | | |||
152 | 106 | | |||
153 | /** | 107 | /** | ||
154 | * @brief Static check to test whether the Compositor is available and active. | 108 | * @brief Static check to test whether the Compositor is available and active. | ||
155 | * | 109 | * | ||
156 | * @return bool @c true if there is a Compositor and it is active, @c false otherwise | 110 | * @return bool @c true if there is a Compositor and it is active, @c false otherwise | ||
157 | **/ | 111 | **/ | ||
158 | static bool compositing() { | 112 | static bool compositing() { | ||
159 | return s_compositor != NULL && s_compositor->isActive(); | 113 | return s_compositor != NULL && s_compositor->isActive(); | ||
160 | } | 114 | } | ||
161 | 115 | | |||
162 | void updateCompositeBlocking(); | 116 | | ||
163 | void updateClientCompositeBlocking(KWin::Client* c); | 117 | virtual void updateCompositeBlocking() = 0; | ||
118 | virtual void updateClientCompositeBlocking(KWin::Client *c) = 0; | ||||
164 | 119 | | |||
165 | // for delayed supportproperty management of effects | 120 | // for delayed supportproperty management of effects | ||
166 | void keepSupportProperty(xcb_atom_t atom); | 121 | void keepSupportProperty(xcb_atom_t atom); | ||
167 | void removeSupportProperty(xcb_atom_t atom); | 122 | void removeSupportProperty(xcb_atom_t atom); | ||
168 | 123 | | |||
169 | Q_SIGNALS: | 124 | Q_SIGNALS: | ||
170 | void compositingToggled(bool active); | 125 | void compositingToggled(bool active); | ||
171 | void aboutToDestroy(); | 126 | void aboutToDestroy(); | ||
172 | void aboutToToggleCompositing(); | 127 | void aboutToToggleCompositing(); | ||
173 | void sceneCreated(); | 128 | void sceneCreated(); | ||
174 | void bufferSwapCompleted(); | 129 | void bufferSwapCompleted(); | ||
175 | 130 | | |||
176 | protected: | 131 | protected: | ||
132 | explicit Compositor(QObject *parent = nullptr); | ||||
177 | void timerEvent(QTimerEvent *te) override; | 133 | void timerEvent(QTimerEvent *te) override; | ||
178 | 134 | | |||
179 | private: | 135 | virtual void start() = 0; | ||
180 | Q_INVOKABLE void start(); | | |||
181 | void stop(); | 136 | void stop(); | ||
182 | 137 | | |||
183 | void claimCompositorSelection(); | 138 | /** | ||
184 | 139 | * @brief Prepares start. | |||
140 | * @return bool @c true if start should be continued and @c if not. | ||||
141 | */ | ||||
142 | bool setupStart(); | ||||
185 | /** | 143 | /** | ||
186 | * Continues the startup after Scene And Workspace are created | 144 | * Continues the startup after Scene And Workspace are created | ||
187 | **/ | 145 | **/ | ||
188 | void startupWithWorkspace(); | 146 | void startupWithWorkspace(); | ||
147 | virtual void performCompositing(); | ||||
148 | | ||||
149 | virtual void configChanged(); | ||||
150 | | ||||
151 | void destroyCompositorSelection(); | ||||
152 | | ||||
153 | static Compositor *s_compositor; | ||||
154 | | ||||
155 | private: | ||||
156 | void claimCompositorSelection(); | ||||
157 | | ||||
189 | void setupX11Support(); | 158 | void setupX11Support(); | ||
190 | 159 | | |||
191 | void setCompositeTimer(); | 160 | void setCompositeTimer(); | ||
192 | void performCompositing(); | | |||
193 | bool windowRepaintsPending() const; | 161 | bool windowRepaintsPending() const; | ||
194 | 162 | | |||
195 | void releaseCompositorSelection(); | 163 | void releaseCompositorSelection(); | ||
196 | void deleteUnusedSupportProperties(); | 164 | void deleteUnusedSupportProperties(); | ||
197 | 165 | | |||
198 | void slotConfigChanged(); | | |||
199 | | ||||
200 | State m_state; | 166 | State m_state; | ||
201 | /** | | |||
202 | * Whether the Compositor is currently suspended, 8 bits encoding the reason | | |||
203 | **/ | | |||
204 | SuspendReasons m_suspended; | | |||
205 | 167 | | |||
206 | QBasicTimer compositeTimer; | 168 | QBasicTimer compositeTimer; | ||
207 | CompositorSelectionOwner *m_selectionOwner; | 169 | CompositorSelectionOwner *m_selectionOwner; | ||
208 | QTimer m_releaseSelectionTimer; | 170 | QTimer m_releaseSelectionTimer; | ||
209 | QList<xcb_atom_t> m_unusedSupportProperties; | 171 | QList<xcb_atom_t> m_unusedSupportProperties; | ||
210 | QTimer m_unusedSupportPropertyTimer; | 172 | QTimer m_unusedSupportPropertyTimer; | ||
211 | qint64 vBlankInterval, fpsInterval; | 173 | qint64 vBlankInterval, fpsInterval; | ||
212 | int m_xrrRefreshRate; | | |||
213 | QRegion repaints_region; | 174 | QRegion repaints_region; | ||
214 | 175 | | |||
215 | qint64 m_timeSinceLastVBlank; | 176 | qint64 m_timeSinceLastVBlank; | ||
216 | 177 | | |||
217 | Scene *m_scene; | 178 | Scene *m_scene; | ||
218 | 179 | | |||
219 | bool m_bufferSwapPending; | 180 | bool m_bufferSwapPending; | ||
220 | bool m_composeAtSwapCompletion; | 181 | bool m_composeAtSwapCompletion; | ||
221 | 182 | | |||
222 | int m_framesToTestForSafety = 3; | 183 | int m_framesToTestForSafety = 3; | ||
223 | QElapsedTimer m_monotonicClock; | 184 | QElapsedTimer m_monotonicClock; | ||
185 | }; | ||||
186 | | ||||
187 | class KWIN_EXPORT WaylandCompositor : public Compositor | ||||
188 | { | ||||
189 | Q_OBJECT | ||||
190 | public: | ||||
191 | static WaylandCompositor* create(QObject *parent = nullptr); | ||||
192 | ~WaylandCompositor() override = default; | ||||
zzag: I guess we don't need it yet. | |||||
It's either way fine. I like to put the destructor in since most people expect it to be somewhere in a class and it's only a single line. Please don't let us discuss every little shit while ignoring the big picture. romangg: It's either way fine. I like to put the destructor in since most people expect it to be… | |||||
193 | | ||||
194 | int refreshRate() const override; | ||||
195 | | ||||
196 | void toggleCompositing() override; | ||||
197 | | ||||
198 | bool checkForOverlayWindow(WId w) const override; | ||||
199 | | ||||
200 | void updateCompositeBlocking() override; | ||||
201 | void updateClientCompositeBlocking(KWin::Client* c) override; | ||||
202 | | ||||
203 | protected: | ||||
204 | void start() override; | ||||
205 | | ||||
206 | private: | ||||
207 | explicit WaylandCompositor(QObject *parent); | ||||
208 | }; | ||||
209 | | ||||
210 | class KWIN_EXPORT X11Compositor : public Compositor | ||||
211 | { | ||||
212 | Q_OBJECT | ||||
213 | public: | ||||
214 | enum SuspendReason { | ||||
215 | NoReasonSuspend = 0, | ||||
216 | UserSuspend = 1 << 0, | ||||
217 | BlockRuleSuspend = 1 << 1, | ||||
218 | ScriptSuspend = 1 << 2, | ||||
219 | AllReasonSuspend = 0xff | ||||
220 | }; | ||||
221 | Q_DECLARE_FLAGS(SuspendReasons, SuspendReason) | ||||
222 | | ||||
223 | static X11Compositor* create(QObject *parent = nullptr); | ||||
224 | ~X11Compositor() override = default; | ||||
225 | | ||||
226 | /** | ||||
227 | * @brief Suspends the Compositor if it is currently active. | ||||
228 | * | ||||
229 | * Note: it is possible that the Compositor is not able to suspend. Use isActive to check | ||||
230 | * whether the Compositor has been suspended. | ||||
231 | * | ||||
232 | * @return void | ||||
233 | * @see resume | ||||
234 | * @see isActive | ||||
235 | **/ | ||||
236 | Q_INVOKABLE void suspend(SuspendReason reason); | ||||
237 | | ||||
238 | /** | ||||
239 | * @brief Resumes the Compositor if it is currently suspended. | ||||
240 | * | ||||
241 | * Note: it is possible that the Compositor cannot be resumed, that is there might be Clients | ||||
242 | * blocking the usage of Compositing or the Scene might be broken. Use isActive to check | ||||
243 | * whether the Compositor has been resumed. Also check isCompositingPossible and | ||||
244 | * isOpenGLBroken. | ||||
245 | * | ||||
246 | * Note: The starting of the Compositor can require some time and is partially done threaded. | ||||
247 | * After this method returns the setup may not have been completed. | ||||
248 | * | ||||
249 | * @return void | ||||
250 | * @see suspend | ||||
251 | * @see isActive | ||||
252 | * @see isCompositingPossible | ||||
253 | * @see isOpenGLBroken | ||||
254 | **/ | ||||
255 | Q_INVOKABLE void resume(SuspendReason reason); | ||||
256 | | ||||
257 | void toggleCompositing() override; | ||||
258 | void reinitialize() override; | ||||
224 | 259 | | |||
225 | KWIN_SINGLETON_VARIABLE(Compositor, s_compositor) | 260 | void configChanged() override; | ||
261 | | ||||
262 | bool checkForOverlayWindow(WId w) const override; | ||||
263 | /** | ||||
264 | * @returns Whether the Scene's Overlay X Window is visible. | ||||
265 | **/ | ||||
266 | bool isOverlayWindowVisible() const; | ||||
267 | | ||||
268 | int refreshRate() const override; | ||||
269 | | ||||
270 | void updateCompositeBlocking() override; | ||||
271 | void updateClientCompositeBlocking(KWin::Client* c) override; | ||||
272 | | ||||
273 | protected: | ||||
274 | void start() override; | ||||
275 | void performCompositing() override; | ||||
276 | | ||||
277 | private: | ||||
278 | explicit X11Compositor(QObject *parent); | ||||
279 | /** | ||||
280 | * Whether the Compositor is currently suspended, 8 bits encoding the reason | ||||
281 | **/ | ||||
282 | SuspendReasons m_suspended; | ||||
283 | | ||||
284 | int m_xrrRefreshRate; | ||||
226 | }; | 285 | }; | ||
227 | 286 | | |||
228 | } | 287 | } |
"For pointers or references, use a single space before '*' or '&', but not after"
(there are other places in this patch where whitespace for pointers needs to be fixed)