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 | |
6 | #include "qeglfskmsintegration_p.h" |
7 | #include "qeglfskmsscreen_p.h" |
8 | |
9 | #include <QtKmsSupport/private/qkmsdevice_p.h> |
10 | |
11 | #include <QtGui/qpa/qplatformwindow.h> |
12 | #include <QtGui/QScreen> |
13 | |
14 | #include <xf86drm.h> |
15 | #include <xf86drmMode.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | Q_LOGGING_CATEGORY(qLcEglfsKmsDebug, "qt.qpa.eglfs.kms") |
20 | |
21 | QEglFSKmsIntegration::QEglFSKmsIntegration() |
22 | : m_device(nullptr) |
23 | { |
24 | } |
25 | |
26 | QEglFSKmsIntegration::~QEglFSKmsIntegration() |
27 | { |
28 | } |
29 | |
30 | void QEglFSKmsIntegration::platformInit() |
31 | { |
32 | qCDebug(qLcEglfsKmsDebug, "platformInit: Load Screen Config"); |
33 | m_screenConfig = createScreenConfig(); |
34 | |
35 | qCDebug(qLcEglfsKmsDebug, "platformInit: Opening DRM device"); |
36 | m_device = createDevice(); |
37 | if (Q_UNLIKELY(!m_device->open())) |
38 | qFatal(msg: "Could not open DRM device"); |
39 | } |
40 | |
41 | void QEglFSKmsIntegration::platformDestroy() |
42 | { |
43 | qCDebug(qLcEglfsKmsDebug, "platformDestroy: Closing DRM device"); |
44 | m_device->close(); |
45 | delete m_device; |
46 | m_device = nullptr; |
47 | delete m_screenConfig; |
48 | m_screenConfig = nullptr; |
49 | } |
50 | |
51 | EGLNativeDisplayType QEglFSKmsIntegration::platformDisplay() const |
52 | { |
53 | Q_ASSERT(m_device); |
54 | return (EGLNativeDisplayType) m_device->nativeDisplay(); |
55 | } |
56 | |
57 | bool QEglFSKmsIntegration::usesDefaultScreen() |
58 | { |
59 | return false; |
60 | } |
61 | |
62 | void QEglFSKmsIntegration::screenInit() |
63 | { |
64 | m_device->createScreens(); |
65 | } |
66 | |
67 | QSurfaceFormat QEglFSKmsIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const |
68 | { |
69 | QSurfaceFormat format(inputFormat); |
70 | format.setRenderableType(QSurfaceFormat::OpenGLES); |
71 | format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); |
72 | format.setRedBufferSize(8); |
73 | format.setGreenBufferSize(8); |
74 | format.setBlueBufferSize(8); |
75 | return format; |
76 | } |
77 | |
78 | bool QEglFSKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
79 | { |
80 | switch (cap) { |
81 | case QPlatformIntegration::ThreadedPixmaps: |
82 | case QPlatformIntegration::OpenGL: |
83 | case QPlatformIntegration::ThreadedOpenGL: |
84 | return true; |
85 | default: |
86 | return false; |
87 | } |
88 | } |
89 | |
90 | void QEglFSKmsIntegration::waitForVSync(QPlatformSurface *surface) const |
91 | { |
92 | QWindow *window = static_cast<QWindow *>(surface->surface()); |
93 | QEglFSKmsScreen *screen = static_cast<QEglFSKmsScreen *>(window->screen()->handle()); |
94 | |
95 | screen->waitForFlip(); |
96 | } |
97 | |
98 | bool QEglFSKmsIntegration::supportsPBuffers() const |
99 | { |
100 | return m_screenConfig->supportsPBuffers(); |
101 | } |
102 | |
103 | void *QEglFSKmsIntegration::nativeResourceForIntegration(const QByteArray &name) |
104 | { |
105 | if (name == QByteArrayLiteral("dri_fd") && m_device) |
106 | return (void *) (qintptr) m_device->fd(); |
107 | |
108 | #if QT_CONFIG(drm_atomic) |
109 | if (name == QByteArrayLiteral("dri_atomic_request") && m_device) |
110 | return (void *) (qintptr) m_device->threadLocalAtomicRequest(); |
111 | #endif |
112 | return nullptr; |
113 | } |
114 | |
115 | void *QEglFSKmsIntegration::nativeResourceForScreen(const QByteArray &resource, QScreen *screen) |
116 | { |
117 | QEglFSKmsScreen *s = static_cast<QEglFSKmsScreen *>(screen->handle()); |
118 | if (s) { |
119 | if (resource == QByteArrayLiteral("dri_crtcid")) |
120 | return (void *) (qintptr) s->output().crtc_id; |
121 | if (resource == QByteArrayLiteral("dri_connectorid")) |
122 | return (void *) (qintptr) s->output().connector_id; |
123 | } |
124 | return nullptr; |
125 | } |
126 | |
127 | QKmsDevice *QEglFSKmsIntegration::device() const |
128 | { |
129 | return m_device; |
130 | } |
131 | |
132 | QKmsScreenConfig *QEglFSKmsIntegration::screenConfig() const |
133 | { |
134 | return m_screenConfig; |
135 | } |
136 | |
137 | QKmsScreenConfig *QEglFSKmsIntegration::createScreenConfig() |
138 | { |
139 | QKmsScreenConfig *screenConfig = new QKmsScreenConfig; |
140 | screenConfig->loadConfig(); |
141 | |
142 | return screenConfig; |
143 | } |
144 | |
145 | QT_END_NAMESPACE |
146 |