Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
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 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | QEglFSWindow::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 | } | - |
65 | | - |
66 | QEglFSWindow::~QEglFSWindow() | - |
67 | { | - |
68 | destroy(); | - |
69 | } | - |
70 | | - |
71 | static WId newWId() | - |
72 | { | - |
73 | static WId id = 0; | - |
74 | | - |
75 | if (id == std::numeric_limits<WId>::max()) | - |
76 | qWarning("QEGLPlatformWindow: Out of window IDs"); | - |
77 | | - |
78 | return ++id; | - |
79 | } | - |
80 | | - |
81 | void QEglFSWindow::create() | - |
82 | { | - |
83 | if (m_flags.testFlag(Created))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
84 | return; never executed: return; | 0 |
85 | | - |
86 | m_winId = newWId(); | - |
87 | | - |
88 | | - |
89 | m_raster = (window()->surfaceType() == QSurface::RasterSurface); | - |
90 | if (m_raster) TRUE | never evaluated | FALSE | never evaluated |
| 0 |
91 | window()->setSurfaceType(QSurface::OpenGLSurface); never executed: window()->setSurfaceType(QSurface::OpenGLSurface); | 0 |
92 | | - |
93 | if (window()->type() == Qt::Desktop) {TRUE | never evaluated | FALSE | never 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)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
103 | return; never executed: return; | 0 |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | QEglFSScreen *screen = this->screen(); | - |
109 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - |
110 | if (screen->primarySurface() != EGL_NO_SURFACE) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
111 | if (Q_UNLIKELY(!isRaster() &&|| !compositor->targetWindow())())) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
| m_format = compositor->targetWindow()->format(); | |
| return; | |
| }#if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK) | |
113 | | - |
114 | | - |
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()); | - |
125 | QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(0, 0), geometry().size())); | - |
126 | | - |
127 | resetSurface(); | - |
128 | | - |
129 | if (Q_UNLIKELY(m_surface == EGL_NO_SURFACE))) {TRUE | never evaluated | FALSE | never 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()) {TRUE | never evaluated | FALSE | never 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())()))TRUE | never evaluated | FALSE | never 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 | | - |
146 | | - |
147 | if (!qt_gl_global_share_context()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
148 | qt_gl_set_global_share_context(context); | - |
149 | | - |
150 | | - |
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 | | - |
156 | void QEglFSWindow::destroy() | - |
157 | { | - |
158 | QEglFSScreen *screen = this->screen(); | - |
159 | if (m_flags.testFlag(HasNativeWindow)) { | - |
160 | QEglFSCursor *cursor = qobject_cast<QEglFSCursor *>(screen->cursor()); | - |
161 | if (cursor) | - |
162 | cursor->resetResources(); | - |
163 | | - |
164 | if (screen->primarySurface() == m_surface) | - |
165 | screen->setPrimarySurface(EGL_NO_SURFACE); | - |
166 | | - |
167 | invalidateSurface(); | - |
168 | } | - |
169 | | - |
170 | m_flags = 0; | - |
171 | QOpenGLCompositor::instance()->removeWindow(this); | - |
172 | } | - |
173 | | - |
174 | void QEglFSWindow::invalidateSurface() | - |
175 | { | - |
176 | if (m_surface != EGL_NO_SURFACE) { | - |
177 | eglDestroySurface(screen()->display(), m_surface); | - |
178 | m_surface = EGL_NO_SURFACE; | - |
179 | } | - |
180 | qt_egl_device_integration()->destroyNativeWindow(m_window); | - |
181 | m_window = 0; | - |
182 | } | - |
183 | | - |
184 | void 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 | } | - |
194 | | - |
195 | void 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) { | - |
202 | if (visible) { | - |
203 | compositor->addWindow(this); | - |
204 | } else { | - |
205 | compositor->removeWindow(this); | - |
206 | windows = compositor->windows(); | - |
207 | if (windows.size()) | - |
208 | windows.last()->sourceWindow()->requestActivate(); | - |
209 | } | - |
210 | } | - |
211 | | - |
212 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
213 | | - |
214 | if (visible) | - |
215 | QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); | - |
216 | } | - |
217 | | - |
218 | void QEglFSWindow::setGeometry(const QRect &r) | - |
219 | { | - |
220 | QRect rect; | - |
221 | bool forceFullscreen = m_flags.testFlag(HasNativeWindow); | - |
222 | if (forceFullscreen) | - |
223 | rect = screen()->availableGeometry(); | - |
224 | else | - |
225 | rect = r; | - |
226 | | - |
227 | QPlatformWindow::setGeometry(rect); | - |
228 | | - |
229 | | - |
230 | if (rect != r) | - |
231 | QWindowSystemInterface::handleGeometryChange(window(), rect, r); | - |
232 | } | - |
233 | | - |
234 | QRect QEglFSWindow::geometry() const | - |
235 | { | - |
236 | | - |
237 | | - |
238 | | - |
239 | if (!m_flags.testFlag(Created) && screen()->primarySurface() == EGL_NO_SURFACE) | - |
240 | return screen()->availableGeometry(); | - |
241 | | - |
242 | return QPlatformWindow::geometry(); | - |
243 | } | - |
244 | | - |
245 | void QEglFSWindow::requestActivateWindow() | - |
246 | { | - |
247 | if (window()->type() != Qt::Desktop) | - |
248 | QOpenGLCompositor::instance()->moveToTop(this); | - |
249 | | - |
250 | QWindow *wnd = window(); | - |
251 | QWindowSystemInterface::handleWindowActivated(wnd); | - |
252 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
253 | } | - |
254 | | - |
255 | void QEglFSWindow::raise() | - |
256 | { | - |
257 | QWindow *wnd = window(); | - |
258 | if (wnd->type() != Qt::Desktop) { | - |
259 | QOpenGLCompositor::instance()->moveToTop(this); | - |
260 | QWindowSystemInterface::handleExposeEvent(wnd, QRect(QPoint(0, 0), wnd->geometry().size())); | - |
261 | } | - |
262 | } | - |
263 | | - |
264 | void QEglFSWindow::lower() | - |
265 | { | - |
266 | QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); | - |
267 | QList<QOpenGLCompositorWindow *> windows = compositor->windows(); | - |
268 | if (window()->type() != Qt::Desktop && windows.count() > 1) { | - |
269 | int idx = windows.indexOf(this); | - |
270 | if (idx > 0) { | - |
271 | compositor->changeWindowIndex(this, idx - 1); | - |
272 | QWindowSystemInterface::handleExposeEvent(windows.last()->sourceWindow(), | - |
273 | QRect(QPoint(0, 0), windows.last()->sourceWindow()->geometry().size())); | - |
274 | } | - |
275 | } | - |
276 | } | - |
277 | | - |
278 | EGLSurface QEglFSWindow::surface() const | - |
279 | { | - |
280 | return m_surface != EGL_NO_SURFACE ? m_surface : screen()->primarySurface(); | - |
281 | } | - |
282 | | - |
283 | QSurfaceFormat QEglFSWindow::format() const | - |
284 | { | - |
285 | return m_format; | - |
286 | } | - |
287 | | - |
288 | EGLNativeWindowType QEglFSWindow::eglWindow() const | - |
289 | { | - |
290 | return m_window; | - |
291 | } | - |
292 | | - |
293 | QEglFSScreen *QEglFSWindow::screen() const | - |
294 | { | - |
295 | return static_cast<QEglFSScreen *>(QPlatformWindow::screen()); | - |
296 | } | - |
297 | | - |
298 | bool QEglFSWindow::isRaster() const | - |
299 | { | - |
300 | return m_raster || window()->surfaceType() == QSurface::RasterGLSurface; | - |
301 | } | - |
302 | | - |
303 | QWindow *QEglFSWindow::sourceWindow() const | - |
304 | { | - |
305 | return window(); | - |
306 | } | - |
307 | | - |
308 | const QPlatformTextureList *QEglFSWindow::textures() const | - |
309 | { | - |
310 | if (m_backingStore) | - |
311 | return m_backingStore->textures(); | - |
312 | | - |
313 | return 0; | - |
314 | } | - |
315 | | - |
316 | void QEglFSWindow::endCompositing() | - |
317 | { | - |
318 | if (m_backingStore) | - |
319 | m_backingStore->notifyComposited(); | - |
320 | } | - |
321 | | - |
322 | WId QEglFSWindow::winId() const | - |
323 | { | - |
324 | return m_winId; | - |
325 | } | - |
326 | | - |
327 | void QEglFSWindow::setOpacity(qreal) | - |
328 | { | - |
329 | if (!isRaster()) | - |
330 | qWarning("QEglFSWindow: Cannot set opacity for non-raster windows"); | - |
331 | | - |
332 | | - |
333 | } | - |
334 | | - |
335 | QT_END_NAMESPACE | - |
| | |