Move QPlatformBackingStoreOpenGLSupport handling out of platform plugins

Allows them to not depend on QtOpenGL just to provide the default
backing store OpenGL support backend.

Change-Id: I90d6d9247ce76848d9d03e2d512fb736c81488d3
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-04-01 18:49:59 +02:00
parent c4e09cf267
commit b39f33e311
12 changed files with 53 additions and 51 deletions

View File

@ -190,16 +190,13 @@ void QPlatformTextureList::clear()
Flushes the given \a region from the specified \a window onto the Flushes the given \a region from the specified \a window onto the
screen, and composes it with the specified \a textures. screen, and composes it with the specified \a textures.
If OpenGLSupport has been enabled using \c setOpenGLSupport, The default implementation retrieves the contents using toTexture()
the default implementation retrieves the contents using toTexture()
and composes using OpenGL. May be reimplemented in subclasses if there and composes using OpenGL. May be reimplemented in subclasses if there
is a more efficient native way to do it. 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 \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 \a window corresponds to a native child widget. \a offset is the position of
the native child relative to the top-level window. the native child relative to the top-level window.
\sa setOpenGLSupport()
*/ */
void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &region, void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &region,
@ -238,8 +235,7 @@ QImage QPlatformBackingStore::toImage() const
The ownership of the texture is not transferred. The caller must not store 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 return value between calls, but instead call this function before each use.
If OpenGLSupport has been enabled using \c setOpenGLSupport, The default implementation returns a cached texture if \a dirtyRegion is empty and
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 \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 toImage() and performs a texture upload. This works only if the value of \a textureSize
is preserved between the calls to this function. is preserved between the calls to this function.
@ -255,8 +251,6 @@ QImage QPlatformBackingStore::toImage() const
flags will be set to include \c TextureFlip. flags will be set to include \c TextureFlip.
\note \a dirtyRegion is relative to the backingstore so no adjustment is needed. \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 GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textureSize, TextureFlags *flags) const
{ {
@ -281,6 +275,12 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textu
QPlatformBackingStore::QPlatformBackingStore(QWindow *window) QPlatformBackingStore::QPlatformBackingStore(QWindow *window)
: d_ptr(new QPlatformBackingStorePrivate(window)) : d_ptr(new QPlatformBackingStorePrivate(window))
{ {
#ifndef QT_NO_OPENGL
if (auto createOpenGLSupport = QPlatformBackingStoreOpenGLSupportBase::factoryFunction()) {
d_ptr->openGLSupport = createOpenGLSupport();
d_ptr->openGLSupport->backingStore = this;
}
#endif
} }
/*! /*!
@ -318,15 +318,27 @@ QBackingStore *QPlatformBackingStore::backingStore() const
} }
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
using FactoryFunction = QPlatformBackingStoreOpenGLSupportBase::FactoryFunction;
/*! /*!
Injects an OpenGL implementation helper. Platform integrations need to Registers a factory function for OpenGL implementation helper.
call this if they intend to use the default OpenGL implementations of
composeAndFlush or toTexture. The QtOpenGL library automatically registers a default function,
unless already set by the platform plugin in other ways.
*/ */
void QPlatformBackingStore::setOpenGLSupport(QPlatformBackingStoreOpenGLSupportBase *openGLSupport) void QPlatformBackingStoreOpenGLSupportBase::setFactoryFunction(FactoryFunction function)
{ {
d_ptr->openGLSupport = openGLSupport; s_factoryFunction = function;
} }
FactoryFunction QPlatformBackingStoreOpenGLSupportBase::factoryFunction()
{
return s_factoryFunction;
}
FactoryFunction QPlatformBackingStoreOpenGLSupportBase::s_factoryFunction = nullptr;
#endif // QT_NO_OPENGL #endif // QT_NO_OPENGL
/*! /*!

View File

@ -117,8 +117,6 @@ public:
QWindow *window() const; QWindow *window() const;
QBackingStore *backingStore() const; QBackingStore *backingStore() const;
void setOpenGLSupport(QPlatformBackingStoreOpenGLSupportBase *openGLSupport);
virtual QPaintDevice *paintDevice() = 0; virtual QPaintDevice *paintDevice() = 0;
virtual void flush(QWindow *window, const QRegion &region, const QPoint &offset) = 0; virtual void flush(QWindow *window, const QRegion &region, const QPoint &offset) = 0;
@ -155,13 +153,24 @@ private:
}; };
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
class Q_GUI_EXPORT QPlatformBackingStoreOpenGLSupportBase // pure interface class Q_GUI_EXPORT QPlatformBackingStoreOpenGLSupportBase
{ {
public: public:
virtual void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset, virtual void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
QPlatformTextureList *textures, bool translucentBackground) = 0; QPlatformTextureList *textures, bool translucentBackground) = 0;
virtual GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const = 0; virtual GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const = 0;
virtual ~QPlatformBackingStoreOpenGLSupportBase() {} virtual ~QPlatformBackingStoreOpenGLSupportBase() {}
using FactoryFunction = QPlatformBackingStoreOpenGLSupportBase *(*)();
static void setFactoryFunction(FactoryFunction);
static FactoryFunction factoryFunction();
protected:
QPlatformBackingStore *backingStore = nullptr;
friend class QPlatformBackingStore;
private:
static FactoryFunction s_factoryFunction;
}; };
#endif // QT_NO_OPENGL #endif // QT_NO_OPENGL

View File

@ -450,6 +450,18 @@ GLuint QPlatformBackingStoreOpenGLSupport::toTexture(const QRegion &dirtyRegion,
return textureId; return textureId;
} }
static QPlatformBackingStoreOpenGLSupportBase *createOpenGLSupport()
{
return new QPlatformBackingStoreOpenGLSupport;
}
static void setDefaultOpenGLSupportFactoryFunction()
{
if (!QPlatformBackingStoreOpenGLSupportBase::factoryFunction())
QPlatformBackingStoreOpenGLSupportBase::setFactoryFunction(createOpenGLSupport);
}
Q_CONSTRUCTOR_FUNCTION(setDefaultOpenGLSupportFactoryFunction);
#endif // QT_NO_OPENGL #endif // QT_NO_OPENGL
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -64,14 +64,12 @@ class QOpenGLBackingStore;
class Q_OPENGL_EXPORT QPlatformBackingStoreOpenGLSupport : public QPlatformBackingStoreOpenGLSupportBase class Q_OPENGL_EXPORT QPlatformBackingStoreOpenGLSupport : public QPlatformBackingStoreOpenGLSupportBase
{ {
public: public:
explicit QPlatformBackingStoreOpenGLSupport(QPlatformBackingStore *backingStore) : backingStore(backingStore) {}
~QPlatformBackingStoreOpenGLSupport() override; ~QPlatformBackingStoreOpenGLSupport() override;
void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset, void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
QPlatformTextureList *textures, bool translucentBackground) override; QPlatformTextureList *textures, bool translucentBackground) override;
GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const override; GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const override;
private: private:
QPlatformBackingStore *backingStore = nullptr;
QScopedPointer<QOpenGLContext> context; QScopedPointer<QOpenGLContext> context;
mutable GLuint textureId = 0; mutable GLuint textureId = 0;
mutable QSize textureSize; mutable QSize textureSize;

View File

@ -289,11 +289,7 @@ QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(Q
if (!QtAndroid::activity()) if (!QtAndroid::activity())
return nullptr; return nullptr;
auto *backingStore = new QAndroidPlatformBackingStore(window); return new QAndroidPlatformBackingStore(window);
#if QT_CONFIG(opengl)
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
#endif // QT_CONFIG(opengl)
return backingStore;
} }
QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const

View File

@ -98,8 +98,6 @@ QT += \
core-private gui-private \ core-private gui-private \
theme_support-private theme_support-private
qtConfig(opengl): QT += opengl-private
CONFIG += no_app_extension_api_only CONFIG += no_app_extension_api_only
qtHaveModule(widgets) { qtHaveModule(widgets) {

View File

@ -68,10 +68,6 @@
#include <QtGui/private/qfontengine_coretext_p.h> #include <QtGui/private/qfontengine_coretext_p.h>
#if QT_CONFIG(opengl)
#include <QtOpenGL/qpa/qplatformbackingstoreopenglsupport.h>
#endif
#ifdef QT_WIDGETS_LIB #ifdef QT_WIDGETS_LIB
#include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qtwidgetsglobal.h>
#if QT_CONFIG(filedialog) #if QT_CONFIG(filedialog)
@ -333,9 +329,6 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi
else else
backingStore = new QNSWindowBackingStore(window); backingStore = new QNSWindowBackingStore(window);
#if QT_CONFIG(opengl)
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
#endif
return backingStore; return backingStore;
} }

View File

@ -191,11 +191,7 @@ QPlatformWindow *QIOSIntegration::createPlatformWindow(QWindow *window) const
// Used when the QWindow's surface type is set by the client to QSurface::RasterSurface // Used when the QWindow's surface type is set by the client to QSurface::RasterSurface
QPlatformBackingStore *QIOSIntegration::createPlatformBackingStore(QWindow *window) const QPlatformBackingStore *QIOSIntegration::createPlatformBackingStore(QWindow *window) const
{ {
auto *backingStore = new QIOSBackingStore(window); return 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 // Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface

View File

@ -181,7 +181,6 @@ QPlatformBackingStore *QWasmIntegration::createPlatformBackingStore(QWindow *win
#ifndef QT_NO_OPENGL #ifndef QT_NO_OPENGL
QWasmCompositor *compositor = QWasmScreen::get(window->screen())->compositor(); QWasmCompositor *compositor = QWasmScreen::get(window->screen())->compositor();
QWasmBackingStore *backingStore = new QWasmBackingStore(compositor, window); QWasmBackingStore *backingStore = new QWasmBackingStore(compositor, window);
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
m_backingStores.insert(window, backingStore); m_backingStores.insert(window, backingStore);
return backingStore; return backingStore;
#else #else

View File

@ -77,11 +77,7 @@ QPlatformPixmap *QWindowsGdiIntegration::createPlatformPixmap(QPlatformPixmap::P
QPlatformBackingStore *QWindowsGdiIntegration::createPlatformBackingStore(QWindow *window) const QPlatformBackingStore *QWindowsGdiIntegration::createPlatformBackingStore(QWindow *window) const
{ {
auto *backingStore = new QWindowsBackingStore(window); return new QWindowsBackingStore(window);
#ifndef QT_NO_OPENGL
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
#endif
return backingStore;
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -208,11 +208,7 @@ QPlatformWindow *QWinRTIntegration::createPlatformWindow(QWindow *window) const
QPlatformBackingStore *QWinRTIntegration::createPlatformBackingStore(QWindow *window) const QPlatformBackingStore *QWinRTIntegration::createPlatformBackingStore(QWindow *window) const
{ {
auto *backingStore = new QWinRTBackingStore(window); return new QWinRTBackingStore(window);
#if QT_CONFIG(opengl)
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
#endif
return backingStore;
} }
QPlatformOpenGLContext *QWinRTIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const QPlatformOpenGLContext *QWinRTIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const

View File

@ -304,9 +304,6 @@ QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *wind
backingStore = new QXcbBackingStore(window); backingStore = new QXcbBackingStore(window);
} }
Q_ASSERT(backingStore); Q_ASSERT(backingStore);
#ifndef QT_NO_OPENGL
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
#endif
return backingStore; return backingStore;
} }