From 7172b5112e5dbf0cb63dec68d2f916a323748aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 31 Mar 2020 15:27:11 +0200 Subject: Move QtPlatformCompositorSupport into QtOpenGL Task-number: QTBUG-83255 Change-Id: Id9ea654db8efb00b487d53aea03d7f23a7ab1a54 Reviewed-by: Laszlo Agocs --- src/opengl/CMakeLists.txt | 8 + src/opengl/opengl.pro | 16 +- src/opengl/qopenglcompositor.cpp | 308 ++++++++++++++ src/opengl/qopenglcompositor_p.h | 124 ++++++ src/opengl/qopenglcompositorbackingstore.cpp | 292 +++++++++++++ src/opengl/qopenglcompositorbackingstore_p.h | 101 +++++ src/opengl/qplatformbackingstoreopenglsupport.cpp | 455 +++++++++++++++++++++ src/opengl/qplatformbackingstoreopenglsupport.h | 87 ++++ src/platformsupport/CMakeLists.txt | 3 - .../platformcompositor/CMakeLists.txt | 23 -- .../platformcompositor/platformcompositor.pro | 19 - .../platformcompositor/qopenglcompositor.cpp | 308 -------------- .../platformcompositor/qopenglcompositor_p.h | 122 ------ .../qopenglcompositorbackingstore.cpp | 292 ------------- .../qopenglcompositorbackingstore_p.h | 99 ----- .../qplatformbackingstoreopenglsupport.cpp | 455 --------------------- .../qplatformbackingstoreopenglsupport.h | 87 ---- src/platformsupport/platformsupport.pro | 2 - src/plugins/platforms/android/CMakeLists.txt | 4 +- src/plugins/platforms/android/android.pro | 2 +- .../android/qandroidplatformintegration.cpp | 2 +- src/plugins/platforms/cocoa/CMakeLists.txt | 4 +- src/plugins/platforms/cocoa/cocoa.pro | 2 +- src/plugins/platforms/cocoa/qcocoaintegration.mm | 2 +- src/plugins/platforms/eglfs/CMakeLists.txt | 4 +- .../platforms/eglfs/api/qeglfsintegration.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfsscreen.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfswindow.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfswindow_p.h | 2 +- .../platforms/eglfs/eglfsdeviceintegration.pro | 3 +- src/plugins/platforms/ios/CMakeLists.txt | 4 +- src/plugins/platforms/ios/kernel.pro | 2 +- src/plugins/platforms/ios/qiosintegration.mm | 2 +- src/plugins/platforms/wasm/qwasmintegration.cpp | 2 +- src/plugins/platforms/wasm/wasm.pro | 2 +- src/plugins/platforms/windows/CMakeLists.txt | 4 +- .../platforms/windows/qwindowsgdiintegration.cpp | 2 +- src/plugins/platforms/windows/windows.pro | 2 +- src/plugins/platforms/winrt/qwinrtintegration.cpp | 2 +- src/plugins/platforms/winrt/winrt.pro | 2 +- src/plugins/platforms/xcb/CMakeLists.txt | 4 +- src/plugins/platforms/xcb/qxcbintegration.cpp | 2 +- src/plugins/platforms/xcb/xcb_qpa_lib.pro | 3 +- 43 files changed, 1420 insertions(+), 1445 deletions(-) create mode 100644 src/opengl/qopenglcompositor.cpp create mode 100644 src/opengl/qopenglcompositor_p.h create mode 100644 src/opengl/qopenglcompositorbackingstore.cpp create mode 100644 src/opengl/qopenglcompositorbackingstore_p.h create mode 100644 src/opengl/qplatformbackingstoreopenglsupport.cpp create mode 100644 src/opengl/qplatformbackingstoreopenglsupport.h delete mode 100644 src/platformsupport/platformcompositor/CMakeLists.txt delete mode 100644 src/platformsupport/platformcompositor/platformcompositor.pro delete mode 100644 src/platformsupport/platformcompositor/qopenglcompositor.cpp delete mode 100644 src/platformsupport/platformcompositor/qopenglcompositor_p.h delete mode 100644 src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp delete mode 100644 src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h delete mode 100644 src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp delete mode 100644 src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.h (limited to 'src') diff --git a/src/opengl/CMakeLists.txt b/src/opengl/CMakeLists.txt index 9050ad0c58..51d6240356 100644 --- a/src/opengl/CMakeLists.txt +++ b/src/opengl/CMakeLists.txt @@ -31,6 +31,8 @@ qt_add_module(OpenGL qopenglvertexarrayobject.cpp qopenglvertexarrayobject.h qopenglwindow.cpp qopenglwindow.h qtopenglglobal.h + qplatformbackingstoreopenglsupport.cpp qplatformbackingstoreopenglsupport.h + DEFINES QT_NO_FOREACH QT_NO_USING_NAMESPACE @@ -92,6 +94,12 @@ qt_extend_target(OpenGL CONDITION QT_FEATURE_vulkan Vulkan::Vulkan_nolink ) +qt_extend_target(OpenGL CONDITION QT_FEATURE_egl + SOURCES + qopenglcompositorbackingstore.cpp qopenglcompositorbackingstore_p.h + qopenglcompositor.cpp qopenglcompositor_p.h +) + qt_add_docs(OpenGL doc/qtopengl.qdocconf ) diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index 37694787f3..f190616ca8 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -37,7 +37,8 @@ HEADERS += \ qopenglversionprofile.h \ qopenglvertexarrayobject.h \ qopenglwindow.h \ - qtopenglglobal.h + qtopenglglobal.h \ + qplatformbackingstoreopenglsupport.h SOURCES += \ qopengl2pexvertexarray.cpp \ @@ -61,7 +62,8 @@ SOURCES += \ qopenglversionprofile.cpp \ qopenglvertexarrayobject.cpp \ qopenglwindow.cpp \ - qopengldebug.cpp + qopengldebug.cpp \ + qplatformbackingstoreopenglsupport.cpp !qtConfig(opengles2) { HEADERS += \ @@ -139,4 +141,14 @@ qtConfig(vulkan) { QMAKE_USE += vulkan/nolink } +qtConfig(egl) { + SOURCES += \ + qopenglcompositorbackingstore.cpp \ + qopenglcompositor.cpp + + HEADERS += \ + qopenglcompositorbackingstore_p.h \ + qopenglcompositor_p.h +} + load(qt_module) diff --git a/src/opengl/qopenglcompositor.cpp b/src/opengl/qopenglcompositor.cpp new file mode 100644 index 0000000000..abfaca3f9c --- /dev/null +++ b/src/opengl/qopenglcompositor.cpp @@ -0,0 +1,308 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "qopenglcompositor_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QOpenGLCompositor + \brief A generic OpenGL-based compositor + \since 5.4 + \internal + \ingroup qpa + + This class provides a lightweight compositor that maintains the + basic stacking order of windows and composites them by drawing + textured quads via OpenGL. + + It it meant to be used by platform plugins that run without a + windowing system. + + It is up to the platform plugin to manage the lifetime of the + compositor (instance(), destroy()), set the correct destination + context and window as early as possible (setTarget()), + register the composited windows as they are shown, activated, + raised and lowered (addWindow(), moveToTop(), etc.), and to + schedule repaints (update()). + + \note To get support for QWidget-based windows, just use + QOpenGLCompositorBackingStore. It will automatically create + textures from the raster-rendered content and trigger the + necessary repaints. + */ + +static QOpenGLCompositor *compositor = 0; + +QOpenGLCompositor::QOpenGLCompositor() + : m_context(0), + m_targetWindow(0), + m_rotation(0) +{ + Q_ASSERT(!compositor); + m_updateTimer.setSingleShot(true); + m_updateTimer.setInterval(0); + connect(&m_updateTimer, SIGNAL(timeout()), SLOT(handleRenderAllRequest())); +} + +QOpenGLCompositor::~QOpenGLCompositor() +{ + Q_ASSERT(compositor == this); + m_blitter.destroy(); + compositor = 0; +} + +void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow, + const QRect &nativeTargetGeometry) +{ + m_context = context; + m_targetWindow = targetWindow; + m_nativeTargetGeometry = nativeTargetGeometry; +} + +void QOpenGLCompositor::setRotation(int degrees) +{ + m_rotation = degrees; + m_rotationMatrix.setToIdentity(); + m_rotationMatrix.rotate(degrees, 0, 0, 1); +} + +void QOpenGLCompositor::update() +{ + if (!m_updateTimer.isActive()) + m_updateTimer.start(); +} + +QImage QOpenGLCompositor::grab() +{ + Q_ASSERT(m_context && m_targetWindow); + m_context->makeCurrent(m_targetWindow); + QScopedPointer fbo(new QOpenGLFramebufferObject(m_nativeTargetGeometry.size())); + renderAll(fbo.data()); + return fbo->toImage(); +} + +void QOpenGLCompositor::handleRenderAllRequest() +{ + Q_ASSERT(m_context && m_targetWindow); + m_context->makeCurrent(m_targetWindow); + renderAll(0); +} + +void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) +{ + if (fbo) + fbo->bind(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glViewport(0, 0, m_nativeTargetGeometry.width(), m_nativeTargetGeometry.height()); + + if (!m_blitter.isCreated()) + m_blitter.create(); + + m_blitter.bind(); + + for (int i = 0; i < m_windows.size(); ++i) + m_windows.at(i)->beginCompositing(); + + for (int i = 0; i < m_windows.size(); ++i) + render(m_windows.at(i)); + + m_blitter.release(); + if (!fbo) + m_context->swapBuffers(m_targetWindow); + else + fbo->release(); + + for (int i = 0; i < m_windows.size(); ++i) + m_windows.at(i)->endCompositing(); +} + +struct BlendStateBinder +{ + BlendStateBinder() : m_blend(false) { + glDisable(GL_BLEND); + } + void set(bool blend) { + if (blend != m_blend) { + if (blend) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } else { + glDisable(GL_BLEND); + } + m_blend = blend; + } + } + ~BlendStateBinder() { + if (m_blend) + glDisable(GL_BLEND); + } + bool m_blend; +}; + +static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) +{ + return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, + topLeftRect.width(), topLeftRect.height()); +} + +static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &sourceWindowRect, + const QRect &targetWindowRect, + QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix) +{ + const QRect clipRect = textures->clipRect(idx); + if (clipRect.isEmpty()) + return; + + const QRect rectInWindow = textures->geometry(idx).translated(sourceWindowRect.topLeft()); + const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); + const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); + + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(clippedRectInWindow, targetWindowRect); + if (rotationMatrix) + target = *rotationMatrix * target; + + const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, rectInWindow.size(), + QOpenGLTextureBlitter::OriginBottomLeft); + + blitter->blit(textures->textureId(idx), target, source); +} + +void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) +{ + const QPlatformTextureList *textures = window->textures(); + if (!textures) + return; + + const QRect targetWindowRect(QPoint(0, 0), m_targetWindow->geometry().size()); + float currentOpacity = 1.0f; + BlendStateBinder blend; + const QRect sourceWindowRect = window->sourceWindow()->geometry(); + for (int i = 0; i < textures->count(); ++i) { + uint textureId = textures->textureId(i); + const float opacity = window->sourceWindow()->opacity(); + if (opacity != currentOpacity) { + currentOpacity = opacity; + m_blitter.setOpacity(currentOpacity); + } + + if (textures->count() > 1 && i == textures->count() - 1) { + // Backingstore for a widget with QOpenGLWidget subwidgets + blend.set(true); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + if (m_rotation) + target = m_rotationMatrix * target; + m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); + } else if (textures->count() == 1) { + // A regular QWidget window + const bool translucent = window->sourceWindow()->requestedFormat().alphaBufferSize() > 0; + blend.set(translucent); + QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); + if (m_rotation) + target = m_rotationMatrix * target; + m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); + } else if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { + // Texture from an FBO belonging to a QOpenGLWidget or QQuickWidget + blend.set(false); + clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); + } + } + + for (int i = 0; i < textures->count(); ++i) { + if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { + blend.set(true); + clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); + } + } + + m_blitter.setOpacity(1.0f); +} + +QOpenGLCompositor *QOpenGLCompositor::instance() +{ + if (!compositor) + compositor = new QOpenGLCompositor; + return compositor; +} + +void QOpenGLCompositor::destroy() +{ + delete compositor; + compositor = 0; +} + +void QOpenGLCompositor::addWindow(QOpenGLCompositorWindow *window) +{ + if (!m_windows.contains(window)) { + m_windows.append(window); + emit topWindowChanged(window); + } +} + +void QOpenGLCompositor::removeWindow(QOpenGLCompositorWindow *window) +{ + m_windows.removeOne(window); + if (!m_windows.isEmpty()) + emit topWindowChanged(m_windows.last()); +} + +void QOpenGLCompositor::moveToTop(QOpenGLCompositorWindow *window) +{ + m_windows.removeOne(window); + m_windows.append(window); + emit topWindowChanged(window); +} + +void QOpenGLCompositor::changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx) +{ + int idx = m_windows.indexOf(window); + if (idx != -1 && idx != newIdx) { + m_windows.move(idx, newIdx); + if (newIdx == m_windows.size() - 1) + emit topWindowChanged(m_windows.last()); + } +} + +QT_END_NAMESPACE diff --git a/src/opengl/qopenglcompositor_p.h b/src/opengl/qopenglcompositor_p.h new file mode 100644 index 0000000000..d0d1c9303d --- /dev/null +++ b/src/opengl/qopenglcompositor_p.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENGLCOMPOSITOR_H +#define QOPENGLCOMPOSITOR_H + +// +// 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. +// + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QOpenGLContext; +class QOpenGLFramebufferObject; +class QWindow; +class QPlatformTextureList; + +class QOpenGLCompositorWindow +{ +public: + virtual ~QOpenGLCompositorWindow() { } + virtual QWindow *sourceWindow() const = 0; + virtual const QPlatformTextureList *textures() const = 0; + virtual void beginCompositing() { } + virtual void endCompositing() { } +}; + +class Q_OPENGL_EXPORT QOpenGLCompositor : public QObject +{ + Q_OBJECT + +public: + static QOpenGLCompositor *instance(); + static void destroy(); + + void setTarget(QOpenGLContext *context, QWindow *window, const QRect &nativeTargetGeometry); + void setRotation(int degrees); + QOpenGLContext *context() const { return m_context; } + QWindow *targetWindow() const { return m_targetWindow; } + + void update(); + QImage grab(); + + QList windows() const { return m_windows; } + void addWindow(QOpenGLCompositorWindow *window); + void removeWindow(QOpenGLCompositorWindow *window); + void moveToTop(QOpenGLCompositorWindow *window); + void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx); + +signals: + void topWindowChanged(QOpenGLCompositorWindow *window); + +private slots: + void handleRenderAllRequest(); + +private: + QOpenGLCompositor(); + ~QOpenGLCompositor(); + + void renderAll(QOpenGLFramebufferObject *fbo); + void render(QOpenGLCompositorWindow *window); + + QOpenGLContext *m_context; + QWindow *m_targetWindow; + QRect m_nativeTargetGeometry; + int m_rotation; + QMatrix4x4 m_rotationMatrix; + QTimer m_updateTimer; + QOpenGLTextureBlitter m_blitter; + QList m_windows; +}; + +QT_END_NAMESPACE + +#endif // QOPENGLCOMPOSITOR_H diff --git a/src/opengl/qopenglcompositorbackingstore.cpp b/src/opengl/qopenglcompositorbackingstore.cpp new file mode 100644 index 0000000000..40400e2a19 --- /dev/null +++ b/src/opengl/qopenglcompositorbackingstore.cpp @@ -0,0 +1,292 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "qopenglcompositorbackingstore_p.h" +#include "qopenglcompositor_p.h" + +#ifndef GL_UNPACK_ROW_LENGTH +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#endif + +QT_BEGIN_NAMESPACE + +/*! + \class QOpenGLCompositorBackingStore + \brief A backing store implementation for OpenGL + \since 5.4 + \internal + \ingroup qpa + + This implementation uploads raster-rendered widget windows into + textures. It is meant to be used with QOpenGLCompositor that + composites the textures onto a single native window using OpenGL. + This means that multiple top-level widgets are supported without + creating actual native windows for each of them. + + \note It is important to call notifyComposited() from the + corresponding platform window's endCompositing() callback + (inherited from QOpenGLCompositorWindow). + + \note When implementing QOpenGLCompositorWindow::textures() for + windows of type RasterSurface or RasterGLSurface, simply return + the list provided by this class' textures(). +*/ + +QOpenGLCompositorBackingStore::QOpenGLCompositorBackingStore(QWindow *window) + : QPlatformBackingStore(window), + m_window(window), + m_bsTexture(0), + m_bsTextureContext(0), + m_textures(new QPlatformTextureList), + m_lockedWidgetTextures(0) +{ +} + +QOpenGLCompositorBackingStore::~QOpenGLCompositorBackingStore() +{ + if (m_bsTexture) { + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + // With render-to-texture-widgets QWidget makes sure the TLW's shareContext() is + // made current before destroying backingstores. That is however not the case for + // windows with regular widgets only. + QScopedPointer tempSurface; + if (!ctx) { + ctx = QOpenGLCompositor::instance()->context(); + tempSurface.reset(new QOffscreenSurface); + tempSurface->setFormat(ctx->format()); + tempSurface->create(); + ctx->makeCurrent(tempSurface.data()); + } + + if (m_bsTextureContext && ctx->shareGroup() == m_bsTextureContext->shareGroup()) + glDeleteTextures(1, &m_bsTexture); + else + qWarning("QOpenGLCompositorBackingStore: Texture is not valid in the current context"); + + if (tempSurface) + ctx->doneCurrent(); + } + + delete m_textures; // this does not actually own any GL resources +} + +QPaintDevice *QOpenGLCompositorBackingStore::paintDevice() +{ + return &m_image; +} + +void QOpenGLCompositorBackingStore::updateTexture() +{ + if (!m_bsTexture) { + m_bsTextureContext = QOpenGLContext::currentContext(); + Q_ASSERT(m_bsTextureContext); + glGenTextures(1, &m_bsTexture); + glBindTexture(GL_TEXTURE_2D, m_bsTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + } else { + glBindTexture(GL_TEXTURE_2D, m_bsTexture); + } + + if (!m_dirty.isNull()) { + QRegion fixed; + QRect imageRect = m_image.rect(); + + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { + for (const QRect &rect : m_dirty) { + QRect r = imageRect & rect; + glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image.width()); + glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, + m_image.constScanLine(r.y()) + r.x() * 4); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + } + } else { + for (const QRect &rect : m_dirty) { + // intersect with image rect to be sure + QRect r = imageRect & rect; + + // if the rect is wide enough it's cheaper to just + // extend it instead of doing an image copy + if (r.width() >= imageRect.width() / 2) { + r.setX(0); + r.setWidth(imageRect.width()); + } + + fixed |= r; + } + for (const QRect &rect : fixed) { + // if the sub-rect is full-width we can pass the image data directly to + // OpenGL instead of copying, since there's no gap between scanlines + if (rect.width() == imageRect.width()) { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, + m_image.constScanLine(rect.y())); + } else { + glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, + m_image.copy(rect).constBits()); + } + } + } + + m_dirty = QRegion(); + } +} + +void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + // Called for ordinary raster windows. + + Q_UNUSED(region); + Q_UNUSED(offset); + + QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); + QOpenGLContext *dstCtx = compositor->context(); + Q_ASSERT(dstCtx); + + QWindow *dstWin = compositor->targetWindow(); + if (!dstWin) + return; + + dstCtx->makeCurrent(dstWin); + updateTexture(); + m_textures->clear(); + m_textures->appendTexture(nullptr, m_bsTexture, window->geometry()); + + compositor->update(); +} + +void QOpenGLCompositorBackingStore::composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, + QPlatformTextureList *textures, + bool translucentBackground) +{ + // QOpenGLWidget/QQuickWidget content provided as textures. The raster content goes on top. + + Q_UNUSED(region); + Q_UNUSED(offset); + Q_UNUSED(translucentBackground); + + QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); + QOpenGLContext *dstCtx = compositor->context(); + Q_ASSERT(dstCtx); // setTarget() must have been called before, e.g. from QEGLFSWindow + + // The compositor's context and the context to which QOpenGLWidget/QQuickWidget + // textures belong are not the same. They share resources, though. + Q_ASSERT(qt_window_private(window)->shareContext()->shareGroup() == dstCtx->shareGroup()); + + QWindow *dstWin = compositor->targetWindow(); + if (!dstWin) + return; + + dstCtx->makeCurrent(dstWin); + + QWindowPrivate::get(window)->lastComposeTime.start(); + + m_textures->clear(); + for (int i = 0; i < textures->count(); ++i) + m_textures->appendTexture(textures->source(i), textures->textureId(i), textures->geometry(i), + textures->clipRect(i), textures->flags(i)); + + updateTexture(); + m_textures->appendTexture(nullptr, m_bsTexture, window->geometry()); + + textures->lock(true); + m_lockedWidgetTextures = textures; + + compositor->update(); +} + +void QOpenGLCompositorBackingStore::notifyComposited() +{ + if (m_lockedWidgetTextures) { + QPlatformTextureList *textureList = m_lockedWidgetTextures; + m_lockedWidgetTextures = 0; // may reenter so null before unlocking + textureList->lock(false); + } +} + +void QOpenGLCompositorBackingStore::beginPaint(const QRegion ®ion) +{ + m_dirty |= region; + + if (m_image.hasAlphaChannel()) { + QPainter p(&m_image); + p.setCompositionMode(QPainter::CompositionMode_Source); + for (const QRect &r : region) + p.fillRect(r, Qt::transparent); + } +} + +void QOpenGLCompositorBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(staticContents); + + QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); + QOpenGLContext *dstCtx = compositor->context(); + QWindow *dstWin = compositor->targetWindow(); + if (!dstWin) + return; + + m_image = QImage(size, QImage::Format_RGBA8888); + + m_window->create(); + + dstCtx->makeCurrent(dstWin); + if (m_bsTexture) { + glDeleteTextures(1, &m_bsTexture); + m_bsTexture = 0; + m_bsTextureContext = nullptr; + } +} + +QImage QOpenGLCompositorBackingStore::toImage() const +{ + return m_image; +} + +QT_END_NAMESPACE diff --git a/src/opengl/qopenglcompositorbackingstore_p.h b/src/opengl/qopenglcompositorbackingstore_p.h new file mode 100644 index 0000000000..fcce75ab4e --- /dev/null +++ b/src/opengl/qopenglcompositorbackingstore_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENGLCOMPOSITORBACKINGSTORE_H +#define QOPENGLCOMPOSITORBACKINGSTORE_H + +// +// 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. +// + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QOpenGLContext; +class QPlatformTextureList; + +class Q_OPENGL_EXPORT QOpenGLCompositorBackingStore : public QPlatformBackingStore +{ +public: + QOpenGLCompositorBackingStore(QWindow *window); + ~QOpenGLCompositorBackingStore(); + + QPaintDevice *paintDevice() override; + + void beginPaint(const QRegion ®ion) override; + + void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; + void resize(const QSize &size, const QRegion &staticContents) override; + + QImage toImage() const override; + void composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, + QPlatformTextureList *textures, + bool translucentBackground) override; + + const QPlatformTextureList *textures() const { return m_textures; } + + void notifyComposited(); + +private: + void updateTexture(); + + QWindow *m_window; + QImage m_image; + QRegion m_dirty; + uint m_bsTexture; + QOpenGLContext *m_bsTextureContext; + QPlatformTextureList *m_textures; + QPlatformTextureList *m_lockedWidgetTextures; +}; + +QT_END_NAMESPACE + +#endif // QOPENGLCOMPOSITORBACKINGSTORE_H diff --git a/src/opengl/qplatformbackingstoreopenglsupport.cpp b/src/opengl/qplatformbackingstoreopenglsupport.cpp new file mode 100644 index 0000000000..511d85a400 --- /dev/null +++ b/src/opengl/qplatformbackingstoreopenglsupport.cpp @@ -0,0 +1,455 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT_NO_OPENGL + +#include "qplatformbackingstoreopenglsupport.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#ifndef GL_TEXTURE_BASE_LEVEL +#define GL_TEXTURE_BASE_LEVEL 0x813C +#endif +#ifndef GL_TEXTURE_MAX_LEVEL +#define GL_TEXTURE_MAX_LEVEL 0x813D +#endif +#ifndef GL_UNPACK_ROW_LENGTH +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#endif +#ifndef GL_RGB10_A2 +#define GL_RGB10_A2 0x8059 +#endif +#ifndef GL_UNSIGNED_INT_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#endif + +#ifndef GL_FRAMEBUFFER_SRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif +#ifndef GL_FRAMEBUFFER_SRGB_CAPABLE +#define GL_FRAMEBUFFER_SRGB_CAPABLE 0x8DBA +#endif + +QT_BEGIN_NAMESPACE + +static inline QRect deviceRect(const QRect &rect, QWindow *window) +{ + QRect deviceRect(rect.topLeft() * window->devicePixelRatio(), + rect.size() * window->devicePixelRatio()); + return deviceRect; +} + +static inline QPoint deviceOffset(const QPoint &pt, QWindow *window) +{ + return pt * window->devicePixelRatio(); +} + +static QRegion deviceRegion(const QRegion ®ion, QWindow *window, const QPoint &offset) +{ + if (offset.isNull() && window->devicePixelRatio() <= 1) + return region; + + QVector rects; + rects.reserve(region.rectCount()); + for (const QRect &rect : region) + rects.append(deviceRect(rect.translated(offset), window)); + + QRegion deviceRegion; + deviceRegion.setRects(rects.constData(), rects.count()); + return deviceRegion; +} + +static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) +{ + return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, + topLeftRect.width(), topLeftRect.height()); +} + +static void blitTextureForWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect, + QOpenGLTextureBlitter *blitter, const QPoint &offset, bool canUseSrgb) +{ + const QRect clipRect = textures->clipRect(idx); + if (clipRect.isEmpty()) + return; + + QRect rectInWindow = textures->geometry(idx); + // relative to the TLW, not necessarily our window (if the flush is for a native child widget), have to adjust + rectInWindow.translate(-offset); + + const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); + const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); + + const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(deviceRect(clippedRectInWindow, window), + deviceWindowRect); + + const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(deviceRect(srcRect, window), + deviceRect(rectInWindow, window).size(), + QOpenGLTextureBlitter::OriginBottomLeft); + + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); + const bool srgb = textures->flags(idx).testFlag(QPlatformTextureList::TextureIsSrgb); + if (srgb && canUseSrgb) + funcs->glEnable(GL_FRAMEBUFFER_SRGB); + + blitter->blit(textures->textureId(idx), target, source); + + if (srgb && canUseSrgb) + funcs->glDisable(GL_FRAMEBUFFER_SRGB); +} + +QPlatformBackingStoreOpenGLSupport::~QPlatformBackingStoreOpenGLSupport() { + if (context) { + QOffscreenSurface offscreenSurface; + offscreenSurface.setFormat(context->format()); + offscreenSurface.create(); + context->makeCurrent(&offscreenSurface); + if (textureId) + context->functions()->glDeleteTextures(1, &textureId); + if (blitter) + blitter->destroy(); + } + delete blitter; +} + +void QPlatformBackingStoreOpenGLSupport::composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, QPlatformTextureList *textures, bool translucentBackground) +{ + if (!qt_window_private(window)->receivedExpose) + return; + + if (!context) { + context.reset(new QOpenGLContext); + context->setFormat(window->requestedFormat()); + context->setScreen(window->screen()); + context->setShareContext(qt_window_private(window)->shareContext()); + if (!context->create()) { + qCWarning(lcQpaBackingStore, "composeAndFlush: QOpenGLContext creation failed"); + return; + } + } + + bool current = context->makeCurrent(window); + + if (!current && context->isValid()) { + delete blitter; + blitter = nullptr; + textureId = 0; + current = context->create() && context->makeCurrent(window); + } + + if (!current) { + qCWarning(lcQpaBackingStore, "composeAndFlush: makeCurrent() failed"); + return; + } + + qCDebug(lcQpaBackingStore) << "Composing and flushing" << region << "of" << window + << "at offset" << offset << "with" << textures->count() << "texture(s) in" << textures; + + QWindowPrivate::get(window)->lastComposeTime.start(); + + QOpenGLFunctions *funcs = context->functions(); + funcs->glViewport(0, 0, qRound(window->width() * window->devicePixelRatio()), qRound(window->height() * window->devicePixelRatio())); + funcs->glClearColor(0, 0, 0, translucentBackground ? 0 : 1); + funcs->glClear(GL_COLOR_BUFFER_BIT); + + if (!blitter) { + blitter = new QOpenGLTextureBlitter; + blitter->create(); + } + + blitter->bind(); + + const QRect deviceWindowRect = deviceRect(QRect(QPoint(), window->size()), window); + const QPoint deviceWindowOffset = deviceOffset(offset, window); + + bool canUseSrgb = false; + // If there are any sRGB textures in the list, check if the destination + // framebuffer is sRGB capable. + for (int i = 0; i < textures->count(); ++i) { + if (textures->flags(i).testFlag(QPlatformTextureList::TextureIsSrgb)) { + GLint cap = 0; + funcs->glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE, &cap); + if (cap) + canUseSrgb = true; + break; + } + } + + // Textures for renderToTexture widgets. + for (int i = 0; i < textures->count(); ++i) { + if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) + blitTextureForWidget(textures, i, window, deviceWindowRect, blitter, offset, canUseSrgb); + } + + // Backingstore texture with the normal widgets. + GLuint textureId = 0; + QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft; + if (QPlatformGraphicsBuffer *graphicsBuffer = backingStore->graphicsBuffer()) { + if (graphicsBuffer->size() != textureSize) { + if (this->textureId) + funcs->glDeleteTextures(1, &this->textureId); + funcs->glGenTextures(1, &this->textureId); + funcs->glBindTexture(GL_TEXTURE_2D, this->textureId); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + } + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + if (QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &needsSwizzle, &premultiplied)) { + textureSize = graphicsBuffer->size(); + } else { + textureSize = QSize(0,0); + } + + graphicsBuffer->unlock(); + } else if (!region.isEmpty()){ + funcs->glBindTexture(GL_TEXTURE_2D, this->textureId); + QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &needsSwizzle, &premultiplied); + graphicsBuffer->unlock(); + } + + if (graphicsBuffer->origin() == QPlatformGraphicsBuffer::OriginBottomLeft) + origin = QOpenGLTextureBlitter::OriginBottomLeft; + textureId = this->textureId; + } else { + QPlatformBackingStore::TextureFlags flags; + textureId = backingStore->toTexture(deviceRegion(region, window, offset), &textureSize, &flags); + needsSwizzle = (flags & QPlatformBackingStore::TextureSwizzle) != 0; + premultiplied = (flags & QPlatformBackingStore::TexturePremultiplied) != 0; + if (flags & QPlatformBackingStore::TextureFlip) + origin = QOpenGLTextureBlitter::OriginBottomLeft; + } + + funcs->glEnable(GL_BLEND); + if (premultiplied) + funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + else + funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + + if (textureId) { + if (needsSwizzle) + blitter->setRedBlueSwizzle(true); + // The backingstore is for the entire tlw. + // In case of native children offset tells the position relative to the tlw. + const QRect srcRect = toBottomLeftRect(deviceWindowRect.translated(deviceWindowOffset), textureSize.height()); + const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, + textureSize, + origin); + blitter->blit(textureId, QMatrix4x4(), source); + if (needsSwizzle) + blitter->setRedBlueSwizzle(false); + } + + // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. + bool blendIsPremultiplied = premultiplied; + for (int i = 0; i < textures->count(); ++i) { + const QPlatformTextureList::Flags flags = textures->flags(i); + if (flags.testFlag(QPlatformTextureList::NeedsPremultipliedAlphaBlending)) { + if (!blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = true; + } + } else { + if (blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = false; + } + } + if (flags.testFlag(QPlatformTextureList::StacksOnTop)) + blitTextureForWidget(textures, i, window, deviceWindowRect, blitter, offset, canUseSrgb); + } + + funcs->glDisable(GL_BLEND); + blitter->release(); + + context->swapBuffers(window); +} + +GLuint QPlatformBackingStoreOpenGLSupport::toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const +{ + Q_ASSERT(textureSize); + Q_ASSERT(flags); + + QImage image = backingStore->toImage(); + QSize imageSize = image.size(); + + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + GLenum internalFormat = GL_RGBA; + GLuint pixelType = GL_UNSIGNED_BYTE; + + bool needsConversion = false; + *flags = { }; + switch (image.format()) { + case QImage::Format_ARGB32_Premultiplied: + *flags |= QPlatformBackingStore::TexturePremultiplied; + Q_FALLTHROUGH(); + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + *flags |= QPlatformBackingStore::TextureSwizzle; + break; + case QImage::Format_RGBA8888_Premultiplied: + *flags |= QPlatformBackingStore::TexturePremultiplied; + Q_FALLTHROUGH(); + case QImage::Format_RGBX8888: + case QImage::Format_RGBA8888: + break; + case QImage::Format_BGR30: + case QImage::Format_A2BGR30_Premultiplied: + if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + internalFormat = GL_RGB10_A2; + *flags |= QPlatformBackingStore::TexturePremultiplied; + } else { + needsConversion = true; + } + break; + case QImage::Format_RGB30: + case QImage::Format_A2RGB30_Premultiplied: + if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + internalFormat = GL_RGB10_A2; + *flags |= QPlatformBackingStore::TextureSwizzle | QPlatformBackingStore::TexturePremultiplied; + } else { + needsConversion = true; + } + break; + default: + needsConversion = true; + break; + } + if (imageSize.isEmpty()) { + *textureSize = imageSize; + return 0; + } + + // Must rely on the input only, not d_ptr. + // With the default composeAndFlush() textureSize is &d_ptr->textureSize. + bool resized = *textureSize != imageSize; + if (dirtyRegion.isEmpty() && !resized) + return textureId; + + *textureSize = imageSize; + + if (needsConversion) + image = image.convertToFormat(QImage::Format_RGBA8888); + + // The image provided by the backingstore may have a stride larger than width * 4, for + // instance on platforms that manually implement client-side decorations. + static const int bytesPerPixel = 4; + const qsizetype strideInPixels = image.bytesPerLine() / bytesPerPixel; + const bool hasUnpackRowLength = !ctx->isOpenGLES() || ctx->format().majorVersion() >= 3; + + QOpenGLFunctions *funcs = ctx->functions(); + + if (hasUnpackRowLength) { + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, strideInPixels); + } else if (strideInPixels != image.width()) { + // No UNPACK_ROW_LENGTH on ES 2.0 and yet we would need it. This case is typically + // hit with QtWayland which is rarely used in combination with a ES2.0-only GL + // implementation. Therefore, accept the performance hit and do a copy. + image = image.copy(); + } + + if (resized) { + if (textureId) + funcs->glDeleteTextures(1, &textureId); + funcs->glGenTextures(1, &textureId); + funcs->glBindTexture(GL_TEXTURE_2D, textureId); + if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); + } + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, imageSize.width(), imageSize.height(), 0, GL_RGBA, pixelType, + const_cast(image.constBits())); + } else { + funcs->glBindTexture(GL_TEXTURE_2D, textureId); + QRect imageRect = image.rect(); + QRect rect = dirtyRegion.boundingRect() & imageRect; + + if (hasUnpackRowLength) { + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, + image.constScanLine(rect.y()) + rect.x() * bytesPerPixel); + } else { + // if the rect is wide enough it's cheaper to just + // extend it instead of doing an image copy + if (rect.width() >= imageRect.width() / 2) { + rect.setX(0); + rect.setWidth(imageRect.width()); + } + + // if the sub-rect is full-width we can pass the image data directly to + // OpenGL instead of copying, since there's no gap between scanlines + + if (rect.width() == imageRect.width()) { + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, + image.constScanLine(rect.y())); + } else { + funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, + image.copy(rect).constBits()); + } + } + } + + if (hasUnpackRowLength) + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + return textureId; +} + +#endif // QT_NO_OPENGL + +QT_END_NAMESPACE diff --git a/src/opengl/qplatformbackingstoreopenglsupport.h b/src/opengl/qplatformbackingstoreopenglsupport.h new file mode 100644 index 0000000000..8868703deb --- /dev/null +++ b/src/opengl/qplatformbackingstoreopenglsupport.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or 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.GPL2 and 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMBACKINGSTOREOPENGLSUPPORT_H +#define QPLATFORMBACKINGSTOREOPENGLSUPPORT_H + +// +// W A R N I N G +// ------------- +// +// This file is part of the QPA API and is not meant to be used +// in applications. Usage of this API may make your code +// source and binary incompatible with future versions of Qt. +// + +#ifndef QT_NO_OPENGL + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QOpenGLTextureBlitter; +class QOpenGLBackingStore; + +class Q_OPENGL_EXPORT QPlatformBackingStoreOpenGLSupport : public QPlatformBackingStoreOpenGLSupportBase +{ +public: + explicit QPlatformBackingStoreOpenGLSupport(QPlatformBackingStore *backingStore) : backingStore(backingStore) {} + ~QPlatformBackingStoreOpenGLSupport() override; + void composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, + QPlatformTextureList *textures, bool translucentBackground) override; + GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const override; + +private: + QPlatformBackingStore *backingStore = nullptr; + QScopedPointer context; + mutable GLuint textureId = 0; + mutable QSize textureSize; + mutable bool needsSwizzle = false; + mutable bool premultiplied = false; + QOpenGLTextureBlitter *blitter = nullptr; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_OPENGL + +#endif // QPLATFORMBACKINGSTOREOPENGLSUPPORT_H diff --git a/src/platformsupport/CMakeLists.txt b/src/platformsupport/CMakeLists.txt index e55937ddc8..ae75c87c97 100644 --- a/src/platformsupport/CMakeLists.txt +++ b/src/platformsupport/CMakeLists.txt @@ -19,9 +19,6 @@ endif() if(QT_FEATURE_xcb OR (UNIX AND NOT UIKIT)) add_subdirectory(services) endif() -if(QT_FEATURE_opengl) - add_subdirectory(platformcompositor) -endif() if(QT_FEATURE_egl) add_subdirectory(eglconvenience) endif() diff --git a/src/platformsupport/platformcompositor/CMakeLists.txt b/src/platformsupport/platformcompositor/CMakeLists.txt deleted file mode 100644 index 1ddc9e719d..0000000000 --- a/src/platformsupport/platformcompositor/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Generated from platformcompositor.pro. - -##################################################################### -## PlatformCompositorSupport Module: -##################################################################### - -qt_add_module(PlatformCompositorSupport - STATIC - INTERNAL_MODULE - SOURCES - qopenglcompositor.cpp qopenglcompositor_p.h - qopenglcompositorbackingstore.cpp qopenglcompositorbackingstore_p.h - qplatformbackingstoreopenglsupport.cpp qplatformbackingstoreopenglsupport.h - DEFINES - QT_NO_CAST_FROM_ASCII - PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::GuiPrivate - Qt::OpenGL -) - -#### Keys ignored in scope 1:.:.:platformcompositor.pro:: -# MODULE = "platformcompositor_support" diff --git a/src/platformsupport/platformcompositor/platformcompositor.pro b/src/platformsupport/platformcompositor/platformcompositor.pro deleted file mode 100644 index 89386ab3ef..0000000000 --- a/src/platformsupport/platformcompositor/platformcompositor.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = QtPlatformCompositorSupport -MODULE = platformcompositor_support - -QT = core-private gui-private opengl -CONFIG += static internal_module - -DEFINES += QT_NO_CAST_FROM_ASCII - -SOURCES += \ - qplatformbackingstoreopenglsupport.cpp \ - qopenglcompositor.cpp \ - qopenglcompositorbackingstore.cpp - -HEADERS += \ - qplatformbackingstoreopenglsupport.h \ - qopenglcompositor_p.h \ - qopenglcompositorbackingstore_p.h - -load(qt_module) diff --git a/src/platformsupport/platformcompositor/qopenglcompositor.cpp b/src/platformsupport/platformcompositor/qopenglcompositor.cpp deleted file mode 100644 index abfaca3f9c..0000000000 --- a/src/platformsupport/platformcompositor/qopenglcompositor.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -#include "qopenglcompositor_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QOpenGLCompositor - \brief A generic OpenGL-based compositor - \since 5.4 - \internal - \ingroup qpa - - This class provides a lightweight compositor that maintains the - basic stacking order of windows and composites them by drawing - textured quads via OpenGL. - - It it meant to be used by platform plugins that run without a - windowing system. - - It is up to the platform plugin to manage the lifetime of the - compositor (instance(), destroy()), set the correct destination - context and window as early as possible (setTarget()), - register the composited windows as they are shown, activated, - raised and lowered (addWindow(), moveToTop(), etc.), and to - schedule repaints (update()). - - \note To get support for QWidget-based windows, just use - QOpenGLCompositorBackingStore. It will automatically create - textures from the raster-rendered content and trigger the - necessary repaints. - */ - -static QOpenGLCompositor *compositor = 0; - -QOpenGLCompositor::QOpenGLCompositor() - : m_context(0), - m_targetWindow(0), - m_rotation(0) -{ - Q_ASSERT(!compositor); - m_updateTimer.setSingleShot(true); - m_updateTimer.setInterval(0); - connect(&m_updateTimer, SIGNAL(timeout()), SLOT(handleRenderAllRequest())); -} - -QOpenGLCompositor::~QOpenGLCompositor() -{ - Q_ASSERT(compositor == this); - m_blitter.destroy(); - compositor = 0; -} - -void QOpenGLCompositor::setTarget(QOpenGLContext *context, QWindow *targetWindow, - const QRect &nativeTargetGeometry) -{ - m_context = context; - m_targetWindow = targetWindow; - m_nativeTargetGeometry = nativeTargetGeometry; -} - -void QOpenGLCompositor::setRotation(int degrees) -{ - m_rotation = degrees; - m_rotationMatrix.setToIdentity(); - m_rotationMatrix.rotate(degrees, 0, 0, 1); -} - -void QOpenGLCompositor::update() -{ - if (!m_updateTimer.isActive()) - m_updateTimer.start(); -} - -QImage QOpenGLCompositor::grab() -{ - Q_ASSERT(m_context && m_targetWindow); - m_context->makeCurrent(m_targetWindow); - QScopedPointer fbo(new QOpenGLFramebufferObject(m_nativeTargetGeometry.size())); - renderAll(fbo.data()); - return fbo->toImage(); -} - -void QOpenGLCompositor::handleRenderAllRequest() -{ - Q_ASSERT(m_context && m_targetWindow); - m_context->makeCurrent(m_targetWindow); - renderAll(0); -} - -void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) -{ - if (fbo) - fbo->bind(); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - glViewport(0, 0, m_nativeTargetGeometry.width(), m_nativeTargetGeometry.height()); - - if (!m_blitter.isCreated()) - m_blitter.create(); - - m_blitter.bind(); - - for (int i = 0; i < m_windows.size(); ++i) - m_windows.at(i)->beginCompositing(); - - for (int i = 0; i < m_windows.size(); ++i) - render(m_windows.at(i)); - - m_blitter.release(); - if (!fbo) - m_context->swapBuffers(m_targetWindow); - else - fbo->release(); - - for (int i = 0; i < m_windows.size(); ++i) - m_windows.at(i)->endCompositing(); -} - -struct BlendStateBinder -{ - BlendStateBinder() : m_blend(false) { - glDisable(GL_BLEND); - } - void set(bool blend) { - if (blend != m_blend) { - if (blend) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } else { - glDisable(GL_BLEND); - } - m_blend = blend; - } - } - ~BlendStateBinder() { - if (m_blend) - glDisable(GL_BLEND); - } - bool m_blend; -}; - -static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) -{ - return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, - topLeftRect.width(), topLeftRect.height()); -} - -static void clippedBlit(const QPlatformTextureList *textures, int idx, const QRect &sourceWindowRect, - const QRect &targetWindowRect, - QOpenGLTextureBlitter *blitter, QMatrix4x4 *rotationMatrix) -{ - const QRect clipRect = textures->clipRect(idx); - if (clipRect.isEmpty()) - return; - - const QRect rectInWindow = textures->geometry(idx).translated(sourceWindowRect.topLeft()); - const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); - const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); - - QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(clippedRectInWindow, targetWindowRect); - if (rotationMatrix) - target = *rotationMatrix * target; - - const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, rectInWindow.size(), - QOpenGLTextureBlitter::OriginBottomLeft); - - blitter->blit(textures->textureId(idx), target, source); -} - -void QOpenGLCompositor::render(QOpenGLCompositorWindow *window) -{ - const QPlatformTextureList *textures = window->textures(); - if (!textures) - return; - - const QRect targetWindowRect(QPoint(0, 0), m_targetWindow->geometry().size()); - float currentOpacity = 1.0f; - BlendStateBinder blend; - const QRect sourceWindowRect = window->sourceWindow()->geometry(); - for (int i = 0; i < textures->count(); ++i) { - uint textureId = textures->textureId(i); - const float opacity = window->sourceWindow()->opacity(); - if (opacity != currentOpacity) { - currentOpacity = opacity; - m_blitter.setOpacity(currentOpacity); - } - - if (textures->count() > 1 && i == textures->count() - 1) { - // Backingstore for a widget with QOpenGLWidget subwidgets - blend.set(true); - QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); - if (m_rotation) - target = m_rotationMatrix * target; - m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); - } else if (textures->count() == 1) { - // A regular QWidget window - const bool translucent = window->sourceWindow()->requestedFormat().alphaBufferSize() > 0; - blend.set(translucent); - QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), targetWindowRect); - if (m_rotation) - target = m_rotationMatrix * target; - m_blitter.blit(textureId, target, QOpenGLTextureBlitter::OriginTopLeft); - } else if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { - // Texture from an FBO belonging to a QOpenGLWidget or QQuickWidget - blend.set(false); - clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); - } - } - - for (int i = 0; i < textures->count(); ++i) { - if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) { - blend.set(true); - clippedBlit(textures, i, sourceWindowRect, targetWindowRect, &m_blitter, m_rotation ? &m_rotationMatrix : nullptr); - } - } - - m_blitter.setOpacity(1.0f); -} - -QOpenGLCompositor *QOpenGLCompositor::instance() -{ - if (!compositor) - compositor = new QOpenGLCompositor; - return compositor; -} - -void QOpenGLCompositor::destroy() -{ - delete compositor; - compositor = 0; -} - -void QOpenGLCompositor::addWindow(QOpenGLCompositorWindow *window) -{ - if (!m_windows.contains(window)) { - m_windows.append(window); - emit topWindowChanged(window); - } -} - -void QOpenGLCompositor::removeWindow(QOpenGLCompositorWindow *window) -{ - m_windows.removeOne(window); - if (!m_windows.isEmpty()) - emit topWindowChanged(m_windows.last()); -} - -void QOpenGLCompositor::moveToTop(QOpenGLCompositorWindow *window) -{ - m_windows.removeOne(window); - m_windows.append(window); - emit topWindowChanged(window); -} - -void QOpenGLCompositor::changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx) -{ - int idx = m_windows.indexOf(window); - if (idx != -1 && idx != newIdx) { - m_windows.move(idx, newIdx); - if (newIdx == m_windows.size() - 1) - emit topWindowChanged(m_windows.last()); - } -} - -QT_END_NAMESPACE diff --git a/src/platformsupport/platformcompositor/qopenglcompositor_p.h b/src/platformsupport/platformcompositor/qopenglcompositor_p.h deleted file mode 100644 index c9414c82c6..0000000000 --- a/src/platformsupport/platformcompositor/qopenglcompositor_p.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QOPENGLCOMPOSITOR_H -#define QOPENGLCOMPOSITOR_H - -// -// 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. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QOpenGLContext; -class QOpenGLFramebufferObject; -class QWindow; -class QPlatformTextureList; - -class QOpenGLCompositorWindow -{ -public: - virtual ~QOpenGLCompositorWindow() { } - virtual QWindow *sourceWindow() const = 0; - virtual const QPlatformTextureList *textures() const = 0; - virtual void beginCompositing() { } - virtual void endCompositing() { } -}; - -class QOpenGLCompositor : public QObject -{ - Q_OBJECT - -public: - static QOpenGLCompositor *instance(); - static void destroy(); - - void setTarget(QOpenGLContext *context, QWindow *window, const QRect &nativeTargetGeometry); - void setRotation(int degrees); - QOpenGLContext *context() const { return m_context; } - QWindow *targetWindow() const { return m_targetWindow; } - - void update(); - QImage grab(); - - QList windows() const { return m_windows; } - void addWindow(QOpenGLCompositorWindow *window); - void removeWindow(QOpenGLCompositorWindow *window); - void moveToTop(QOpenGLCompositorWindow *window); - void changeWindowIndex(QOpenGLCompositorWindow *window, int newIdx); - -signals: - void topWindowChanged(QOpenGLCompositorWindow *window); - -private slots: - void handleRenderAllRequest(); - -private: - QOpenGLCompositor(); - ~QOpenGLCompositor(); - - void renderAll(QOpenGLFramebufferObject *fbo); - void render(QOpenGLCompositorWindow *window); - - QOpenGLContext *m_context; - QWindow *m_targetWindow; - QRect m_nativeTargetGeometry; - int m_rotation; - QMatrix4x4 m_rotationMatrix; - QTimer m_updateTimer; - QOpenGLTextureBlitter m_blitter; - QList m_windows; -}; - -QT_END_NAMESPACE - -#endif // QOPENGLCOMPOSITOR_H diff --git a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp b/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp deleted file mode 100644 index 40400e2a19..0000000000 --- a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include "qopenglcompositorbackingstore_p.h" -#include "qopenglcompositor_p.h" - -#ifndef GL_UNPACK_ROW_LENGTH -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#endif - -QT_BEGIN_NAMESPACE - -/*! - \class QOpenGLCompositorBackingStore - \brief A backing store implementation for OpenGL - \since 5.4 - \internal - \ingroup qpa - - This implementation uploads raster-rendered widget windows into - textures. It is meant to be used with QOpenGLCompositor that - composites the textures onto a single native window using OpenGL. - This means that multiple top-level widgets are supported without - creating actual native windows for each of them. - - \note It is important to call notifyComposited() from the - corresponding platform window's endCompositing() callback - (inherited from QOpenGLCompositorWindow). - - \note When implementing QOpenGLCompositorWindow::textures() for - windows of type RasterSurface or RasterGLSurface, simply return - the list provided by this class' textures(). -*/ - -QOpenGLCompositorBackingStore::QOpenGLCompositorBackingStore(QWindow *window) - : QPlatformBackingStore(window), - m_window(window), - m_bsTexture(0), - m_bsTextureContext(0), - m_textures(new QPlatformTextureList), - m_lockedWidgetTextures(0) -{ -} - -QOpenGLCompositorBackingStore::~QOpenGLCompositorBackingStore() -{ - if (m_bsTexture) { - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - // With render-to-texture-widgets QWidget makes sure the TLW's shareContext() is - // made current before destroying backingstores. That is however not the case for - // windows with regular widgets only. - QScopedPointer tempSurface; - if (!ctx) { - ctx = QOpenGLCompositor::instance()->context(); - tempSurface.reset(new QOffscreenSurface); - tempSurface->setFormat(ctx->format()); - tempSurface->create(); - ctx->makeCurrent(tempSurface.data()); - } - - if (m_bsTextureContext && ctx->shareGroup() == m_bsTextureContext->shareGroup()) - glDeleteTextures(1, &m_bsTexture); - else - qWarning("QOpenGLCompositorBackingStore: Texture is not valid in the current context"); - - if (tempSurface) - ctx->doneCurrent(); - } - - delete m_textures; // this does not actually own any GL resources -} - -QPaintDevice *QOpenGLCompositorBackingStore::paintDevice() -{ - return &m_image; -} - -void QOpenGLCompositorBackingStore::updateTexture() -{ - if (!m_bsTexture) { - m_bsTextureContext = QOpenGLContext::currentContext(); - Q_ASSERT(m_bsTextureContext); - glGenTextures(1, &m_bsTexture); - glBindTexture(GL_TEXTURE_2D, m_bsTexture); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_image.width(), m_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - } else { - glBindTexture(GL_TEXTURE_2D, m_bsTexture); - } - - if (!m_dirty.isNull()) { - QRegion fixed; - QRect imageRect = m_image.rect(); - - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - for (const QRect &rect : m_dirty) { - QRect r = imageRect & rect; - glPixelStorei(GL_UNPACK_ROW_LENGTH, m_image.width()); - glTexSubImage2D(GL_TEXTURE_2D, 0, r.x(), r.y(), r.width(), r.height(), GL_RGBA, GL_UNSIGNED_BYTE, - m_image.constScanLine(r.y()) + r.x() * 4); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - } - } else { - for (const QRect &rect : m_dirty) { - // intersect with image rect to be sure - QRect r = imageRect & rect; - - // if the rect is wide enough it's cheaper to just - // extend it instead of doing an image copy - if (r.width() >= imageRect.width() / 2) { - r.setX(0); - r.setWidth(imageRect.width()); - } - - fixed |= r; - } - for (const QRect &rect : fixed) { - // if the sub-rect is full-width we can pass the image data directly to - // OpenGL instead of copying, since there's no gap between scanlines - if (rect.width() == imageRect.width()) { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, - m_image.constScanLine(rect.y())); - } else { - glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, - m_image.copy(rect).constBits()); - } - } - } - - m_dirty = QRegion(); - } -} - -void QOpenGLCompositorBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) -{ - // Called for ordinary raster windows. - - Q_UNUSED(region); - Q_UNUSED(offset); - - QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); - QOpenGLContext *dstCtx = compositor->context(); - Q_ASSERT(dstCtx); - - QWindow *dstWin = compositor->targetWindow(); - if (!dstWin) - return; - - dstCtx->makeCurrent(dstWin); - updateTexture(); - m_textures->clear(); - m_textures->appendTexture(nullptr, m_bsTexture, window->geometry()); - - compositor->update(); -} - -void QOpenGLCompositorBackingStore::composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, - QPlatformTextureList *textures, - bool translucentBackground) -{ - // QOpenGLWidget/QQuickWidget content provided as textures. The raster content goes on top. - - Q_UNUSED(region); - Q_UNUSED(offset); - Q_UNUSED(translucentBackground); - - QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); - QOpenGLContext *dstCtx = compositor->context(); - Q_ASSERT(dstCtx); // setTarget() must have been called before, e.g. from QEGLFSWindow - - // The compositor's context and the context to which QOpenGLWidget/QQuickWidget - // textures belong are not the same. They share resources, though. - Q_ASSERT(qt_window_private(window)->shareContext()->shareGroup() == dstCtx->shareGroup()); - - QWindow *dstWin = compositor->targetWindow(); - if (!dstWin) - return; - - dstCtx->makeCurrent(dstWin); - - QWindowPrivate::get(window)->lastComposeTime.start(); - - m_textures->clear(); - for (int i = 0; i < textures->count(); ++i) - m_textures->appendTexture(textures->source(i), textures->textureId(i), textures->geometry(i), - textures->clipRect(i), textures->flags(i)); - - updateTexture(); - m_textures->appendTexture(nullptr, m_bsTexture, window->geometry()); - - textures->lock(true); - m_lockedWidgetTextures = textures; - - compositor->update(); -} - -void QOpenGLCompositorBackingStore::notifyComposited() -{ - if (m_lockedWidgetTextures) { - QPlatformTextureList *textureList = m_lockedWidgetTextures; - m_lockedWidgetTextures = 0; // may reenter so null before unlocking - textureList->lock(false); - } -} - -void QOpenGLCompositorBackingStore::beginPaint(const QRegion ®ion) -{ - m_dirty |= region; - - if (m_image.hasAlphaChannel()) { - QPainter p(&m_image); - p.setCompositionMode(QPainter::CompositionMode_Source); - for (const QRect &r : region) - p.fillRect(r, Qt::transparent); - } -} - -void QOpenGLCompositorBackingStore::resize(const QSize &size, const QRegion &staticContents) -{ - Q_UNUSED(staticContents); - - QOpenGLCompositor *compositor = QOpenGLCompositor::instance(); - QOpenGLContext *dstCtx = compositor->context(); - QWindow *dstWin = compositor->targetWindow(); - if (!dstWin) - return; - - m_image = QImage(size, QImage::Format_RGBA8888); - - m_window->create(); - - dstCtx->makeCurrent(dstWin); - if (m_bsTexture) { - glDeleteTextures(1, &m_bsTexture); - m_bsTexture = 0; - m_bsTextureContext = nullptr; - } -} - -QImage QOpenGLCompositorBackingStore::toImage() const -{ - return m_image; -} - -QT_END_NAMESPACE diff --git a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h b/src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h deleted file mode 100644 index d88738ea8f..0000000000 --- a/src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QOPENGLCOMPOSITORBACKINGSTORE_H -#define QOPENGLCOMPOSITORBACKINGSTORE_H - -// -// 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. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QOpenGLContext; -class QPlatformTextureList; - -class QOpenGLCompositorBackingStore : public QPlatformBackingStore -{ -public: - QOpenGLCompositorBackingStore(QWindow *window); - ~QOpenGLCompositorBackingStore(); - - QPaintDevice *paintDevice() override; - - void beginPaint(const QRegion ®ion) override; - - void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; - void resize(const QSize &size, const QRegion &staticContents) override; - - QImage toImage() const override; - void composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, - QPlatformTextureList *textures, - bool translucentBackground) override; - - const QPlatformTextureList *textures() const { return m_textures; } - - void notifyComposited(); - -private: - void updateTexture(); - - QWindow *m_window; - QImage m_image; - QRegion m_dirty; - uint m_bsTexture; - QOpenGLContext *m_bsTextureContext; - QPlatformTextureList *m_textures; - QPlatformTextureList *m_lockedWidgetTextures; -}; - -QT_END_NAMESPACE - -#endif // QOPENGLCOMPOSITORBACKINGSTORE_H diff --git a/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp b/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp deleted file mode 100644 index 511d85a400..0000000000 --- a/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp +++ /dev/null @@ -1,455 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_OPENGL - -#include "qplatformbackingstoreopenglsupport.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#ifndef GL_TEXTURE_BASE_LEVEL -#define GL_TEXTURE_BASE_LEVEL 0x813C -#endif -#ifndef GL_TEXTURE_MAX_LEVEL -#define GL_TEXTURE_MAX_LEVEL 0x813D -#endif -#ifndef GL_UNPACK_ROW_LENGTH -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#endif -#ifndef GL_RGB10_A2 -#define GL_RGB10_A2 0x8059 -#endif -#ifndef GL_UNSIGNED_INT_2_10_10_10_REV -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#endif - -#ifndef GL_FRAMEBUFFER_SRGB -#define GL_FRAMEBUFFER_SRGB 0x8DB9 -#endif -#ifndef GL_FRAMEBUFFER_SRGB_CAPABLE -#define GL_FRAMEBUFFER_SRGB_CAPABLE 0x8DBA -#endif - -QT_BEGIN_NAMESPACE - -static inline QRect deviceRect(const QRect &rect, QWindow *window) -{ - QRect deviceRect(rect.topLeft() * window->devicePixelRatio(), - rect.size() * window->devicePixelRatio()); - return deviceRect; -} - -static inline QPoint deviceOffset(const QPoint &pt, QWindow *window) -{ - return pt * window->devicePixelRatio(); -} - -static QRegion deviceRegion(const QRegion ®ion, QWindow *window, const QPoint &offset) -{ - if (offset.isNull() && window->devicePixelRatio() <= 1) - return region; - - QVector rects; - rects.reserve(region.rectCount()); - for (const QRect &rect : region) - rects.append(deviceRect(rect.translated(offset), window)); - - QRegion deviceRegion; - deviceRegion.setRects(rects.constData(), rects.count()); - return deviceRegion; -} - -static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) -{ - return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, - topLeftRect.width(), topLeftRect.height()); -} - -static void blitTextureForWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect, - QOpenGLTextureBlitter *blitter, const QPoint &offset, bool canUseSrgb) -{ - const QRect clipRect = textures->clipRect(idx); - if (clipRect.isEmpty()) - return; - - QRect rectInWindow = textures->geometry(idx); - // relative to the TLW, not necessarily our window (if the flush is for a native child widget), have to adjust - rectInWindow.translate(-offset); - - const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); - const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); - - const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(deviceRect(clippedRectInWindow, window), - deviceWindowRect); - - const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(deviceRect(srcRect, window), - deviceRect(rectInWindow, window).size(), - QOpenGLTextureBlitter::OriginBottomLeft); - - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - const bool srgb = textures->flags(idx).testFlag(QPlatformTextureList::TextureIsSrgb); - if (srgb && canUseSrgb) - funcs->glEnable(GL_FRAMEBUFFER_SRGB); - - blitter->blit(textures->textureId(idx), target, source); - - if (srgb && canUseSrgb) - funcs->glDisable(GL_FRAMEBUFFER_SRGB); -} - -QPlatformBackingStoreOpenGLSupport::~QPlatformBackingStoreOpenGLSupport() { - if (context) { - QOffscreenSurface offscreenSurface; - offscreenSurface.setFormat(context->format()); - offscreenSurface.create(); - context->makeCurrent(&offscreenSurface); - if (textureId) - context->functions()->glDeleteTextures(1, &textureId); - if (blitter) - blitter->destroy(); - } - delete blitter; -} - -void QPlatformBackingStoreOpenGLSupport::composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, QPlatformTextureList *textures, bool translucentBackground) -{ - if (!qt_window_private(window)->receivedExpose) - return; - - if (!context) { - context.reset(new QOpenGLContext); - context->setFormat(window->requestedFormat()); - context->setScreen(window->screen()); - context->setShareContext(qt_window_private(window)->shareContext()); - if (!context->create()) { - qCWarning(lcQpaBackingStore, "composeAndFlush: QOpenGLContext creation failed"); - return; - } - } - - bool current = context->makeCurrent(window); - - if (!current && context->isValid()) { - delete blitter; - blitter = nullptr; - textureId = 0; - current = context->create() && context->makeCurrent(window); - } - - if (!current) { - qCWarning(lcQpaBackingStore, "composeAndFlush: makeCurrent() failed"); - return; - } - - qCDebug(lcQpaBackingStore) << "Composing and flushing" << region << "of" << window - << "at offset" << offset << "with" << textures->count() << "texture(s) in" << textures; - - QWindowPrivate::get(window)->lastComposeTime.start(); - - QOpenGLFunctions *funcs = context->functions(); - funcs->glViewport(0, 0, qRound(window->width() * window->devicePixelRatio()), qRound(window->height() * window->devicePixelRatio())); - funcs->glClearColor(0, 0, 0, translucentBackground ? 0 : 1); - funcs->glClear(GL_COLOR_BUFFER_BIT); - - if (!blitter) { - blitter = new QOpenGLTextureBlitter; - blitter->create(); - } - - blitter->bind(); - - const QRect deviceWindowRect = deviceRect(QRect(QPoint(), window->size()), window); - const QPoint deviceWindowOffset = deviceOffset(offset, window); - - bool canUseSrgb = false; - // If there are any sRGB textures in the list, check if the destination - // framebuffer is sRGB capable. - for (int i = 0; i < textures->count(); ++i) { - if (textures->flags(i).testFlag(QPlatformTextureList::TextureIsSrgb)) { - GLint cap = 0; - funcs->glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE, &cap); - if (cap) - canUseSrgb = true; - break; - } - } - - // Textures for renderToTexture widgets. - for (int i = 0; i < textures->count(); ++i) { - if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) - blitTextureForWidget(textures, i, window, deviceWindowRect, blitter, offset, canUseSrgb); - } - - // Backingstore texture with the normal widgets. - GLuint textureId = 0; - QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft; - if (QPlatformGraphicsBuffer *graphicsBuffer = backingStore->graphicsBuffer()) { - if (graphicsBuffer->size() != textureSize) { - if (this->textureId) - funcs->glDeleteTextures(1, &this->textureId); - funcs->glGenTextures(1, &this->textureId); - funcs->glBindTexture(GL_TEXTURE_2D, this->textureId); - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - } - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - if (QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &needsSwizzle, &premultiplied)) { - textureSize = graphicsBuffer->size(); - } else { - textureSize = QSize(0,0); - } - - graphicsBuffer->unlock(); - } else if (!region.isEmpty()){ - funcs->glBindTexture(GL_TEXTURE_2D, this->textureId); - QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &needsSwizzle, &premultiplied); - graphicsBuffer->unlock(); - } - - if (graphicsBuffer->origin() == QPlatformGraphicsBuffer::OriginBottomLeft) - origin = QOpenGLTextureBlitter::OriginBottomLeft; - textureId = this->textureId; - } else { - QPlatformBackingStore::TextureFlags flags; - textureId = backingStore->toTexture(deviceRegion(region, window, offset), &textureSize, &flags); - needsSwizzle = (flags & QPlatformBackingStore::TextureSwizzle) != 0; - premultiplied = (flags & QPlatformBackingStore::TexturePremultiplied) != 0; - if (flags & QPlatformBackingStore::TextureFlip) - origin = QOpenGLTextureBlitter::OriginBottomLeft; - } - - funcs->glEnable(GL_BLEND); - if (premultiplied) - funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - else - funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - - if (textureId) { - if (needsSwizzle) - blitter->setRedBlueSwizzle(true); - // The backingstore is for the entire tlw. - // In case of native children offset tells the position relative to the tlw. - const QRect srcRect = toBottomLeftRect(deviceWindowRect.translated(deviceWindowOffset), textureSize.height()); - const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, - textureSize, - origin); - blitter->blit(textureId, QMatrix4x4(), source); - if (needsSwizzle) - blitter->setRedBlueSwizzle(false); - } - - // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. - bool blendIsPremultiplied = premultiplied; - for (int i = 0; i < textures->count(); ++i) { - const QPlatformTextureList::Flags flags = textures->flags(i); - if (flags.testFlag(QPlatformTextureList::NeedsPremultipliedAlphaBlending)) { - if (!blendIsPremultiplied) { - funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - blendIsPremultiplied = true; - } - } else { - if (blendIsPremultiplied) { - funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - blendIsPremultiplied = false; - } - } - if (flags.testFlag(QPlatformTextureList::StacksOnTop)) - blitTextureForWidget(textures, i, window, deviceWindowRect, blitter, offset, canUseSrgb); - } - - funcs->glDisable(GL_BLEND); - blitter->release(); - - context->swapBuffers(window); -} - -GLuint QPlatformBackingStoreOpenGLSupport::toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const -{ - Q_ASSERT(textureSize); - Q_ASSERT(flags); - - QImage image = backingStore->toImage(); - QSize imageSize = image.size(); - - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - GLenum internalFormat = GL_RGBA; - GLuint pixelType = GL_UNSIGNED_BYTE; - - bool needsConversion = false; - *flags = { }; - switch (image.format()) { - case QImage::Format_ARGB32_Premultiplied: - *flags |= QPlatformBackingStore::TexturePremultiplied; - Q_FALLTHROUGH(); - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - *flags |= QPlatformBackingStore::TextureSwizzle; - break; - case QImage::Format_RGBA8888_Premultiplied: - *flags |= QPlatformBackingStore::TexturePremultiplied; - Q_FALLTHROUGH(); - case QImage::Format_RGBX8888: - case QImage::Format_RGBA8888: - break; - case QImage::Format_BGR30: - case QImage::Format_A2BGR30_Premultiplied: - if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; - internalFormat = GL_RGB10_A2; - *flags |= QPlatformBackingStore::TexturePremultiplied; - } else { - needsConversion = true; - } - break; - case QImage::Format_RGB30: - case QImage::Format_A2RGB30_Premultiplied: - if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; - internalFormat = GL_RGB10_A2; - *flags |= QPlatformBackingStore::TextureSwizzle | QPlatformBackingStore::TexturePremultiplied; - } else { - needsConversion = true; - } - break; - default: - needsConversion = true; - break; - } - if (imageSize.isEmpty()) { - *textureSize = imageSize; - return 0; - } - - // Must rely on the input only, not d_ptr. - // With the default composeAndFlush() textureSize is &d_ptr->textureSize. - bool resized = *textureSize != imageSize; - if (dirtyRegion.isEmpty() && !resized) - return textureId; - - *textureSize = imageSize; - - if (needsConversion) - image = image.convertToFormat(QImage::Format_RGBA8888); - - // The image provided by the backingstore may have a stride larger than width * 4, for - // instance on platforms that manually implement client-side decorations. - static const int bytesPerPixel = 4; - const qsizetype strideInPixels = image.bytesPerLine() / bytesPerPixel; - const bool hasUnpackRowLength = !ctx->isOpenGLES() || ctx->format().majorVersion() >= 3; - - QOpenGLFunctions *funcs = ctx->functions(); - - if (hasUnpackRowLength) { - funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, strideInPixels); - } else if (strideInPixels != image.width()) { - // No UNPACK_ROW_LENGTH on ES 2.0 and yet we would need it. This case is typically - // hit with QtWayland which is rarely used in combination with a ES2.0-only GL - // implementation. Therefore, accept the performance hit and do a copy. - image = image.copy(); - } - - if (resized) { - if (textureId) - funcs->glDeleteTextures(1, &textureId); - funcs->glGenTextures(1, &textureId); - funcs->glBindTexture(GL_TEXTURE_2D, textureId); - if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - } - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, imageSize.width(), imageSize.height(), 0, GL_RGBA, pixelType, - const_cast(image.constBits())); - } else { - funcs->glBindTexture(GL_TEXTURE_2D, textureId); - QRect imageRect = image.rect(); - QRect rect = dirtyRegion.boundingRect() & imageRect; - - if (hasUnpackRowLength) { - funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, - image.constScanLine(rect.y()) + rect.x() * bytesPerPixel); - } else { - // if the rect is wide enough it's cheaper to just - // extend it instead of doing an image copy - if (rect.width() >= imageRect.width() / 2) { - rect.setX(0); - rect.setWidth(imageRect.width()); - } - - // if the sub-rect is full-width we can pass the image data directly to - // OpenGL instead of copying, since there's no gap between scanlines - - if (rect.width() == imageRect.width()) { - funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, - image.constScanLine(rect.y())); - } else { - funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, - image.copy(rect).constBits()); - } - } - } - - if (hasUnpackRowLength) - funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - return textureId; -} - -#endif // QT_NO_OPENGL - -QT_END_NAMESPACE diff --git a/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.h b/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.h deleted file mode 100644 index 5523b18f76..0000000000 --- a/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or 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.GPL2 and 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPLATFORMBACKINGSTOREOPENGLSUPPORT_H -#define QPLATFORMBACKINGSTOREOPENGLSUPPORT_H - -// -// W A R N I N G -// ------------- -// -// This file is part of the QPA API and is not meant to be used -// in applications. Usage of this API may make your code -// source and binary incompatible with future versions of Qt. -// - -#ifndef QT_NO_OPENGL - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -class QOpenGLTextureBlitter; -class QOpenGLBackingStore; - -class QPlatformBackingStoreOpenGLSupport : public QPlatformBackingStoreOpenGLSupportBase -{ -public: - explicit QPlatformBackingStoreOpenGLSupport(QPlatformBackingStore *backingStore) : backingStore(backingStore) {} - ~QPlatformBackingStoreOpenGLSupport() override; - void composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, - QPlatformTextureList *textures, bool translucentBackground) override; - GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const override; - -private: - QPlatformBackingStore *backingStore = nullptr; - QScopedPointer context; - mutable GLuint textureId = 0; - mutable QSize textureSize; - mutable bool needsSwizzle = false; - mutable bool premultiplied = false; - QOpenGLTextureBlitter *blitter = nullptr; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_OPENGL - -#endif // QPLATFORMBACKINGSTOREOPENGLSUPPORT_H diff --git a/src/platformsupport/platformsupport.pro b/src/platformsupport/platformsupport.pro index ae71ecaded..f8f37b53a2 100644 --- a/src/platformsupport/platformsupport.pro +++ b/src/platformsupport/platformsupport.pro @@ -19,8 +19,6 @@ qtConfig(evdev)|qtConfig(tslib)|qtConfig(libinput)|qtConfig(integrityhid)|qtConf if(unix:!uikit)|qtConfig(xcb): \ SUBDIRS += services -qtConfig(opengl): \ - SUBDIRS += platformcompositor qtConfig(egl): \ SUBDIRS += eglconvenience qtConfig(xlib):qtConfig(opengl):!qtConfig(opengles2): \ diff --git a/src/plugins/platforms/android/CMakeLists.txt b/src/plugins/platforms/android/CMakeLists.txt index c61d8653c7..3d61c1e959 100644 --- a/src/plugins/platforms/android/CMakeLists.txt +++ b/src/plugins/platforms/android/CMakeLists.txt @@ -76,9 +76,9 @@ qt_extend_target(QAndroidIntegrationPlugin CONDITION QT_FEATURE_vulkan qandroidplatformvulkanwindow.cpp qandroidplatformvulkanwindow.h ) -qt_extend_target(QAndroidIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate +qt_extend_target(QAndroidIntegrationPlugin CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) qt_extend_target(QAndroidIntegrationPlugin CONDITION QT_FEATURE_android_style_assets diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 2baf04addd..80d3bdd37f 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -7,7 +7,7 @@ QT += \ eventdispatcher_support-private accessibility_support-private \ fontdatabase_support-private egl_support-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private OTHER_FILES += $$PWD/android.json diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 837b1974a6..aa57cb18f9 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -44,7 +44,7 @@ #include #include #if QT_CONFIG(opengl) -#include +#include #endif #include #include diff --git a/src/plugins/platforms/cocoa/CMakeLists.txt b/src/plugins/platforms/cocoa/CMakeLists.txt index c4750113f1..599359b09c 100644 --- a/src/plugins/platforms/cocoa/CMakeLists.txt +++ b/src/plugins/platforms/cocoa/CMakeLists.txt @@ -111,9 +111,9 @@ qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_sessionmanager qcocoasessionmanager.cpp qcocoasessionmanager.h ) -qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate +qt_extend_target(QCocoaIntegrationPlugin CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) qt_extend_target(QCocoaIntegrationPlugin CONDITION TARGET Qt::Widgets diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 9bd95bbceb..eed276aed3 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -98,7 +98,7 @@ QT += \ core-private gui-private \ theme_support-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private CONFIG += no_app_extension_api_only diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 27e0bb5f30..1fbe09fa9c 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -69,7 +69,7 @@ #include #if QT_CONFIG(opengl) -#include +#include #endif #ifdef QT_WIDGETS_LIB diff --git a/src/plugins/platforms/eglfs/CMakeLists.txt b/src/plugins/platforms/eglfs/CMakeLists.txt index cef9b94859..622fbe6037 100644 --- a/src/plugins/platforms/eglfs/CMakeLists.txt +++ b/src/plugins/platforms/eglfs/CMakeLists.txt @@ -44,9 +44,9 @@ qt_extend_target(EglFSDeviceIntegration CONDITION TARGET Qt::InputSupportPrivate Qt::InputSupportPrivate ) -qt_extend_target(EglFSDeviceIntegration CONDITION TARGET Qt::PlatformCompositorSupportPrivate +qt_extend_target(EglFSDeviceIntegration CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) qt_extend_target(EglFSDeviceIntegration CONDITION QT_FEATURE_vulkan diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp index e26d984cc1..8cf030f391 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp @@ -73,7 +73,7 @@ #include #include #ifndef QT_NO_OPENGL -# include +# include #endif #include diff --git a/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp b/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp index 1d3e5ca6af..81f2e07f6b 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp @@ -43,7 +43,7 @@ #include #include #ifndef QT_NO_OPENGL -# include +# include #endif #include "qeglfsscreen_p.h" diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp index f7e116eb88..e3b49f79dd 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp @@ -45,7 +45,7 @@ #ifndef QT_NO_OPENGL # include # include -# include +# include #endif #include diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h index 7bf74c25ee..130b87eef7 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h @@ -57,7 +57,7 @@ #include #ifndef QT_NO_OPENGL -# include +# include #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro index 8bb7b614f1..782ea59145 100644 --- a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro +++ b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro @@ -17,8 +17,7 @@ QT += \ qtHaveModule(input_support-private): \ QT += input_support-private -qtHaveModule(platformcompositor_support-private): \ - QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 diff --git a/src/plugins/platforms/ios/CMakeLists.txt b/src/plugins/platforms/ios/CMakeLists.txt index 0236f0d27d..6acff8b074 100644 --- a/src/plugins/platforms/ios/CMakeLists.txt +++ b/src/plugins/platforms/ios/CMakeLists.txt @@ -47,9 +47,9 @@ qt_disable_apple_app_extension_api_only(QIOSIntegrationPlugin) ## Scopes: ##################################################################### -extend_target(QIOSIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate +extend_target(QIOSIntegrationPlugin CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) extend_target(QIOSIntegrationPlugin CONDITION NOT TVOS diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro index 859fa6e079..50907abbc3 100644 --- a/src/plugins/platforms/ios/kernel.pro +++ b/src/plugins/platforms/ios/kernel.pro @@ -8,7 +8,7 @@ qtConfig(shared): CONFIG += static QT += \ core-private gui-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AudioToolbox diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 3b01342b8e..8b68c83eef 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -67,7 +67,7 @@ #import #if QT_CONFIG(opengl) -#include +#include #endif #include diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 37cc6185c5..fd76f64dc9 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -41,7 +41,7 @@ #include "qwasmwindow.h" #ifndef QT_NO_OPENGL # include "qwasmbackingstore.h" -# include +# include #endif #include "qwasmfontdatabase.h" #if defined(Q_OS_UNIX) diff --git a/src/plugins/platforms/wasm/wasm.pro b/src/plugins/platforms/wasm/wasm.pro index 1aee4a3e58..0eefe90163 100644 --- a/src/plugins/platforms/wasm/wasm.pro +++ b/src/plugins/platforms/wasm/wasm.pro @@ -4,7 +4,7 @@ QT += \ core-private gui-private \ eventdispatcher_support-private fontdatabase_support-private egl_support-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 diff --git a/src/plugins/platforms/windows/CMakeLists.txt b/src/plugins/platforms/windows/CMakeLists.txt index c79a5a335b..cb79a5d9d0 100644 --- a/src/plugins/platforms/windows/CMakeLists.txt +++ b/src/plugins/platforms/windows/CMakeLists.txt @@ -86,9 +86,9 @@ qt_add_resource(QWindowsIntegrationPlugin "openglblacklists" ## Scopes: ##################################################################### -qt_extend_target(QWindowsIntegrationPlugin CONDITION TARGET Qt::PlatformCompositorSupportPrivate +qt_extend_target(QWindowsIntegrationPlugin CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) qt_extend_target(QWindowsIntegrationPlugin CONDITION QT_FEATURE_accessibility diff --git a/src/plugins/platforms/windows/qwindowsgdiintegration.cpp b/src/plugins/platforms/windows/qwindowsgdiintegration.cpp index 7e9595321a..3b25840e16 100644 --- a/src/plugins/platforms/windows/qwindowsgdiintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsgdiintegration.cpp @@ -46,7 +46,7 @@ #include #if QT_CONFIG(opengl) -#include +#include #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/windows/windows.pro b/src/plugins/platforms/windows/windows.pro index ff5201e290..d311744675 100644 --- a/src/plugins/platforms/windows/windows.pro +++ b/src/plugins/platforms/windows/windows.pro @@ -5,7 +5,7 @@ QT += \ eventdispatcher_support-private \ fontdatabase_support-private theme_support-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private qtConfig(accessibility): QT += accessibility_support-private diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp index f7d44c6f28..0f76d7d65b 100644 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ b/src/plugins/platforms/winrt/qwinrtintegration.cpp @@ -54,7 +54,7 @@ # include "uiautomation/qwinrtuiaaccessibility.h" #endif #if QT_CONFIG(opengl) -#include +#include #endif #include diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro index 7ac49f73c4..3d9f9a36d1 100644 --- a/src/plugins/platforms/winrt/winrt.pro +++ b/src/plugins/platforms/winrt/winrt.pro @@ -6,7 +6,7 @@ QT += \ core-private gui-private \ fontdatabase_support-private egl_support-private -qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ diff --git a/src/plugins/platforms/xcb/CMakeLists.txt b/src/plugins/platforms/xcb/CMakeLists.txt index 1d481832f1..6e4388cc3f 100644 --- a/src/plugins/platforms/xcb/CMakeLists.txt +++ b/src/plugins/platforms/xcb/CMakeLists.txt @@ -71,9 +71,9 @@ qt_disable_apple_app_extension_api_only(XcbQpa) ## Scopes: ##################################################################### -qt_extend_target(XcbQpa CONDITION TARGET Qt::PlatformCompositorSupportPrivate +qt_extend_target(XcbQpa CONDITION QT_FEATURE_opengl PUBLIC_LIBRARIES - Qt::PlatformCompositorSupportPrivate + Qt::OpenGLPrivate ) qt_extend_target(XcbQpa CONDITION TARGET Qt::LinuxAccessibilitySupportPrivate diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index cea0511822..986ba862e5 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -62,7 +62,7 @@ #include #include #if QT_CONFIG(opengl) -#include +#include #endif #include diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index 8154d300b1..eced76ec31 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -9,8 +9,7 @@ QT += \ edid_support-private \ xkbcommon_support-private -qtHaveModule(platformcompositor_support-private): \ - QT += platformcompositor_support-private +qtConfig(opengl): QT += opengl-private qtHaveModule(linuxaccessibility_support-private): \ QT += linuxaccessibility_support-private -- cgit v1.2.3