diff options
20 files changed, 672 insertions, 424 deletions
diff --git a/src/gui/kernel/qplatformgraphicsbufferhelper.h b/src/gui/kernel/qplatformgraphicsbufferhelper.h index bfe61713d4..36afd4877b 100644 --- a/src/gui/kernel/qplatformgraphicsbufferhelper.h +++ b/src/gui/kernel/qplatformgraphicsbufferhelper.h @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE namespace QPlatformGraphicsBufferHelper { - bool lockAndBindToTexture(QPlatformGraphicsBuffer *graphicsBuffer, bool *swizzleRandB, bool *premultipliedB, const QRect &rect = QRect()); + Q_GUI_EXPORT bool lockAndBindToTexture(QPlatformGraphicsBuffer *graphicsBuffer, bool *swizzleRandB, bool *premultipliedB, const QRect &rect = QRect()); bool bindSWToTexture(const QPlatformGraphicsBuffer *graphicsBuffer, bool *swizzleRandB = nullptr, bool *premultipliedB = nullptr, const QRect &rect = QRect()); } diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index c092a7153f..e8ac494e04 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -40,43 +40,8 @@ #include "qplatformbackingstore.h" #include <qwindow.h> #include <qpixmap.h> -#include <private/qwindow_p.h> - -#include <qopengl.h> -#include <qopenglcontext.h> -#include <QtGui/QMatrix4x4> -#include <QtGui/QOpenGLShaderProgram> -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLFunctions> -#ifndef QT_NO_OPENGL -#include <QtGui/qopengltextureblitter.h> -#include <QtGui/qoffscreensurface.h> -#endif -#include <qpa/qplatformgraphicsbuffer.h> -#include <qpa/qplatformgraphicsbufferhelper.h> -#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 +#include <QtCore/private/qobject_p.h> QT_BEGIN_NAMESPACE @@ -88,38 +53,19 @@ public: QPlatformBackingStorePrivate(QWindow *w) : window(w) , backingStore(nullptr) -#ifndef QT_NO_OPENGL - , textureId(0) - , blitter(nullptr) -#endif { } ~QPlatformBackingStorePrivate() { #ifndef QT_NO_OPENGL - 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; + delete openGLSupport; #endif } QWindow *window; QBackingStore *backingStore; #ifndef QT_NO_OPENGL - QScopedPointer<QOpenGLContext> context; - mutable GLuint textureId; - mutable QSize textureSize; - mutable bool needsSwizzle; - mutable bool premultiplied; - QOpenGLTextureBlitter *blitter; + QPlatformBackingStoreOpenGLSupportBase *openGLSupport = nullptr; #endif }; @@ -240,83 +186,20 @@ void QPlatformTextureList::clear() */ #ifndef QT_NO_OPENGL - -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<QRect> 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); -} - /*! Flushes the given \a region from the specified \a window onto the screen, and composes it with the specified \a textures. - The default implementation retrieves the contents using toTexture() + If OpenGLSupport has been enabled using \c setOpenGLSupport, + the default implementation retrieves the contents using toTexture() and composes using OpenGL. May be reimplemented in subclasses if there is a more efficient native way to do it. \note \a region is relative to the window which may not be top-level in case \a window corresponds to a native child widget. \a offset is the position of the native child relative to the top-level window. + + \sa setOpenGLSupport() */ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®ion, @@ -324,162 +207,13 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®i QPlatformTextureList *textures, bool translucentBackground) { - if (!qt_window_private(window)->receivedExpose) - return; - - if (!d_ptr->context) { - d_ptr->context.reset(new QOpenGLContext); - d_ptr->context->setFormat(d_ptr->window->requestedFormat()); - d_ptr->context->setScreen(d_ptr->window->screen()); - d_ptr->context->setShareContext(qt_window_private(d_ptr->window)->shareContext()); - if (!d_ptr->context->create()) { - qCWarning(lcQpaBackingStore, "composeAndFlush: QOpenGLContext creation failed"); - return; - } - } - - bool current = d_ptr->context->makeCurrent(window); - - if (!current && !d_ptr->context->isValid()) { - delete d_ptr->blitter; - d_ptr->blitter = nullptr; - d_ptr->textureId = 0; - current = d_ptr->context->create() && d_ptr->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 = d_ptr->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 (!d_ptr->blitter) { - d_ptr->blitter = new QOpenGLTextureBlitter; - d_ptr->blitter->create(); - } - - d_ptr->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, d_ptr->blitter, offset, canUseSrgb); - } - - // Backingstore texture with the normal widgets. - GLuint textureId = 0; - QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft; - if (QPlatformGraphicsBuffer *graphicsBuffer = this->graphicsBuffer()) { - if (graphicsBuffer->size() != d_ptr->textureSize) { - if (d_ptr->textureId) - funcs->glDeleteTextures(1, &d_ptr->textureId); - funcs->glGenTextures(1, &d_ptr->textureId); - funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->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, &d_ptr->needsSwizzle, &d_ptr->premultiplied)) { - d_ptr->textureSize = graphicsBuffer->size(); - } else { - d_ptr->textureSize = QSize(0,0); - } - - graphicsBuffer->unlock(); - } else if (!region.isEmpty()){ - funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->textureId); - QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &d_ptr->needsSwizzle, &d_ptr->premultiplied); - graphicsBuffer->unlock(); - } - - if (graphicsBuffer->origin() == QPlatformGraphicsBuffer::OriginBottomLeft) - origin = QOpenGLTextureBlitter::OriginBottomLeft; - textureId = d_ptr->textureId; - } else { - TextureFlags flags; - textureId = toTexture(deviceRegion(region, window, offset), &d_ptr->textureSize, &flags); - d_ptr->needsSwizzle = (flags & TextureSwizzle) != 0; - d_ptr->premultiplied = (flags & TexturePremultiplied) != 0; - if (flags & TextureFlip) - origin = QOpenGLTextureBlitter::OriginBottomLeft; - } - - funcs->glEnable(GL_BLEND); - if (d_ptr->premultiplied) - funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + if (auto *c = d_ptr->openGLSupport) + c->composeAndFlush(window, region, offset, textures, translucentBackground); else - funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - - if (textureId) { - if (d_ptr->needsSwizzle) - d_ptr->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), d_ptr->textureSize.height()); - const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, - d_ptr->textureSize, - origin); - d_ptr->blitter->blit(textureId, QMatrix4x4(), source); - if (d_ptr->needsSwizzle) - d_ptr->blitter->setRedBlueSwizzle(false); - } - - // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. - bool blendIsPremultiplied = d_ptr->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, d_ptr->blitter, offset, canUseSrgb); - } - - funcs->glDisable(GL_BLEND); - d_ptr->blitter->release(); - - d_ptr->context->swapBuffers(window); + qWarning() << Q_FUNC_INFO << "no opengl support set"; } #endif + /*! Implemented in subclasses to return the content of the backingstore as a QImage. @@ -504,7 +238,8 @@ QImage QPlatformBackingStore::toImage() const The ownership of the texture is not transferred. The caller must not store the return value between calls, but instead call this function before each use. - The default implementation returns a cached texture if \a dirtyRegion is empty and + If OpenGLSupport has been enabled using \c setOpenGLSupport, + the default implementation returns a cached texture if \a dirtyRegion is empty and \a textureSize matches the backingstore size, otherwise it retrieves the content using toImage() and performs a texture upload. This works only if the value of \a textureSize is preserved between the calls to this function. @@ -520,141 +255,17 @@ QImage QPlatformBackingStore::toImage() const flags will be set to include \c TextureFlip. \note \a dirtyRegion is relative to the backingstore so no adjustment is needed. + + \sa setOpenGLSupport() */ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textureSize, TextureFlags *flags) const { - Q_ASSERT(textureSize); - Q_ASSERT(flags); - - QImage image = 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 |= TexturePremultiplied; - Q_FALLTHROUGH(); - case QImage::Format_RGB32: - case QImage::Format_ARGB32: - *flags |= TextureSwizzle; - break; - case QImage::Format_RGBA8888_Premultiplied: - *flags |= 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 |= 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 |= TextureSwizzle | TexturePremultiplied; - } else { - needsConversion = true; - } - break; - default: - needsConversion = true; - break; - } - if (imageSize.isEmpty()) { - *textureSize = imageSize; + if (auto *c = d_ptr->openGLSupport) + return c->toTexture(dirtyRegion, textureSize, flags); + else { + qWarning() << Q_FUNC_INFO << "no opengl support set"; 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 d_ptr->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 int 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 (d_ptr->textureId) - funcs->glDeleteTextures(1, &d_ptr->textureId); - funcs->glGenTextures(1, &d_ptr->textureId); - funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->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<uchar*>(image.constBits())); - } else { - funcs->glBindTexture(GL_TEXTURE_2D, d_ptr->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 d_ptr->textureId; } #endif // QT_NO_OPENGL @@ -706,6 +317,18 @@ QBackingStore *QPlatformBackingStore::backingStore() const return d_ptr->backingStore; } +#ifndef QT_NO_OPENGL +/*! + Injects an OpenGL implementation helper. Platform integrations need to + call this if they intend to use the default OpenGL implementations of + composeAndFlush or toTexture. +*/ +void QPlatformBackingStore::setOpenGLSupport(QPlatformBackingStoreOpenGLSupportBase *openGLSupport) +{ + d_ptr->openGLSupport = openGLSupport; +} +#endif // QT_NO_OPENGL + /*! This function is called before painting onto the surface begins, with the \a region in which the painting will occur. diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h index 7aa054f1e2..2a3d7d20b5 100644 --- a/src/gui/painting/qplatformbackingstore.h +++ b/src/gui/painting/qplatformbackingstore.h @@ -67,11 +67,10 @@ class QRect; class QPoint; class QImage; class QPlatformBackingStorePrivate; -class QPlatformWindow; class QPlatformTextureList; class QPlatformTextureListPrivate; -class QOpenGLContext; class QPlatformGraphicsBuffer; +class QPlatformBackingStoreOpenGLSupportBase; #ifndef QT_NO_OPENGL class Q_GUI_EXPORT QPlatformTextureList : public QObject @@ -118,6 +117,8 @@ public: QWindow *window() const; QBackingStore *backingStore() const; + void setOpenGLSupport(QPlatformBackingStoreOpenGLSupportBase *openGLSupport); + virtual QPaintDevice *paintDevice() = 0; virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) = 0; @@ -154,6 +155,17 @@ private: }; #ifndef QT_NO_OPENGL +class Q_GUI_EXPORT QPlatformBackingStoreOpenGLSupportBase // pure interface +{ +public: + virtual void composeAndFlush(QWindow *window, const QRegion ®ion, const QPoint &offset, + QPlatformTextureList *textures, bool translucentBackground) = 0; + virtual GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const = 0; + virtual ~QPlatformBackingStoreOpenGLSupportBase() {} +}; +#endif // QT_NO_OPENGL + +#ifndef QT_NO_OPENGL Q_DECLARE_OPERATORS_FOR_FLAGS(QPlatformBackingStore::TextureFlags) #endif diff --git a/src/platformsupport/platformcompositor/platformcompositor.pro b/src/platformsupport/platformcompositor/platformcompositor.pro index 81c31571d0..c257d3e42c 100644 --- a/src/platformsupport/platformcompositor/platformcompositor.pro +++ b/src/platformsupport/platformcompositor/platformcompositor.pro @@ -7,10 +7,12 @@ 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 diff --git a/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp b/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp new file mode 100644 index 0000000000..bcd2b90a87 --- /dev/null +++ b/src/platformsupport/platformcompositor/qplatformbackingstoreopenglsupport.cpp @@ -0,0 +1,456 @@ +/**************************************************************************** +** +** 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 <QtGui/private/qwindow_p.h> + +#include <qpa/qplatformgraphicsbuffer.h> +#include <qpa/qplatformgraphicsbufferhelper.h> + +#include <QtGui/qopengl.h> +#include <QtGui/QOpenGLFunctions> +#include <QtGui/QOpenGLContext> +#include <QtGui/QOpenGLTextureBlitter> + +#include <QtGui/QOffscreenSurface> + +#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<QRect> 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 int 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<uchar*>(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 new file mode 100644 index 0000000000..5523b18f76 --- /dev/null +++ b/src/platformsupport/platformcompositor/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 <QtGui/qtguiglobal.h> +#include <qpa/qplatformbackingstore.h> + +#include <QtGui/QOpenGLContext> + +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<QOpenGLContext> 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/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 61cac51633..8ea78f7cba 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -9,6 +9,8 @@ QT += \ qtConfig(vulkan): QT += vulkan_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + OTHER_FILES += $$PWD/android.json INCLUDEPATH += \ diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index e0c437be27..ae584965e6 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -43,6 +43,9 @@ #include <QtGui/private/qguiapplication_p.h> #include <QGuiApplication> #include <QOpenGLContext> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif #include <QThread> #include <QOffscreenSurface> @@ -275,7 +278,12 @@ QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(Q { if (!QtAndroid::activity()) return nullptr; - return new QAndroidPlatformBackingStore(window); + + auto *backingStore = new QAndroidPlatformBackingStore(window); +#if QT_CONFIG(opengl) + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif // QT_CONFIG(opengl) + return backingStore; } QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index a919963cf4..953346c56e 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -101,6 +101,8 @@ QT += \ qtConfig(vulkan): QT += vulkan_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + CONFIG += no_app_extension_api_only qtHaveModule(widgets) { diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index a77b97f538..b2698b05fe 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -68,6 +68,10 @@ #include <QtFontDatabaseSupport/private/qfontengine_coretext_p.h> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif + #ifdef QT_WIDGETS_LIB #include <QtWidgets/qtwidgetsglobal.h> #if QT_CONFIG(filedialog) @@ -324,10 +328,16 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi return nullptr; } + QPlatformBackingStore *backingStore = nullptr; if (platformWindow->view().layer) - return new QCALayerBackingStore(window); + backingStore = new QCALayerBackingStore(window); else - return new QNSWindowBackingStore(window); + backingStore = new QNSWindowBackingStore(window); + +#if QT_CONFIG(opengl) + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } QAbstractEventDispatcher *QCocoaIntegration::createEventDispatcher() const diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro index 71257d09f7..01e0105223 100644 --- a/src/plugins/platforms/ios/kernel.pro +++ b/src/plugins/platforms/ios/kernel.pro @@ -9,6 +9,8 @@ QT += \ core-private gui-private \ clipboard_support-private fontdatabase_support-private graphics_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AudioToolbox OBJECTIVE_SOURCES = \ diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 9eca0eaad3..d724e65717 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -65,6 +65,10 @@ #import <AudioToolbox/AudioServices.h> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif + #include <QtDebug> QT_BEGIN_NAMESPACE @@ -186,7 +190,11 @@ QPlatformWindow *QIOSIntegration::createPlatformWindow(QWindow *window) const // Used when the QWindow's surface type is set by the client to QSurface::RasterSurface QPlatformBackingStore *QIOSIntegration::createPlatformBackingStore(QWindow *window) const { - return new QIOSBackingStore(window); + auto *backingStore = new QIOSBackingStore(window); +#if QT_CONFIG(opengl) + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } // Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index fd53cd0bae..ce83ad4e2f 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -41,6 +41,7 @@ #include "qwasmwindow.h" #ifndef QT_NO_OPENGL # include "qwasmbackingstore.h" +# include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> #endif #include "qwasmfontdatabase.h" #if defined(Q_OS_UNIX) @@ -185,6 +186,7 @@ QPlatformBackingStore *QWasmIntegration::createPlatformBackingStore(QWindow *win #ifndef QT_NO_OPENGL QWasmCompositor *compositor = QWasmScreen::get(window->screen())->compositor(); QWasmBackingStore *backingStore = new QWasmBackingStore(compositor, window); + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); m_backingStores.insert(window, backingStore); return backingStore; #else diff --git a/src/plugins/platforms/wasm/wasm.pro b/src/plugins/platforms/wasm/wasm.pro index c8b28fb37d..1aee4a3e58 100644 --- a/src/plugins/platforms/wasm/wasm.pro +++ b/src/plugins/platforms/wasm/wasm.pro @@ -4,6 +4,8 @@ QT += \ core-private gui-private \ eventdispatcher_support-private fontdatabase_support-private egl_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 diff --git a/src/plugins/platforms/windows/qwindowsgdiintegration.cpp b/src/plugins/platforms/windows/qwindowsgdiintegration.cpp index c88f669eb5..7e9595321a 100644 --- a/src/plugins/platforms/windows/qwindowsgdiintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsgdiintegration.cpp @@ -45,6 +45,10 @@ #include <QtCore/qdebug.h> #include <QtGui/private/qpixmap_raster_p.h> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif + QT_BEGIN_NAMESPACE class QWindowsGdiIntegrationPrivate @@ -73,7 +77,11 @@ QPlatformPixmap *QWindowsGdiIntegration::createPlatformPixmap(QPlatformPixmap::P QPlatformBackingStore *QWindowsGdiIntegration::createPlatformBackingStore(QWindow *window) const { - return new QWindowsBackingStore(window); + auto *backingStore = new QWindowsBackingStore(window); +#ifndef QT_NO_OPENGL + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/windows.pro b/src/plugins/platforms/windows/windows.pro index 50a3bb41a9..8a27bd2770 100644 --- a/src/plugins/platforms/windows/windows.pro +++ b/src/plugins/platforms/windows/windows.pro @@ -5,6 +5,8 @@ QT += \ eventdispatcher_support-private \ fontdatabase_support-private theme_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + qtConfig(accessibility): QT += accessibility_support-private qtConfig(vulkan): QT += vulkan_support-private diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp index 27d3746933..dd8cd80fd9 100644 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ b/src/plugins/platforms/winrt/qwinrtintegration.cpp @@ -53,6 +53,9 @@ #if QT_CONFIG(accessibility) # include "uiautomation/qwinrtuiaaccessibility.h" #endif +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif #include <QtGui/QOffscreenSurface> #include <QtGui/QOpenGLContext> @@ -205,7 +208,11 @@ QPlatformWindow *QWinRTIntegration::createPlatformWindow(QWindow *window) const QPlatformBackingStore *QWinRTIntegration::createPlatformBackingStore(QWindow *window) const { - return new QWinRTBackingStore(window); + auto *backingStore = new QWinRTBackingStore(window); +#if QT_CONFIG(opengl) + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } QPlatformOpenGLContext *QWinRTIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro index 43dc8f074c..7ac49f73c4 100644 --- a/src/plugins/platforms/winrt/winrt.pro +++ b/src/plugins/platforms/winrt/winrt.pro @@ -6,6 +6,8 @@ QT += \ core-private gui-private \ fontdatabase_support-private egl_support-private +qtHaveModule(platformcompositor_support-private): QT += platformcompositor_support-private + DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ QMAKE_USE_PRIVATE += d3d11 ws2_32 diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 3fd989e1f9..cea0511822 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -61,6 +61,9 @@ #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> #include <QtServiceSupport/private/qgenericunixservices_p.h> +#if QT_CONFIG(opengl) +#include <QtPlatformCompositorSupport/qpa/qplatformbackingstoreopenglsupport.h> +#endif #include <stdio.h> @@ -288,16 +291,23 @@ QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLCont QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const { - const bool isTrayIconWindow = QXcbWindow::isTrayIconWindow(window); - if (isTrayIconWindow) - return new QXcbSystemTrayBackingStore(window); + QPlatformBackingStore *backingStore = nullptr; + const bool isTrayIconWindow = QXcbWindow::isTrayIconWindow(window); + if (isTrayIconWindow) { + backingStore = new QXcbSystemTrayBackingStore(window); #if QT_CONFIG(xcb_native_painting) - if (nativePaintingEnabled()) - return new QXcbNativeBackingStore(window); + } else if (nativePaintingEnabled()) { + backingStore = new QXcbNativeBackingStore(window); #endif - - return new QXcbBackingStore(window); + } else { + backingStore = new QXcbBackingStore(window); + } + Q_ASSERT(backingStore); +#ifndef QT_NO_OPENGL + backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore)); +#endif + return backingStore; } QPlatformOffscreenSurface *QXcbIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index a5d05faa9c..1f651e7697 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -9,6 +9,9 @@ QT += \ edid_support-private \ xkbcommon_support-private +qtHaveModule(platformcompositor_support-private): \ + QT += platformcompositor_support-private + qtHaveModule(linuxaccessibility_support-private): \ QT += linuxaccessibility_support-private |