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

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