Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
17
19 : mUpdatePending(false),
20 mCursor(0),
21 mDepth(16),
22 mFormat(QImage::Format_RGB16),
23 mPainter(nullptr)
24{
25}
26
28{
29 delete mPainter;
30}
31
37
39{
40 if (event->type() == QEvent::UpdateRequest) {
41 doRedraw();
42 mUpdatePending = false;
43 return true;
44 }
45 return QObject::event(event);
46}
47
49{
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();
68}
69
78
90
102
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
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
122{
123 return mWindowStack.size();
124}
125
127{
128 const QRect intersection = rect.intersected(mGeometry);
129 const QPoint screenOffset = mGeometry.topLeft();
130 mRepaintRegion += intersection.translated(-screenOffset); // global to local translation
132}
133
141
146
156
158{
159 return true;
160}
161
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
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
203 touchedRegion += mCursor->drawCursor(*mPainter);
204 }
205 touchedRegion += mRepaintRegion;
207
208 return touchedRegion;
209}
210
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
220QFbScreen::Flags QFbScreen::flags() const
221{
222 return { };
223}
224
226
227#include "moc_qfbscreen_p.cpp"
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
\inmodule QtCore
Definition qcoreevent.h:45
@ UpdateRequest
Definition qcoreevent.h:113
const QImage image()
virtual bool isOnScreen() const
Definition qfbcursor_p.h:63
QRect dirtyRect()
virtual QRect lastPainted() const
Definition qfbcursor_p.h:64
virtual QRect drawCursor(QPainter &painter)
Definition qfbcursor.cpp:88
virtual bool isDirty() const
Definition qfbcursor_p.h:62
QImage mScreenImage
Definition qfbscreen_p.h:89
QFbWindow * windowForId(WId wid) const
virtual int windowCount() const
virtual Flags flags() const
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
Definition qfbscreen_p.h:45
QList< QFbWindow * > mWindowStack
Definition qfbscreen_p.h:80
virtual void topWindowChanged(QWindow *)
Definition qfbscreen_p.h:59
QWindow * topLevelAt(const QPoint &p) const override
Return the given top level window for a given position.
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
virtual bool initialize()
virtual void lower(QFbWindow *window)
Definition qfbscreen.cpp:91
QRegion mRepaintRegion
Definition qfbscreen_p.h:81
QWindow * topWindow() const
void initializeCompositor()
Definition qfbscreen.cpp:32
void setGeometry(const QRect &rect)
virtual void raise(QFbWindow *window)
Definition qfbscreen.cpp:79
virtual QRegion doRedraw()
void setPhysicalSize(const QSize &size)
QFbCursor * mCursor
Definition qfbscreen_p.h:84
virtual void setDirty(const QRect &rect)
QRect mGeometry
Definition qfbscreen_p.h:85
QImage::Format mFormat
Definition qfbscreen_p.h:87
bool mUpdatePending
Definition qfbscreen_p.h:82
virtual void removeWindow(QFbWindow *window)
Definition qfbscreen.cpp:70
QSizeF mPhysicalSize
Definition qfbscreen_p.h:88
virtual void addWindow(QFbWindow *window)
Definition qfbscreen.cpp:48
void scheduleUpdate()
\inmodule QtGui
Definition qimage.h:37
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
Definition qimage.cpp:4589
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
void removeAt(qsizetype i)
Definition qlist.h:590
bool removeOne(const AT &t)
Definition qlist.h:598
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void move(qsizetype from, qsizetype to)
Definition qlist.h:610
void prepend(rvalue_ref t)
Definition qlist.h:473
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition qobject.cpp:1389
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
@ CompositionMode_SourceOver
Definition qpainter.h:98
@ CompositionMode_Source
Definition qpainter.h:101
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
QScreen * screen() const
void resizeMaximizedWindows()
Convenience method to resize all the maximized and fullscreen windows of this platform screen.
virtual QRect availableGeometry() const
Reimplement in subclass to return the pixel geometry of the available space This normally is the desk...
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
QRect intersected(const QRect &other) const noexcept
Definition qrect.h:415
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr QRect translated(int dx, int dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:261
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
bool intersects(const QRegion &r) const
Definition qregion.cpp:613
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
\inmodule QtCore
Definition qsize.h:25
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r=Qt::OtherFocusReason)
\inmodule QtGui
Definition qwindow.h:63
rect
[4]
Combined button and popup list for selecting options.
@ transparent
Definition qnamespace.h:47
@ black
Definition qnamespace.h:30
@ Window
Definition qnamespace.h:207
@ Dialog
Definition qnamespace.h:208
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
struct _cl_event * event
GLfloat GLfloat p
[1]
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962