-
Notifications
You must be signed in to change notification settings - Fork 18
/
composite.h
285 lines (228 loc) · 7.64 KB
/
composite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2011 Arthur Arlt <[email protected]>
Copyright (C) 2012 Martin Gräßlin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#pragma once
#include <kwinglobals.h>
#include <QObject>
#include <QElapsedTimer>
#include <QTimer>
#include <QBasicTimer>
#include <QRegion>
namespace KWin
{
class CompositorSelectionOwner;
class Scene;
class X11Client;
class UKUI_KWIN_EXPORT Compositor : public QObject
{
Q_OBJECT
public:
enum class State {
On = 0,
Off,
Starting,
Stopping
};
~Compositor() override;
static Compositor *self();
// when adding repaints caused by a window, you probably want to use
// either Toplevel::addRepaint() or Toplevel::addWorkspaceRepaint()
void addRepaint(const QRect& r);
void addRepaint(const QRegion& r);
void addRepaint(int x, int y, int w, int h);
void addRepaintFull();
/**
* Schedules a new repaint if no repaint is currently scheduled.
*/
void scheduleRepaint();
/**
* Notifies the compositor that SwapBuffers() is about to be called.
* Rendering of the next frame will be deferred until bufferSwapComplete()
* is called.
*/
void aboutToSwapBuffers();
/**
* Notifies the compositor that a pending buffer swap has completed.
*/
void bufferSwapComplete();
/**
* Toggles compositing, that is if the Compositor is suspended it will be resumed
* and if the Compositor is active it will be suspended.
* Invoked by keybinding (shortcut default: Shift + Alt + F12).
*/
virtual void toggleCompositing() = 0;
/**
* Re-initializes the Compositor completely.
* Connected to the D-Bus signal org.kde.KWin /KWin reinitCompositing
*/
virtual void reinitialize();
/**
* Whether the Compositor is active. That is a Scene is present and the Compositor is
* not shutting down itself.
*/
bool isActive();
virtual int refreshRate() const = 0;
Scene *scene() const {
return m_scene;
}
/**
* @brief Static check to test whether the Compositor is available and active.
*
* @return bool @c true if there is a Compositor and it is active, @c false otherwise
*/
static bool compositing() {
return s_compositor != nullptr && s_compositor->isActive();
}
// for delayed supportproperty management of effects
void keepSupportProperty(xcb_atom_t atom);
void removeSupportProperty(xcb_atom_t atom);
Q_SIGNALS:
void compositingToggled(bool active);
void aboutToDestroy();
void aboutToToggleCompositing();
void sceneCreated();
void bufferSwapCompleted();
protected:
explicit Compositor(QObject *parent = nullptr);
void timerEvent(QTimerEvent *te) override;
virtual void start() = 0;
void stop();
/**
* @brief Prepares start.
* @return bool @c true if start should be continued and @c if not.
*/
bool setupStart();
/**
* Continues the startup after Scene And Workspace are created
*/
void startupWithWorkspace();
virtual void performCompositing();
virtual void configChanged();
void destroyCompositorSelection();
static Compositor *s_compositor;
private:
void claimCompositorSelection();
void setupX11Support();
void setCompositeTimer();
bool windowRepaintsPending() const;
void releaseCompositorSelection();
void deleteUnusedSupportProperties();
State m_state;
QBasicTimer compositeTimer;
CompositorSelectionOwner *m_selectionOwner;
QTimer m_releaseSelectionTimer;
QList<xcb_atom_t> m_unusedSupportProperties;
QTimer m_unusedSupportPropertyTimer;
qint64 vBlankInterval, fpsInterval;
QRegion repaints_region;
qint64 m_timeSinceLastVBlank;
Scene *m_scene;
bool m_bufferSwapPending;
bool m_composeAtSwapCompletion;
int m_framesToTestForSafety = 3;
QElapsedTimer m_monotonicClock;
};
class UKUI_KWIN_EXPORT WaylandCompositor : public Compositor
{
Q_OBJECT
public:
static WaylandCompositor *create(QObject *parent = nullptr);
int refreshRate() const override;
void toggleCompositing() override;
protected:
void start() override;
private:
explicit WaylandCompositor(QObject *parent);
};
class UKUI_KWIN_EXPORT X11Compositor : public Compositor
{
Q_OBJECT
public:
enum SuspendReason {
NoReasonSuspend = 0,
UserSuspend = 1 << 0,
BlockRuleSuspend = 1 << 1,
ScriptSuspend = 1 << 2,
AllReasonSuspend = 0xff
};
Q_DECLARE_FLAGS(SuspendReasons, SuspendReason)
Q_ENUM(SuspendReason)
Q_FLAG(SuspendReasons)
static X11Compositor *create(QObject *parent = nullptr);
/**
* @brief Suspends the Compositor if it is currently active.
*
* Note: it is possible that the Compositor is not able to suspend. Use isActive to check
* whether the Compositor has been suspended.
*
* @return void
* @see resume
* @see isActive
*/
void suspend(SuspendReason reason);
/**
* @brief Resumes the Compositor if it is currently suspended.
*
* Note: it is possible that the Compositor cannot be resumed, that is there might be Clients
* blocking the usage of Compositing or the Scene might be broken. Use isActive to check
* whether the Compositor has been resumed. Also check isCompositingPossible and
* isOpenGLBroken.
*
* Note: The starting of the Compositor can require some time and is partially done threaded.
* After this method returns the setup may not have been completed.
*
* @return void
* @see suspend
* @see isActive
* @see isCompositingPossible
* @see isOpenGLBroken
*/
void resume(SuspendReason reason);
void toggleCompositing() override;
void reinitialize() override;
void configChanged() override;
/**
* Checks whether @p w is the Scene's overlay window.
*/
bool checkForOverlayWindow(WId w) const;
/**
* @returns Whether the Scene's Overlay X Window is visible.
*/
bool isOverlayWindowVisible() const;
int refreshRate() const override;
void updateClientCompositeBlocking(X11Client *client = nullptr);
static X11Compositor *self();
protected:
void start() override;
void performCompositing() override;
private:
explicit X11Compositor(QObject *parent);
/**
* Whether the Compositor is currently suspended, 8 bits encoding the reason
*/
SuspendReasons m_suspended;
int m_xrrRefreshRate;
/*!
* \author Yunpeng Zhu.
* \brief 标记混成是否在第一次开机时被打开
* 当未打开时,强制去开启
* 目的:规避远程桌面下,无法通过dbus开关混成的bug
* 该bug的根因在于一个用户下有两个kwin但只有一套dbus,
* 正向解决方案为:修改kwin的dbus逻辑
*/
bool m_isStartOnFirst;
};
}