Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/eglfs/qeglfswindow.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 <qpa/qwindowsysteminterface.h> | - | ||||||||||||
36 | #include <qpa/qplatformintegration.h> | - | ||||||||||||
37 | #include <private/qguiapplication_p.h> | - | ||||||||||||
38 | #include <QtGui/private/qopenglcontext_p.h> | - | ||||||||||||
39 | #include <QtGui/QOpenGLContext> | - | ||||||||||||
40 | #include <QtPlatformSupport/private/qeglconvenience_p.h> | - | ||||||||||||
41 | #include <QtPlatformSupport/private/qopenglcompositorbackingstore_p.h> | - | ||||||||||||
42 | - | |||||||||||||
43 | #include "qeglfswindow.h" | - | ||||||||||||
44 | #include "qeglfscursor.h" | - | ||||||||||||
45 | #include "qeglfshooks.h" | - | ||||||||||||
46 | - | |||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
48 | - | |||||||||||||
49 | QEglFSWindow::QEglFSWindow(QWindow *w) | - | ||||||||||||
50 | : QPlatformWindow(w), | - | ||||||||||||
51 | m_backingStore(0), | - | ||||||||||||
52 | m_raster(false), | - | ||||||||||||
53 | m_winId(0), | - | ||||||||||||
54 | m_surface(EGL_NO_SURFACE), | - | ||||||||||||
55 | m_window(0), | - | ||||||||||||
56 | m_flags(0) | - | ||||||||||||
57 | { | - | ||||||||||||
58 | } never executed: end of block | 0 | ||||||||||||
59 | - | |||||||||||||
60 | QEglFSWindow::~QEglFSWindow() | - | ||||||||||||
61 | { | - | ||||||||||||
62 | destroy(); | - | ||||||||||||
63 | } never executed: end of block | 0 | ||||||||||||
64 | - | |||||||||||||
65 | static WId newWId() | - | ||||||||||||
66 | { | - | ||||||||||||
67 | static WId id = 0; | - | ||||||||||||
68 | - | |||||||||||||
69 | if (id == std::numeric_limits<WId>::max())
| 0 | ||||||||||||
70 | qWarning("QEGLPlatformWindow: Out of window IDs"); never executed: QMessageLogger(__FILE__, 70, __PRETTY_FUNCTION__).warning("QEGLPlatformWindow: Out of window IDs"); | 0 | ||||||||||||
71 | - | |||||||||||||
72 | return ++id; never executed: return ++id; | 0 | ||||||||||||
73 | } | - | ||||||||||||
74 | - | |||||||||||||
75 | void QEglFSWindow::create() | - | ||||||||||||
76 | { | - | ||||||||||||
77 | if (m_flags.testFlag(Created))
| 0 | ||||||||||||
78 | return; never executed: return; | 0 | ||||||||||||
79 | - | |||||||||||||
80 | m_winId = newWId(); | - | ||||||||||||
81 | - | |||||||||||||
82 | // Save the original surface type before changing to OpenGLSurface. | - | ||||||||||||
83 | m_raster = (window()->surfaceType() == QSurface::RasterSurface); | - | ||||||||||||
84 | if (m_raster) // change to OpenGL, but not for RasterGLSurface
| 0 | ||||||||||||
85 | window()->setSurfaceType(QSurface::OpenGLSurface); never executed: window()->setSurfaceType(QSurface::OpenGLSurface); | 0 | ||||||||||||
86 | - | |||||||||||||
87 | if (window()->type() == Qt::Desktop) {
| 0 | ||||||||||||
88 | QRect fullscreenRect(QPoint(), screen()->availableGeometry().size()); | - | ||||||||||||
89 | QPlatformWindow::setGeometry(fullscreenRect); | - | ||||||||||||
90 | QWindowSystemInterface::handleGeometryChange(window(), fullscreenRect); | - | ||||||||||||
91 | return; never executed: return; | 0 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | m_flags = Created; | - | ||||||||||||
95 | - | |||||||||||||
96 | if (window()->type() == Qt::Desktop)
| 0 | ||||||||||||
97 | return; never executed: return; | 0 | ||||||||||||
98 | - | |||||||||||||
99 | // Stop if there is already a window backed by a native window and surface. Additional | - | ||||||||||||
100 | // raster windows will not have their own native window, surface and context. Instead, | - | ||||||||||||
101 | // they will be composited onto the root window's surface. | - | ||||||||||||
102 | QEglFSScreen *screen = this->screen(); | - | ||||||||||||
103 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - | ||||||||||||
104 | if (screen->primarySurface() != EGL_NO_SURFACE) {
| 0 | ||||||||||||
105 | if (isRaster() && compositor->targetWindow()) {
| 0 | ||||||||||||
106 | m_format = compositor->targetWindow()->format(); | - | ||||||||||||
107 | return; never executed: return; | 0 | ||||||||||||
108 | } | - | ||||||||||||
109 | - | |||||||||||||
110 | #if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK) | - | ||||||||||||
111 | // We can have either a single OpenGL window or multiple raster windows. | - | ||||||||||||
112 | // Other combinations cannot work. | - | ||||||||||||
113 | qFatal("EGLFS: OpenGL windows cannot be mixed with others."); | - | ||||||||||||
114 | #endif | - | ||||||||||||
115 | - | |||||||||||||
116 | return; never executed: return; | 0 | ||||||||||||
117 | } | - | ||||||||||||
118 | - | |||||||||||||
119 | m_flags |= HasNativeWindow; | - | ||||||||||||
120 | setGeometry(QRect()); // will become fullscreen | - | ||||||||||||
121 | QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), geometry().size())); | - | ||||||||||||
122 | - | |||||||||||||
123 | resetSurface(); | - | ||||||||||||
124 | - | |||||||||||||
125 | if (m_surface == EGL_NO_SURFACE) {
| 0 | ||||||||||||
126 | EGLint error = eglGetError(); | - | ||||||||||||
127 | eglTerminate(screen->display()); | - | ||||||||||||
128 | qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error); | - | ||||||||||||
129 | } never executed: end of block | 0 | ||||||||||||
130 | - | |||||||||||||
131 | screen->setPrimarySurface(m_surface); | - | ||||||||||||
132 | - | |||||||||||||
133 | if (isRaster()) {
| 0 | ||||||||||||
134 | QOpenGLContext *context = new QOpenGLContext(QGuiApplication::instance()); | - | ||||||||||||
135 | context->setShareContext(qt_gl_global_share_context()); | - | ||||||||||||
136 | context->setFormat(m_format); | - | ||||||||||||
137 | context->setScreen(window()->screen()); | - | ||||||||||||
138 | if (!context->create())
| 0 | ||||||||||||
139 | qFatal("EGLFS: Failed to create compositing context"); never executed: QMessageLogger(__FILE__, 139, __PRETTY_FUNCTION__).fatal("EGLFS: Failed to create compositing context"); | 0 | ||||||||||||
140 | compositor->setTarget(context, window()); | - | ||||||||||||
141 | // If there is a "root" window into which raster and QOpenGLWidget content is | - | ||||||||||||
142 | // composited, all other contexts must share with its context. | - | ||||||||||||
143 | if (!qt_gl_global_share_context()) {
| 0 | ||||||||||||
144 | qt_gl_set_global_share_context(context); | - | ||||||||||||
145 | // What we set up here is in effect equivalent to the application setting | - | ||||||||||||
146 | // AA_ShareOpenGLContexts. Set the attribute to be fully consistent. | - | ||||||||||||
147 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); | - | ||||||||||||
148 | } never executed: end of block | 0 | ||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||
151 | - | |||||||||||||
152 | void QEglFSWindow::destroy() | - | ||||||||||||
153 | { | - | ||||||||||||
154 | QEglFSScreen *screen = this->screen(); | - | ||||||||||||
155 | if (m_flags.testFlag(HasNativeWindow)) {
| 0 | ||||||||||||
156 | QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(screen->cursor()); | - | ||||||||||||
157 | if (cursor)
| 0 | ||||||||||||
158 | cursor->resetResources(); never executed: cursor->resetResources(); | 0 | ||||||||||||
159 | - | |||||||||||||
160 | if (screen->primarySurface() == m_surface)
| 0 | ||||||||||||
161 | screen->setPrimarySurface(EGL_NO_SURFACE); never executed: screen->setPrimarySurface(((EGLSurface)0)); | 0 | ||||||||||||
162 | - | |||||||||||||
163 | invalidateSurface(); | - | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | - | |||||||||||||
166 | m_flags = 0; | - | ||||||||||||
167 | QOpenGLCompositor::instance()->removeWindow(this); | - | ||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||
169 | - | |||||||||||||
170 | void QEglFSWindow::invalidateSurface() | - | ||||||||||||
171 | { | - | ||||||||||||
172 | if (m_surface != EGL_NO_SURFACE) {
| 0 | ||||||||||||
173 | eglDestroySurface(screen()->display(), m_surface); | - | ||||||||||||
174 | m_surface = EGL_NO_SURFACE; | - | ||||||||||||
175 | } never executed: end of block | 0 | ||||||||||||
176 | qt_egl_device_integration()->destroyNativeWindow(m_window); | - | ||||||||||||
177 | m_window = 0; | - | ||||||||||||
178 | } never executed: end of block | 0 | ||||||||||||
179 | - | |||||||||||||
180 | void QEglFSWindow::resetSurface() | - | ||||||||||||
181 | { | - | ||||||||||||
182 | EGLDisplay display = screen()->display(); | - | ||||||||||||
183 | QSurfaceFormat platformFormat = qt_egl_device_integration()->surfaceFormatFor(window()->requestedFormat()); | - | ||||||||||||
184 | - | |||||||||||||
185 | m_config = QEglFSIntegration::chooseConfig(display, platformFormat); | - | ||||||||||||
186 | m_format = q_glFormatFromConfig(display, m_config, platformFormat); | - | ||||||||||||
187 | m_window = qt_egl_device_integration()->createNativeWindow(this, screen()->geometry().size(), m_format); | - | ||||||||||||
188 | m_surface = eglCreateWindowSurface(display, m_config, m_window, NULL); | - | ||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||
190 | - | |||||||||||||
191 | void QEglFSWindow::setVisible(bool visible) | - | ||||||||||||
192 | { | - | ||||||||||||
193 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - | ||||||||||||
194 | QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - | ||||||||||||
195 | QWindow *wnd = window(); | - | ||||||||||||
196 | - | |||||||||||||
197 | if (wnd->type() != Qt::Desktop) {
| 0 | ||||||||||||
198 | if (visible) {
| 0 | ||||||||||||
199 | compositor->addWindow(this); | - | ||||||||||||
200 | } else { never executed: end of block | 0 | ||||||||||||
201 | compositor->removeWindow(this); | - | ||||||||||||
202 | windows = compositor->windows(); | - | ||||||||||||
203 | if (windows.size())
| 0 | ||||||||||||
204 | windows.last()->sourceWindow()->requestActivate(); never executed: windows.last()->sourceWindow()->requestActivate(); | 0 | ||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||
206 | } | - | ||||||||||||
207 | - | |||||||||||||
208 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - | ||||||||||||
209 | - | |||||||||||||
210 | if (visible)
| 0 | ||||||||||||
211 | QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); never executed: QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); | 0 | ||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||
213 | - | |||||||||||||
214 | void QEglFSWindow::setGeometry(const QRect &r) | - | ||||||||||||
215 | { | - | ||||||||||||
216 | QRect rect; | - | ||||||||||||
217 | bool forceFullscreen = m_flags.testFlag(HasNativeWindow); | - | ||||||||||||
218 | if (forceFullscreen)
| 0 | ||||||||||||
219 | rect = screen()->availableGeometry(); never executed: rect = screen()->availableGeometry(); | 0 | ||||||||||||
220 | else | - | ||||||||||||
221 | rect = r; never executed: rect = r; | 0 | ||||||||||||
222 | - | |||||||||||||
223 | QPlatformWindow::setGeometry(rect); | - | ||||||||||||
224 | - | |||||||||||||
225 | // if we corrected the size, trigger a resize event | - | ||||||||||||
226 | if (rect != r)
| 0 | ||||||||||||
227 | QWindowSystemInterface::handleGeometryChange(window(), rect, r); never executed: QWindowSystemInterface::handleGeometryChange(window(), rect, r); | 0 | ||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||
229 | - | |||||||||||||
230 | QRect QEglFSWindow::geometry() const | - | ||||||||||||
231 | { | - | ||||||||||||
232 | // For yet-to-become-fullscreen windows report the geometry covering the entire | - | ||||||||||||
233 | // screen. This is particularly important for Quick where the root object may get | - | ||||||||||||
234 | // sized to some geometry queried before calling create(). | - | ||||||||||||
235 | if (!m_flags.testFlag(Created) && screen()->primarySurface() == EGL_NO_SURFACE)
| 0 | ||||||||||||
236 | return screen()->availableGeometry(); never executed: return screen()->availableGeometry(); | 0 | ||||||||||||
237 | - | |||||||||||||
238 | return QPlatformWindow::geometry(); never executed: return QPlatformWindow::geometry(); | 0 | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | void QEglFSWindow::requestActivateWindow() | - | ||||||||||||
242 | { | - | ||||||||||||
243 | if (window()->type() != Qt::Desktop)
| 0 | ||||||||||||
244 | QOpenGLCompositor::instance()->moveToTop(this); never executed: QOpenGLCompositor::instance()->moveToTop(this); | 0 | ||||||||||||
245 | - | |||||||||||||
246 | QWindow *wnd = window(); | - | ||||||||||||
247 | QWindowSystemInterface::handleWindowActivated(wnd); | - | ||||||||||||
248 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - | ||||||||||||
249 | } never executed: end of block | 0 | ||||||||||||
250 | - | |||||||||||||
251 | void QEglFSWindow::raise() | - | ||||||||||||
252 | { | - | ||||||||||||
253 | QWindow *wnd = window(); | - | ||||||||||||
254 | if (wnd->type() != Qt::Desktop) {
| 0 | ||||||||||||
255 | QOpenGLCompositor::instance()->moveToTop(this); | - | ||||||||||||
256 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - | ||||||||||||
257 | } never executed: end of block | 0 | ||||||||||||
258 | } never executed: end of block | 0 | ||||||||||||
259 | - | |||||||||||||
260 | void QEglFSWindow::lower() | - | ||||||||||||
261 | { | - | ||||||||||||
262 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - | ||||||||||||
263 | QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - | ||||||||||||
264 | if (window()->type() != Qt::Desktop && windows.count() > 1) {
| 0 | ||||||||||||
265 | int idx = windows.indexOf(this); | - | ||||||||||||
266 | if (idx > 0) {
| 0 | ||||||||||||
267 | compositor->changeWindowIndex(this, idx - 1); | - | ||||||||||||
268 | QWindowSystemInterface::handleExposeEvent(windows.last()->sourceWindow(), | - | ||||||||||||
269 | QRect(QPoint(0, 0), windows.last()->sourceWindow()->geometry().size())); | - | ||||||||||||
270 | } never executed: end of block | 0 | ||||||||||||
271 | } never executed: end of block | 0 | ||||||||||||
272 | } never executed: end of block | 0 | ||||||||||||
273 | - | |||||||||||||
274 | EGLSurface QEglFSWindow::surface() const | - | ||||||||||||
275 | { | - | ||||||||||||
276 | return m_surface != EGL_NO_SURFACE ? m_surface : screen()->primarySurface(); never executed: return m_surface != ((EGLSurface)0) ? m_surface : screen()->primarySurface();
| 0 | ||||||||||||
277 | } | - | ||||||||||||
278 | - | |||||||||||||
279 | QSurfaceFormat QEglFSWindow::format() const | - | ||||||||||||
280 | { | - | ||||||||||||
281 | return m_format; never executed: return m_format; | 0 | ||||||||||||
282 | } | - | ||||||||||||
283 | - | |||||||||||||
284 | EGLNativeWindowType QEglFSWindow::eglWindow() const | - | ||||||||||||
285 | { | - | ||||||||||||
286 | return m_window; never executed: return m_window; | 0 | ||||||||||||
287 | } | - | ||||||||||||
288 | - | |||||||||||||
289 | QEglFSScreen *QEglFSWindow::screen() const | - | ||||||||||||
290 | { | - | ||||||||||||
291 | return static_cast<QEglFSScreen *>(QPlatformWindow::screen()); never executed: return static_cast<QEglFSScreen *>(QPlatformWindow::screen()); | 0 | ||||||||||||
292 | } | - | ||||||||||||
293 | - | |||||||||||||
294 | bool QEglFSWindow::isRaster() const | - | ||||||||||||
295 | { | - | ||||||||||||
296 | return m_raster || window()->surfaceType() == QSurface::RasterGLSurface; never executed: return m_raster || window()->surfaceType() == QSurface::RasterGLSurface;
| 0 | ||||||||||||
297 | } | - | ||||||||||||
298 | - | |||||||||||||
299 | QWindow *QEglFSWindow::sourceWindow() const | - | ||||||||||||
300 | { | - | ||||||||||||
301 | return window(); never executed: return window(); | 0 | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | const QPlatformTextureList *QEglFSWindow::textures() const | - | ||||||||||||
305 | { | - | ||||||||||||
306 | if (m_backingStore)
| 0 | ||||||||||||
307 | return m_backingStore->textures(); never executed: return m_backingStore->textures(); | 0 | ||||||||||||
308 | - | |||||||||||||
309 | return 0; never executed: return 0; | 0 | ||||||||||||
310 | } | - | ||||||||||||
311 | - | |||||||||||||
312 | void QEglFSWindow::endCompositing() | - | ||||||||||||
313 | { | - | ||||||||||||
314 | if (m_backingStore)
| 0 | ||||||||||||
315 | m_backingStore->notifyComposited(); never executed: m_backingStore->notifyComposited(); | 0 | ||||||||||||
316 | } never executed: end of block | 0 | ||||||||||||
317 | - | |||||||||||||
318 | WId QEglFSWindow::winId() const | - | ||||||||||||
319 | { | - | ||||||||||||
320 | return m_winId; never executed: return m_winId; | 0 | ||||||||||||
321 | } | - | ||||||||||||
322 | - | |||||||||||||
323 | void QEglFSWindow::setOpacity(qreal) | - | ||||||||||||
324 | { | - | ||||||||||||
325 | if (!isRaster())
| 0 | ||||||||||||
326 | qWarning("QEglFSWindow: Cannot set opacity for non-raster windows"); never executed: QMessageLogger(__FILE__, 326, __PRETTY_FUNCTION__).warning("QEglFSWindow: Cannot set opacity for non-raster windows"); | 0 | ||||||||||||
327 | - | |||||||||||||
328 | // Nothing to do here. The opacity is stored in the QWindow. | - | ||||||||||||
329 | } never executed: end of block | 0 | ||||||||||||
330 | - | |||||||||||||
331 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |