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
qeglfsscreen.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 <QtCore/qtextstream.h>
5#include <QtGui/qwindow.h>
6#include <QtGui/private/qguiapplication_p.h>
7#include <qpa/qwindowsysteminterface.h>
8#include <qpa/qplatformcursor.h>
9#ifndef QT_NO_OPENGL
10# include <QtOpenGL/private/qopenglcompositor_p.h>
11#endif
12
13#include "qeglfsscreen_p.h"
14#include "qeglfswindow_p.h"
15#include "qeglfshooks_p.h"
16
18
20 : m_dpy(dpy),
21 m_surface(EGL_NO_SURFACE),
22 m_cursor(nullptr)
23{
24 m_cursor = qt_egl_device_integration()->createCursor(this);
25}
26
28{
29 delete m_cursor;
30}
31
33{
35
36 static int rotation = qEnvironmentVariableIntValue("QT_QPA_EGLFS_ROTATION");
37 switch (rotation) {
38 case 0:
39 case 180:
40 case -180:
41 break;
42 case 90:
43 case -90: {
44 int h = r.height();
45 r.setHeight(r.width());
46 r.setWidth(h);
47 break;
48 }
49 default:
50 qWarning("Invalid rotation %d specified in QT_QPA_EGLFS_ROTATION", rotation);
51 break;
52 }
53
54 return r;
55}
56
58{
59 return QRect(QPoint(0, 0), qt_egl_device_integration()->screenSize());
60}
61
63{
65}
66
71
76
81
86
91
96
98{
99 return m_cursor;
100}
101
106
107void QEglFSScreen::setPrimarySurface(EGLSurface surface)
108{
109 m_surface = surface;
110}
111
113{
114#ifndef QT_NO_OPENGL
116 const QList<QOpenGLCompositorWindow *> windows = compositor->windows();
118
119 // Generate enter and leave events like a real windowing system would do.
120 if (windows.isEmpty())
121 return;
122
123 // First window is always fullscreen.
124 if (windows.size() == 1) {
125 QWindow *window = windows[0]->sourceWindow();
126 if (platformIntegration->pointerWindow() != window) {
127 platformIntegration->setPointerWindow(window);
129 }
130 return;
131 }
132
133 QWindow *enter = nullptr, *leave = nullptr;
134 for (int i = windows.size() - 1; i >= 0; --i) {
135 QWindow *window = windows[i]->sourceWindow();
136 const QRect geom = window->geometry();
137 if (geom.contains(pos)) {
138 if (platformIntegration->pointerWindow() != window) {
139 leave = platformIntegration->pointerWindow();
140 platformIntegration->setPointerWindow(window);
141 enter = window;
142 }
143 break;
144 }
145 }
146
147 if (enter && leave) {
148 QWindowSystemInterface::handleEnterLeaveEvent(enter, leave, enter->mapFromGlobal(pos), pos);
149 } else if (enter) {
150 QWindowSystemInterface::handleEnterEvent(enter, enter->mapFromGlobal(pos), pos);
151 } else if (leave) {
153 }
154#else
155 Q_UNUSED(pos);
156#endif
157}
158
159QPixmap QEglFSScreen::grabWindow(WId wid, int x, int y, int width, int height) const
160{
161#ifndef QT_NO_OPENGL
163 const QList<QOpenGLCompositorWindow *> windows = compositor->windows();
165
166 QImage img;
167
168 QEglFSWindow *primaryWin = static_cast<QEglFSWindow *>(windows.first()->sourceWindow()->handle());
169 if (primaryWin->isRaster() || primaryWin->backingStore()) {
170 // Request the compositor to render everything into an FBO and read it back. This
171 // is of course slow, but it's safe and reliable. It will not include the mouse
172 // cursor, which is a plus.
173 img = compositor->grab();
174 } else {
175 // Just a single OpenGL window without compositing. Do not support this case for now. Doing
176 // glReadPixels is not an option since it would read from the back buffer which may have
177 // undefined content when calling right after a swapBuffers (unless preserved swap is
178 // available and enabled, but we have no support for that).
179 qWarning("grabWindow: Not supported for non-composited OpenGL content. Use QQuickWindow::grabWindow() instead.");
180 return QPixmap();
181 }
182
183 if (!wid) {
184 const QSize screenSize = geometry().size();
185 if (width < 0)
186 width = screenSize.width() - x;
187 if (height < 0)
188 height = screenSize.height() - y;
189 return QPixmap::fromImage(img).copy(x, y, width, height);
190 }
191
193 const QWindow *window = w->sourceWindow();
194 if (window->winId() == wid) {
195 const QRect geom = window->geometry();
196 if (width < 0)
197 width = geom.width() - x;
198 if (height < 0)
199 height = geom.height() - y;
200 QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height));
201 rect &= window->geometry();
202 return QPixmap::fromImage(img).copy(rect);
203 }
204 }
205#else // QT_NO_OPENGL
206 Q_UNUSED(wid);
207 Q_UNUSED(x);
208 Q_UNUSED(y);
211#endif
212 return QPixmap();
213}
214
216{
217#ifndef QT_NO_OPENGL
219 const QList<QOpenGLCompositorWindow *> windows = compositor->windows();
220 const int windowCount = windows.size();
221
222 // Higher z-order is at the end of the list
223 for (int i = windowCount - 1; i >= 0; i--) {
224 QWindow *window = windows[i]->sourceWindow();
225 if (window->isVisible() && window->geometry().contains(point))
226 return window;
227 }
228#endif
229
230 return QPlatformScreen::topLevelAt(point);
231}
232
virtual QSizeF physicalScreenSize() const
virtual Qt::ScreenOrientation nativeOrientation() const
virtual QImage::Format screenFormat() const
virtual QPlatformCursor * createCursor(QPlatformScreen *screen) const
virtual Qt::ScreenOrientation orientation() const
void setPointerWindow(QWindow *pointerWindow)
QPointer< QWindow > pointerWindow()
QPlatformCursor * cursor() const override
Reimplement this function in subclass to return the cursor of the screen.
void handleCursorMove(const QPoint &pos)
QWindow * topLevelAt(const QPoint &point) const override
Return the given top level window for a given position.
QEglFSScreen(EGLDisplay display)
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
virtual QRect rawGeometry() const
QDpi logicalBaseDpi() const override
Reimplement to return the base logical DPI for the platform.
qreal refreshRate() const override
Reimplement this function in subclass to return the vertical refresh rate of the screen,...
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
QSizeF physicalSize() const override
Reimplement this function in subclass to return the physical size of the screen, in millimeters.
QPixmap grabWindow(WId wid, int x, int y, int width, int height) const override
This function is called when Qt needs to be able to grab the content of a window.
QDpi logicalDpi() const override
Reimplement this function in subclass to return the logical horizontal and vertical dots per inch met...
Qt::ScreenOrientation orientation() const override
Reimplement this function in subclass to return the current orientation of the screen,...
int depth() const override
Reimplement in subclass to return current depth of the screen.
Qt::ScreenOrientation nativeOrientation() const override
Reimplement this function in subclass to return the native orientation of the screen,...
static QPlatformIntegration * platformIntegration()
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
T & first()
Definition qlist.h:645
A generic OpenGL-based compositor.
static QOpenGLCompositor * instance()
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
The QPlatformCursor class provides information about pointer device events (movement,...
QWindowList windows() const
Return all windows residing on this screen.
virtual QWindow * topLevelAt(const QPoint &point) const
Return the given top level window for a given position.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:855
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
static void handleLeaveEvent(QWindow *window)
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local=QPointF(), const QPointF &global=QPointF())
This method can be used to ensure leave and enter events are both in queue when moving from one QWind...
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
\inmodule QtGui
Definition qwindow.h:63
rect
[4]
Combined button and popup list for selecting options.
ScreenOrientation
Definition qnamespace.h:271
QEglFSDeviceIntegration * qt_egl_device_integration()
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
QPair< qreal, qreal > QDpi
#define qWarning
Definition qlogging.h:166
static QOpenGLCompositor * compositor
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean r
[2]
GLint GLsizei width
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLint void * img
Definition qopenglext.h:233
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
#define leave(x)
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]