Debian Codegraph @

src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/qeglfskmsvsp2device.cpp

raw
1 // Copyright (C) 2015 Pier Luigi Fiorini <[email protected]>
2 // Copyright (C) 2017 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
6 #include "qeglfskmsvsp2device.h"
7 #include "qeglfskmsvsp2screen.h"
8
9 #include "qeglfsintegration_p.h"
10
11 #include <QtCore/QLoggingCategory>
12 #include <QtCore/private/qcore_unix_p.h>
13
14 QT_BEGIN_NAMESPACE
15
16 Q_DECLARE_LOGGING_CATEGORY(qLcEglfsKmsDebug)
17
18 QEglFSKmsVsp2Device::QEglFSKmsVsp2Device(QKmsScreenConfig *screenConfig, const QString &path)
19 : QEglFSKmsDevice(screenConfig, path)
20 {
21 }
22
23 bool QEglFSKmsVsp2Device::open()
24 {
25 Q_ASSERT(fd() == -1);
26 Q_ASSERT(m_gbm_device == nullptr);
27
28 int fd = qt_safe_open(devicePath().toLocal8Bit().constData(), O_RDWR | O_CLOEXEC);
29 if (fd == -1) {
30 qErrnoWarning("Could not open DRM device %s", qPrintable(devicePath()));
31 return false;
32 }
33
34 qCDebug(qLcEglfsKmsDebug) << "Creating GBM device for file descriptor" << fd
35 << "obtained from" << devicePath();
36 m_gbm_device = gbm_create_device(fd);
37 if (!m_gbm_device) {
38 qErrnoWarning("Could not create GBM device");
39 qt_safe_close(fd);
40 fd = -1;
41 return false;
42 }
43
44 setFd(fd);
45
46 return true;
47 }
48
49 void QEglFSKmsVsp2Device::close()
50 {
51 // Note: screens are gone at this stage.
52
53 if (m_gbm_device) {
54 gbm_device_destroy(m_gbm_device);
55 m_gbm_device = nullptr;
56 }
57
58 if (fd() != -1) {
59 qt_safe_close(fd());
60 setFd(-1);
61 }
62 }
63
64 void *QEglFSKmsVsp2Device::nativeDisplay() const
65 {
66 return m_gbm_device;
67 }
68
69 gbm_device * QEglFSKmsVsp2Device::gbmDevice() const
70 {
71 return m_gbm_device;
72 }
73
74 QPlatformScreen *QEglFSKmsVsp2Device::createScreen(const QKmsOutput &output)
75 {
76 auto *screen = new QEglFSKmsVsp2Screen(this, output);
77
78 return screen;
79 }
80
81 QPlatformScreen *QEglFSKmsVsp2Device::createHeadlessScreen()
82 {
83 qWarning() << Q_FUNC_INFO << "Not implemented yet";
84 return nullptr;
85 }
86
87 void QEglFSKmsVsp2Device::registerScreenCloning(QPlatformScreen *screen,
88 QPlatformScreen *screenThisScreenClones,
89 const QList<QPlatformScreen *> &screensCloningThisScreen)
90 {
91 Q_UNUSED(screen);
92 qWarning() << Q_FUNC_INFO << "Not implemented yet";
93 if (!screenThisScreenClones && screensCloningThisScreen.isEmpty())
94 return;
95
96 // auto *vsp2Screen = static_cast<QEglFSKmsVsp2Screen *>(screen);
97 // vsp2Screen->initCloning(screenThisScreenClones, screensCloningThisScreen);
98 }
99
100 QT_END_NAMESPACE