Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qeglfsintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/qtextstream.h>
5#include <QtGui/private/qguiapplication_p.h>
6
7#include <qpa/qplatformwindow.h>
8#include <QtGui/QSurfaceFormat>
9#include <QtGui/QScreen>
10#ifndef QT_NO_OPENGL
11# include <QtGui/QOpenGLContext>
12# include <QtGui/QOffscreenSurface>
13#endif
14#include <QtGui/QWindow>
15#include <QtCore/QLoggingCategory>
16#include <qpa/qwindowsysteminterface.h>
17#include <qpa/qplatforminputcontextfactory_p.h>
18
19#include "qeglfsintegration_p.h"
20#include "qeglfswindow_p.h"
21#include "qeglfshooks_p.h"
22#ifndef QT_NO_OPENGL
23# include "qeglfscontext_p.h"
24# include "qeglfscursor_p.h"
25#endif
27
28#include <QtGui/private/qeglconvenience_p.h>
29#ifndef QT_NO_OPENGL
30# include <QtGui/private/qeglplatformcontext_p.h>
31# include <QtGui/private/qeglpbuffer_p.h>
32#endif
33
34#include <QtGui/private/qgenericunixfontdatabase_p.h>
35#include <QtGui/private/qgenericunixservices_p.h>
36#include <QtGui/private/qgenericunixthemes_p.h>
37#include <QtGui/private/qgenericunixeventdispatcher_p.h>
38#include <QtFbSupport/private/qfbvthandler_p.h>
39#ifndef QT_NO_OPENGL
40# include <QtOpenGL/private/qopenglcompositorbackingstore_p.h>
41#endif
42
43#if QT_CONFIG(libinput)
44#include <QtInputSupport/private/qlibinputhandler_p.h>
45#endif
46
47#if QT_CONFIG(evdev)
48#include <QtInputSupport/private/qevdevmousemanager_p.h>
49#include <QtInputSupport/private/qevdevkeyboardmanager_p.h>
50#include <QtInputSupport/private/qevdevtouchmanager_p.h>
51#endif
52
53#if QT_CONFIG(tslib)
54#include <QtInputSupport/private/qtslib_p.h>
55#endif
56
57#if QT_CONFIG(integrityhid)
58#include <QtInputSupport/qintegrityhidmanager.h>
59#endif
60
61static void initResources()
62{
63#ifndef QT_NO_CURSOR
65#endif
66}
67
69
70using namespace Qt::StringLiterals;
71
73 : m_kbdMgr(nullptr),
74 m_display(EGL_NO_DISPLAY),
75 m_inputContext(nullptr),
76 m_fontDb(new QGenericUnixFontDatabase),
77 m_services(new QGenericUnixServices),
78 m_disableInputHandlers(false)
79{
80 m_disableInputHandlers = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DISABLE_INPUT");
81
83}
84
86{
88
89 m_display = qt_egl_device_integration()->createDisplay(nativeDisplay());
90 if (Q_UNLIKELY(m_display == EGL_NO_DISPLAY))
91 qFatal("Could not open egl display");
92
93 EGLint major, minor;
94 if (Q_UNLIKELY(!eglInitialize(m_display, &major, &minor)))
95 qFatal("Could not initialize egl display");
96
97 m_inputContext = QPlatformInputContextFactory::create();
98
99 m_vtHandler.reset(new QFbVtHandler);
100
101 if (qt_egl_device_integration()->usesDefaultScreen())
103 else
105
106 // Input code may rely on the screens, so do it only after the screen init.
107 if (!m_disableInputHandlers)
109}
110
112{
113 const auto toplevels = qGuiApp->topLevelWindows();
114 for (QWindow *w : toplevels)
115 w->destroy();
116
118
119 if (m_display != EGL_NO_DISPLAY)
120 eglTerminate(m_display);
121
123}
124
126{
127 return createUnixEventDispatcher();
128}
129
131{
132 return m_services.data();
133}
134
136{
137 return m_fontDb.data();
138}
139
144
146{
147#ifndef QT_NO_OPENGL
149 if (!window->handle())
150 window->create();
151 static_cast<QEglFSWindow *>(window->handle())->setBackingStore(bs);
152 return bs;
153#else
155 return nullptr;
156#endif
157}
158
160{
163 w->create();
164
165 const auto showWithoutActivating = window->property("_q_showWithoutActivating");
166 if (showWithoutActivating.isValid() && showWithoutActivating.toBool())
167 return w;
168
169 // Activate only the window for the primary screen to make input work
170 if (window->type() != Qt::ToolTip && window->screen() == QGuiApplication::primaryScreen())
171 w->requestActivateWindow();
172
173 return w;
174}
175
176#ifndef QT_NO_OPENGL
178{
179 EGLDisplay dpy = context->screen() ? static_cast<QEglFSScreen *>(context->screen()->handle())->display() : display();
180 QPlatformOpenGLContext *share = context->shareHandle();
181
184 EGLConfig config = QEglFSDeviceIntegration::chooseConfig(dpy, adjustedFormat);
185 ctx = new QEglFSContext(adjustedFormat, share, dpy, &config);
186
187 return ctx;
188}
189
191{
192 return QEGLPlatformContext::createFrom<QEglFSContext>(context, contextDisplay, display(), shareContext);
193}
194
196{
197 EGLDisplay dpy = surface->screen() ? static_cast<QEglFSScreen *>(surface->screen()->handle())->display() : display();
199 if (qt_egl_device_integration()->supportsPBuffers()) {
200 QEGLPlatformContext::Flags flags;
201 if (!qt_egl_device_integration()->supportsSurfacelessContexts())
203 return new QEGLPbuffer(dpy, fmt, surface, flags);
204 } else {
205 return new QEglFSOffscreenWindow(dpy, fmt, surface);
206 }
207 // Never return null. Multiple QWindows are not supported by this plugin.
208}
209#endif // QT_NO_OPENGL
210
212{
213 // We assume that devices will have more and not less capabilities
215 return true;
216
217 switch (cap) {
218 case ThreadedPixmaps: return true;
219#ifndef QT_NO_OPENGL
220 case OpenGL: return true;
221 case ThreadedOpenGL: return true;
222 case RasterGLSurface: return true;
223#else
224 case OpenGL: return false;
225 case ThreadedOpenGL: return false;
226 case RasterGLSurface: return false;
227#endif
228 case WindowManagement: return false;
229 case OpenGLOnRasterSurface: return true;
231 }
232}
233
235{
236 return const_cast<QEglFSIntegration *>(this);
237}
238
250
251static int resourceType(const QByteArray &key)
252{
253 static const QByteArray names[] = { // match ResourceType
254 QByteArrayLiteral("egldisplay"),
255 QByteArrayLiteral("eglwindow"),
256 QByteArrayLiteral("eglcontext"),
257 QByteArrayLiteral("eglconfig"),
258 QByteArrayLiteral("nativedisplay"),
259 QByteArrayLiteral("display"),
260 QByteArrayLiteral("server_wl_display"),
261 QByteArrayLiteral("eglsurface"),
262 QByteArrayLiteral("vksurface")
263 };
264 const QByteArray *end = names + sizeof(names) / sizeof(names[0]);
265 const QByteArray *result = std::find(names, end, key);
266 if (result == end)
267 result = std::find(names, end, key.toLower());
268 return int(result - names);
269}
270
272{
273 void *result = nullptr;
274
275 switch (resourceType(resource)) {
276 case EglDisplay:
277 result = display();
278 break;
279 case NativeDisplay:
280 result = reinterpret_cast<void*>(nativeDisplay());
281 break;
282 case WaylandDisplay:
284 break;
285 default:
287 break;
288 }
289
290 return result;
291}
292
294{
295 void *result = nullptr;
296
297 switch (resourceType(resource)) {
298 case XlibDisplay:
299 // Play nice when using the x11 hooks: Be compatible with xcb that allows querying
300 // the X Display pointer, which is nothing but our native display.
301 result = reinterpret_cast<void*>(nativeDisplay());
302 break;
303 default:
305 break;
306 }
307
308 return result;
309}
310
312{
313 void *result = nullptr;
314
315 switch (resourceType(resource)) {
316 case EglDisplay:
317 if (window && window->handle())
318 result = static_cast<QEglFSScreen *>(window->handle()->screen())->display();
319 else
320 result = display();
321 break;
322 case EglWindow:
323 if (window && window->handle())
324 result = reinterpret_cast<void*>(static_cast<QEglFSWindow *>(window->handle())->eglWindow());
325 break;
326 case EglSurface:
327 if (window && window->handle())
328 result = reinterpret_cast<void*>(static_cast<QEglFSWindow *>(window->handle())->surface());
329 break;
330 default:
331 break;
332 }
333
334 return result;
335}
336
337#ifndef QT_NO_OPENGL
339{
340 void *result = nullptr;
341
342 switch (resourceType(resource)) {
343 case EglContext:
344 if (context->handle())
345 result = static_cast<QEglFSContext *>(context->handle())->eglContext();
346 break;
347 case EglConfig:
348 if (context->handle())
349 result = static_cast<QEglFSContext *>(context->handle())->eglConfig();
350 break;
351 case EglDisplay:
352 if (context->handle())
353 result = static_cast<QEglFSContext *>(context->handle())->eglDisplay();
354 break;
355 default:
356 break;
357 }
358
359 return result;
360}
361
363{
365
366 QEglFSContext *handle = static_cast<QEglFSContext *>(context->handle());
367 if (!handle)
368 return nullptr;
369
370 return handle->eglContext();
371}
372#endif
373
375{
376#ifndef QT_NO_OPENGL
377 if (resource.compare("get_egl_context", Qt::CaseInsensitive) == 0)
379#else
380 Q_UNUSED(resource);
381#endif
382 return nullptr;
383}
384
385QFunctionPointer QEglFSIntegration::platformFunction(const QByteArray &function) const
386{
388}
389
397
398#if QT_CONFIG(evdev)
399void QEglFSIntegration::loadKeymap(const QString &filename)
400{
401 if (m_kbdMgr)
402 m_kbdMgr->loadKeymap(filename);
403 else
404 qWarning("QEglFSIntegration: Cannot load keymap, no keyboard handler found");
405}
406
407void QEglFSIntegration::switchLang()
408{
409 if (m_kbdMgr)
411 else
412 qWarning("QEglFSIntegration: Cannot switch language, no keyboard handler found");
413}
414#endif
415
417{
418#if QT_CONFIG(libinput)
419 if (!qEnvironmentVariableIntValue("QT_QPA_EGLFS_NO_LIBINPUT")) {
420 new QLibInputHandler("libinput"_L1, QString());
421 return;
422 }
423#endif
424
425#if QT_CONFIG(tslib)
426 bool useTslib = qEnvironmentVariableIntValue("QT_QPA_EGLFS_TSLIB");
427 if (useTslib)
428 new QTsLibMouseHandler("TsLib"_L1, QString() /* spec */);
429#endif
430
431#if QT_CONFIG(evdev)
432 m_kbdMgr = new QEvdevKeyboardManager("EvdevKeyboard"_L1, QString() /* spec */, this);
433 new QEvdevMouseManager("EvdevMouse"_L1, QString() /* spec */, this);
434#if QT_CONFIG(tslib)
435 if (!useTslib)
436#endif
437 new QEvdevTouchManager("EvdevTouch"_L1, QString() /* spec */, this);
438#endif
439
440#if QT_CONFIG(integrityhid)
441 new QIntegrityHIDManager("HID", "", this);
442#endif
443}
444
445EGLNativeDisplayType QEglFSIntegration::nativeDisplay() const
446{
448}
449
\inmodule QtCore
Definition qbytearray.h:57
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qbytearray.h:664
A pbuffer-based implementation of QPlatformOffscreenSurface for EGL.
EGLContext eglContext() const
virtual QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const
virtual void * nativeResourceForIntegration(const QByteArray &name)
static EGLConfig chooseConfig(EGLDisplay display, const QSurfaceFormat &format)
virtual QFunctionPointer platformFunction(const QByteArray &function) const
virtual QEglFSWindow * createWindow(QWindow *window) const
virtual EGLDisplay createDisplay(EGLNativeDisplayType nativeDisplay)
virtual EGLNativeDisplayType platformDisplay() const
virtual void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
bool hasCapability(QPlatformIntegration::Capability cap) const override
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QPlatformTheme * createPlatformTheme(const QString &name) const override
QFunctionPointer platformFunction(const QByteArray &function) const override
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
virtual void createInputHandlers()
void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override
QVariant styleHint(QPlatformIntegration::StyleHint hint) const override
void * nativeResourceForIntegration(const QByteArray &resource) override
QPlatformNativeInterface * nativeInterface() const override
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
QOpenGLContext * createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const override
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
EGLDisplay display() const
QEvdevKeyboardManager * m_kbdMgr
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
void destroy() override
Called before the platform integration is deleted.
NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) override
void * nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) override
QPlatformServices * services() const override
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
Factory function for QPlatformOpenGLContext.
void loadKeymap(const QString &file)
@ ExcludeUserInputEvents
Definition qeventloop.h:27
static QPlatformTheme * createUnixTheme(const QString &name)
Creates a UNIX theme according to the detected desktop environment.
QScreen * primaryScreen
the primary (or default) screen of the application.
\inmodule QtGui
QScreen * screen() const
Returns the screen to which the offscreen surface is connected.
QSurfaceFormat requestedFormat() const
Returns the requested surfaceformat of this offscreen surface.
A backing store implementation for OpenGL.
\inmodule QtGui
The QPlatformBackingStore class provides the drawing area for top-level windows.
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
static QPlatformInputContext * create()
virtual QVariant styleHint(StyleHint hint) const
virtual bool hasCapability(Capability cap) const
Capability
Capabilities are used to determine specific features of a platform integration.
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
void *(* NativeResourceForContextFunction)(QOpenGLContext *context)
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
The QPlatformServices provides the backend for desktop-related functionality.
The QPlatformTheme class allows customizing the UI based on themes.
The QPlatformWindow class provides an abstraction for top-level windows.
T * data() const noexcept
Returns the value of the pointer referenced by this object.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtCore
Definition qvariant.h:65
static bool flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Make Qt Gui process all events on the event queue immediately.
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary=false)
Should be called by the implementation whenever a new screen is added.
\inmodule QtGui
Definition qwindow.h:63
EGLContext ctx
QCursor cursor
Combined button and popup list for selecting options.
@ CaseInsensitive
@ ToolTip
Definition qnamespace.h:213
static void * context
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
#define Q_UNLIKELY(x)
QEglFSDeviceIntegration * qt_egl_device_integration()
static void initResources()
@ NativeDisplay
@ WaylandDisplay
@ XlibDisplay
static int resourceType(const QByteArray &key)
static void * eglContextForContext(QOpenGLContext *context)
EGLConfig config
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define qGuiApp
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
GLuint64 GLenum void * handle
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLuint GLuint end
GLbitfield flags
GLuint name
GLuint GLuint * names
GLuint64EXT * result
[6]
GLenum cap
static void initResources()
Definition qpdf.cpp:39
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_UNUSED(x)
#define Q_INIT_RESOURCE(name)
Definition qtresource.h:14
QVideoFrameFormat::PixelFormat fmt
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]