qeglfswindow.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9