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:
parent
c4e09cf267
commit
b39f33e311
@ -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 ®ion,
|
||||
@ -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)
|
||||
{
|
||||
d_ptr->openGLSupport = openGLSupport;
|
||||
s_factoryFunction = function;
|
||||
}
|
||||
|
||||
FactoryFunction QPlatformBackingStoreOpenGLSupportBase::factoryFunction()
|
||||
{
|
||||
return s_factoryFunction;
|
||||
}
|
||||
|
||||
FactoryFunction QPlatformBackingStoreOpenGLSupportBase::s_factoryFunction = nullptr;
|
||||
|
||||
#endif // QT_NO_OPENGL
|
||||
|
||||
/*!
|
||||
|
@ -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 ®ion, 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 ®ion, 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
|
||||
|
||||
|
@ -450,6 +450,18 @@ GLuint QPlatformBackingStoreOpenGLSupport::toTexture(const QRegion &dirtyRegion,
|
||||
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
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -64,14 +64,12 @@ 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<QOpenGLContext> context;
|
||||
mutable GLuint textureId = 0;
|
||||
mutable QSize textureSize;
|
||||
|
@ -289,11 +289,7 @@ QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(Q
|
||||
if (!QtAndroid::activity())
|
||||
return nullptr;
|
||||
|
||||
auto *backingStore = new QAndroidPlatformBackingStore(window);
|
||||
#if QT_CONFIG(opengl)
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif // QT_CONFIG(opengl)
|
||||
return backingStore;
|
||||
return new QAndroidPlatformBackingStore(window);
|
||||
}
|
||||
|
||||
QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
|
||||
|
@ -98,8 +98,6 @@ QT += \
|
||||
core-private gui-private \
|
||||
theme_support-private
|
||||
|
||||
qtConfig(opengl): QT += opengl-private
|
||||
|
||||
CONFIG += no_app_extension_api_only
|
||||
|
||||
qtHaveModule(widgets) {
|
||||
|
@ -68,10 +68,6 @@
|
||||
|
||||
#include <QtGui/private/qfontengine_coretext_p.h>
|
||||
|
||||
#if QT_CONFIG(opengl)
|
||||
#include <QtOpenGL/qpa/qplatformbackingstoreopenglsupport.h>
|
||||
#endif
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
#include <QtWidgets/qtwidgetsglobal.h>
|
||||
#if QT_CONFIG(filedialog)
|
||||
@ -333,9 +329,6 @@ QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *wi
|
||||
else
|
||||
backingStore = new QNSWindowBackingStore(window);
|
||||
|
||||
#if QT_CONFIG(opengl)
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif
|
||||
return backingStore;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
QPlatformBackingStore *QIOSIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
auto *backingStore = new QIOSBackingStore(window);
|
||||
#if QT_CONFIG(opengl)
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif
|
||||
return backingStore;
|
||||
return new QIOSBackingStore(window);
|
||||
}
|
||||
|
||||
// Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface
|
||||
|
@ -181,7 +181,6 @@ 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
|
||||
|
@ -77,11 +77,7 @@ QPlatformPixmap *QWindowsGdiIntegration::createPlatformPixmap(QPlatformPixmap::P
|
||||
|
||||
QPlatformBackingStore *QWindowsGdiIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
auto *backingStore = new QWindowsBackingStore(window);
|
||||
#ifndef QT_NO_OPENGL
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif
|
||||
return backingStore;
|
||||
return new QWindowsBackingStore(window);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -208,11 +208,7 @@ QPlatformWindow *QWinRTIntegration::createPlatformWindow(QWindow *window) const
|
||||
|
||||
QPlatformBackingStore *QWinRTIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
auto *backingStore = new QWinRTBackingStore(window);
|
||||
#if QT_CONFIG(opengl)
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif
|
||||
return backingStore;
|
||||
return new QWinRTBackingStore(window);
|
||||
}
|
||||
|
||||
QPlatformOpenGLContext *QWinRTIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
|
||||
|
@ -304,9 +304,6 @@ QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *wind
|
||||
backingStore = new QXcbBackingStore(window);
|
||||
}
|
||||
Q_ASSERT(backingStore);
|
||||
#ifndef QT_NO_OPENGL
|
||||
backingStore->setOpenGLSupport(new QPlatformBackingStoreOpenGLSupport(backingStore));
|
||||
#endif
|
||||
return backingStore;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user