Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qfbscreen.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qfbscreen_p.h"
5
#
include
"qfbcursor_p.h"
6
#
include
"qfbwindow_p.h"
7
#
include
"qfbbackingstore_p.h"
8
9
#
include
<
QtGui
/
QPainter
>
10
#
include
<
QtCore
/
QCoreApplication
>
11
#
include
<
qpa
/
qwindowsysteminterface
.
h
>
12
13
#
include
<
QtCore
/
QDebug
>
14
#
include
<
QtCore
/
QElapsedTimer
>
15
16
QT_BEGIN_NAMESPACE
17
18
QFbScreen::QFbScreen()
19
: mUpdatePending(
false
),
20
mCursor(0),
21
mDepth(16),
22
mFormat(QImage::Format_RGB16),
23
mPainter(
nullptr
)
24
{
25
}
26
27
QFbScreen
::~
QFbScreen
()
28
{
29
delete
mPainter;
30
}
31
32
void
QFbScreen
::
initializeCompositor
()
33
{
34
mScreenImage = QImage(mGeometry.size(), mFormat);
35
scheduleUpdate
(
)
;
36
}
37
38
bool
QFbScreen
::
event
(QEvent *event)
39
{
40
if
(event->type() == QEvent::UpdateRequest) {
41
doRedraw();
42
mUpdatePending
=
false
;
43
return
true
;
44
}
45
return
QObject::event(event);
46
}
47
48
void
QFbScreen
::
addWindow
(
QFbWindow
*window)
49
{
50
mWindowStack.prepend(window);
51
if
(!mPendingBackingStores.isEmpty()) {
52
//check if we have a backing store for this window
53
for
(
int
i = 0; i < mPendingBackingStores.size(); ++i) {
54
QFbBackingStore
*bs = mPendingBackingStores.at(i);
55
// this gets called during QWindow::create() at a point where the
56
// invariant (window->handle()->window() == window) is broken
57
if
(bs->window() == window->window()) {
58
window
->
setBackingStore
(
bs
)
;
59
mPendingBackingStores.removeAt(i);
60
break
;
61
}
62
}
63
}
64
setDirty(window->geometry());
65
QWindow *w = topWindow();
66
QWindowSystemInterface::handleFocusWindowChanged(w);
67
topWindowChanged(w);
68
}
69
70
void
QFbScreen
::
removeWindow
(
QFbWindow
*window)
71
{
72
mWindowStack.removeOne(window);
73
setDirty(window->geometry());
74
QWindow *w = topWindow();
75
QWindowSystemInterface::handleFocusWindowChanged(w);
76
topWindowChanged(w);
77
}
78
79
void
QFbScreen
::
raise
(
QFbWindow
*window)
80
{
81
int
index = mWindowStack.indexOf(window);
82
if
(index <= 0)
83
return
;
84
mWindowStack.move(index, 0);
85
setDirty(window->geometry());
86
QWindow *w = topWindow();
87
QWindowSystemInterface::handleFocusWindowChanged(w);
88
topWindowChanged(w);
89
}
90
91
void
QFbScreen
::
lower
(
QFbWindow
*window)
92
{
93
int
index = mWindowStack.indexOf(window);
94
if
(index == -1 || index == (mWindowStack.size() - 1))
95
return
;
96
mWindowStack.move(index, mWindowStack.size() - 1);
97
setDirty(window->geometry());
98
QWindow *w = topWindow();
99
QWindowSystemInterface::handleFocusWindowChanged(w);
100
topWindowChanged(w);
101
}
102
103
QWindow *
QFbScreen
::
topWindow
()
const
104
{
105
for
(QFbWindow *fbw : mWindowStack) {
106
if
(fbw->window()->type() == Qt::Window || fbw->window()->type() == Qt::Dialog)
107
return
fbw->window();
108
}
109
return
nullptr
;
110
}
111
112
QWindow *
QFbScreen
::
topLevelAt
(
const
QPoint & p)
const
113
{
114
for
(QFbWindow *fbw : mWindowStack) {
115
if
(fbw->geometry().contains(p,
false
) && fbw->window()->isVisible())
116
return
fbw->window();
117
}
118
return
nullptr
;
119
}
120
121
int
QFbScreen
::
windowCount
()
const
122
{
123
return
mWindowStack.size();
124
}
125
126
void
QFbScreen
::setDirty(
const
QRect &rect)
127
{
128
const
QRect intersection = rect.intersected(mGeometry);
129
const
QPoint screenOffset = mGeometry.topLeft();
130
mRepaintRegion += intersection.translated(-screenOffset);
// global to local translation
131
scheduleUpdate
(
)
;
132
}
133
134
void
QFbScreen
::
scheduleUpdate
()
135
{
136
if
(!
mUpdatePending
) {
137
mUpdatePending
=
true
;
138
QCoreApplication::postEvent(
this
,
new
QEvent(QEvent::UpdateRequest));
139
}
140
}
141
142
void
QFbScreen
::
setPhysicalSize
(
const
QSize &size)
143
{
144
mPhysicalSize = size;
145
}
146
147
void
QFbScreen
::
setGeometry
(
const
QRect &rect)
148
{
149
delete
mPainter;
150
mPainter =
nullptr
;
151
mGeometry = rect;
152
mScreenImage = QImage(mGeometry.size(), mFormat);
153
QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(), availableGeometry());
154
resizeMaximizedWindows();
155
}
156
157
bool
QFbScreen
::
initialize
()
158
{
159
return
true
;
160
}
161
162
QRegion
QFbScreen
::
doRedraw
()
163
{
164
const
QPoint screenOffset = mGeometry.topLeft();
165
166
QRegion touchedRegion;
167
if
(
mCursor
&&
mCursor
->
isDirty
(
)
&&
mCursor
->
isOnScreen
(
)
) {
168
const
QRect lastCursor =
mCursor
->dirtyRect();
169
mRepaintRegion += lastCursor;
170
}
171
if
(mRepaintRegion.isEmpty() && (!mCursor || !mCursor->isDirty()))
172
return
touchedRegion;
173
174
if
(!mPainter)
175
mPainter =
new
QPainter(&mScreenImage);
176
177
const
QRect screenRect = mGeometry.translated(-screenOffset);
178
for
(QRect rect : mRepaintRegion) {
179
rect = rect.intersected(screenRect);
180
if
(rect.isEmpty())
181
continue
;
182
183
mPainter->setCompositionMode(QPainter::CompositionMode_Source);
184
mPainter->fillRect(rect, mScreenImage.hasAlphaChannel() ? Qt::transparent : Qt::black);
185
186
for
(
int
layerIndex = mWindowStack.size() - 1; layerIndex != -1; layerIndex--) {
187
if
(!mWindowStack[layerIndex]->window()->isVisible())
188
continue
;
189
190
const
QRect windowRect = mWindowStack[layerIndex]->geometry().translated(-screenOffset);
191
const
QRect windowIntersect = rect.translated(-windowRect.left(), -windowRect.top());
192
QFbBackingStore *backingStore = mWindowStack[layerIndex]->backingStore();
193
if
(backingStore) {
194
backingStore->lock();
195
mPainter->drawImage(rect, backingStore->image(), windowIntersect);
196
backingStore->unlock();
197
}
198
}
199
}
200
201
if
(mCursor && (mCursor->isDirty() || mRepaintRegion.intersects(mCursor->lastPainted()))) {
202
mPainter->setCompositionMode(QPainter::CompositionMode_SourceOver);
203
touchedRegion +=
mCursor
->drawCursor(*mPainter);
204
}
205
touchedRegion += mRepaintRegion;
206
mRepaintRegion = QRegion();
207
208
return
touchedRegion;
209
}
210
211
QFbWindow
*
QFbScreen
::
windowForId
(WId wid)
const
212
{
213
for
(
int
i = 0; i < mWindowStack.size(); ++i) {
214
if
(mWindowStack[i]->winId() == wid)
215
return
mWindowStack[i];
216
}
217
return
nullptr
;
218
}
219
220
QFbScreen
::
Flags
QFbScreen
::
flags
()
const
221
{
222
return
{ };
223
}
224
225
QT_END_NAMESPACE
226
227
#
include
"moc_qfbscreen_p.cpp"
QFbBackingStore
Definition
qfbbackingstore_p.h:29
QFbCursor::isOnScreen
virtual bool isOnScreen() const
Definition
qfbcursor_p.h:63
QFbCursor::isDirty
virtual bool isDirty() const
Definition
qfbcursor_p.h:62
QFbScreen
Definition
qfbscreen_p.h:30
QFbScreen::windowForId
QFbWindow * windowForId(WId wid) const
Definition
qfbscreen.cpp:211
QFbScreen::windowCount
virtual int windowCount() const
Definition
qfbscreen.cpp:121
QFbScreen::flags
virtual Flags flags() const
Definition
qfbscreen.cpp:220
QFbScreen::topLevelAt
QWindow * topLevelAt(const QPoint &p) const override
Return the given top level window for a given position.
Definition
qfbscreen.cpp:112
QFbScreen::event
bool event(QEvent *event) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition
qfbscreen.cpp:38
QFbScreen::initialize
virtual bool initialize()
Definition
qfbscreen.cpp:157
QFbScreen::lower
virtual void lower(QFbWindow *window)
Definition
qfbscreen.cpp:91
QFbScreen::topWindow
QWindow * topWindow() const
Definition
qfbscreen.cpp:103
QFbScreen::initializeCompositor
void initializeCompositor()
Definition
qfbscreen.cpp:32
QFbScreen::setGeometry
void setGeometry(const QRect &rect)
Definition
qfbscreen.cpp:147
QFbScreen::raise
virtual void raise(QFbWindow *window)
Definition
qfbscreen.cpp:79
QFbScreen::doRedraw
virtual QRegion doRedraw()
Definition
qfbscreen.cpp:162
QFbScreen::setPhysicalSize
void setPhysicalSize(const QSize &size)
Definition
qfbscreen.cpp:142
QFbScreen::mCursor
QFbCursor * mCursor
Definition
qfbscreen_p.h:83
QFbScreen::~QFbScreen
~QFbScreen()
Definition
qfbscreen.cpp:27
QFbScreen::mUpdatePending
bool mUpdatePending
Definition
qfbscreen_p.h:81
QFbScreen::removeWindow
virtual void removeWindow(QFbWindow *window)
Definition
qfbscreen.cpp:70
QFbScreen::addWindow
virtual void addWindow(QFbWindow *window)
Definition
qfbscreen.cpp:48
QFbScreen::scheduleUpdate
void scheduleUpdate()
Definition
qfbscreen.cpp:134
QFbWindow
Definition
qfbwindow_p.h:27
QFbWindow::setBackingStore
void setBackingStore(QFbBackingStore *store)
Definition
qfbwindow_p.h:44
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
platformsupport
fbconvenience
qfbscreen.cpp
Generated on
for Qt by
1.18.0