1// Copyright (C) 2016 Pelagicore AG
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 "qeglfskmsegldevice.h"
5#include "qeglfskmsegldevicescreen.h"
6#include "qeglfskmsegldeviceintegration.h"
7#include "private/qeglfsintegration_p.h"
8#include "private/qeglfscursor_p.h"
9
10#include <QtCore/private/qcore_unix_p.h>
11
12QT_BEGIN_NAMESPACE
13
14QEglFSKmsEglDevice::QEglFSKmsEglDevice(QEglFSKmsEglDeviceIntegration *devInt, QKmsScreenConfig *screenConfig, const QString &path)
15 : QEglFSKmsDevice(screenConfig, path),
16 m_devInt(devInt),
17 m_globalCursor(nullptr)
18{
19}
20
21bool QEglFSKmsEglDevice::open()
22{
23 Q_ASSERT(fd() == -1);
24
25 int fd = -1;
26
27 if (devicePath().compare(s: "drm-nvdc") == 0)
28 fd = drmOpen(name: devicePath().toLocal8Bit().constData(), busid: nullptr);
29 else
30 fd = qt_safe_open(pathname: devicePath().toLocal8Bit().constData(), O_RDWR);
31 if (Q_UNLIKELY(fd < 0))
32 qFatal(msg: "Could not open DRM (NV) device");
33
34 setFd(fd);
35
36 return true;
37}
38
39void QEglFSKmsEglDevice::close()
40{
41 // Note: screens are gone at this stage.
42
43 if (drmClose(fd: fd()) == -1)
44 qErrnoWarning(msg: "Could not close DRM (NV) device");
45
46 setFd(-1);
47}
48
49void *QEglFSKmsEglDevice::nativeDisplay() const
50{
51 return m_devInt->eglDevice();
52}
53
54QPlatformScreen *QEglFSKmsEglDevice::createScreen(const QKmsOutput &output)
55{
56 QEglFSKmsScreen *screen = new QEglFSKmsEglDeviceScreen(this, output);
57#if QT_CONFIG(opengl)
58 if (!m_globalCursor && !screenConfig()->separateScreens()) {
59 qCDebug(qLcEglfsKmsDebug, "Creating new global mouse cursor");
60 m_globalCursor = new QEglFSCursor(screen);
61 }
62#endif
63 return screen;
64}
65
66void QEglFSKmsEglDevice::destroyGlobalCursor()
67{
68 if (m_globalCursor) {
69 qCDebug(qLcEglfsKmsDebug, "Destroying global mouse cursor");
70 delete m_globalCursor;
71 m_globalCursor = nullptr;
72 }
73}
74
75QT_END_NAMESPACE
76

source code of qtbase/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp