summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-04-01 18:49:59 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-05-29 19:01:57 +0200
commitb39f33e311b603c6835b919778100e60759fa870 (patch)
tree4e84e3623060a7213be82696cf6c6d4fea11423c /src/gui
parentc4e09cf26790d6d293efd0e389517dcaf7f34d85 (diff)
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>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qplatformbackingstore.cpp38
-rw-r--r--src/gui/painting/qplatformbackingstore.h15
2 files changed, 37 insertions, 16 deletions
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index e8ac494e04..743c183475 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -190,16 +190,13 @@ void QPlatformTextureList::clear()
Flushes the given \a region from the specified \a window onto the
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
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 &region,
@@ -238,8 +235,7 @@ 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.
- 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
toImage() and performs a texture upload. This works only if the value of \a textureSize
is preserved between the calls to this function.
@@ -255,8 +251,6 @@ 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
{
@@ -281,6 +275,12 @@ GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textu
QPlatformBackingStore::QPlatformBackingStore(QWindow *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
+
+using FactoryFunction = QPlatformBackingStoreOpenGLSupportBase::FactoryFunction;
+
/*!
- Injects an OpenGL implementation helper. Platform integrations need to
- call this if they intend to use the default OpenGL implementations of
- composeAndFlush or toTexture.
+ Registers a factory function for OpenGL implementation helper.
+
+ 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)
+{
+ s_factoryFunction = function;
+}
+
+FactoryFunction QPlatformBackingStoreOpenGLSupportBase::factoryFunction()
{
- d_ptr->openGLSupport = openGLSupport;
+ return s_factoryFunction;
}
+
+FactoryFunction QPlatformBackingStoreOpenGLSupportBase::s_factoryFunction = nullptr;
+
#endif // QT_NO_OPENGL
/*!
diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h
index 2a3d7d20b5..e0fdca2f21 100644
--- a/src/gui/painting/qplatformbackingstore.h
+++ b/src/gui/painting/qplatformbackingstore.h
@@ -117,8 +117,6 @@ public:
QWindow *window() const;
QBackingStore *backingStore() const;
- void setOpenGLSupport(QPlatformBackingStoreOpenGLSupportBase *openGLSupport);
-
virtual QPaintDevice *paintDevice() = 0;
virtual void flush(QWindow *window, const QRegion &region, const QPoint &offset) = 0;
@@ -155,13 +153,24 @@ private:
};
#ifndef QT_NO_OPENGL
-class Q_GUI_EXPORT QPlatformBackingStoreOpenGLSupportBase // pure interface
+class Q_GUI_EXPORT QPlatformBackingStoreOpenGLSupportBase
{
public:
virtual void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
QPlatformTextureList *textures, bool translucentBackground) = 0;
virtual GLuint toTexture(const QRegion &dirtyRegion, QSize *textureSize, QPlatformBackingStore::TextureFlags *flags) const = 0;
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