| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> |
| 4 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 5 | ** Copyright (C) 2016 Pelagicore AG |
| 6 | ** Contact: https://www.qt.io/licensing/ |
| 7 | ** |
| 8 | ** This file is part of the plugins of the Qt Toolkit. |
| 9 | ** |
| 10 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 11 | ** Commercial License Usage |
| 12 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 13 | ** accordance with the commercial license agreement provided with the |
| 14 | ** Software or, alternatively, in accordance with the terms contained in |
| 15 | ** a written agreement between you and The Qt Company. For licensing terms |
| 16 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 17 | ** information use the contact form at https://www.qt.io/contact-us. |
| 18 | ** |
| 19 | ** GNU Lesser General Public License Usage |
| 20 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 21 | ** General Public License version 3 as published by the Free Software |
| 22 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 23 | ** packaging of this file. Please review the following information to |
| 24 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 25 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 26 | ** |
| 27 | ** GNU General Public License Usage |
| 28 | ** Alternatively, this file may be used under the terms of the GNU |
| 29 | ** General Public License version 2.0 or (at your option) the GNU General |
| 30 | ** Public license version 3 or any later version approved by the KDE Free |
| 31 | ** Qt Foundation. The licenses are as published by the Free Software |
| 32 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 33 | ** included in the packaging of this file. Please review the following |
| 34 | ** information to ensure the GNU General Public License requirements will |
| 35 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 36 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 37 | ** |
| 38 | ** $QT_END_LICENSE$ |
| 39 | ** |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | #include "qeglfskmsintegration_p.h" |
| 43 | #include "qeglfskmsscreen_p.h" |
| 44 | |
| 45 | #include <QtKmsSupport/private/qkmsdevice_p.h> |
| 46 | |
| 47 | #include <QtGui/qpa/qplatformwindow.h> |
| 48 | #include <QtGui/QScreen> |
| 49 | |
| 50 | #include <xf86drm.h> |
| 51 | #include <xf86drmMode.h> |
| 52 | |
| 53 | QT_BEGIN_NAMESPACE |
| 54 | |
| 55 | Q_LOGGING_CATEGORY(qLcEglfsKmsDebug, "qt.qpa.eglfs.kms") |
| 56 | |
| 57 | QEglFSKmsIntegration::QEglFSKmsIntegration() |
| 58 | : m_device(nullptr) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | QEglFSKmsIntegration::~QEglFSKmsIntegration() |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | void QEglFSKmsIntegration::platformInit() |
| 67 | { |
| 68 | qCDebug(qLcEglfsKmsDebug, "platformInit: Load Screen Config"); |
| 69 | m_screenConfig = createScreenConfig(); |
| 70 | |
| 71 | qCDebug(qLcEglfsKmsDebug, "platformInit: Opening DRM device"); |
| 72 | m_device = createDevice(); |
| 73 | if (Q_UNLIKELY(!m_device->open())) |
| 74 | qFatal("Could not open DRM device"); |
| 75 | } |
| 76 | |
| 77 | void QEglFSKmsIntegration::platformDestroy() |
| 78 | { |
| 79 | qCDebug(qLcEglfsKmsDebug, "platformDestroy: Closing DRM device"); |
| 80 | m_device->close(); |
| 81 | delete m_device; |
| 82 | m_device = nullptr; |
| 83 | delete m_screenConfig; |
| 84 | m_screenConfig = nullptr; |
| 85 | } |
| 86 | |
| 87 | EGLNativeDisplayType QEglFSKmsIntegration::platformDisplay() const |
| 88 | { |
| 89 | Q_ASSERT(m_device); |
| 90 | return (EGLNativeDisplayType) m_device->nativeDisplay(); |
| 91 | } |
| 92 | |
| 93 | bool QEglFSKmsIntegration::usesDefaultScreen() |
| 94 | { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | void QEglFSKmsIntegration::screenInit() |
| 99 | { |
| 100 | m_device->createScreens(); |
| 101 | } |
| 102 | |
| 103 | QSurfaceFormat QEglFSKmsIntegration::surfaceFormatFor(const QSurfaceFormat &inputFormat) const |
| 104 | { |
| 105 | QSurfaceFormat format(inputFormat); |
| 106 | format.setRenderableType(QSurfaceFormat::OpenGLES); |
| 107 | format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); |
| 108 | format.setRedBufferSize(8); |
| 109 | format.setGreenBufferSize(8); |
| 110 | format.setBlueBufferSize(8); |
| 111 | return format; |
| 112 | } |
| 113 | |
| 114 | bool QEglFSKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 115 | { |
| 116 | switch (cap) { |
| 117 | case QPlatformIntegration::ThreadedPixmaps: |
| 118 | case QPlatformIntegration::OpenGL: |
| 119 | case QPlatformIntegration::ThreadedOpenGL: |
| 120 | return true; |
| 121 | default: |
| 122 | return false; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void QEglFSKmsIntegration::waitForVSync(QPlatformSurface *surface) const |
| 127 | { |
| 128 | QWindow *window = static_cast<QWindow *>(surface->surface()); |
| 129 | QEglFSKmsScreen *screen = static_cast<QEglFSKmsScreen *>(window->screen()->handle()); |
| 130 | |
| 131 | screen->waitForFlip(); |
| 132 | } |
| 133 | |
| 134 | bool QEglFSKmsIntegration::supportsPBuffers() const |
| 135 | { |
| 136 | return m_screenConfig->supportsPBuffers(); |
| 137 | } |
| 138 | |
| 139 | void *QEglFSKmsIntegration::nativeResourceForIntegration(const QByteArray &name) |
| 140 | { |
| 141 | if (name == QByteArrayLiteral("dri_fd") && m_device) |
| 142 | return (void *) (qintptr) m_device->fd(); |
| 143 | |
| 144 | #if QT_CONFIG(drm_atomic) |
| 145 | if (name == QByteArrayLiteral("dri_atomic_request") && m_device) |
| 146 | return (void *) (qintptr) m_device->threadLocalAtomicRequest(); |
| 147 | #endif |
| 148 | return nullptr; |
| 149 | } |
| 150 | |
| 151 | void *QEglFSKmsIntegration::nativeResourceForScreen(const QByteArray &resource, QScreen *screen) |
| 152 | { |
| 153 | QEglFSKmsScreen *s = static_cast<QEglFSKmsScreen *>(screen->handle()); |
| 154 | if (s) { |
| 155 | if (resource == QByteArrayLiteral("dri_crtcid")) |
| 156 | return (void *) (qintptr) s->output().crtc_id; |
| 157 | if (resource == QByteArrayLiteral("dri_connectorid")) |
| 158 | return (void *) (qintptr) s->output().connector_id; |
| 159 | } |
| 160 | return nullptr; |
| 161 | } |
| 162 | |
| 163 | QKmsDevice *QEglFSKmsIntegration::device() const |
| 164 | { |
| 165 | return m_device; |
| 166 | } |
| 167 | |
| 168 | QKmsScreenConfig *QEglFSKmsIntegration::screenConfig() const |
| 169 | { |
| 170 | return m_screenConfig; |
| 171 | } |
| 172 | |
| 173 | QKmsScreenConfig *QEglFSKmsIntegration::createScreenConfig() |
| 174 | { |
| 175 | QKmsScreenConfig *screenConfig = new QKmsScreenConfig; |
| 176 | screenConfig->loadConfig(); |
| 177 | |
| 178 | return screenConfig; |
| 179 | } |
| 180 | |
| 181 | QT_END_NAMESPACE |
| 182 |