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
qeglfskmsgbmdevice.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
8
9#include <private/qeglfsintegration_p.h>
10
11#include <QtCore/QLoggingCategory>
12#include <QtCore/private/qcore_unix_p.h>
13
14#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
15
17
18Q_DECLARE_LOGGING_CATEGORY(qLcEglfsKmsDebug)
19
21 : QEglFSKmsDevice(screenConfig, path)
22 , m_gbm_device(nullptr)
23 , m_globalCursor(nullptr)
24{
25}
26
28{
29 Q_ASSERT(fd() == -1);
30 Q_ASSERT(m_gbm_device == nullptr);
31
32 int fd = qt_safe_open(devicePath().toLocal8Bit().constData(), O_RDWR | O_CLOEXEC);
33 if (fd == -1) {
34 qErrnoWarning("Could not open DRM device %s", qPrintable(devicePath()));
35 return false;
36 }
37
38 qCDebug(qLcEglfsKmsDebug) << "Creating GBM device for file descriptor" << fd
39 << "obtained from" << devicePath();
40 m_gbm_device = gbm_create_device(fd);
41 if (!m_gbm_device) {
42 qErrnoWarning("Could not create GBM device");
44 fd = -1;
45 return false;
46 }
47
48 setFd(fd);
49
50 if (usesEventReader()) {
51 qCDebug(qLcEglfsKmsDebug, "Using dedicated drm event reading thread");
52 m_eventReader.create(this);
53 } else {
54 qCDebug(qLcEglfsKmsDebug, "Not using dedicated drm event reading thread; "
55 "threaded multi-screen setups may experience problems");
56 }
57
58 return true;
59}
60
62{
63 // Note: screens are gone at this stage.
64
65 if (usesEventReader())
66 m_eventReader.destroy();
67
68 if (m_gbm_device) {
69 gbm_device_destroy(m_gbm_device);
70 m_gbm_device = nullptr;
71 }
72
73 if (fd() != -1) {
75 setFd(-1);
76 }
77}
78
80{
81 return m_gbm_device;
82}
83
85{
86 return m_gbm_device;
87}
88
90{
91 return m_globalCursor;
92}
93
94// Cannot do this from close(), it may be too late.
95// Call this from the last screen dtor instead.
97{
98 if (m_globalCursor) {
99 qCDebug(qLcEglfsKmsDebug, "Destroying global GBM mouse cursor");
100 delete m_globalCursor;
101 m_globalCursor = nullptr;
102 }
103}
104
106{
107 if (!m_globalCursor && screenConfig()->hwCursor()) {
108 qCDebug(qLcEglfsKmsDebug, "Creating new global GBM mouse cursor");
109 m_globalCursor = new QEglFSKmsGbmCursor(screen);
110 }
111}
112
121
126
128 QPlatformScreen *screenThisScreenClones,
129 const QList<QPlatformScreen *> &screensCloningThisScreen)
130{
131 if (!screenThisScreenClones && screensCloningThisScreen.isEmpty())
132 return;
133
134 QEglFSKmsGbmScreen *gbmScreen = static_cast<QEglFSKmsGbmScreen *>(screen);
135 gbmScreen->initCloning(screenThisScreenClones, screensCloningThisScreen);
136}
137
139 bool isPrimary,
140 const QPoint &virtualPos,
141 const QList<QPlatformScreen *> &virtualSiblings)
142{
143 QEglFSKmsDevice::registerScreen(screen, isPrimary, virtualPos, virtualSiblings);
144 if (screenConfig()->hwCursor() && m_globalCursor)
145 m_globalCursor->reevaluateVisibilityForScreens();
146}
147
149{
150 static const bool eventReaderThreadDisabled = qEnvironmentVariableIntValue("QT_QPA_EGLFS_KMS_NO_EVENT_READER_THREAD");
151 return !eventReaderThreadDisabled;
152}
153
void registerScreen(QPlatformScreen *screen, bool isPrimary, const QPoint &virtualPos, const QList< QPlatformScreen * > &virtualSiblings) override
void create(QEglFSKmsDevice *device)
void registerScreen(QPlatformScreen *screen, bool isPrimary, const QPoint &virtualPos, const QList< QPlatformScreen * > &virtualSiblings) override
QPlatformScreen * createScreen(const QKmsOutput &output) override
gbm_device * gbmDevice() const
QPlatformScreen * createHeadlessScreen() override
QPlatformCursor * globalCursor() const
void * nativeDisplay() const override
void registerScreenCloning(QPlatformScreen *screen, QPlatformScreen *screenThisScreenClones, const QList< QPlatformScreen * > &screensCloningThisScreen) override
void createGlobalCursor(QEglFSKmsGbmScreen *screen)
void initCloning(QPlatformScreen *screenThisScreenClones, const QList< QPlatformScreen * > &screensCloningThisScreen)
int fd() const
void setFd(int fd)
QKmsScreenConfig * screenConfig() const
QString devicePath() const
The QPlatformCursor class provides information about pointer device events (movement,...
The QPlatformScreen class provides an abstraction for visual displays.
\inmodule QtCore\reentrant
Definition qpoint.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static int qt_safe_close(int fd)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint64 GLenum GLint fd
GLsizei const GLchar *const * path
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define qPrintable(string)
Definition qstring.h:1531
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QT_BEGIN_NAMESPACE typedef uchar * output