diff options
Diffstat (limited to 'src/hardwareintegration/compositor')
48 files changed, 653 insertions, 2011 deletions
diff --git a/src/hardwareintegration/compositor/CMakeLists.txt b/src/hardwareintegration/compositor/CMakeLists.txt new file mode 100644 index 000000000..8da6b3ce1 --- /dev/null +++ b/src/hardwareintegration/compositor/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Generated from compositor.pro. + +if(QT_FEATURE_wayland_egl) + add_subdirectory(wayland-egl) +endif() diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp index 760762572..1380bd5b8 100644 --- a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp +++ b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "brcmbuffer.h" diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h index 7350961a2..6a21c3f5c 100644 --- a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h +++ b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef BRCMBUFFER_H #define BRCMBUFFER_H @@ -33,8 +7,8 @@ #include <QtWaylandCompositor/private/qwayland-server-wayland.h> #include <QtWaylandCompositor/private/qwaylandutils_p.h> +#include <QtCore/QList> #include <QtCore/QSize> -#include <QtCore/QVector> #include <EGL/egl.h> @@ -60,7 +34,7 @@ protected: void buffer_destroy(Resource *resource) override; private: - QVector<EGLint> m_handle; + QList<EGLint> m_handle; bool m_invertedY = false; QSize m_size; }; diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp index 8ddb4f951..178a2e30a 100644 --- a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp +++ b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "brcmeglintegration.h" #include "brcmbuffer.h" @@ -67,48 +41,46 @@ BrcmEglIntegration::BrcmEglIntegration() { } -bool BrcmEglIntegration::initializeHardware(struct ::wl_display *display) +void BrcmEglIntegration::initializeHardware(struct ::wl_display *display) { Q_D(BrcmEglIntegration); QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - if (!nativeInterface) - return false; + if (nativeInterface) { + d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay"); + if (!d->egl_display) + qWarning("Failed to acquire EGL display from platform integration"); - d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay"); - if (!d->egl_display) - qWarning("Failed to acquire EGL display from platform integration"); + d->eglQueryGlobalImageBRCM = (PFNEGLQUERYGLOBALIMAGEBRCMPROC) eglGetProcAddress("eglQueryGlobalImageBRCM"); - d->eglQueryGlobalImageBRCM = (PFNEGLQUERYGLOBALIMAGEBRCMPROC) eglGetProcAddress("eglQueryGlobalImageBRCM"); + if (!d->eglQueryGlobalImageBRCM) { + qWarning("Failed to resolve eglQueryGlobalImageBRCM"); + return; + } - if (!d->eglQueryGlobalImageBRCM) { - qWarning("Failed to resolve eglQueryGlobalImageBRCM"); - return false; - } - - d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); - if (!d->glEGLImageTargetTexture2DOES) { - qWarning("Failed to resolve glEGLImageTargetTexture2DOES"); - return false; - } + if (!d->glEGLImageTargetTexture2DOES) { + qWarning("Failed to resolve glEGLImageTargetTexture2DOES"); + return; + } - d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); + d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); - if (!d->eglCreateImageKHR) { - qWarning("Failed to resolve eglCreateImageKHR"); - return false; - } + if (!d->eglCreateImageKHR) { + qWarning("Failed to resolve eglCreateImageKHR"); + return; + } - d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); + d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - if (!d->eglDestroyImageKHR) { - qWarning("Failed to resolve eglDestroyImageKHR"); - return false; + if (!d->eglDestroyImageKHR) { + qWarning("Failed to resolve eglDestroyImageKHR"); + return; + } + d->valid = true; + init(display, 1); } - d->valid = true; - init(display, 1); - return true; } QtWayland::ClientBuffer *BrcmEglIntegration::createBufferFor(wl_resource *buffer) diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h index 4bc98e8c5..4ee5d404e 100644 --- a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h +++ b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef BRCMEGLINTEGRATION_H #define BRCMEGLINTEGRATION_H @@ -47,7 +21,7 @@ class BrcmEglIntegration : public QtWayland::ClientBufferIntegration, public QtW public: BrcmEglIntegration(); - bool initializeHardware(struct ::wl_display *display) override; + void initializeHardware(struct ::wl_display *display) override; QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; protected: diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri b/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri index 2df101092..41f483c48 100644 --- a/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri @@ -1,6 +1,6 @@ INCLUDEPATH += $$PWD -QMAKE_USE_PRIVATE += egl wayland-server +QMAKE_USE_PRIVATE += egl drm wayland-server SOURCES += \ $$PWD/dmabufserverbufferintegration.cpp diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp index 133e1eca7..a217c1c89 100644 --- a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp @@ -1,36 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "dmabufserverbufferintegration.h" +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <drm_fourcc.h> #include <unistd.h> @@ -126,7 +100,7 @@ QOpenGLTexture *DmaBufServerBuffer::toOpenGlTexture() bool DmaBufServerBuffer::bufferInUse() { - return resourceMap().count() > 0; + return resourceMap().size() > 0; } DmaBufServerBufferIntegration::DmaBufServerBufferIntegration() diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h index 4e9f8c741..eb559686c 100644 --- a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h @@ -1,35 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DMABUFSERVERBUFFERINTEGRATION_H #define DMABUFSERVERBUFFERINTEGRATION_H +#include <QtCore/QVariant> #include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h> #include "qwayland-server-qt-dmabuf-server-buffer.h" diff --git a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp index 03b389eff..3c49f30a4 100644 --- a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp +++ b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp @@ -1,36 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "drmeglserverbufferintegration.h" +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> QT_BEGIN_NAMESPACE @@ -113,7 +87,7 @@ QOpenGLTexture *DrmEglServerBuffer::toOpenGlTexture() bool DrmEglServerBuffer::bufferInUse() { - return resourceMap().count() > 0; + return resourceMap().size() > 0; } DrmEglServerBufferIntegration::DrmEglServerBufferIntegration() diff --git a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h index eab5f0c56..e99a62542 100644 --- a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h +++ b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h @@ -1,35 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DRMEGLSERVERBUFFERINTEGRATION_H #define DRMEGLSERVERBUFFERINTEGRATION_H +#include <QtCore/QVariant> #include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h> #include "qwayland-server-drm-egl-server-buffer.h" diff --git a/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.cpp b/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.cpp index a0abf6972..c30bf5ae3 100644 --- a/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.cpp +++ b/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "vsp2hardwarelayerintegration.h" @@ -41,7 +15,9 @@ extern "C" { #include <QWaylandQuickOutput> #include <QQuickWindow> -#include <QtPlatformHeaders/qeglfsfunctions.h> +#include <qpa/qlatformscreen_p.h> + +using namespace QNativeInterface::Private; QT_BEGIN_NAMESPACE @@ -56,13 +32,17 @@ Vsp2Buffer::Vsp2Buffer(wl_kms_buffer *kmsBuffer) Vsp2Layer::Vsp2Layer(QWaylandQuickHardwareLayer *hwLayer, Vsp2HardwareLayerIntegration *integration) : m_hwLayer(hwLayer) { + auto *wlItem = m_hwLayer->waylandItem(); + m_screen = dynamic_cast<QVsp2Screen*>(wlItem->window()->screen()->handle()); + Q_ASSERT(m_screen); + connect(hwLayer, &QWaylandQuickHardwareLayer::stackingLevelChanged, this, [integration](){ integration->recreateVspLayers(); }); connect(hwLayer->waylandItem(), &QWaylandQuickItem::surfaceChanged, this, &Vsp2Layer::handleSurfaceChanged); connect(hwLayer->waylandItem(), &QQuickItem::opacityChanged, this, &Vsp2Layer::updateOpacity); connect(hwLayer->waylandItem()->window(), &QQuickWindow::afterSynchronizing, this, &Vsp2Layer::updatePosition); - hwLayer->disableSceneGraphPainting(); + hwLayer->setSceneGraphPainting(false); QWaylandViewPrivate::get(hwLayer->waylandItem()->view())->independentFrameCallback = true; handleSurfaceChanged(); } @@ -76,16 +56,17 @@ void Vsp2Layer::enableVspLayer() m_buffer = Vsp2Buffer(kmsBuffer); updatePosition(); + + m_layerIndex = m_screen->addLayer(m_buffer.dmabufFd, m_buffer.size, m_position, m_buffer.drmPixelFormat, m_buffer.bytesPerLine); + auto *wlItem = m_hwLayer->waylandItem(); - m_screen = wlItem->window()->screen(); - m_layerIndex = QEglFSFunctions::vsp2AddLayer(m_screen, m_buffer.dmabufFd, m_buffer.size, m_position, m_buffer.drmPixelFormat, m_buffer.bytesPerLine); wlItem->surface()->frameStarted(); updateOpacity(); } void Vsp2Layer::disableVspLayer() { - QEglFSFunctions::vsp2RemoveLayer(m_screen, m_layerIndex); + m_screen->removeLayer(m_layerIndex); m_layerIndex = -1; m_screen = nullptr; } @@ -112,9 +93,9 @@ void Vsp2Layer::handleBufferCommitted() } m_buffer = newBuffer; + m_screen->setLayerBuffer(m_layerIndex, m_buffer.dmabufFd); + auto *wlItem = m_hwLayer->waylandItem(); - m_screen = wlItem->window()->screen(); - QEglFSFunctions::vsp2SetLayerBuffer(m_screen, m_layerIndex, m_buffer.dmabufFd); wlItem->surface()->frameStarted(); } @@ -147,14 +128,14 @@ void Vsp2Layer::updatePosition() m_position = globalGeometry.topLeft().toPoint(); if (isEnabled()) - QEglFSFunctions::vsp2SetLayerPosition(m_screen, m_layerIndex, m_position); + m_screen->setLayerPosition(m_layerIndex, m_position); } void Vsp2Layer::updateOpacity() { if (isEnabled()) { qreal opacity = m_hwLayer->waylandItem()->opacity(); - QEglFSFunctions::vsp2SetLayerAlpha(m_screen, m_layerIndex, opacity); + m_screen->setLayerAlpha(m_layerIndex, opacity); } } @@ -181,7 +162,7 @@ wl_kms_buffer *Vsp2Layer::nextKmsBuffer() void Vsp2HardwareLayerIntegration::enableVspLayers() { - for (auto &layer : qAsConst(m_layers)) { + for (auto &layer : std::as_const(m_layers)) { Q_ASSERT(!layer->isEnabled()); layer->enableVspLayer(); } @@ -216,7 +197,8 @@ Vsp2HardwareLayerIntegration::Vsp2HardwareLayerIntegration() << "You need to set QT_QPA_PLATFORM=eglfs and QT_QPA_EGLFS_INTEGRATION=eglfs_kms_vsp2"; } static Vsp2HardwareLayerIntegration *s_instance = this; - QEglFSFunctions::vsp2AddBlendListener(QGuiApplication::primaryScreen(), [](){ + auto screen = dynamic_cast<QVsp2Screen*>(QGuiApplication::primaryScreen()->handle()); + screen->addBlendListener([](){ s_instance->sendFrameCallbacks(); }); } @@ -243,7 +225,7 @@ void Vsp2HardwareLayerIntegration::remove(QWaylandQuickHardwareLayer *hwLayer) void Vsp2HardwareLayerIntegration::sendFrameCallbacks() { - for (auto &layer : qAsConst(m_layers)) { + for (auto &layer : std::as_const(m_layers)) { if (auto *surface = layer->hwLayer()->waylandItem()->surface()) surface->sendFrameCallbacks(); } diff --git a/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.h b/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.h index 64b562d8e..3ec77957f 100644 --- a/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.h +++ b/src/hardwareintegration/compositor/hardwarelayer/vsp2/vsp2hardwarelayerintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef VSP2HARDWARELAYERINTEGRATION_H #define VSP2HARDWARELAYERINTEGRATION_H @@ -40,6 +14,10 @@ struct wl_kms_buffer; QT_BEGIN_NAMESPACE +namespace QNativeInterface::Private { +struct QVsp2Screen; +} + class QScreen; class QWaylandSurface; class QWaylandQuickHardwareLayer; @@ -56,7 +34,7 @@ public: void remove(QWaylandQuickHardwareLayer *layer) override; void sendFrameCallbacks(); - QVector<QSharedPointer<Vsp2Layer>> m_layers; + QList<QSharedPointer<Vsp2Layer>> m_layers; private: void enableVspLayers(); void disableVspLayers(); @@ -86,7 +64,7 @@ public: bool isEnabled() { return m_layerIndex != -1; } QWaylandQuickHardwareLayer *hwLayer() const { return m_hwLayer; } -public slots: +public Q_SLOTS: void handleBufferCommitted(); void handleSurfaceChanged(); void updatePosition(); @@ -95,7 +73,7 @@ public slots: private: wl_kms_buffer *nextKmsBuffer(); int m_layerIndex = -1; - QScreen *m_screen = nullptr; + QVsp2Screen *m_screen = nullptr; QPoint m_position; QWaylandQuickHardwareLayer *m_hwLayer = nullptr; QWaylandSurface *m_surface = nullptr; diff --git a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp index f9ef5635d..f28c6df6d 100644 --- a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp +++ b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "libhybriseglserverbufferintegration.h" diff --git a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h index addbb71f5..3759a3329 100644 --- a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h +++ b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef LIBHYBRISEGLSERVERBUFFERINTEGRATION_H #define LIBHYBRISEGLSERVERBUFFERINTEGRATION_H @@ -83,8 +57,8 @@ private: int32_t m_stride; QOpenGLTexture *m_texture = nullptr; QtWaylandServer::qt_libhybris_egl_server_buffer::format m_hybris_format; - QVector<int32_t> m_ints; - QVector<int32_t> m_fds; + QList<int32_t> m_ints; + QList<int32_t> m_fds; }; class LibHybrisEglServerBufferIntegration : diff --git a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linux-dmabuf-unstable-v1.pri b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linux-dmabuf-unstable-v1.pri index a7630040e..a8baefc98 100644 --- a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linux-dmabuf-unstable-v1.pri +++ b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linux-dmabuf-unstable-v1.pri @@ -1,12 +1,10 @@ INCLUDEPATH += $$PWD -QMAKE_USE_PRIVATE += egl wayland-server +QMAKE_USE_PRIVATE += egl drm wayland-server CONFIG += wayland-scanner WAYLANDSERVERSOURCES += $$PWD/../../../3rdparty/protocol/linux-dmabuf-unstable-v1.xml -QT += egl_support-private - SOURCES += \ $$PWD/linuxdmabufclientbufferintegration.cpp \ $$PWD/linuxdmabuf.cpp diff --git a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.cpp b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.cpp index 28015d35b..a608b9c4d 100644 --- a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.cpp +++ b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.cpp @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "linuxdmabuf.h" #include "linuxdmabufclientbufferintegration.h" #include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/private/qwltextureorphanage_p.h> #include <drm_fourcc.h> #include <drm_mode.h> @@ -44,7 +19,7 @@ LinuxDmabuf::LinuxDmabuf(wl_display *display, LinuxDmabufClientBufferIntegration { } -void LinuxDmabuf::setSupportedModifiers(const QHash<uint32_t, QVector<uint64_t>> &modifiers) +void LinuxDmabuf::setSupportedModifiers(const QHash<uint32_t, QList<uint64_t>> &modifiers) { Q_ASSERT(resourceMap().isEmpty()); m_modifiers = modifiers; @@ -58,7 +33,7 @@ void LinuxDmabuf::zwp_linux_dmabuf_v1_bind_resource(Resource *resource) // send DRM_FORMAT_MOD_INVALID when no modifiers are supported for a format if (modifiers.isEmpty()) modifiers << DRM_FORMAT_MOD_INVALID; - for (const auto &modifier : qAsConst(modifiers)) { + for (const auto &modifier : std::as_const(modifiers)) { if (resource->version() >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) { const uint32_t modifier_lo = modifier & 0xFFFFFFFF; const uint32_t modifier_hi = modifier >> 32; @@ -118,7 +93,7 @@ bool LinuxDmabufParams::handleCreateParams(Resource *resource, int width, int he // check for holes in plane sequence auto planeIds = m_planes.keys(); std::sort(planeIds.begin(), planeIds.end()); - for (int i = 0; i < planeIds.count(); ++i) { + for (int i = 0; i < planeIds.size(); ++i) { if (uint(i) != planeIds[i]) { wl_resource_post_error(resource->handle, ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, @@ -283,10 +258,17 @@ LinuxDmabufWlBuffer::~LinuxDmabufWlBuffer() void LinuxDmabufWlBuffer::buffer_destroy(Resource *resource) { Q_UNUSED(resource); + + QMutexLocker locker(&m_texturesLock); + for (uint32_t i = 0; i < m_planesNumber; ++i) { if (m_textures[i] != nullptr) { - m_clientBufferIntegration->deleteGLTextureWhenPossible(m_textures[i]); + QtWayland::QWaylandTextureOrphanage::instance()->admitTexture(m_textures[i], + m_texturesContext[i]); m_textures[i] = nullptr; + m_texturesContext[i] = nullptr; + QObject::disconnect(m_texturesAboutToBeDestroyedConnection[i]); + m_texturesAboutToBeDestroyedConnection[i] = QMetaObject::Connection(); } if (m_eglImages[i] != EGL_NO_IMAGE_KHR) { m_clientBufferIntegration->deleteImage(m_eglImages[i]); @@ -308,9 +290,40 @@ void LinuxDmabufWlBuffer::initImage(uint32_t plane, EGLImageKHR image) void LinuxDmabufWlBuffer::initTexture(uint32_t plane, QOpenGLTexture *texture) { + QMutexLocker locker(&m_texturesLock); + Q_ASSERT(plane < m_planesNumber); Q_ASSERT(m_textures.at(plane) == nullptr); + Q_ASSERT(QOpenGLContext::currentContext()); m_textures[plane] = texture; + m_texturesContext[plane] = QOpenGLContext::currentContext(); + + m_texturesAboutToBeDestroyedConnection[plane] = + QObject::connect(m_texturesContext[plane], &QOpenGLContext::aboutToBeDestroyed, + m_texturesContext[plane], [this, plane]() { + + QMutexLocker locker(&this->m_texturesLock); + + // See above lock - there is a chance that this has already been removed from m_textures[plane]! + // Furthermore, we can trust that all the rest (e.g. disconnect) has also been properly executed! + if (this->m_textures[plane] == nullptr) + return; + + delete this->m_textures[plane]; + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO + << "texture deleted due to QOpenGLContext::aboutToBeDestroyed!" + << "Pointer (now dead) was:" << (void*)(this->m_textures[plane]) + << " Associated context (about to die too) is: " << (void*)(this->m_texturesContext[plane]); + + this->m_textures[plane] = nullptr; + this->m_texturesContext[plane] = nullptr; + + QObject::disconnect(this->m_texturesAboutToBeDestroyedConnection[plane]); + this->m_texturesAboutToBeDestroyedConnection[plane] = QMetaObject::Connection(); + + }, Qt::DirectConnection); } void LinuxDmabufWlBuffer::buffer_destroy_resource(Resource *resource) diff --git a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.h b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.h index 8554721e1..dba4e3980 100644 --- a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.h +++ b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabuf.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef LINUXDMABUF_H #define LINUXDMABUF_H @@ -35,11 +9,15 @@ #include <QtWaylandCompositor/private/qwayland-server-wayland.h> #include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> +#include <QtOpenGL/QOpenGLTexture> #include <QtCore/QObject> #include <QtCore/QHash> #include <QtCore/QSize> #include <QtCore/QTextStream> -#include <QtGui/QOpenGLTexture> + +#include <array> +#include <QtGui/QOpenGLContext> +#include <QtCore/QMutex> #include <EGL/egl.h> #include <EGL/eglext.h> @@ -58,6 +36,12 @@ #define DRM_FORMAT_MOD_INVALID fourcc_mod_code(NONE, DRM_FORMAT_RESERVED) #endif +// Copied from eglmesaext.h +#ifndef EGL_WL_bind_wayland_display +typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display); +#endif + QT_BEGIN_NAMESPACE class QWaylandCompositor; @@ -77,14 +61,14 @@ class LinuxDmabuf : public QtWaylandServer::zwp_linux_dmabuf_v1 public: explicit LinuxDmabuf(wl_display *display, LinuxDmabufClientBufferIntegration *clientBufferIntegration); - void setSupportedModifiers(const QHash<uint32_t, QVector<uint64_t>> &modifiers); + void setSupportedModifiers(const QHash<uint32_t, QList<uint64_t>> &modifiers); protected: void zwp_linux_dmabuf_v1_bind_resource(Resource *resource) override; void zwp_linux_dmabuf_v1_create_params(Resource *resource, uint32_t params_id) override; private: - QHash<uint32_t, QVector<uint64_t>> m_modifiers; // key=DRM format, value=supported DRM modifiers for format + QHash<uint32_t, QList<uint64_t>> m_modifiers; // key=DRM format, value=supported DRM modifiers for format LinuxDmabufClientBufferIntegration *m_clientBufferIntegration; }; @@ -141,6 +125,10 @@ private: LinuxDmabufClientBufferIntegration *m_clientBufferIntegration = nullptr; std::array<EGLImageKHR, MaxDmabufPlanes> m_eglImages = { {EGL_NO_IMAGE_KHR, EGL_NO_IMAGE_KHR, EGL_NO_IMAGE_KHR, EGL_NO_IMAGE_KHR} }; std::array<QOpenGLTexture *, MaxDmabufPlanes> m_textures = { {nullptr, nullptr, nullptr, nullptr} }; + std::array<QOpenGLContext *, MaxDmabufPlanes> m_texturesContext = { {nullptr, nullptr, nullptr, nullptr} }; + std::array<QMetaObject::Connection, MaxDmabufPlanes> m_texturesAboutToBeDestroyedConnection = { {QMetaObject::Connection(), QMetaObject::Connection(), QMetaObject::Connection(), QMetaObject::Connection()} }; + QMutex m_texturesLock; + void freeResources(); void buffer_destroy(Resource *resource) override; diff --git a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.cpp b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.cpp index fc711e5a1..205f25d1f 100644 --- a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.cpp +++ b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.cpp @@ -1,41 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "linuxdmabufclientbufferintegration.h" #include "linuxdmabuf.h" #include <QtWaylandCompositor/QWaylandCompositor> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> +#include <QtWaylandCompositor/private/qwltextureorphanage_p.h> #include <qpa/qplatformnativeinterface.h> +#include <QtOpenGL/QOpenGLTexture> +#include <QtCore/QVarLengthArray> #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <EGL/egl.h> #include <EGL/eglext.h> @@ -105,6 +81,11 @@ static QOpenGLTexture::TextureFormat openGLFormatFromBufferFormat(QWaylandBuffer } } +// Initialize the EGLImage for a dmabuf buffer which conceptually consists of a +// single plane. Note that depending on the modifiers, the buffer may be actually +// transported as multiple dmabuf planes which must be combined into a single +// EGLImage. For formats where the buffer needs to be represented as multiple +// EGLImages (e.g., various YUV formats) a different approach is required. bool LinuxDmabufClientBufferIntegration::initSimpleTexture(LinuxDmabufWlBuffer *dmabufBuffer) { bool success = true; @@ -118,79 +99,67 @@ bool LinuxDmabufClientBufferIntegration::initSimpleTexture(LinuxDmabufWlBuffer * success = false; } - for (uint32_t i = 0; i < dmabufBuffer->planesNumber(); ++i) { - QVarLengthArray<EGLint, 17> attribs; - switch (i) { - case 0: - attribs = { - EGL_WIDTH, dmabufBuffer->size().width(), - EGL_HEIGHT, dmabufBuffer->size().height(), - EGL_LINUX_DRM_FOURCC_EXT, EGLint(dmabufBuffer->drmFormat()), - EGL_DMA_BUF_PLANE0_FD_EXT, dmabufBuffer->plane(i).fd, - EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGLint(dmabufBuffer->plane(i).offset), - EGL_DMA_BUF_PLANE0_PITCH_EXT, EGLint(dmabufBuffer->plane(i).stride), - EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGLint(dmabufBuffer->plane(i).modifiers & 0xffffffff), - EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, EGLint(dmabufBuffer->plane(i).modifiers >> 32), - EGL_NONE - }; - break; - case 1: - attribs = { - EGL_WIDTH, dmabufBuffer->size().width(), - EGL_HEIGHT, dmabufBuffer->size().height(), - EGL_LINUX_DRM_FOURCC_EXT, EGLint(dmabufBuffer->drmFormat()), - EGL_DMA_BUF_PLANE1_FD_EXT, dmabufBuffer->plane(i).fd, - EGL_DMA_BUF_PLANE1_OFFSET_EXT, EGLint(dmabufBuffer->plane(i).offset), - EGL_DMA_BUF_PLANE1_PITCH_EXT, EGLint(dmabufBuffer->plane(i).stride), - EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, EGLint(dmabufBuffer->plane(i).modifiers & 0xffffffff), - EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT, EGLint(dmabufBuffer->plane(i).modifiers >> 32), - EGL_NONE - }; - break; - case 2: - attribs = { - EGL_WIDTH, dmabufBuffer->size().width(), - EGL_HEIGHT, dmabufBuffer->size().height(), - EGL_LINUX_DRM_FOURCC_EXT, EGLint(dmabufBuffer->drmFormat()), - EGL_DMA_BUF_PLANE2_FD_EXT, dmabufBuffer->plane(i).fd, - EGL_DMA_BUF_PLANE2_OFFSET_EXT, EGLint(dmabufBuffer->plane(i).offset), - EGL_DMA_BUF_PLANE2_PITCH_EXT, EGLint(dmabufBuffer->plane(i).stride), - EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, EGLint(dmabufBuffer->plane(i).modifiers & 0xffffffff), - EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT, EGLint(dmabufBuffer->plane(i).modifiers >> 32), - EGL_NONE - }; - break; - case 3: - attribs = { - EGL_WIDTH, dmabufBuffer->size().width(), - EGL_HEIGHT, dmabufBuffer->size().height(), - EGL_LINUX_DRM_FOURCC_EXT, EGLint(dmabufBuffer->drmFormat()), - EGL_DMA_BUF_PLANE3_FD_EXT, dmabufBuffer->plane(i).fd, - EGL_DMA_BUF_PLANE3_OFFSET_EXT, EGLint(dmabufBuffer->plane(i).offset), - EGL_DMA_BUF_PLANE3_PITCH_EXT, EGLint(dmabufBuffer->plane(i).stride), - EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, EGLint(dmabufBuffer->plane(i).modifiers & 0xffffffff), - EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT, EGLint(dmabufBuffer->plane(i).modifiers >> 32), - EGL_NONE - }; + // 6 entries for the common attribs plus 10 per possible plane, plus 1 for + // the final EGL_NONE sentinel. + QVarLengthArray<EGLint, 6 + 10 * 4 + 1> attribs; + + attribs.append(EGL_WIDTH); + attribs.append(dmabufBuffer->size().width()); + attribs.append(EGL_HEIGHT); + attribs.append(dmabufBuffer->size().height()); + attribs.append(EGL_LINUX_DRM_FOURCC_EXT); + attribs.append(EGLint(dmabufBuffer->drmFormat())); + +#define ADD_PLANE_ATTRIBS(plane_idx) { \ + attribs.append(EGL_DMA_BUF_PLANE ## plane_idx ## _FD_EXT); \ + attribs.append(dmabufBuffer->plane(plane_idx).fd); \ + attribs.append(EGL_DMA_BUF_PLANE ## plane_idx ## _OFFSET_EXT); \ + attribs.append(EGLint(dmabufBuffer->plane(plane_idx).offset)); \ + attribs.append(EGL_DMA_BUF_PLANE ## plane_idx ## _PITCH_EXT); \ + attribs.append(EGLint(dmabufBuffer->plane(plane_idx).stride)); \ + if (dmabufBuffer->plane(plane_idx).modifiers != DRM_FORMAT_MOD_INVALID) { \ + attribs.append(EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_LO_EXT); \ + attribs.append(EGLint(dmabufBuffer->plane(plane_idx).modifiers & 0xffffffff)); \ + attribs.append(EGL_DMA_BUF_PLANE ## plane_idx ## _MODIFIER_HI_EXT); \ + attribs.append(EGLint(dmabufBuffer->plane(plane_idx).modifiers >> 32)); \ + } \ +} + + switch (dmabufBuffer->planesNumber()) { + case 4: + ADD_PLANE_ATTRIBS(3); + Q_FALLTHROUGH(); + case 3: + ADD_PLANE_ATTRIBS(2); + Q_FALLTHROUGH(); + case 2: + ADD_PLANE_ATTRIBS(1); + Q_FALLTHROUGH(); + case 1: + ADD_PLANE_ATTRIBS(0); break; - default: - return false; - } + default: + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Buffer uses invalid number of planes:" << dmabufBuffer->planesNumber(); + return false; + } - // note: EGLImageKHR does NOT take ownership of the file descriptors - EGLImageKHR image = egl_create_image(m_eglDisplay, - EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, - (EGLClientBuffer) nullptr, - attribs.constData()); + attribs.append(EGL_NONE); - if (image == EGL_NO_IMAGE_KHR) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "failed to create EGL image for plane" << i; - success = false; - } + // note: EGLImageKHR does NOT take ownership of the file descriptors + EGLImageKHR image = egl_create_image(m_eglDisplay, + EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + (EGLClientBuffer) nullptr, + attribs.constData()); - dmabufBuffer->initImage(i, image); + if (image == EGL_NO_IMAGE_KHR) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "failed to create EGL image from" << + dmabufBuffer->planesNumber() << "plane(s)"; + success = false; } + + dmabufBuffer->initImage(0, image); + return success; } @@ -273,9 +242,15 @@ LinuxDmabufClientBufferIntegration::LinuxDmabufClientBufferIntegration() LinuxDmabufClientBufferIntegration::~LinuxDmabufClientBufferIntegration() { m_importedBuffers.clear(); + + if (egl_unbind_wayland_display != nullptr && m_displayBound) { + Q_ASSERT(m_wlDisplay != nullptr); + if (!egl_unbind_wayland_display(m_eglDisplay, m_wlDisplay)) + qCWarning(qLcWaylandCompositorHardwareIntegration) << "eglUnbindWaylandDisplayWL failed"; + } } -bool LinuxDmabufClientBufferIntegration::initializeHardware(struct ::wl_display *display) +void LinuxDmabufClientBufferIntegration::initializeHardware(struct ::wl_display *display) { m_linuxDmabuf.reset(new LinuxDmabuf(display, this)); @@ -286,107 +261,94 @@ bool LinuxDmabufClientBufferIntegration::initializeHardware(struct ::wl_display egl_query_dmabuf_formats_ext = reinterpret_cast<PFNEGLQUERYDMABUFFORMATSEXTPROC>(eglGetProcAddress("eglQueryDmaBufFormatsEXT")); if (!egl_query_dmabuf_modifiers_ext || !egl_query_dmabuf_formats_ext) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglQueryDmaBufModifiersEXT and eglQueryDmaBufFormatsEXT."; - return false; + return; } egl_bind_wayland_display = reinterpret_cast<PFNEGLBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglBindWaylandDisplayWL")); egl_unbind_wayland_display = reinterpret_cast<PFNEGLUNBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglUnbindWaylandDisplayWL")); if ((!egl_bind_wayland_display || !egl_unbind_wayland_display) && !ignoreBindDisplay) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglBindWaylandDisplayWL and eglUnbindWaylandDisplayWL."; - return false; + return; } egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR")); egl_destroy_image = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR")); if (!egl_create_image || !egl_destroy_image) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglCreateImageKHR and eglDestroyImageKHR."; - return false; + return; } // initialize EGL display QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); if (!nativeInterface) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. No native platform interface available."; - return false; + return; } m_eglDisplay = nativeInterface->nativeResourceForIntegration("EglDisplay"); if (!m_eglDisplay) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not get EglDisplay for window."; - return false; + return; } const char *extensionString = eglQueryString(m_eglDisplay, EGL_EXTENSIONS); if (!extensionString || !strstr(extensionString, "EGL_EXT_image_dma_buf_import")) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. There is no EGL_EXT_image_dma_buf_import extension."; - return false; + return; } if (strstr(extensionString, "EGL_EXT_image_dma_buf_import_modifiers")) m_supportsDmabufModifiers = true; if (egl_bind_wayland_display && egl_unbind_wayland_display) { m_displayBound = egl_bind_wayland_display(m_eglDisplay, display); - if (!m_displayBound) { - if (ignoreBindDisplay) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Could not bind Wayland display. Ignoring."; - } else { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not bind Wayland display."; - return false; - } - } + if (!m_displayBound) + qCDebug(qLcWaylandCompositorHardwareIntegration) << "Wayland display already bound by other client buffer integration."; + m_wlDisplay = display; } // request and sent formats/modifiers only after egl_display is bound - QHash<uint32_t, QVector<uint64_t>> modifiers; + QHash<uint32_t, QList<uint64_t>> modifiers; for (const auto &format : supportedDrmFormats()) { modifiers[format] = supportedDrmModifiers(format); } m_linuxDmabuf->setSupportedModifiers(modifiers); - return true; } -QVector<uint32_t> LinuxDmabufClientBufferIntegration::supportedDrmFormats() +QList<uint32_t> LinuxDmabufClientBufferIntegration::supportedDrmFormats() { if (!egl_query_dmabuf_formats_ext) - return QVector<uint32_t>(); + return QList<uint32_t>(); // request total number of formats EGLint count = 0; EGLBoolean success = egl_query_dmabuf_formats_ext(m_eglDisplay, 0, nullptr, &count); if (success && count > 0) { - QVector<uint32_t> drmFormats(count); + QList<uint32_t> drmFormats(count); if (egl_query_dmabuf_formats_ext(m_eglDisplay, count, (EGLint *) drmFormats.data(), &count)) return drmFormats; } - return QVector<uint32_t>(); + return QList<uint32_t>(); } -QVector<uint64_t> LinuxDmabufClientBufferIntegration::supportedDrmModifiers(uint32_t format) +QList<uint64_t> LinuxDmabufClientBufferIntegration::supportedDrmModifiers(uint32_t format) { if (!egl_query_dmabuf_modifiers_ext) - return QVector<uint64_t>(); + return QList<uint64_t>(); // request total number of formats EGLint count = 0; EGLBoolean success = egl_query_dmabuf_modifiers_ext(m_eglDisplay, format, 0, nullptr, nullptr, &count); if (success && count > 0) { - QVector<uint64_t> modifiers(count); + QList<uint64_t> modifiers(count); if (egl_query_dmabuf_modifiers_ext(m_eglDisplay, format, count, modifiers.data(), nullptr, &count)) { return modifiers; } } - return QVector<uint64_t>(); -} - -void LinuxDmabufClientBufferIntegration::deleteOrphanedTextures() -{ - Q_ASSERT(QOpenGLContext::currentContext()); - qDeleteAll(m_orphanedTextures); - m_orphanedTextures.clear(); + return QList<uint64_t>(); } void LinuxDmabufClientBufferIntegration::deleteImage(EGLImageKHR image) @@ -396,16 +358,12 @@ void LinuxDmabufClientBufferIntegration::deleteImage(EGLImageKHR image) QtWayland::ClientBuffer *LinuxDmabufClientBufferIntegration::createBufferFor(wl_resource *resource) { - // fallback for shared memory buffers - if (wl_shm_buffer_get(resource)) - return nullptr; - auto it = m_importedBuffers.find(resource); if (it != m_importedBuffers.end()) { m_importedBuffers.value(resource); return new LinuxDmabufClientBuffer(this, it.value()->resource()->handle, m_importedBuffers.value(resource)); } - qCWarning(qLcWaylandCompositorHardwareIntegration) << "could not create client buffer for dmabuf buffer"; + return nullptr; } @@ -439,7 +397,7 @@ LinuxDmabufClientBuffer::LinuxDmabufClientBuffer(LinuxDmabufClientBufferIntegrat QOpenGLTexture *LinuxDmabufClientBuffer::toOpenGlTexture(int plane) { // At this point we should have a valid OpenGL context, so it's safe to destroy textures - m_integration->deleteOrphanedTextures(); + QtWayland::QWaylandTextureOrphanage::instance()->deleteTextures(); if (!m_buffer) return nullptr; @@ -457,6 +415,7 @@ QOpenGLTexture *LinuxDmabufClientBuffer::toOpenGlTexture(int plane) } if (m_textureDirty) { + m_textureDirty = false; texture->bind(); glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); m_integration->gl_egl_image_target_texture_2d(target, d->image(plane)); diff --git a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.h b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.h index 8909fa89f..b72a24d5d 100644 --- a/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.h +++ b/src/hardwareintegration/compositor/linux-dmabuf-unstable-v1/linuxdmabufclientbufferintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef LINUXDMABUFCLIENTBUFFERINTEGRATION_H #define LINUXDMABUFCLIENTBUFFERINTEGRATION_H @@ -35,6 +9,7 @@ #include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> #include <QtWaylandCompositor/private/qwlclientbuffer_p.h> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> +#include <QtCore/QMutex> #include <drm_fourcc.h> @@ -67,13 +42,11 @@ public: LinuxDmabufClientBufferIntegration(); ~LinuxDmabufClientBufferIntegration() override; - bool initializeHardware(struct ::wl_display *display) override; + void initializeHardware(struct ::wl_display *display) override; QtWayland::ClientBuffer *createBufferFor(wl_resource *resource) override; bool importBuffer(wl_resource *resource, LinuxDmabufWlBuffer *linuxDmabufBuffer); void removeBuffer(wl_resource *resource); - void deleteOrphanedTextures(); void deleteImage(EGLImageKHR image); - void deleteGLTextureWhenPossible(QOpenGLTexture *texture) { m_orphanedTextures << texture; } PFNGLEGLIMAGETARGETTEXTURE2DOESPROC gl_egl_image_target_texture_2d = nullptr; private: @@ -88,12 +61,13 @@ private: bool initSimpleTexture(LinuxDmabufWlBuffer *dmabufBuffer); bool initYuvTexture(LinuxDmabufWlBuffer *dmabufBuffer); - QVector<uint32_t> supportedDrmFormats(); - QVector<uint64_t> supportedDrmModifiers(uint32_t format); + QList<uint32_t> supportedDrmFormats(); + QList<uint64_t> supportedDrmModifiers(uint32_t format); EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; + ::wl_display *m_wlDisplay = nullptr; bool m_displayBound = false; - QVector<QOpenGLTexture *> m_orphanedTextures; + QHash<EGLint, YuvFormatConversion> m_yuvFormats; bool m_supportsDmabufModifiers = false; QHash<struct ::wl_resource *, LinuxDmabufWlBuffer *> m_importedBuffers; diff --git a/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.cpp b/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.cpp index 7d7efee36..6dc99e193 100644 --- a/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.cpp +++ b/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.cpp @@ -1,36 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "shmserverbufferintegration.h" +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <QtCore/QSharedMemory> #include <QtCore/QDebug> @@ -59,7 +33,8 @@ ShmServerBuffer::ShmServerBuffer(ShmServerBufferIntegration *integration, const } QString key = "qt_shm_emulation_" + QString::number(qimage.cacheKey()); - m_shm = new QSharedMemory(key); + // ### Use proper native keys the next time we can break protocol compatibility + QT_IGNORE_DEPRECATIONS(m_shm = new QSharedMemory(key);) qsizetype shm_size = qimage.sizeInBytes(); bool ok = m_shm->create(shm_size) && m_shm->lock(); if (ok) { @@ -86,7 +61,8 @@ struct ::wl_resource *ShmServerBuffer::resourceForClient(struct ::wl_client *cli } struct ::wl_resource *shm_integration_resource = integrationResource->handle; Resource *resource = add(client, 1); - m_integration->send_server_buffer_created(shm_integration_resource, resource->handle, m_shm->key(), m_width, m_height, m_bpl, m_shm_format); + QT_IGNORE_DEPRECATIONS(const QString shmKey = m_shm->key();) + m_integration->send_server_buffer_created(shm_integration_resource, resource->handle, shmKey, m_width, m_height, m_bpl, m_shm_format); return resource->handle; } return bufferResource->handle; @@ -94,7 +70,7 @@ struct ::wl_resource *ShmServerBuffer::resourceForClient(struct ::wl_client *cli bool ShmServerBuffer::bufferInUse() { - return resourceMap().count() > 0; + return resourceMap().size() > 0; } QOpenGLTexture *ShmServerBuffer::toOpenGlTexture() diff --git a/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.h b/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.h index 95439f080..527e65cb7 100644 --- a/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.h +++ b/src/hardwareintegration/compositor/shm-emulation-server/shmserverbufferintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef SHMSERVERBUFFERINTEGRATION_H #define SHMSERVERBUFFERINTEGRATION_H diff --git a/src/hardwareintegration/compositor/vulkan-server/vulkan-server.pri b/src/hardwareintegration/compositor/vulkan-server/vulkan-server.pri index 63a96ad0f..9a457a173 100644 --- a/src/hardwareintegration/compositor/vulkan-server/vulkan-server.pri +++ b/src/hardwareintegration/compositor/vulkan-server/vulkan-server.pri @@ -1,8 +1,7 @@ INCLUDEPATH += $$PWD $$PWD/../../../3rdparty/util -QT += vulkan_support-private - QMAKE_USE_PRIVATE += wayland-server +QT += opengl-private SOURCES += \ $$PWD/vulkanserverbufferintegration.cpp \ diff --git a/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.cpp b/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.cpp index 69af5f9f2..1b5aea29a 100644 --- a/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.cpp +++ b/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.cpp @@ -1,38 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "vulkanserverbufferintegration.h" #include "vulkanwrapper.h" +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <QtGui/QOffscreenSurface> #include <QtGui/qopengl.h> @@ -42,7 +16,7 @@ #include <QtCore/QDebug> QT_BEGIN_NAMESPACE -static constexpr bool extraDebug = false; +static constexpr bool vsbiExtraDebug = false; #define DECL_GL_FUNCTION(name, type) \ type name @@ -205,7 +179,7 @@ QOpenGLTexture *VulkanServerBuffer::toOpenGlTexture() return nullptr; funcs->glCreateMemoryObjectsEXT(1, &m_memoryObject); - if (extraDebug) qDebug() << "glCreateMemoryObjectsEXT" << Qt::hex << glGetError(); + if (vsbiExtraDebug) qDebug() << "glCreateMemoryObjectsEXT" << Qt::hex << glGetError(); int dupfd = fcntl(m_fd, F_DUPFD_CLOEXEC, 0); @@ -215,7 +189,7 @@ QOpenGLTexture *VulkanServerBuffer::toOpenGlTexture() } funcs->glImportMemoryFdEXT(m_memoryObject, m_memorySize, GL_HANDLE_TYPE_OPAQUE_FD_EXT, dupfd); - if (extraDebug) qDebug() << "glImportMemoryFdEXT" << Qt::hex << glGetError(); + if (vsbiExtraDebug) qDebug() << "glImportMemoryFdEXT" << Qt::hex << glGetError(); if (!m_texture) @@ -223,13 +197,13 @@ QOpenGLTexture *VulkanServerBuffer::toOpenGlTexture() m_texture->create(); GLuint texId = m_texture->textureId(); - if (extraDebug) qDebug() << "created texture" << texId << Qt::hex << glGetError(); + if (vsbiExtraDebug) qDebug() << "created texture" << texId << Qt::hex << glGetError(); m_texture->bind(); - if (extraDebug) qDebug() << "bound texture" << texId << Qt::hex << glGetError(); + if (vsbiExtraDebug) qDebug() << "bound texture" << texId << Qt::hex << glGetError(); funcs->glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, m_glInternalFormat, m_size.width(), m_size.height(), m_memoryObject, 0 ); - if (extraDebug) qDebug() << "glTexStorageMem2DEXT" << Qt::hex << glGetError(); - if (extraDebug) qDebug() << "format" << Qt::hex << m_glInternalFormat << GL_RGBA8; + if (vsbiExtraDebug) qDebug() << "glTexStorageMem2DEXT" << Qt::hex << glGetError(); + if (vsbiExtraDebug) qDebug() << "format" << Qt::hex << m_glInternalFormat << GL_RGBA8; return m_texture; @@ -248,7 +222,7 @@ void VulkanServerBuffer::releaseOpenGlTexture() bool VulkanServerBuffer::bufferInUse() { - return (m_texture && m_texture->isCreated()) || resourceMap().count() > 0; + return (m_texture && m_texture->isCreated()) || resourceMap().size() > 0; } void VulkanServerBuffer::server_buffer_release(Resource *resource) @@ -294,14 +268,17 @@ QtWayland::ServerBuffer *VulkanServerBufferIntegration::createServerBufferFromIm return new VulkanServerBuffer(this, qimage, format); } -QtWayland::ServerBuffer *VulkanServerBufferIntegration::createServerBufferFromData(const QByteArray &data, const QSize &size, uint glInternalFormat) +QtWayland::ServerBuffer * +VulkanServerBufferIntegration::createServerBufferFromData(QByteArrayView view, const QSize &size, + uint glInternalFormat) { if (!m_vulkanWrapper) { CurrentContext current; m_vulkanWrapper = new VulkanWrapper(current.context()); } - auto *vImage = m_vulkanWrapper->createTextureImageFromData(reinterpret_cast<const uchar*>(data.constData()), data.size(), size, glInternalFormat); + auto *vImage = m_vulkanWrapper->createTextureImageFromData( + reinterpret_cast<const uchar *>(view.constData()), view.size(), size, glInternalFormat); if (vImage) return new VulkanServerBuffer(this, vImage, glInternalFormat, size); diff --git a/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.h b/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.h index 6e2c51dd4..ab1899fb2 100644 --- a/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.h +++ b/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef VULKANSERVERBUFFERINTEGRATION_H #define VULKANSERVERBUFFERINTEGRATION_H @@ -90,7 +64,8 @@ public: bool supportsFormat(QtWayland::ServerBuffer::Format format) const override; QtWayland::ServerBuffer *createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override; - QtWayland::ServerBuffer *createServerBufferFromData(const QByteArray &data, const QSize &size, uint glInternalFormat) override; + QtWayland::ServerBuffer *createServerBufferFromData(QByteArrayView view, const QSize &size, + uint glInternalFormat) override; private: VulkanWrapper *m_vulkanWrapper = nullptr; diff --git a/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.cpp b/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.cpp index 608609d6c..bf3700aec 100644 --- a/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.cpp +++ b/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // NOTE: Some of the code below is adapted from the public domain code at https://vulkan-tutorial.com/ @@ -34,9 +8,10 @@ #include "vulkanwrapper.h" #include <QImage> +#include <QVarLengthArray> #include <QOpenGLContext> #include <QtGui/qopengl.h> -#include <QtVulkanSupport/private/qvkconvenience_p.h> +#include <QtOpenGL/private/qvkconvenience_p.h> #include <set> @@ -46,7 +21,7 @@ QT_BEGIN_NAMESPACE -static constexpr bool extraDebug = false; +static constexpr bool vwExtraDebug = false; #define DECL_VK_FUNCTION(name) \ PFN_ ## name name = nullptr; @@ -225,7 +200,7 @@ VulkanImageWrapper *VulkanWrapperPrivate::createImage(VkFormat format, VkImageTi return nullptr; } - QScopedPointer<VulkanImageWrapper> imageWrapper(new VulkanImageWrapper); + std::unique_ptr imageWrapper = std::make_unique<VulkanImageWrapper>(); imageWrapper->textureImage = image; imageWrapper->imgMemSize = memSize; imageWrapper->imgSize = size; @@ -253,7 +228,7 @@ VulkanImageWrapper *VulkanWrapperPrivate::createImage(VkFormat format, VkImageTi int res = vkBindImageMemory(m_device, image, imageWrapper->textureImageMemory, 0); Q_UNUSED(res); - if (extraDebug) qDebug() << "vkBindImageMemory res" << res; + if (vwExtraDebug) qDebug() << "vkBindImageMemory res" << res; VkMemoryGetFdInfoKHR memoryFdInfo = {}; memoryFdInfo.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; @@ -261,9 +236,9 @@ VulkanImageWrapper *VulkanWrapperPrivate::createImage(VkFormat format, VkImageTi memoryFdInfo.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; res = vkGetMemoryFdKHR(m_device, &memoryFdInfo, &imageWrapper->imgFd); - if (extraDebug) qDebug() << "vkGetMemoryFdKHR res" << res << "fd" << imageWrapper->imgFd; + if (vwExtraDebug) qDebug() << "vkGetMemoryFdKHR res" << res << "fd" << imageWrapper->imgFd; - return imageWrapper.take(); + return imageWrapper.release(); } @@ -356,19 +331,19 @@ VkCommandBuffer VulkanWrapperPrivate::beginSingleTimeCommands() allocInfo.commandPool = m_commandPool; allocInfo.commandBufferCount = 1; - if (extraDebug) qDebug() << "allocating..."; + if (vwExtraDebug) qDebug() << "allocating..."; VkCommandBuffer commandBuffer; int res = vkAllocateCommandBuffers(m_device, &allocInfo, &commandBuffer); Q_UNUSED(res); - if (extraDebug) qDebug() << "vkAllocateCommandBuffers res" << res; + if (vwExtraDebug) qDebug() << "vkAllocateCommandBuffers res" << res; VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; res = vkBeginCommandBuffer(commandBuffer, &beginInfo); - if (extraDebug) qDebug() << "BEGIN res" << res; + if (vwExtraDebug) qDebug() << "BEGIN res" << res; return commandBuffer; } @@ -377,7 +352,7 @@ void VulkanWrapperPrivate::endSingleTimeCommands(VkCommandBuffer commandBuffer) { int res = vkEndCommandBuffer(commandBuffer); Q_UNUSED(res); - if (extraDebug) qDebug() << "END res" << res; + if (vwExtraDebug) qDebug() << "END res" << res; VkSubmitInfo submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; @@ -434,7 +409,7 @@ QueueFamilyIndices VulkanWrapperPrivate::findQueueFamilies(VkPhysicalDevice devi uint32_t queueFamilyCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr); - if (extraDebug) qDebug() << "queueFamilyCount" << queueFamilyCount; + if (vwExtraDebug) qDebug() << "queueFamilyCount" << queueFamilyCount; std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount); @@ -507,7 +482,7 @@ VulkanImageWrapper *VulkanWrapperPrivate::createTextureImageFromData(const uchar int texWidth = size.width(); int texHeight = size.height(); bool ok; - if (extraDebug) qDebug("image load %p %dx%d", pixels, texWidth, texHeight); + if (vwExtraDebug) qDebug("image load %p %dx%d", pixels, texWidth, texHeight); if (!pixels) { qCritical("VulkanWrapper: failed to load texture image!"); return nullptr; @@ -522,17 +497,17 @@ VulkanImageWrapper *VulkanWrapperPrivate::createTextureImageFromData(const uchar void* data; vkMapMemory(m_device, stagingBufferMemory, 0, bufferSize, 0, &data); - if (extraDebug) qDebug() << "mapped" << data << bufferSize; + if (vwExtraDebug) qDebug() << "mapped" << data << bufferSize; memcpy(data, pixels, static_cast<size_t>(bufferSize)); vkUnmapMemory(m_device, stagingBufferMemory); - if (extraDebug) qDebug() << "creating image..."; + if (vwExtraDebug) qDebug() << "creating image..."; - QScopedPointer<VulkanImageWrapper> imageWrapper(createImage(vkFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size, bufferSize)); - if (imageWrapper.isNull()) + std::unique_ptr<VulkanImageWrapper> imageWrapper(createImage(vkFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, size, bufferSize)); + if (!imageWrapper) return nullptr; - if (extraDebug) qDebug() << "transition..."; + if (vwExtraDebug) qDebug() << "transition..."; const VkImage textureImage = imageWrapper->textureImage; @@ -541,14 +516,14 @@ VulkanImageWrapper *VulkanWrapperPrivate::createTextureImageFromData(const uchar if (!ok) return nullptr; - if (extraDebug) qDebug() << "copyBufferToImage..."; + if (vwExtraDebug) qDebug() << "copyBufferToImage..."; copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight)); transitionImageLayout(textureImage, vkFormat, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); vkDestroyBuffer(m_device, stagingBuffer, nullptr); vkFreeMemory(m_device, stagingBufferMemory, nullptr); - return imageWrapper.take(); + return imageWrapper.release(); } void VulkanWrapperPrivate::freeTextureImage(VulkanImageWrapper *imageWrapper) @@ -566,7 +541,7 @@ void VulkanWrapperPrivate::freeTextureImage(VulkanImageWrapper *imageWrapper) VulkanWrapperPrivate::VulkanWrapperPrivate(QOpenGLContext *glContext) { - if (extraDebug) qDebug("Creating Vulkan instance"); + if (vwExtraDebug) qDebug("Creating Vulkan instance"); VkApplicationInfo applicationInfo = {}; applicationInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; applicationInfo.pNext = nullptr; @@ -598,7 +573,7 @@ VulkanWrapperPrivate::VulkanWrapperPrivate(QOpenGLContext *glContext) VkResult instanceCreationResult = vkCreateInstance(&instanceCreateInfo, nullptr, &m_instance); - if (extraDebug) qDebug() << "result" << instanceCreationResult; + if (vwExtraDebug) qDebug() << "result" << instanceCreationResult; if (instanceCreationResult != VK_SUCCESS) { qCritical() << "VulkanWrapper: Failed to create Vulkan instance: Error " @@ -610,12 +585,12 @@ VulkanWrapperPrivate::VulkanWrapperPrivate(QOpenGLContext *glContext) uint32_t devCount; auto res = vkEnumeratePhysicalDevices(m_instance, &devCount, nullptr); - if (extraDebug) qDebug() << "vkEnumeratePhysicalDevices res =" << res << "count =" << devCount; + if (vwExtraDebug) qDebug() << "vkEnumeratePhysicalDevices res =" << res << "count =" << devCount; QVarLengthArray<VkPhysicalDevice, 5> dev(devCount); res = vkEnumeratePhysicalDevices(m_instance, &devCount, dev.data()); - if (extraDebug) qDebug() << "...devs res =" << res << "count =" << devCount; + if (vwExtraDebug) qDebug() << "...devs res =" << res << "count =" << devCount; #ifdef VULKAN_SERVER_BUFFER_EXTRA_DEBUG VkPhysicalDeviceProperties props; diff --git a/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.h b/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.h index 159e3ac84..a2f55fd75 100644 --- a/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.h +++ b/src/hardwareintegration/compositor/vulkan-server/vulkanwrapper.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef VULKANWRAPPER_H #define VULKANWRAPPER_H diff --git a/src/hardwareintegration/compositor/wayland-egl/CMakeLists.txt b/src/hardwareintegration/compositor/wayland-egl/CMakeLists.txt new file mode 100644 index 000000000..f31928550 --- /dev/null +++ b/src/hardwareintegration/compositor/wayland-egl/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## WaylandEglCompositorHwIntegrationPrivate Module: +##################################################################### +qt_find_package(EGL) # special case + +qt_internal_add_module(WaylandEglCompositorHwIntegrationPrivate + CONFIG_MODULE_NAME wayland_egl_compositor_hw_integration + INTERNAL_MODULE + SOURCES + waylandeglclientbufferintegration.cpp waylandeglclientbufferintegration_p.h + INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} + LIBRARIES + EGL::EGL + Wayland::Egl + Wayland::Server + PUBLIC_LIBRARIES + Qt::Core + Qt::Gui + Qt::WaylandCompositorPrivate + NO_GENERATE_CPP_EXPORTS +) + +qt_internal_extend_target(WaylandEglCompositorHwIntegrationPrivate CONDITION NOT QT_FEATURE_egl_x11 + DEFINES + QT_EGL_NO_X11 +) diff --git a/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri b/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri index e20c6802c..23615f316 100644 --- a/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri +++ b/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri @@ -2,10 +2,8 @@ INCLUDEPATH += $$PWD QMAKE_USE_PRIVATE += egl wayland-server wayland-egl -QT += egl_support-private - SOURCES += \ $$PWD/waylandeglclientbufferintegration.cpp HEADERS += \ - $$PWD/waylandeglclientbufferintegration.h + $$PWD/waylandeglclientbufferintegration_p.h diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp index cb3369c4b..c8819ba1f 100644 --- a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp +++ b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp @@ -1,39 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "waylandeglclientbufferintegration.h" +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "waylandeglclientbufferintegration_p.h" #include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/private/qwltextureorphanage_p.h> #include <qpa/qplatformnativeinterface.h> +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <QtGui/QOffscreenSurface> #include <qpa/qplatformscreen.h> #include <QtGui/QWindow> @@ -42,8 +17,9 @@ #include <QMutex> #include <QMutexLocker> +#include <QVarLengthArray> #include <QtCore/private/qcore_unix_p.h> -#include <QtEglSupport/private/qeglstreamconvenience_p.h> +#include <QtGui/private/qeglstreamconvenience_p.h> #ifndef GL_TEXTURE_EXTERNAL_OES #define GL_TEXTURE_EXTERNAL_OES 0x8D65 @@ -151,7 +127,11 @@ struct BufferState EGLint egl_format = EGL_TEXTURE_RGBA; QVarLengthArray<EGLImageKHR, 3> egl_images; - QOpenGLTexture *textures[3] = {}; + QOpenGLTexture *textures[3] = {nullptr, nullptr, nullptr}; + QOpenGLContext *texturesContext[3] = {nullptr, nullptr, nullptr}; + QMetaObject::Connection texturesAboutToBeDestroyedConnection[3] = {QMetaObject::Connection(), QMetaObject::Connection(), QMetaObject::Connection()}; + QMutex texturesLock; + EGLStreamKHR egl_stream = EGL_NO_STREAM_KHR; bool isYInverted = true; @@ -168,17 +148,15 @@ public: void initEglTexture(WaylandEglClientBuffer *buffer, EGLint format); bool ensureContext(); bool initEglStream(WaylandEglClientBuffer *buffer, struct ::wl_resource *bufferHandle); + void setupBufferAndCleanup(BufferState *bs, QOpenGLTexture *texture, int plane); void handleEglstreamTexture(WaylandEglClientBuffer *buffer, wl_resource *bufferHandle); void registerBuffer(struct ::wl_resource *buffer, BufferState state); - void deleteGLTextureWhenPossible(QOpenGLTexture *texture) { orphanedTextures << texture; } - void deleteOrphanedTextures(); EGLDisplay egl_display = EGL_NO_DISPLAY; bool display_bound = false; ::wl_display *wlDisplay = nullptr; QOffscreenSurface *offscreenSurface = nullptr; QOpenGLContext *localContext = nullptr; - QVector<QOpenGLTexture *> orphanedTextures; PFNEGLBINDWAYLANDDISPLAYWL egl_bind_wayland_display = nullptr; PFNEGLUNBINDWAYLANDDISPLAYWL egl_unbind_wayland_display = nullptr; @@ -259,7 +237,14 @@ void WaylandEglClientBufferIntegrationPrivate::initEglTexture(WaylandEglClientBu } for (int i = 0; i < planes; i++) { - const EGLint attribs[] = { EGL_WAYLAND_PLANE_WL, i, EGL_NONE }; + EGLint attribs[5] = { EGL_WAYLAND_PLANE_WL, i, EGL_NONE }; +#ifdef EGL_EXT_protected_content + if (buffer->isProtected()) { + attribs[2] = EGL_PROTECTED_CONTENT_EXT; + attribs[3] = EGL_TRUE; + attribs[4] = EGL_NONE; + } +#endif EGLImageKHR image = egl_create_image(egl_display, EGL_NO_CONTEXT, EGL_WAYLAND_BUFFER_WL, @@ -272,6 +257,8 @@ void WaylandEglClientBufferIntegrationPrivate::initEglTexture(WaylandEglClientBu } state.egl_images << image; + + QMutexLocker locker(&state.texturesLock); state.textures[i] = nullptr; } } @@ -298,6 +285,50 @@ bool WaylandEglClientBufferIntegrationPrivate::ensureContext() return localContextNeeded; } + +void WaylandEglClientBufferIntegrationPrivate::setupBufferAndCleanup(BufferState *bs, QOpenGLTexture *texture, int plane) +{ + QMutexLocker locker(&bs->texturesLock); + + bs->textures[plane] = texture; + bs->texturesContext[plane] = QOpenGLContext::currentContext(); + + Q_ASSERT(bs->texturesContext[plane] != nullptr); + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO + << "(egl) creating a cleanup-lambda for QOpenGLContext::aboutToBeDestroyed!" + << ", texture: " << bs->textures[plane] + << ", ctx: " << (void*)bs->texturesContext[plane]; + + bs->texturesAboutToBeDestroyedConnection[plane] = + QObject::connect(bs->texturesContext[plane], &QOpenGLContext::aboutToBeDestroyed, + bs->texturesContext[plane], [bs, plane]() { + + QMutexLocker locker(&bs->texturesLock); + + // See above lock - there is a chance that this has already been removed from textures[plane]! + // Furthermore, we can trust that all the rest (e.g. disconnect) has also been properly executed! + if (bs->textures[plane] == nullptr) + return; + + delete bs->textures[plane]; + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO + << "texture deleted due to QOpenGLContext::aboutToBeDestroyed!" + << "Pointer (now dead) was:" << (void*)(bs->textures[plane]) + << " Associated context (about to die too) is: " << (void*)(bs->texturesContext[plane]); + + bs->textures[plane] = nullptr; + bs->texturesContext[plane] = nullptr; + + QObject::disconnect(bs->texturesAboutToBeDestroyedConnection[plane]); + bs->texturesAboutToBeDestroyedConnection[plane] = QMetaObject::Connection(); + + }, Qt::DirectConnection); +} + bool WaylandEglClientBufferIntegrationPrivate::initEglStream(WaylandEglClientBuffer *buffer, wl_resource *bufferHandle) { BufferState &state = *buffer->d; @@ -331,7 +362,11 @@ bool WaylandEglClientBufferIntegrationPrivate::initEglStream(WaylandEglClientBuf auto texture = new QOpenGLTexture(static_cast<QOpenGLTexture::Target>(GL_TEXTURE_EXTERNAL_OES)); texture->create(); - state.textures[0] = texture; // TODO: support multiple planes for the streaming case + setupBufferAndCleanup(buffer->d, texture, 0); + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << " NEW texture! It's pointer and ctx pointer: " + << (void*)state.textures[0] << "; " << (void*)state.texturesContext[0]; texture->bind(); @@ -375,13 +410,6 @@ void WaylandEglClientBufferIntegrationPrivate::handleEglstreamTexture(WaylandEgl localContext->doneCurrent(); } -void WaylandEglClientBufferIntegrationPrivate::deleteOrphanedTextures() -{ - Q_ASSERT(QOpenGLContext::currentContext()); - qDeleteAll(orphanedTextures); - orphanedTextures.clear(); -} - WaylandEglClientBufferIntegration::WaylandEglClientBufferIntegration() : d_ptr(new WaylandEglClientBufferIntegrationPrivate) { @@ -398,7 +426,7 @@ WaylandEglClientBufferIntegration::~WaylandEglClientBufferIntegration() } } -bool WaylandEglClientBufferIntegration::initializeHardware(struct wl_display *display) +void WaylandEglClientBufferIntegration::initializeHardware(struct wl_display *display) { Q_D(WaylandEglClientBufferIntegration); @@ -408,21 +436,21 @@ bool WaylandEglClientBufferIntegration::initializeHardware(struct wl_display *di if (!nativeInterface) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. No native platform interface available."; - return false; + return; } d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay"); if (!d->egl_display) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not get EglDisplay for window."; - return false; + return; } const char *extensionString = eglQueryString(d->egl_display, EGL_EXTENSIONS); if ((!extensionString || !strstr(extensionString, "EGL_WL_bind_wayland_display")) && !ignoreBindDisplay) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. There is no EGL_WL_bind_wayland_display extension."; - return false; + return; } d->egl_bind_wayland_display = reinterpret_cast<PFNEGLBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglBindWaylandDisplayWL")); @@ -430,14 +458,14 @@ bool WaylandEglClientBufferIntegration::initializeHardware(struct wl_display *di if ((!d->egl_bind_wayland_display || !d->egl_unbind_wayland_display) && !ignoreBindDisplay) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglBindWaylandDisplayWL and eglUnbindWaylandDisplayWL."; - return false; + return; } d->egl_query_wayland_buffer = reinterpret_cast<PFNEGLQUERYWAYLANDBUFFERWL_compat>(eglGetProcAddress("eglQueryWaylandBufferWL")); if (!d->egl_query_wayland_buffer) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglQueryWaylandBufferWL."; - return false; + return; } d->egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR")); @@ -445,32 +473,26 @@ bool WaylandEglClientBufferIntegration::initializeHardware(struct wl_display *di if (!d->egl_create_image || !d->egl_destroy_image) { qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize EGL display. Could not find eglCreateImageKHR and eglDestroyImageKHR."; - return false; + return; } if (d->egl_bind_wayland_display && d->egl_unbind_wayland_display) { d->display_bound = d->egl_bind_wayland_display(d->egl_display, display); - if (!d->display_bound) { - if (!ignoreBindDisplay) { - qCWarning(qLcWaylandCompositorHardwareIntegration) - << "Failed to initialize EGL display. Could not bind Wayland display."; - return false; - } else { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Could not bind Wayland display. Ignoring."; - } - } + if (!d->display_bound) + qCDebug(qLcWaylandCompositorHardwareIntegration) << "Wayland display already bound by other client buffer integration."; d->wlDisplay = display; } d->funcs = new QEGLStreamConvenience; d->funcs->initialize(d->egl_display); - - return true; } QtWayland::ClientBuffer *WaylandEglClientBufferIntegration::createBufferFor(wl_resource *buffer) { - if (wl_shm_buffer_get(buffer)) + Q_D(WaylandEglClientBufferIntegration); + int w = -1; + bool q = d->egl_query_wayland_buffer(d->egl_display, buffer, EGL_WIDTH, &w); + if (!q || w <= 0) return nullptr; return new WaylandEglClientBuffer(this, buffer); } @@ -503,9 +525,29 @@ WaylandEglClientBuffer::~WaylandEglClientBuffer() if (d->egl_stream) p->funcs->destroy_stream(p->egl_display, d->egl_stream); - for (auto *texture : d->textures) - p->deleteGLTextureWhenPossible(texture); } + + { + QMutexLocker locker(&d->texturesLock); + + for (int i=0; i<3; i++) { + if (d->textures[i] != nullptr) { + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO << " handing over texture!" + << (void*)d->textures[i] << "; " << (void*)d->texturesContext[i] + << " ... current context might be the same: " << QOpenGLContext::currentContext(); + + QtWayland::QWaylandTextureOrphanage::instance()->admitTexture( + d->textures[i], d->texturesContext[i]); + d->textures[i] = nullptr; // in case the aboutToBeDestroyed lambda is called while we where here + d->texturesContext[i] = nullptr; + QObject::disconnect(d->texturesAboutToBeDestroyedConnection[i]); + d->texturesAboutToBeDestroyedConnection[i] = QMetaObject::Connection(); + } + } + } + delete d; } @@ -548,7 +590,7 @@ QOpenGLTexture *WaylandEglClientBuffer::toOpenGlTexture(int plane) { auto *p = WaylandEglClientBufferIntegrationPrivate::get(m_integration); // At this point we should have a valid OpenGL context, so it's safe to destroy textures - p->deleteOrphanedTextures(); + QtWayland::QWaylandTextureOrphanage::instance()->deleteTextures(); if (!m_buffer) return nullptr; @@ -564,13 +606,18 @@ QOpenGLTexture *WaylandEglClientBuffer::toOpenGlTexture(int plane) texture->setFormat(openGLFormatFromEglFormat(d->egl_format)); texture->setSize(d->size.width(), d->size.height()); texture->create(); - d->textures[plane] = texture; + p->setupBufferAndCleanup(this->d, texture, plane); } if (m_textureDirty) { + m_textureDirty = false; texture->bind(); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); p->gl_egl_image_target_texture_2d(target, d->egl_images[plane]); +#ifdef GL_EXT_protected_textures + if (isProtected()) + glTexParameteri(target, GL_TEXTURE_PROTECTED_EXT, GL_TRUE); +#endif } return texture; } @@ -584,6 +631,15 @@ void WaylandEglClientBuffer::setCommitted(QRegion &damage) } } +bool WaylandEglClientBuffer::isProtected() +{ + if (m_integration && m_buffer) + return m_integration->isProtected(m_buffer); + + return false; +} + + QWaylandSurface::Origin WaylandEglClientBuffer::origin() const { return d->isYInverted ? QWaylandSurface::OriginTopLeft : QWaylandSurface::OriginBottomLeft; diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h deleted file mode 100644 index 3b9959e2f..000000000 --- a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef WAYLANDEGLINTEGRATION_H -#define WAYLANDEGLINTEGRATION_H - -#include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> -#include <QtCore/QScopedPointer> -#include <QtWaylandCompositor/private/qwlclientbuffer_p.h> - -QT_BEGIN_NAMESPACE - -class WaylandEglClientBufferIntegrationPrivate; - -class WaylandEglClientBufferIntegration : public QtWayland::ClientBufferIntegration -{ - Q_DECLARE_PRIVATE(WaylandEglClientBufferIntegration) -public: - WaylandEglClientBufferIntegration(); - ~WaylandEglClientBufferIntegration() override; - - bool initializeHardware(struct ::wl_display *display) override; - - QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; - -private: - Q_DISABLE_COPY(WaylandEglClientBufferIntegration) - QScopedPointer<WaylandEglClientBufferIntegrationPrivate> d_ptr; -}; - -struct BufferState; - -class WaylandEglClientBuffer : public QtWayland::ClientBuffer -{ -public: - ~WaylandEglClientBuffer() override; - - QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override; - QSize size() const override; - QWaylandSurface::Origin origin() const override; - quintptr lockNativeBuffer() override; - void unlockNativeBuffer(quintptr native_buffer) const override; - QOpenGLTexture *toOpenGlTexture(int plane) override; - void setCommitted(QRegion &damage) override; - -private: - friend class WaylandEglClientBufferIntegration; - friend class WaylandEglClientBufferIntegrationPrivate; - - WaylandEglClientBuffer(WaylandEglClientBufferIntegration* integration, wl_resource *bufferResource); - - BufferState *d = nullptr; - WaylandEglClientBufferIntegration *m_integration = nullptr; -}; - -QT_END_NAMESPACE - -#endif // WAYLANDEGLINTEGRATION_H diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration_p.h b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration_p.h new file mode 100644 index 000000000..ca4dd3736 --- /dev/null +++ b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration_p.h @@ -0,0 +1,69 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef WAYLANDEGLINTEGRATION_H +#define WAYLANDEGLINTEGRATION_H + +#include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> +#include <QtCore/QScopedPointer> +#include <QtWaylandCompositor/private/qwlclientbuffer_p.h> + +QT_BEGIN_NAMESPACE + +class WaylandEglClientBufferIntegrationPrivate; + +class Q_WAYLANDCOMPOSITOR_EXPORT WaylandEglClientBufferIntegration : public QtWayland::ClientBufferIntegration +{ + Q_DECLARE_PRIVATE(WaylandEglClientBufferIntegration) +public: + WaylandEglClientBufferIntegration(); + ~WaylandEglClientBufferIntegration() override; + + void initializeHardware(struct ::wl_display *display) override; + + QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; + +private: + Q_DISABLE_COPY(WaylandEglClientBufferIntegration) + QScopedPointer<WaylandEglClientBufferIntegrationPrivate> d_ptr; +}; + +struct BufferState; + +class Q_WAYLANDCOMPOSITOR_EXPORT WaylandEglClientBuffer : public QtWayland::ClientBuffer +{ +public: + WaylandEglClientBuffer(WaylandEglClientBufferIntegration* integration, wl_resource *bufferResource); + ~WaylandEglClientBuffer() override; + + QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override; + QSize size() const override; + QWaylandSurface::Origin origin() const override; + quintptr lockNativeBuffer() override; + void unlockNativeBuffer(quintptr native_buffer) const override; + QOpenGLTexture *toOpenGlTexture(int plane) override; + void setCommitted(QRegion &damage) override; + bool isProtected() override; + +private: + friend class WaylandEglClientBufferIntegration; + friend class WaylandEglClientBufferIntegrationPrivate; + + BufferState *d = nullptr; + WaylandEglClientBufferIntegration *m_integration = nullptr; +}; + +QT_END_NAMESPACE + +#endif // WAYLANDEGLINTEGRATION_H diff --git a/src/hardwareintegration/compositor/wayland-eglstream-controller/wayland-eglstream-controller.pri b/src/hardwareintegration/compositor/wayland-eglstream-controller/wayland-eglstream-controller.pri index 931475ef6..9d9228e29 100644 --- a/src/hardwareintegration/compositor/wayland-eglstream-controller/wayland-eglstream-controller.pri +++ b/src/hardwareintegration/compositor/wayland-eglstream-controller/wayland-eglstream-controller.pri @@ -5,8 +5,6 @@ QMAKE_USE_PRIVATE += egl wayland-server wayland-egl CONFIG += wayland-scanner WAYLANDSERVERSOURCES += $$PWD/../../../3rdparty/protocol/wl-eglstream-controller.xml -QT += egl_support-private - SOURCES += \ $$PWD/waylandeglstreamintegration.cpp \ $$PWD/waylandeglstreamcontroller.cpp diff --git a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.cpp b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.cpp index d2e0d52e7..c2689b2b2 100644 --- a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.cpp +++ b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.cpp @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "waylandeglstreamcontroller.h" #include "waylandeglstreamintegration.h" diff --git a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.h b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.h index 5ce70b7fa..54db28250 100644 --- a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.h +++ b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamcontroller.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef WAYLANDEGLSTREAMCONTROLLER_H #define WAYLANDEGLSTREAMCONTROLLER_H @@ -35,11 +9,11 @@ #include <QtWaylandCompositor/private/qwayland-server-wayland.h> #include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> +#include <QtOpenGL/QOpenGLTexture> #include <QtCore/QObject> #include <QtCore/QHash> #include <QtCore/QSize> #include <QtCore/QTextStream> -#include <QtGui/QOpenGLTexture> #include <EGL/egl.h> #include <EGL/eglext.h> diff --git a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.cpp b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.cpp index 86bd07df3..0924f0fd7 100644 --- a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.cpp +++ b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.cpp @@ -1,46 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "waylandeglstreamintegration.h" #include "waylandeglstreamcontroller.h" #include <QtWaylandCompositor/QWaylandCompositor> +#include <QtOpenGL/QOpenGLTexture> #include <QtGui/QGuiApplication> #include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> #include <QtGui/QOffscreenSurface> +#include <QtCore/QMutexLocker> -#include <QtEglSupport/private/qeglstreamconvenience_p.h> +#include <QtGui/private/qeglstreamconvenience_p.h> #include <qpa/qplatformnativeinterface.h> #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> #include <QtWaylandCompositor/private/qwlbuffermanager_p.h> +#include <QtWaylandCompositor/private/qwltextureorphanage_p.h> #include <EGL/egl.h> #include <EGL/eglext.h> @@ -135,7 +111,11 @@ struct BufferState BufferState() = default; EGLint egl_format = EGL_TEXTURE_EXTERNAL_WL; - QOpenGLTexture *textures[3] = {}; + QOpenGLTexture *textures[3] = {nullptr, nullptr, nullptr}; + QOpenGLContext *texturesContext[3] = {nullptr, nullptr, nullptr}; + QMetaObject::Connection texturesAboutToBeDestroyedConnection[3] = {QMetaObject::Connection(), QMetaObject::Connection(), QMetaObject::Connection()}; + QMutex texturesLock; + EGLStreamKHR egl_stream = EGL_NO_STREAM_KHR; bool isYInverted = false; @@ -149,15 +129,14 @@ public: bool ensureContext(); bool initEglStream(WaylandEglStreamClientBuffer *buffer, struct ::wl_resource *bufferHandle); + void setupBufferAndCleanup(BufferState *bs, QOpenGLTexture *texture, int plane); void handleEglstreamTexture(WaylandEglStreamClientBuffer *buffer); - void deleteGLTextureWhenPossible(QOpenGLTexture *texture) { orphanedTextures << texture; } - void deleteOrphanedTextures(); EGLDisplay egl_display = EGL_NO_DISPLAY; bool display_bound = false; + ::wl_display *wlDisplay = nullptr; QOffscreenSurface *offscreenSurface = nullptr; QOpenGLContext *localContext = nullptr; - QVector<QOpenGLTexture *> orphanedTextures; WaylandEglStreamController *eglStreamController = nullptr; @@ -175,13 +154,6 @@ public: bool WaylandEglStreamClientBufferIntegrationPrivate::shuttingDown = false; -void WaylandEglStreamClientBufferIntegrationPrivate::deleteOrphanedTextures() -{ - Q_ASSERT(QOpenGLContext::currentContext()); - qDeleteAll(orphanedTextures); - orphanedTextures.clear(); -} - bool WaylandEglStreamClientBufferIntegrationPrivate::ensureContext() { bool localContextNeeded = false; @@ -205,6 +177,49 @@ bool WaylandEglStreamClientBufferIntegrationPrivate::ensureContext() } +void WaylandEglStreamClientBufferIntegrationPrivate::setupBufferAndCleanup(BufferState *bs, QOpenGLTexture *texture, int plane) +{ + QMutexLocker locker(&bs->texturesLock); + + bs->textures[plane] = texture; + bs->texturesContext[plane] = QOpenGLContext::currentContext(); + + Q_ASSERT(bs->texturesContext[plane] != nullptr); + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO + << "(eglstream) creating a cleanup-lambda for QOpenGLContext::aboutToBeDestroyed!" + << ", texture: " << bs->textures[plane] + << ", ctx: " << (void*)bs->texturesContext[plane]; + + bs->texturesAboutToBeDestroyedConnection[plane] = + QObject::connect(bs->texturesContext[plane], &QOpenGLContext::aboutToBeDestroyed, + bs->texturesContext[plane], [bs, plane]() { + + QMutexLocker locker(&bs->texturesLock); + + // See above lock - there is a chance that this has already been removed from textures[plane]! + // Furthermore, we can trust that all the rest (e.g. disconnect) has also been properly executed! + if (bs->textures[plane] == nullptr) + return; + + delete bs->textures[plane]; + + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO + << "texture deleted due to QOpenGLContext::aboutToBeDestroyed!" + << "Pointer (now dead) was:" << (void*)(bs->textures[plane]) + << " Associated context (about to die too) is: " << (void*)(bs->texturesContext[plane]); + + bs->textures[plane] = nullptr; + bs->texturesContext[plane] = nullptr; + + QObject::disconnect(bs->texturesAboutToBeDestroyedConnection[plane]); + bs->texturesAboutToBeDestroyedConnection[plane] = QMetaObject::Connection(); + + }, Qt::DirectConnection); +} + bool WaylandEglStreamClientBufferIntegrationPrivate::initEglStream(WaylandEglStreamClientBuffer *buffer, wl_resource *bufferHandle) { BufferState &state = *buffer->d; @@ -235,7 +250,7 @@ bool WaylandEglStreamClientBufferIntegrationPrivate::initEglStream(WaylandEglStr auto texture = new QOpenGLTexture(static_cast<QOpenGLTexture::Target>(GL_TEXTURE_EXTERNAL_OES)); texture->create(); - state.textures[0] = texture; // TODO: support multiple planes + setupBufferAndCleanup(buffer->d, texture, 0); texture->bind(); @@ -282,7 +297,13 @@ WaylandEglStreamClientBufferIntegration::WaylandEglStreamClientBufferIntegration WaylandEglStreamClientBufferIntegration::~WaylandEglStreamClientBufferIntegration() { + Q_D(WaylandEglStreamClientBufferIntegration); WaylandEglStreamClientBufferIntegrationPrivate::shuttingDown = true; + if (d->egl_unbind_wayland_display != nullptr && d->display_bound) { + Q_ASSERT(d->wlDisplay != nullptr); + if (!d->egl_unbind_wayland_display(d->egl_display, d->wlDisplay)) + qCWarning(qLcWaylandCompositorHardwareIntegration) << "eglUnbindWaylandDisplayWL failed"; + } } void WaylandEglStreamClientBufferIntegration::attachEglStreamConsumer(struct ::wl_resource *wl_surface, struct ::wl_resource *wl_buffer) @@ -290,15 +311,14 @@ void WaylandEglStreamClientBufferIntegration::attachEglStreamConsumer(struct ::w Q_D(WaylandEglStreamClientBufferIntegration); Q_UNUSED(wl_surface); - // NOTE: must use getBuffer to create the buffer here, so the buffer will end up in the buffer manager's hash - + auto *clientBuffer = new WaylandEglStreamClientBuffer(this, wl_buffer); auto *bufferManager = QWaylandCompositorPrivate::get(m_compositor)->bufferManager(); - auto *clientBuffer = static_cast<WaylandEglStreamClientBuffer*>(bufferManager->getBuffer(wl_buffer)); + bufferManager->registerBuffer(wl_buffer, clientBuffer); d->initEglStream(clientBuffer, wl_buffer); } -bool WaylandEglStreamClientBufferIntegration::initializeHardware(struct wl_display *display) +void WaylandEglStreamClientBufferIntegration::initializeHardware(struct wl_display *display) { Q_D(WaylandEglStreamClientBufferIntegration); @@ -307,56 +327,46 @@ bool WaylandEglStreamClientBufferIntegration::initializeHardware(struct wl_displ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); if (!nativeInterface) { qWarning("QtCompositor: Failed to initialize EGL display. No native platform interface available."); - return false; + return; } d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay"); if (!d->egl_display) { qWarning("QtCompositor: Failed to initialize EGL display. Could not get EglDisplay for window."); - return false; + return; } const char *extensionString = eglQueryString(d->egl_display, EGL_EXTENSIONS); if ((!extensionString || !strstr(extensionString, "EGL_WL_bind_wayland_display")) && !ignoreBindDisplay) { qWarning("QtCompositor: Failed to initialize EGL display. There is no EGL_WL_bind_wayland_display extension."); - return false; + return; } d->egl_bind_wayland_display = reinterpret_cast<PFNEGLBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglBindWaylandDisplayWL")); d->egl_unbind_wayland_display = reinterpret_cast<PFNEGLUNBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglUnbindWaylandDisplayWL")); if ((!d->egl_bind_wayland_display || !d->egl_unbind_wayland_display) && !ignoreBindDisplay) { qWarning("QtCompositor: Failed to initialize EGL display. Could not find eglBindWaylandDisplayWL and eglUnbindWaylandDisplayWL."); - return false; + return; } d->egl_query_wayland_buffer = reinterpret_cast<PFNEGLQUERYWAYLANDBUFFERWL_compat>(eglGetProcAddress("eglQueryWaylandBufferWL")); if (!d->egl_query_wayland_buffer) { qWarning("QtCompositor: Failed to initialize EGL display. Could not find eglQueryWaylandBufferWL."); - return false; + return; } if (d->egl_bind_wayland_display && d->egl_unbind_wayland_display) { d->display_bound = d->egl_bind_wayland_display(d->egl_display, display); - if (!d->display_bound) { - if (!ignoreBindDisplay) { - qWarning("QtCompositor: Failed to initialize EGL display. Could not bind Wayland display."); - return false; - } else { - qWarning("QtCompositor: Could not bind Wayland display. Ignoring."); - } - } + if (!d->display_bound) + qCDebug(qLcWaylandCompositorHardwareIntegration) << "Wayland display already bound by other client buffer integration."; + + d->wlDisplay = display; } d->eglStreamController = new WaylandEglStreamController(display, this); d->funcs = new QEGLStreamConvenience; d->funcs->initialize(d->egl_display); - if (!d->funcs->initialized) { - qWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize eglstreams API"; - return false; - } - - return true; } QtWayland::ClientBuffer *WaylandEglStreamClientBufferIntegration::createBufferFor(wl_resource *buffer) @@ -389,10 +399,29 @@ WaylandEglStreamClientBuffer::~WaylandEglStreamClientBuffer() if (p) { if (d->egl_stream) p->funcs->destroy_stream(p->egl_display, d->egl_stream); + } + + { + QMutexLocker locker(&d->texturesLock); + + for (int i=0; i<3; i++) { + if (d->textures[i] != nullptr) { - for (auto *texture : d->textures) - p->deleteGLTextureWhenPossible(texture); + qCDebug(qLcWaylandCompositorHardwareIntegration) + << Q_FUNC_INFO << " handing over texture!" + << (void*)d->textures[i] << "; " << (void*)d->texturesContext[i] + << " ... current context might be the same: " << QOpenGLContext::currentContext(); + + QtWayland::QWaylandTextureOrphanage::instance()->admitTexture( + d->textures[i], d->texturesContext[i]); + d->textures[i] = nullptr; // in case the aboutToBeDestroyed lambda is called while we where here + d->texturesContext[i] = nullptr; + QObject::disconnect(d->texturesAboutToBeDestroyedConnection[i]); + d->texturesAboutToBeDestroyedConnection[i] = QMetaObject::Connection(); + } + } } + delete d; } @@ -415,9 +444,8 @@ QWaylandSurface::Origin WaylandEglStreamClientBuffer::origin() const QOpenGLTexture *WaylandEglStreamClientBuffer::toOpenGlTexture(int plane) { - auto *p = WaylandEglStreamClientBufferIntegrationPrivate::get(m_integration); // At this point we should have a valid OpenGL context, so it's safe to destroy textures - p->deleteOrphanedTextures(); + QtWayland::QWaylandTextureOrphanage::instance()->deleteTextures(); if (!m_buffer) return nullptr; diff --git a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.h b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.h index 35d2c80d3..3f4f7f27a 100644 --- a/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.h +++ b/src/hardwareintegration/compositor/wayland-eglstream-controller/waylandeglstreamintegration.h @@ -1,31 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef WAYLANDEGLSTREAMINTEGRATION_H #define WAYLANDEGLSTREAMINTEGRATION_H @@ -44,7 +18,7 @@ public: WaylandEglStreamClientBufferIntegration(); ~WaylandEglStreamClientBufferIntegration() override; - bool initializeHardware(struct ::wl_display *display) override; + void initializeHardware(struct ::wl_display *display) override; QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri b/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri deleted file mode 100644 index 6d0f81659..000000000 --- a/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri +++ /dev/null @@ -1,11 +0,0 @@ -include($$PWD/../xcomposite_share/xcomposite_share.pri) - -QMAKE_USE_PRIVATE += egl wayland-server x11 - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/xcompositeeglintegration.h - -SOURCES += \ - $$PWD/xcompositeeglintegration.cpp diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp deleted file mode 100644 index 3c302c7f6..000000000 --- a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "xcompositeeglintegration.h" - -#include "wayland-xcomposite-server-protocol.h" - -#include <QtWaylandCompositor/QWaylandCompositor> -#include <QtGui/QGuiApplication> -#include <QtGui/QOpenGLTexture> -#include <qpa/qplatformnativeinterface.h> -#include <qpa/qplatformopenglcontext.h> - -#include "xcompositebuffer.h" -#include "xcompositehandler.h" -#include <X11/extensions/Xcomposite.h> - -#include <QtCore/QDebug> - -QT_BEGIN_NAMESPACE - -QVector<EGLint> eglbuildSpec() -{ - QVector<EGLint> spec; - - spec.append(EGL_SURFACE_TYPE); spec.append(EGL_WINDOW_BIT | EGL_PIXMAP_BIT); - spec.append(EGL_RENDERABLE_TYPE); spec.append(EGL_OPENGL_ES2_BIT); - spec.append(EGL_BIND_TO_TEXTURE_RGBA); spec.append(EGL_TRUE); - spec.append(EGL_ALPHA_SIZE); spec.append(8); - spec.append(EGL_NONE); - return spec; -} - -XCompositeEglClientBufferIntegration::XCompositeEglClientBufferIntegration() -{ - -} - -bool XCompositeEglClientBufferIntegration::initializeHardware(struct ::wl_display *) -{ - QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); - if (nativeInterface) { - mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForIntegration("Display")); - if (!mDisplay) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "could not retrieve Display from platform integration"; - return false; - } - mEglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForIntegration("EGLDisplay")); - if (!mEglDisplay) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "could not retrieve EGLDisplay from platform integration"; - return false; - } - } else { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Platform integration doesn't have native interface"; - return false; - } - new XCompositeHandler(m_compositor, mDisplay); - return true; -} - -QtWayland::ClientBuffer *XCompositeEglClientBufferIntegration::createBufferFor(wl_resource *buffer) -{ - if (wl_shm_buffer_get(buffer)) - return nullptr; - return new XCompositeEglClientBuffer(this, buffer); -} - - -XCompositeEglClientBuffer::XCompositeEglClientBuffer(XCompositeEglClientBufferIntegration *integration, wl_resource *bufferResource) - : QtWayland::ClientBuffer(bufferResource) - , m_integration(integration) -{ -} - -QOpenGLTexture *XCompositeEglClientBuffer::toOpenGlTexture(int plane) -{ - Q_UNUSED(plane); - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - Pixmap pixmap = XCompositeNameWindowPixmap(m_integration->xDisplay(), compositorBuffer->window()); - - QVector<EGLint> eglConfigSpec = eglbuildSpec(); - - EGLint matching = 0; - EGLConfig config; - bool matched = eglChooseConfig(m_integration->eglDisplay(),eglConfigSpec.constData(),&config,1,&matching); - if (!matched || !matching) { - qWarning("Could not retrieve a suitable EGL config"); - return nullptr; - } - - QVector<EGLint> attribList; - - attribList.append(EGL_TEXTURE_FORMAT); - attribList.append(EGL_TEXTURE_RGBA); - attribList.append(EGL_TEXTURE_TARGET); - attribList.append(EGL_TEXTURE_2D); - attribList.append(EGL_NONE); - - EGLSurface surface = eglCreatePixmapSurface(m_integration->eglDisplay(), config, reinterpret_cast<EGLNativePixmapType>(pixmap), attribList.constData()); - if (surface == EGL_NO_SURFACE) { - qDebug() << "Failed to create eglsurface" << pixmap << compositorBuffer->window(); - } - - compositorBuffer->setOrigin(QWaylandSurface::OriginTopLeft); - - if (!m_texture) { - m_texture = new QOpenGLTexture(QOpenGLTexture::Target2D); - m_texture->create(); - } - m_texture->bind(); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - if (!eglBindTexImage(m_integration->eglDisplay(),surface,EGL_BACK_BUFFER)) { - qWarning() << "Failed to bind"; - } - - // eglDestroySurface(mEglDisplay,surface); - return m_texture; -} - - -QWaylandSurface::Origin XCompositeEglClientBuffer::origin() const -{ - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - return compositorBuffer->origin(); -} - -QSize XCompositeEglClientBuffer::size() const -{ - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - - return compositorBuffer->size(); -} - -QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h deleted file mode 100644 index 2c3116df1..000000000 --- a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef XCOMPOSITEEGLINTEGRATION_H -#define XCOMPOSITEEGLINTEGRATION_H - -#include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> - -#include <QtWaylandCompositor/QWaylandCompositor> -#include <QtWaylandCompositor/private/qwlclientbuffer_p.h> -#include "xlibinclude.h" - -#include <EGL/egl.h> - -QT_BEGIN_NAMESPACE - -class XCompositeEglClientBufferIntegration : public QtWayland::ClientBufferIntegration -{ -public: - XCompositeEglClientBufferIntegration(); - - bool initializeHardware(struct ::wl_display *display) override; - QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; - inline Display *xDisplay() const { return mDisplay; } - inline EGLDisplay eglDisplay() const { return mEglDisplay; } - -private: - Display *mDisplay = nullptr; - EGLDisplay mEglDisplay = EGL_NO_DISPLAY; -}; - -class XCompositeEglClientBuffer : public QtWayland::ClientBuffer -{ -public: - XCompositeEglClientBuffer(XCompositeEglClientBufferIntegration *integration, wl_resource *bufferResource); - - QSize size() const override; - QWaylandSurface::Origin origin() const override; - QOpenGLTexture *toOpenGlTexture(int plane) override; - QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override { - return QWaylandBufferRef::BufferFormatEgl_RGBA; - } - -private: - QOpenGLTexture *m_texture = nullptr; - XCompositeEglClientBufferIntegration *m_integration = nullptr; -}; - -QT_END_NAMESPACE - -#endif // XCOMPOSITEEGLINTEGRATION_H diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri b/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri deleted file mode 100644 index 423ae1815..000000000 --- a/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri +++ /dev/null @@ -1,11 +0,0 @@ -include($$PWD/../xcomposite_share/xcomposite_share.pri) - -QMAKE_USE_PRIVATE += wayland-server glx - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/xcompositeglxintegration.h - -SOURCES += \ - $$PWD/xcompositeglxintegration.cpp diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp deleted file mode 100644 index db4390252..000000000 --- a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "xcompositeglxintegration.h" - -#include "wayland-xcomposite-server-protocol.h" - -#include <qpa/qplatformnativeinterface.h> -#include <qpa/qplatformintegration.h> -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> - -#include "xcompositebuffer.h" -#include "xcompositehandler.h" -#include <X11/extensions/Xcomposite.h> - -#include <QtCore/QDebug> - -QT_BEGIN_NAMESPACE - -QVector<int> qglx_buildSpec() -{ - QVector<int> spec(48); - int i = 0; - - spec[i++] = GLX_LEVEL; - spec[i++] = 0; - spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_PIXMAP_BIT | GLX_WINDOW_BIT; - spec[i++] = GLX_BIND_TO_TEXTURE_TARGETS_EXT; spec[i++] = GLX_TEXTURE_2D_BIT_EXT; - spec[i++] = GLX_BIND_TO_TEXTURE_RGB_EXT; spec[i++] = true; - - spec[i++] = 0; - return spec; -} - - -XCompositeGLXClientBufferIntegration::XCompositeGLXClientBufferIntegration() -{ - qDebug() << "Loading GLX integration"; -} - -XCompositeGLXClientBufferIntegration::~XCompositeGLXClientBufferIntegration() -{ - delete mHandler; -} - -bool XCompositeGLXClientBufferIntegration::initializeHardware(struct ::wl_display *) -{ - qDebug() << "Initializing GLX integration"; - QPlatformNativeInterface *nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); - if (nativeInterface) { - mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForIntegration("Display")); - if (!mDisplay) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "could not retrieve Display from platform integration"; - return false; - } - } else { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Platform integration doesn't have native interface"; - return false; - } - mScreen = XDefaultScreen(mDisplay); - - mHandler = new XCompositeHandler(m_compositor, mDisplay); - - QOpenGLContext *glContext = new QOpenGLContext(); - glContext->create(); - - m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT")); - if (!m_glxBindTexImageEXT) { - qCWarning(qLcWaylandCompositorHardwareIntegration) << "Did not find glxBindTexImageExt, everything will FAIL!"; - return false; - } - m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT")); - if (!m_glxReleaseTexImageEXT) { - qDebug() << "Did not find glxReleaseTexImageExt"; - } - - delete glContext; - return true; -} - -QtWayland::ClientBuffer *XCompositeGLXClientBufferIntegration::createBufferFor(wl_resource *buffer) -{ - if (wl_shm_buffer_get(buffer)) - return nullptr; - return new XCompositeGLXClientBuffer(this, buffer); -} - -XCompositeGLXClientBuffer::XCompositeGLXClientBuffer(XCompositeGLXClientBufferIntegration *integration, wl_resource *bufferResource) - : QtWayland::ClientBuffer(bufferResource) - , m_integration(integration) -{ -} - - -QOpenGLTexture *XCompositeGLXClientBuffer::toOpenGlTexture(int plane) -{ - Q_UNUSED(plane); - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - Pixmap pixmap = XCompositeNameWindowPixmap(m_integration->xDisplay(), compositorBuffer->window()); - - QVector<int> glxConfigSpec = qglx_buildSpec(); - int numberOfConfigs; - GLXFBConfig *configs = glXChooseFBConfig(m_integration->xDisplay(),m_integration->xScreen(),glxConfigSpec.constData(),&numberOfConfigs); - - QVector<int> attribList; - attribList.append(GLX_TEXTURE_FORMAT_EXT); - attribList.append(GLX_TEXTURE_FORMAT_RGB_EXT); - attribList.append(GLX_TEXTURE_TARGET_EXT); - attribList.append(GLX_TEXTURE_2D_EXT); - attribList.append(0); - - if (!m_glxPixmap) - m_glxPixmap = glXCreatePixmap(m_integration->xDisplay(), *configs, pixmap, attribList.constData()); - - uint inverted = 0; - glXQueryDrawable(m_integration->xDisplay(), m_glxPixmap, GLX_Y_INVERTED_EXT,&inverted); - compositorBuffer->setOrigin(inverted ? QWaylandSurface::OriginBottomLeft : QWaylandSurface::OriginTopLeft); - - XFree(configs); - auto tex = m_texture; - if (!m_texture) { - tex = new QOpenGLTexture(QOpenGLTexture::Target2D); - tex->create(); - m_texture = tex; - } - tex->bind(); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - m_integration->m_glxBindTexImageEXT(m_integration->xDisplay(),m_glxPixmap,GLX_FRONT_EXT, nullptr); - - // TODO: release in the destructor? - // m_glxReleaseTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT); - return tex; -} - - -QWaylandSurface::Origin XCompositeGLXClientBuffer::origin() const -{ - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - return compositorBuffer->origin(); -} - -QSize XCompositeGLXClientBuffer::size() const -{ - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); - - return compositorBuffer->size(); -} - -QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h deleted file mode 100644 index 6763d5916..000000000 --- a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef XCOMPOSITEGLXINTEGRATION_H -#define XCOMPOSITEGLXINTEGRATION_H - -#include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> -#include <QtWaylandCompositor/private/qwlclientbuffer_p.h> -#include "xlibinclude.h" - -#define GLX_GLXEXT_PROTOTYPES -#include <GL/glx.h> -#include <GL/glxext.h> - -QT_BEGIN_NAMESPACE - -class XCompositeHandler; - -class XCompositeGLXClientBufferIntegration : public QtWayland::ClientBufferIntegration -{ -public: - XCompositeGLXClientBufferIntegration(); - ~XCompositeGLXClientBufferIntegration() override; - - bool initializeHardware(struct ::wl_display *display) override; - QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; - - inline Display *xDisplay() const { return mDisplay; } - inline int xScreen() const { return mScreen; } - - PFNGLXBINDTEXIMAGEEXTPROC m_glxBindTexImageEXT; - PFNGLXRELEASETEXIMAGEEXTPROC m_glxReleaseTexImageEXT; - -private: - Display *mDisplay = nullptr; - int mScreen; - XCompositeHandler *mHandler = nullptr; -}; - -class XCompositeGLXClientBuffer : public QtWayland::ClientBuffer -{ -public: - XCompositeGLXClientBuffer(XCompositeGLXClientBufferIntegration *integration, wl_resource *bufferResource); - - QSize size() const override; - QWaylandSurface::Origin origin() const override; - QOpenGLTexture *toOpenGlTexture(int plane) override; - QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override { - return QWaylandBufferRef::BufferFormatEgl_RGBA; - } - -private: - QOpenGLTexture *m_texture = nullptr; - XCompositeGLXClientBufferIntegration *m_integration = nullptr; - GLXPixmap m_glxPixmap = 0; -}; - -QT_END_NAMESPACE - -#endif // XCOMPOSITEGLXINTEGRATION_H diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri b/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri deleted file mode 100644 index 69ab6aa10..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri +++ /dev/null @@ -1,16 +0,0 @@ -INCLUDEPATH += $$PWD - -QMAKE_USE += xcomposite -CONFIG += wayland-scanner -WAYLANDSERVERSOURCES += $$PWD/../../../extensions/xcomposite.xml $$PWD/../../../3rdparty/protocol/wayland.xml - -HEADERS += \ - $$PWD/xcompositebuffer.h \ - $$PWD/xcompositehandler.h \ - $$PWD/xlibinclude.h - -SOURCES += \ - $$PWD/xcompositebuffer.cpp \ - $$PWD/xcompositehandler.cpp - -QT += gui-private diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp deleted file mode 100644 index 67cef0049..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "xcompositebuffer.h" - -QT_BEGIN_NAMESPACE - -XCompositeBuffer::XCompositeBuffer(Window window, const QSize &size, - struct ::wl_client *client, uint32_t id) - : QtWaylandServer::wl_buffer(client, id, 1) - , mWindow(window) - , mOrigin(QWaylandSurface::OriginBottomLeft) - , mSize(size) -{ -} - -void XCompositeBuffer::buffer_destroy_resource(Resource *) -{ - delete this; -} - -void XCompositeBuffer::buffer_destroy(Resource *resource) -{ - wl_resource_destroy(resource->handle); -} - -Window XCompositeBuffer::window() -{ - return mWindow; -} - -QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h deleted file mode 100644 index 4bf035f24..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef XCOMPOSITEBUFFER_H -#define XCOMPOSITEBUFFER_H - -#include <qwayland-server-wayland.h> - -#include <QtWaylandCompositor/private/qwaylandutils_p.h> - -#include <QtWaylandCompositor/QWaylandSurface> -#include <QtWaylandCompositor/QWaylandCompositor> - -#include <QtCore/QSize> - -#include <QtCore/QTextStream> -#include <QtCore/QDataStream> -#include <QtCore/QMetaType> -#include <QtCore/QVariant> - -#include <X11/X.h> - -QT_BEGIN_NAMESPACE - -class XCompositeBuffer : public QtWaylandServer::wl_buffer -{ -public: - XCompositeBuffer(Window window, const QSize &size, - struct ::wl_client *client, uint32_t id); - - Window window(); - - QWaylandSurface::Origin origin() const { return mOrigin; } - void setOrigin(QWaylandSurface::Origin origin) { mOrigin = origin; } - - QSize size() const { return mSize; } - - static XCompositeBuffer *fromResource(struct ::wl_resource *resource) { return QtWayland::fromResource<XCompositeBuffer *>(resource); } - -protected: - void buffer_destroy_resource(Resource *) override; - void buffer_destroy(Resource *) override; - -private: - Window mWindow; - QWaylandSurface::Origin mOrigin; - QSize mSize; -}; - -QT_END_NAMESPACE - -#endif // XCOMPOSITORBUFFER_H diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp deleted file mode 100644 index 1e43c033a..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "xcompositehandler.h" - -#include "wayland-xcomposite-server-protocol.h" - -#include "xcompositebuffer.h" -#include <X11/extensions/Xcomposite.h> - -QT_BEGIN_NAMESPACE - -XCompositeHandler::XCompositeHandler(QWaylandCompositor *compositor, Display *display) - : QtWaylandServer::qt_xcomposite(compositor->display(), 1) -{ - mFakeRootWindow = new QWindow(); - mFakeRootWindow->setGeometry(QRect(-1,-1,1,1)); - mFakeRootWindow->create(); - mFakeRootWindow->show(); - - int composite_event_base, composite_error_base; - if (!XCompositeQueryExtension(display, &composite_event_base, &composite_error_base)) - qFatal("XComposite required"); - - mDisplayString = QString::fromLocal8Bit(XDisplayString(display)); -} - -void XCompositeHandler::xcomposite_bind_resource(Resource *resource) -{ - send_root(resource->handle, mDisplayString, mFakeRootWindow->winId()); -} - -void XCompositeHandler::xcomposite_create_buffer(Resource *resource, uint32_t id, uint32_t window, - int32_t width, int32_t height) -{ - new XCompositeBuffer(Window(window), QSize(width, height), resource->client(), id); -} - -QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h deleted file mode 100644 index 5ff72e265..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef XCOMPOSITEHANDLER_H -#define XCOMPOSITEHANDLER_H - -#include <QtWaylandCompositor/QWaylandCompositor> - -#include "xlibinclude.h" - -#include "qwayland-server-xcomposite.h" -#include <wayland-server-core.h> - -QT_BEGIN_NAMESPACE - -class XCompositeHandler : public QtWaylandServer::qt_xcomposite -{ -public: - XCompositeHandler(QWaylandCompositor *compositor, Display *display); - -private: - QWindow *mFakeRootWindow = nullptr; - - QString mDisplayString; - - void xcomposite_bind_resource(Resource *resource) override; - void xcomposite_create_buffer(Resource *resource, uint32_t id, uint32_t x_window, - int32_t width, int32_t height) override; - -}; - -QT_END_NAMESPACE - -#endif // XCOMPOSITEHANDLER_H diff --git a/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h b/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h deleted file mode 100644 index ca3542aaa..000000000 --- a/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef XLIBINCLUDE_H -#define XLIBINCLUDE_H - -#include <QtCore/QEvent> -#include <QtCore/QTextStream> -#include <QtCore/QDataStream> -#include <QtCore/QMetaType> -#include <QtCore/QVariant> -#include <QtGui/QCursor> -#include <QtGui/private/qguiapplication_p.h> - -#include <X11/Xlib.h> -#include "X11/extensions/Xcomposite.h" - -enum { - XFocusOut = FocusOut, - XFocusIn = FocusIn, - XKeyPress = KeyPress, - XKeyRelease = KeyRelease, - XNone = None, - XRevertToParent = RevertToParent, - XGrayScale = GrayScale, - XCursorShape = CursorShape -}; -#undef FocusOut -#undef FocusIn -#undef KeyPress -#undef KeyRelease -#undef None -#undef RevertToParent -#undef GrayScale -#undef CursorShape - -#ifdef FontChange -#undef FontChange -#endif - -#endif //XLIBINCLUDE_H |