Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qeglfskmsgbmintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// Copyright (C) 2016 The Qt Company Ltd.
3// Copyright (C) 2016 Pelagicore AG
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
11#include "private/qeglfscursor_p.h"
12
13#include <QtCore/QLoggingCategory>
14#include <QtCore/QFileSystemWatcher>
15#include <QtGui/QScreen>
16#include <QtDeviceDiscoverySupport/private/qdevicediscovery_p.h>
17
18#include <gbm.h>
19
21
22QEglFSKmsGbmIntegration::QEglFSKmsGbmIntegration()
23{
24 qCDebug(qLcEglfsKmsDebug, "New DRM/KMS via GBM integration created");
25}
26
27QEglFSKmsGbmIntegration::~QEglFSKmsGbmIntegration()
28{
29}
30
31#ifndef EGL_EXT_platform_base
33#endif
34
35#ifndef EGL_PLATFORM_GBM_KHR
36#define EGL_PLATFORM_GBM_KHR 0x31D7
37#endif
38
39EGLDisplay QEglFSKmsGbmIntegration::createDisplay(EGLNativeDisplayType nativeDisplay)
40{
41 qCDebug(qLcEglfsKmsDebug, "Querying EGLDisplay");
42 EGLDisplay display;
43
44 PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay = nullptr;
45 const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
46 if (extensions && (strstr(extensions, "EGL_KHR_platform_gbm") || strstr(extensions, "EGL_MESA_platform_gbm"))) {
47 getPlatformDisplay = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
48 eglGetProcAddress("eglGetPlatformDisplayEXT"));
49 }
50
51 if (getPlatformDisplay) {
52 display = getPlatformDisplay(EGL_PLATFORM_GBM_KHR, nativeDisplay, nullptr);
53 } else {
54 qCDebug(qLcEglfsKmsDebug, "No eglGetPlatformDisplay for GBM, falling back to eglGetDisplay");
55 display = eglGetDisplay(nativeDisplay);
56 }
57
58 return display;
59}
60
61EGLNativeWindowType QEglFSKmsGbmIntegration::createNativeOffscreenWindow(const QSurfaceFormat &format)
62{
63 Q_UNUSED(format);
64 Q_ASSERT(device());
65
66 gbm_surface *surface = gbm_surface_create(static_cast<QEglFSKmsGbmDevice *>(device())->gbmDevice(),
67 1, 1,
68 GBM_FORMAT_XRGB8888,
69 GBM_BO_USE_RENDERING);
70
71 return reinterpret_cast<EGLNativeWindowType>(surface);
72}
73
74void QEglFSKmsGbmIntegration::destroyNativeWindow(EGLNativeWindowType window)
75{
76 gbm_surface *surface = reinterpret_cast<gbm_surface *>(window);
77 gbm_surface_destroy(surface);
78}
79
80QPlatformCursor *QEglFSKmsGbmIntegration::createCursor(QPlatformScreen *screen) const
81{
82#if QT_CONFIG(opengl)
83 if (!screenConfig()->hwCursor()) {
84 qCDebug(qLcEglfsKmsDebug, "Using plain OpenGL mouse cursor");
85 return new QEglFSCursor(screen);
86 }
87#else
88 Q_UNUSED(screen);
89#endif
90 return nullptr;
91}
92
93void QEglFSKmsGbmIntegration::presentBuffer(QPlatformSurface *surface)
94{
95 QWindow *window = static_cast<QWindow *>(surface->surface());
96 QEglFSKmsGbmScreen *screen = static_cast<QEglFSKmsGbmScreen *>(window->screen()->handle());
97 screen->flip();
98}
99
100QKmsDevice *QEglFSKmsGbmIntegration::createDevice()
101{
102
103 m_deviceDiscovery = std::unique_ptr<QDeviceDiscovery>(QDeviceDiscovery::create(QDeviceDiscovery::Device_VideoMask));
104 m_kmsConfigWatcher = std::unique_ptr<QFileSystemWatcher>(new QFileSystemWatcher());
105
106 QString path = screenConfig()->devicePath();
107 if (!path.isEmpty()) {
108 qCDebug(qLcEglfsKmsDebug) << "GBM: Using DRM device" << path << "specified in config file";
109 } else {
110 const QStringList devices = m_deviceDiscovery->scanConnectedDevices();
111 qCDebug(qLcEglfsKmsDebug) << "Found the following video devices:" << devices;
112
113 if (Q_UNLIKELY(devices.isEmpty()))
114 qFatal("Could not find DRM device!");
115
116 path = devices.first();
117 qCDebug(qLcEglfsKmsDebug) << "Using" << path;
118 }
119
120 bool hotreload = !qEnvironmentVariable("QT_QPA_EGLFS_HOTPLUG_ENABLED").isEmpty();
121 if (hotreload) {
122 qCWarning(qLcEglfsKmsDebug) << "EGLFS/KMS: Hot-Reload on KMS-events enabled, be aware that"
123 << "this requires actions in UI code for proper functionallity"
124 << "(e.g. close/open windows on screen's disconnect/connect)";
125 QObject::connect(m_deviceDiscovery.get(), &QDeviceDiscovery::deviceChanged,
126 m_deviceDiscovery.get(), [this](const QString &deviceNode) {
127 qCDebug(qLcEglfsKmsDebug) << "KMS device changed:" << deviceNode;
128 m_device->checkConnectedScreens();
129 });
130 }
131
132 QString json = qEnvironmentVariable("QT_QPA_EGLFS_KMS_CONFIG");
133 if (json.isEmpty())
134 json = qEnvironmentVariable("QT_QPA_KMS_CONFIG");
135
136 if (!json.isEmpty()) {
137 m_kmsConfigWatcher->addPath(json);
138 QObject::connect(m_kmsConfigWatcher.get(), &QFileSystemWatcher::fileChanged,
139 m_kmsConfigWatcher.get(), [this, json]() {
140 qCDebug(qLcEglfsKmsDebug) << "KMS config-file has changed! path:"
141 << json;
142 m_screenConfig->refreshConfig();
143 m_device->updateScreens();
144 m_kmsConfigWatcher->addPath(json); // as per QFileSystemWatcher doc we have to re-add
145 // the path in case it's a new file
146 });
147 }
148
149 return new QEglFSKmsGbmDevice(screenConfig(), path);
150}
151
152QEglFSWindow *QEglFSKmsGbmIntegration::createWindow(QWindow *window) const
153{
154 return new QEglFSKmsGbmWindow(window, this);
155}
156
157QT_END_NAMESPACE
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
void * native_display
void const EGLint * attrib_list
#define EGL_PLATFORM_GBM_KHR