Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/eglfs/qeglfsscreen.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include <QtCore/qtextstream.h> | - | ||||||||||||
35 | #include <QtGui/qwindow.h> | - | ||||||||||||
36 | #include <qpa/qwindowsysteminterface.h> | - | ||||||||||||
37 | #include <qpa/qplatformcursor.h> | - | ||||||||||||
38 | #include <QtPlatformSupport/private/qopenglcompositor_p.h> | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qeglfsscreen.h" | - | ||||||||||||
41 | #include "qeglfswindow.h" | - | ||||||||||||
42 | #include "qeglfshooks.h" | - | ||||||||||||
43 | - | |||||||||||||
44 | QT_BEGIN_NAMESPACE | - | ||||||||||||
45 | - | |||||||||||||
46 | QEglFSScreen::QEglFSScreen(EGLDisplay dpy) | - | ||||||||||||
47 | : m_dpy(dpy), | - | ||||||||||||
48 | m_surface(EGL_NO_SURFACE), | - | ||||||||||||
49 | m_cursor(0) | - | ||||||||||||
50 | { | - | ||||||||||||
51 | m_cursor = qt_egl_device_integration()->createCursor(this); | - | ||||||||||||
52 | } never executed: end of block | 0 | ||||||||||||
53 | - | |||||||||||||
54 | QEglFSScreen::~QEglFSScreen() | - | ||||||||||||
55 | { | - | ||||||||||||
56 | delete m_cursor; | - | ||||||||||||
57 | QOpenGLCompositor::destroy(); | - | ||||||||||||
58 | } never executed: end of block | 0 | ||||||||||||
59 | - | |||||||||||||
60 | QRect QEglFSScreen::geometry() const | - | ||||||||||||
61 | { | - | ||||||||||||
62 | return QRect(QPoint(0, 0), qt_egl_device_integration()->screenSize()); never executed: return QRect(QPoint(0, 0), qt_egl_device_integration()->screenSize()); | 0 | ||||||||||||
63 | } | - | ||||||||||||
64 | - | |||||||||||||
65 | int QEglFSScreen::depth() const | - | ||||||||||||
66 | { | - | ||||||||||||
67 | return qt_egl_device_integration()->screenDepth(); never executed: return qt_egl_device_integration()->screenDepth(); | 0 | ||||||||||||
68 | } | - | ||||||||||||
69 | - | |||||||||||||
70 | QImage::Format QEglFSScreen::format() const | - | ||||||||||||
71 | { | - | ||||||||||||
72 | return qt_egl_device_integration()->screenFormat(); never executed: return qt_egl_device_integration()->screenFormat(); | 0 | ||||||||||||
73 | } | - | ||||||||||||
74 | - | |||||||||||||
75 | QSizeF QEglFSScreen::physicalSize() const | - | ||||||||||||
76 | { | - | ||||||||||||
77 | return qt_egl_device_integration()->physicalScreenSize(); never executed: return qt_egl_device_integration()->physicalScreenSize(); | 0 | ||||||||||||
78 | } | - | ||||||||||||
79 | - | |||||||||||||
80 | QDpi QEglFSScreen::logicalDpi() const | - | ||||||||||||
81 | { | - | ||||||||||||
82 | return qt_egl_device_integration()->logicalDpi(); never executed: return qt_egl_device_integration()->logicalDpi(); | 0 | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | qreal QEglFSScreen::pixelDensity() const | - | ||||||||||||
86 | { | - | ||||||||||||
87 | return qt_egl_device_integration()->pixelDensity(); never executed: return qt_egl_device_integration()->pixelDensity(); | 0 | ||||||||||||
88 | } | - | ||||||||||||
89 | - | |||||||||||||
90 | Qt::ScreenOrientation QEglFSScreen::nativeOrientation() const | - | ||||||||||||
91 | { | - | ||||||||||||
92 | return qt_egl_device_integration()->nativeOrientation(); never executed: return qt_egl_device_integration()->nativeOrientation(); | 0 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | Qt::ScreenOrientation QEglFSScreen::orientation() const | - | ||||||||||||
96 | { | - | ||||||||||||
97 | return qt_egl_device_integration()->orientation(); never executed: return qt_egl_device_integration()->orientation(); | 0 | ||||||||||||
98 | } | - | ||||||||||||
99 | - | |||||||||||||
100 | QPlatformCursor *QEglFSScreen::cursor() const | - | ||||||||||||
101 | { | - | ||||||||||||
102 | return m_cursor; never executed: return m_cursor; | 0 | ||||||||||||
103 | } | - | ||||||||||||
104 | - | |||||||||||||
105 | qreal QEglFSScreen::refreshRate() const | - | ||||||||||||
106 | { | - | ||||||||||||
107 | return qt_egl_device_integration()->refreshRate(); never executed: return qt_egl_device_integration()->refreshRate(); | 0 | ||||||||||||
108 | } | - | ||||||||||||
109 | - | |||||||||||||
110 | void QEglFSScreen::setPrimarySurface(EGLSurface surface) | - | ||||||||||||
111 | { | - | ||||||||||||
112 | m_surface = surface; | - | ||||||||||||
113 | } never executed: end of block | 0 | ||||||||||||
114 | - | |||||||||||||
115 | void QEglFSScreen::handleCursorMove(const QPoint &pos) | - | ||||||||||||
116 | { | - | ||||||||||||
117 | const QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - | ||||||||||||
118 | const QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - | ||||||||||||
119 | - | |||||||||||||
120 | // Generate enter and leave events like a real windowing system would do. | - | ||||||||||||
121 | if (windows.isEmpty())
| 0 | ||||||||||||
122 | return; never executed: return; | 0 | ||||||||||||
123 | - | |||||||||||||
124 | // First window is always fullscreen. | - | ||||||||||||
125 | if (windows.count() == 1) {
| 0 | ||||||||||||
126 | QWindow *window = windows[0]->sourceWindow(); | - | ||||||||||||
127 | if (m_pointerWindow != window) {
| 0 | ||||||||||||
128 | m_pointerWindow = window; | - | ||||||||||||
129 | QWindowSystemInterface::handleEnterEvent(window, window->mapFromGlobal(pos), pos); | - | ||||||||||||
130 | } never executed: end of block | 0 | ||||||||||||
131 | return; never executed: return; | 0 | ||||||||||||
132 | } | - | ||||||||||||
133 | - | |||||||||||||
134 | QWindow *enter = 0, *leave = 0; | - | ||||||||||||
135 | for (int i = windows.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||
136 | QWindow *window = windows[i]->sourceWindow(); | - | ||||||||||||
137 | const QRect geom = window->geometry(); | - | ||||||||||||
138 | if (geom.contains(pos)) {
| 0 | ||||||||||||
139 | if (m_pointerWindow != window) {
| 0 | ||||||||||||
140 | leave = m_pointerWindow; | - | ||||||||||||
141 | m_pointerWindow = window; | - | ||||||||||||
142 | enter = window; | - | ||||||||||||
143 | } never executed: end of block | 0 | ||||||||||||
144 | break; never executed: break; | 0 | ||||||||||||
145 | } | - | ||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||
147 | - | |||||||||||||
148 | if (enter && leave)
| 0 | ||||||||||||
149 | QWindowSystemInterface::handleEnterLeaveEvent(enter, leave, enter->mapFromGlobal(pos), pos); never executed: QWindowSystemInterface::handleEnterLeaveEvent(enter, leave, enter->mapFromGlobal(pos), pos); | 0 | ||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||
151 | - | |||||||||||||
152 | QPixmap QEglFSScreen::grabWindow(WId wid, int x, int y, int width, int height) const | - | ||||||||||||
153 | { | - | ||||||||||||
154 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - | ||||||||||||
155 | const QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - | ||||||||||||
156 | Q_ASSERT(!windows.isEmpty()); | - | ||||||||||||
157 | - | |||||||||||||
158 | QImage img; | - | ||||||||||||
159 | - | |||||||||||||
160 | if (static_cast<QEglFSWindow *>(windows.first()->sourceWindow()->handle())->isRaster()) {
| 0 | ||||||||||||
161 | // Request the compositor to render everything into an FBO and read it back. This | - | ||||||||||||
162 | // is of course slow, but it's safe and reliable. It will not include the mouse | - | ||||||||||||
163 | // cursor, which is a plus. | - | ||||||||||||
164 | img = compositor->grab(); | - | ||||||||||||
165 | } else { never executed: end of block | 0 | ||||||||||||
166 | // Just a single OpenGL window without compositing. Do not support this case for now. Doing | - | ||||||||||||
167 | // glReadPixels is not an option since it would read from the back buffer which may have | - | ||||||||||||
168 | // undefined content when calling right after a swapBuffers (unless preserved swap is | - | ||||||||||||
169 | // available and enabled, but we have no support for that). | - | ||||||||||||
170 | qWarning("grabWindow: Not supported for non-composited OpenGL content. Use QQuickWindow::grabWindow() instead."); | - | ||||||||||||
171 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||
172 | } | - | ||||||||||||
173 | - | |||||||||||||
174 | if (!wid) {
| 0 | ||||||||||||
175 | const QSize screenSize = geometry().size(); | - | ||||||||||||
176 | if (width < 0)
| 0 | ||||||||||||
177 | width = screenSize.width() - x; never executed: width = screenSize.width() - x; | 0 | ||||||||||||
178 | if (height < 0)
| 0 | ||||||||||||
179 | height = screenSize.height() - y; never executed: height = screenSize.height() - y; | 0 | ||||||||||||
180 | return QPixmap::fromImage(img).copy(x, y, width, height); never executed: return QPixmap::fromImage(img).copy(x, y, width, height); | 0 | ||||||||||||
181 | } | - | ||||||||||||
182 | - | |||||||||||||
183 | foreach (QOpenGLCompositorWindow *w, windows) { | - | ||||||||||||
184 | const QWindow *window = w->sourceWindow(); | - | ||||||||||||
185 | if (window->winId() == wid) {
| 0 | ||||||||||||
186 | const QRect geom = window->geometry(); | - | ||||||||||||
187 | if (width < 0)
| 0 | ||||||||||||
188 | width = geom.width() - x; never executed: width = geom.width() - x; | 0 | ||||||||||||
189 | if (height < 0)
| 0 | ||||||||||||
190 | height = geom.height() - y; never executed: height = geom.height() - y; | 0 | ||||||||||||
191 | QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height)); | - | ||||||||||||
192 | rect &= window->geometry(); | - | ||||||||||||
193 | return QPixmap::fromImage(img).copy(rect); never executed: return QPixmap::fromImage(img).copy(rect); | 0 | ||||||||||||
194 | } | - | ||||||||||||
195 | } never executed: end of block | 0 | ||||||||||||
196 | - | |||||||||||||
197 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||
198 | } | - | ||||||||||||
199 | - | |||||||||||||
200 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |