qeglfsintegration.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/eglfs/qeglfsintegration.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 <QtGui/private/qguiapplication_p.h>-
42-
43#include <qpa/qplatformwindow.h>-
44#include <QtGui/QSurfaceFormat>-
45#include <QtGui/QOpenGLContext>-
46#include <QtGui/QScreen>-
47#include <QtGui/QOffscreenSurface>-
48#include <QtGui/QWindow>-
49#include <QtCore/QLoggingCategory>-
50#include <qpa/qwindowsysteminterface.h>-
51#include <qpa/qplatforminputcontextfactory_p.h>-
52#include <private/qgenericunixthemes_p.h>-
53-
54#include "qeglfsintegration.h"-
55#include "qeglfswindow.h"-
56#include "qeglfshooks.h"-
57#include "qeglfscontext.h"-
58#include "qeglfsoffscreenwindow.h"-
59#include "qeglfscursor.h"-
60-
61#include <QtPlatformSupport/private/qeglconvenience_p.h>-
62#include <QtPlatformSupport/private/qeglplatformcontext_p.h>-
63#include <QtPlatformSupport/private/qeglpbuffer_p.h>-
64-
65#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>-
66#include <QtPlatformSupport/private/qgenericunixservices_p.h>-
67#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>-
68#include <QtPlatformSupport/private/qfbvthandler_p.h>-
69#include <QtPlatformSupport/private/qopenglcompositorbackingstore_p.h>-
70-
71#include <QtPlatformHeaders/QEGLNativeContext>-
72-
73#ifndef QT_NO_LIBINPUT-
74#include <QtPlatformSupport/private/qlibinputhandler_p.h>-
75#endif-
76-
77#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID)-
78#include <QtPlatformSupport/private/qevdevmousemanager_p.h>-
79#include <QtPlatformSupport/private/qevdevkeyboardmanager_p.h>-
80#include <QtPlatformSupport/private/qevdevtouchmanager_p.h>-
81#endif-
82-
83#if !defined(QT_NO_TSLIB) && !defined(Q_OS_ANDROID)-
84#include <QtPlatformSupport/private/qtslib_p.h>-
85#endif-
86-
87#include <QtPlatformHeaders/qeglfsfunctions.h>-
88-
89static void initResources()-
90{-
91#ifndef QT_NO_CURSOR-
92 Q_INIT_RESOURCE(cursor);-
93#endif-
94}
never executed: end of block
0
95-
96QT_BEGIN_NAMESPACE-
97-
98QEglFSIntegration::QEglFSIntegration()-
99 : m_display(EGL_NO_DISPLAY),-
100 m_inputContext(0),-
101 m_fontDb(new QGenericUnixFontDatabase),-
102 m_services(new QGenericUnixServices),-
103 m_kbdMgr(0),-
104 m_disableInputHandlers(false)-
105{-
106 m_disableInputHandlers = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DISABLE_INPUT");-
107-
108 initResources();-
109}
never executed: end of block
0
110-
111void QEglFSIntegration::addScreen(QPlatformScreen *screen)-
112{-
113 screenAdded(screen);-
114}
never executed: end of block
0
115-
116void QEglFSIntegration::removeScreen(QPlatformScreen *screen)-
117{-
118 destroyScreen(screen);-
119}
never executed: end of block
0
120-
121void QEglFSIntegration::initialize()-
122{-
123 qt_egl_device_integration()->platformInit();-
124-
125 m_display = qt_egl_device_integration()->createDisplay(nativeDisplay());-
126 if (Q_UNLIKELY(m_display == EGL_NO_DISPLAY))
__builtin_expe...ay)0)), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
127 qFatal("Could not open egl display");
never executed: QMessageLogger(__FILE__, 127, __PRETTY_FUNCTION__).fatal("Could not open egl display");
0
128-
129 EGLint major, minor;-
130 if (Q_UNLIKELY(!eglInitialize(m_display, &major, &minor)))
__builtin_expe...inor)), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
131 qFatal("Could not initialize egl display");
never executed: QMessageLogger(__FILE__, 131, __PRETTY_FUNCTION__).fatal("Could not initialize egl display");
0
132-
133 m_inputContext = QPlatformInputContextFactory::create();-
134-
135 m_vtHandler.reset(new QFbVtHandler);-
136-
137 if (qt_egl_device_integration()->usesDefaultScreen())
qt_egl_device_...efaultScreen()Description
TRUEnever evaluated
FALSEnever evaluated
0
138 addScreen(new QEglFSScreen(display()));
never executed: addScreen(new QEglFSScreen(display()));
0
139 else-
140 qt_egl_device_integration()->screenInit();
never executed: qt_egl_device_integration()->screenInit();
0
141-
142 // Input code may rely on the screens, so do it only after the screen init.-
143 if (!m_disableInputHandlers)
!m_disableInputHandlersDescription
TRUEnever evaluated
FALSEnever evaluated
0
144 createInputHandlers();
never executed: createInputHandlers();
0
145}
never executed: end of block
0
146-
147void QEglFSIntegration::destroy()-
148{-
149 foreach (QWindow *w, qGuiApp->topLevelWindows())-
150 w->destroy();
never executed: w->destroy();
0
151-
152 qt_egl_device_integration()->screenDestroy();-
153-
154 if (m_display != EGL_NO_DISPLAY)
m_display != ((EGLDisplay)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
155 eglTerminate(m_display);
never executed: eglTerminate(m_display);
0
156-
157 qt_egl_device_integration()->platformDestroy();-
158}
never executed: end of block
0
159-
160QAbstractEventDispatcher *QEglFSIntegration::createEventDispatcher() const-
161{-
162 return createUnixEventDispatcher();
never executed: return createUnixEventDispatcher();
0
163}-
164-
165QPlatformServices *QEglFSIntegration::services() const-
166{-
167 return m_services.data();
never executed: return m_services.data();
0
168}-
169-
170QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const-
171{-
172 return m_fontDb.data();
never executed: return m_fontDb.data();
0
173}-
174-
175QPlatformTheme *QEglFSIntegration::createPlatformTheme(const QString &name) const-
176{-
177 return QGenericUnixTheme::createUnixTheme(name);
never executed: return QGenericUnixTheme::createUnixTheme(name);
0
178}-
179-
180QPlatformBackingStore *QEglFSIntegration::createPlatformBackingStore(QWindow *window) const-
181{-
182 QOpenGLCompositorBackingStore *bs = new QOpenGLCompositorBackingStore(window);-
183 if (!window->handle())
!window->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
184 window->create();
never executed: window->create();
0
185 static_cast<QEglFSWindow *>(window->handle())->setBackingStore(bs);-
186 return bs;
never executed: return bs;
0
187}-
188-
189QPlatformWindow *QEglFSIntegration::createPlatformWindow(QWindow *window) const-
190{-
191 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);-
192 QEglFSWindow *w = qt_egl_device_integration()->createWindow(window);-
193 w->create();-
194 if (window->type() != Qt::ToolTip)
window->type() != Qt::ToolTipDescription
TRUEnever evaluated
FALSEnever evaluated
0
195 w->requestActivateWindow();
never executed: w->requestActivateWindow();
0
196 return w;
never executed: return w;
0
197}-
198-
199QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const-
200{-
201 EGLDisplay dpy = context->screen() ? static_cast<QEglFSScreen *>(context->screen()->handle())->display() : display();
context->screen()Description
TRUEnever evaluated
FALSEnever evaluated
0
202 QPlatformOpenGLContext *share = context->shareHandle();-
203 QVariant nativeHandle = context->nativeHandle();-
204-
205 QEglFSContext *ctx;-
206 QSurfaceFormat adjustedFormat = qt_egl_device_integration()->surfaceFormatFor(context->format());-
207 if (nativeHandle.isNull()) {
nativeHandle.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
208 EGLConfig config = QEglFSIntegration::chooseConfig(dpy, adjustedFormat);-
209 ctx = new QEglFSContext(adjustedFormat, share, dpy, &config, QVariant());-
210 } else {
never executed: end of block
0
211 ctx = new QEglFSContext(adjustedFormat, share, dpy, 0, nativeHandle);-
212 }
never executed: end of block
0
213 nativeHandle = QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx->eglContext(), dpy));-
214-
215 context->setNativeHandle(nativeHandle);-
216 return ctx;
never executed: return ctx;
0
217}-
218-
219QPlatformOffscreenSurface *QEglFSIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const-
220{-
221 EGLDisplay dpy = surface->screen() ? static_cast<QEglFSScreen *>(surface->screen()->handle())->display() : display();
surface->screen()Description
TRUEnever evaluated
FALSEnever evaluated
0
222 QSurfaceFormat fmt = qt_egl_device_integration()->surfaceFormatFor(surface->requestedFormat());-
223 if (qt_egl_device_integration()->supportsPBuffers()) {
qt_egl_device_...ortsPBuffers()Description
TRUEnever evaluated
FALSEnever evaluated
0
224 QEGLPlatformContext::Flags flags = 0;-
225 if (!qt_egl_device_integration()->supportsSurfacelessContexts())
!qt_egl_device...lessContexts()Description
TRUEnever evaluated
FALSEnever evaluated
0
226 flags |= QEGLPlatformContext::NoSurfaceless;
never executed: flags |= QEGLPlatformContext::NoSurfaceless;
0
227 return new QEGLPbuffer(dpy, fmt, surface, flags);
never executed: return new QEGLPbuffer(dpy, fmt, surface, flags);
0
228 } else {-
229 return new QEglFSOffscreenWindow(dpy, fmt, surface);
never executed: return new QEglFSOffscreenWindow(dpy, fmt, surface);
0
230 }-
231 // Never return null. Multiple QWindows are not supported by this plugin.-
232}-
233-
234bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const-
235{-
236 // We assume that devices will have more and not less capabilities-
237 if (qt_egl_device_integration()->hasCapability(cap))
qt_egl_device_...apability(cap)Description
TRUEnever evaluated
FALSEnever evaluated
0
238 return true;
never executed: return true;
0
239-
240 switch (cap) {-
241 case ThreadedPixmaps: return true;
never executed: return true;
never executed: case ThreadedPixmaps:
0
242 case OpenGL: return true;
never executed: return true;
never executed: case OpenGL:
0
243 case ThreadedOpenGL: return true;
never executed: return true;
never executed: case ThreadedOpenGL:
0
244 case WindowManagement: return false;
never executed: return false;
never executed: case WindowManagement:
0
245 case RasterGLSurface: return true;
never executed: return true;
never executed: case RasterGLSurface:
0
246 default: return QPlatformIntegration::hasCapability(cap);
never executed: return QPlatformIntegration::hasCapability(cap);
never executed: default:
0
247 }-
248}-
249-
250QPlatformNativeInterface *QEglFSIntegration::nativeInterface() const-
251{-
252 return const_cast<QEglFSIntegration *>(this);
never executed: return const_cast<QEglFSIntegration *>(this);
0
253}-
254-
255enum ResourceType {-
256 EglDisplay,-
257 EglWindow,-
258 EglContext,-
259 EglConfig,-
260 NativeDisplay,-
261 XlibDisplay,-
262 WaylandDisplay-
263};-
264-
265static int resourceType(const QByteArray &key)-
266{-
267 static const QByteArray names[] = { // match ResourceType-
268 QByteArrayLiteral("egldisplay"),-
269 QByteArrayLiteral("eglwindow"),-
270 QByteArrayLiteral("eglcontext"),-
271 QByteArrayLiteral("eglconfig"),-
272 QByteArrayLiteral("nativedisplay"),-
273 QByteArrayLiteral("display"),-
274 QByteArrayLiteral("server_wl_display")-
275 };-
276 const QByteArray *end = names + sizeof(names) / sizeof(names[0]);-
277 const QByteArray *result = std::find(names, end, key);-
278 if (result == end)
result == endDescription
TRUEnever evaluated
FALSEnever evaluated
0
279 result = std::find(names, end, key.toLower());
never executed: result = std::find(names, end, key.toLower());
0
280 return int(result - names);
never executed: return int(result - names);
0
281}-
282-
283void *QEglFSIntegration::nativeResourceForIntegration(const QByteArray &resource)-
284{-
285 void *result = 0;-
286-
287 switch (resourceType(resource)) {-
288 case EglDisplay:
never executed: case EglDisplay:
0
289 result = display();-
290 break;
never executed: break;
0
291 case NativeDisplay:
never executed: case NativeDisplay:
0
292 result = reinterpret_cast<void*>(nativeDisplay());-
293 break;
never executed: break;
0
294 case WaylandDisplay:
never executed: case WaylandDisplay:
0
295 result = qt_egl_device_integration()->wlDisplay();-
296 break;
never executed: break;
0
297 default:
never executed: default:
0
298 break;
never executed: break;
0
299 }-
300-
301 return result;
never executed: return result;
0
302}-
303-
304void *QEglFSIntegration::nativeResourceForScreen(const QByteArray &resource, QScreen *)-
305{-
306 void *result = 0;-
307-
308 switch (resourceType(resource)) {-
309 case XlibDisplay:
never executed: case XlibDisplay:
0
310 // Play nice when using the x11 hooks: Be compatible with xcb that allows querying-
311 // the X Display pointer, which is nothing but our native display.-
312 result = reinterpret_cast<void*>(nativeDisplay());-
313 break;
never executed: break;
0
314 default:
never executed: default:
0
315 break;
never executed: break;
0
316 }-
317-
318 return result;
never executed: return result;
0
319}-
320-
321void *QEglFSIntegration::nativeResourceForWindow(const QByteArray &resource, QWindow *window)-
322{-
323 void *result = 0;-
324-
325 switch (resourceType(resource)) {-
326 case EglDisplay:
never executed: case EglDisplay:
0
327 if (window && window->handle())
windowDescription
TRUEnever evaluated
FALSEnever evaluated
window->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
328 result = static_cast<QEglFSScreen *>(window->handle()->screen())->display();
never executed: result = static_cast<QEglFSScreen *>(window->handle()->screen())->display();
0
329 else-
330 result = display();
never executed: result = display();
0
331 break;
never executed: break;
0
332 case EglWindow:
never executed: case EglWindow:
0
333 if (window && window->handle())
windowDescription
TRUEnever evaluated
FALSEnever evaluated
window->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
334 result = reinterpret_cast<void*>(static_cast<QEglFSWindow *>(window->handle())->eglWindow());
never executed: result = reinterpret_cast<void*>(static_cast<QEglFSWindow *>(window->handle())->eglWindow());
0
335 break;
never executed: break;
0
336 default:
never executed: default:
0
337 break;
never executed: break;
0
338 }-
339-
340 return result;
never executed: return result;
0
341}-
342-
343void *QEglFSIntegration::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)-
344{-
345 void *result = 0;-
346-
347 switch (resourceType(resource)) {-
348 case EglContext:
never executed: case EglContext:
0
349 if (context->handle())
context->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
350 result = static_cast<QEglFSContext *>(context->handle())->eglContext();
never executed: result = static_cast<QEglFSContext *>(context->handle())->eglContext();
0
351 break;
never executed: break;
0
352 case EglConfig:
never executed: case EglConfig:
0
353 if (context->handle())
context->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
354 result = static_cast<QEglFSContext *>(context->handle())->eglConfig();
never executed: result = static_cast<QEglFSContext *>(context->handle())->eglConfig();
0
355 break;
never executed: break;
0
356 case EglDisplay:
never executed: case EglDisplay:
0
357 if (context->handle())
context->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
358 result = static_cast<QEglFSContext *>(context->handle())->eglDisplay();
never executed: result = static_cast<QEglFSContext *>(context->handle())->eglDisplay();
0
359 break;
never executed: break;
0
360 default:
never executed: default:
0
361 break;
never executed: break;
0
362 }-
363-
364 return result;
never executed: return result;
0
365}-
366-
367static void *eglContextForContext(QOpenGLContext *context)-
368{-
369 Q_ASSERT(context);-
370-
371 QEglFSContext *handle = static_cast<QEglFSContext *>(context->handle());-
372 if (!handle)
!handleDescription
TRUEnever evaluated
FALSEnever evaluated
0
373 return 0;
never executed: return 0;
0
374-
375 return handle->eglContext();
never executed: return handle->eglContext();
0
376}-
377-
378QPlatformNativeInterface::NativeResourceForContextFunction QEglFSIntegration::nativeResourceFunctionForContext(const QByteArray &resource)-
379{-
380 QByteArray lowerCaseResource = resource.toLower();-
381 if (lowerCaseResource == "get_egl_context")
lowerCaseResou...t_egl_context"Description
TRUEnever evaluated
FALSEnever evaluated
0
382 return NativeResourceForContextFunction(eglContextForContext);
never executed: return NativeResourceForContextFunction(eglContextForContext);
0
383-
384 return 0;
never executed: return 0;
0
385}-
386-
387QFunctionPointer QEglFSIntegration::platformFunction(const QByteArray &function) const-
388{-
389#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID)-
390 if (function == QEglFSFunctions::loadKeymapTypeIdentifier())
function == QE...peIdentifier()Description
TRUEnever evaluated
FALSEnever evaluated
0
391 return QFunctionPointer(loadKeymapStatic);
never executed: return QFunctionPointer(loadKeymapStatic);
0
392#else-
393 Q_UNUSED(function)-
394#endif-
395-
396 return 0;
never executed: return 0;
0
397}-
398-
399void QEglFSIntegration::loadKeymapStatic(const QString &filename)-
400{-
401#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID)-
402 QEglFSIntegration *self = static_cast<QEglFSIntegration *>(QGuiApplicationPrivate::platformIntegration());-
403 if (self->m_kbdMgr)
self->m_kbdMgrDescription
TRUEnever evaluated
FALSEnever evaluated
0
404 self->m_kbdMgr->loadKeymap(filename);
never executed: self->m_kbdMgr->loadKeymap(filename);
0
405 else-
406 qWarning("QEglFSIntegration: Cannot load keymap, no keyboard handler found");
never executed: QMessageLogger(__FILE__, 406, __PRETTY_FUNCTION__).warning("QEglFSIntegration: Cannot load keymap, no keyboard handler found");
0
407#else-
408 Q_UNUSED(filename);-
409#endif-
410}-
411-
412void QEglFSIntegration::createInputHandlers()-
413{-
414#ifndef QT_NO_LIBINPUT-
415 if (!qEnvironmentVariableIntValue("QT_QPA_EGLFS_NO_LIBINPUT")) {-
416 new QLibInputHandler(QLatin1String("libinput"), QString());-
417 return;-
418 }-
419#endif-
420-
421 bool useTslib = false;-
422#ifndef QT_NO_TSLIB-
423 useTslib = qEnvironmentVariableIntValue("QT_QPA_EGLFS_TSLIB");-
424 if (useTslib)-
425 new QTsLibMouseHandler(QLatin1String("TsLib"), QString() /* spec */);-
426#endif-
427-
428#if !defined(QT_NO_EVDEV) && !defined(Q_OS_ANDROID)-
429 m_kbdMgr = new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this);-
430 new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this);-
431 if (!useTslib)
!useTslibDescription
TRUEnever evaluated
FALSEnever evaluated
0
432 new QEvdevTouchManager(QLatin1String("EvdevTouch"), QString() /* spec */, this);
never executed: new QEvdevTouchManager(QLatin1String("EvdevTouch"), QString() , this);
0
433#endif-
434}
never executed: end of block
0
435-
436EGLNativeDisplayType QEglFSIntegration::nativeDisplay() const-
437{-
438 return qt_egl_device_integration()->platformDisplay();
never executed: return qt_egl_device_integration()->platformDisplay();
0
439}-
440-
441EGLConfig QEglFSIntegration::chooseConfig(EGLDisplay display, const QSurfaceFormat &format)-
442{-
443 class Chooser : public QEglConfigChooser {-
444 public:-
445 Chooser(EGLDisplay display)-
446 : QEglConfigChooser(display) { }
never executed: end of block
0
447 bool filterConfig(EGLConfig config) const Q_DECL_OVERRIDE {-
448 return qt_egl_device_integration()->filterConfig(display(), config)
never executed: return qt_egl_device_integration()->filterConfig(display(), config) && QEglConfigChooser::filterConfig(config);
0
449 && QEglConfigChooser::filterConfig(config);
never executed: return qt_egl_device_integration()->filterConfig(display(), config) && QEglConfigChooser::filterConfig(config);
0
450 }-
451 };-
452-
453 Chooser chooser(display);-
454 chooser.setSurfaceType(qt_egl_device_integration()->surfaceType());-
455 chooser.setSurfaceFormat(format);-
456 return chooser.chooseConfig();
never executed: return chooser.chooseConfig();
0
457}-
458-
459QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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