diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-06-19 11:29:16 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-11-11 11:48:25 +0100 |
commit | f52c9653c98382bc5e03bb645baf63b91c33eece (patch) | |
tree | bf68d17baf0cd8f727ad2c6a9629add42c8cdb19 | |
parent | 220e397742442f8a7b81566eef196725440e74ea (diff) | |
download | qtwayland-f52c9653c98382bc5e03bb645baf63b91c33eece.tar.gz |
Port shared texture provider to RHI-on-OpenGL
There is no actual need for the SharedTexture subclass, since
the OpenGL context is guaranteed to be bound when the
createTexture() call is made, and we don't support the buffer
changing after it has been received.
Task-number: QTBUG-78673
Change-Id: I73e0f755e0618c67dabeccb0085bb44560f2a214
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
-rw-r--r-- | src/compositor/extensions/qwltexturesharingextension.cpp | 80 | ||||
-rw-r--r-- | src/imports/texture-sharing/sharedtextureprovider.cpp | 63 | ||||
-rw-r--r-- | src/imports/texture-sharing/sharedtextureprovider.h | 21 |
3 files changed, 25 insertions, 139 deletions
diff --git a/src/compositor/extensions/qwltexturesharingextension.cpp b/src/compositor/extensions/qwltexturesharingextension.cpp index ef1d82fe..c90fde1e 100644 --- a/src/compositor/extensions/qwltexturesharingextension.cpp +++ b/src/compositor/extensions/qwltexturesharingextension.cpp @@ -50,74 +50,6 @@ QT_BEGIN_NAMESPACE -class SharedTexture : public QSGTexture -{ - Q_OBJECT -public: - SharedTexture(QtWayland::ServerBuffer *buffer); - - //TODO: QRhiTexture - - int textureId() const;//######### override; - qint64 comparisonKey() const override; - QSize textureSize() const override; - bool hasAlphaChannel() const override; - bool hasMipmaps() const override; - - void bind(); //###### override; - -private: - void updateGLTexture() const; - QtWayland::ServerBuffer *m_buffer = nullptr; - mutable QOpenGLTexture *m_tex = nullptr; -}; - -SharedTexture::SharedTexture(QtWayland::ServerBuffer *buffer) - : m_buffer(buffer), m_tex(nullptr) -{ -} - -int SharedTexture::textureId() const -{ - updateGLTexture(); - return m_tex ? m_tex->textureId() : 0; -} - -qint64 SharedTexture::comparisonKey() const -{ - return m_tex ? qint64(m_tex->textureId()) : qint64(this); -} - -QSize SharedTexture::textureSize() const -{ - updateGLTexture(); - return m_tex ? QSize(m_tex->width(), m_tex->height()) : QSize(); -} - -bool SharedTexture::hasAlphaChannel() const -{ - return true; -} - -bool SharedTexture::hasMipmaps() const -{ - updateGLTexture(); - return m_tex ? (m_tex->mipLevels() > 1) : false; -} - -void SharedTexture::bind() -{ - updateGLTexture(); - if (m_tex) - m_tex->bind(); -} - -inline void SharedTexture::updateGLTexture() const -{ - if (!m_tex && m_buffer) - m_tex = m_buffer->toOpenGlTexture(); -} - class SharedTextureFactory : public QQuickTextureFactory { public: @@ -142,9 +74,17 @@ public: return m_buffer ? (m_buffer->size().width() * m_buffer->size().height() * 4) : 0; } - QSGTexture *createTexture(QQuickWindow *) const override + QSGTexture *createTexture(QQuickWindow *window) const override { - return new SharedTexture(const_cast<QtWayland::ServerBuffer *>(m_buffer)); + if (m_buffer != nullptr) { + QOpenGLTexture *texture = const_cast<QtWayland::ServerBuffer *>(m_buffer)->toOpenGlTexture(); + return QNativeInterface::QSGOpenGLTexture::fromNative(texture->textureId(), + window, + m_buffer->size(), + QQuickWindow::TextureHasAlphaChannel); + } + + return nullptr; } private: diff --git a/src/imports/texture-sharing/sharedtextureprovider.cpp b/src/imports/texture-sharing/sharedtextureprovider.cpp index a7d61d51..45da3333 100644 --- a/src/imports/texture-sharing/sharedtextureprovider.cpp +++ b/src/imports/texture-sharing/sharedtextureprovider.cpp @@ -49,6 +49,7 @@ #include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h> #include <QtGui/QGuiApplication> #include <QtGui/private/qguiapplication_p.h> +#include <QtQuick/private/qsgrhisupport_p.h> #include <QtGui/qpa/qplatformnativeinterface.h> #include <QtGui/QWindow> #include <QOpenGLTexture> @@ -60,52 +61,6 @@ QT_BEGIN_NAMESPACE -SharedTexture::SharedTexture(QtWaylandClient::QWaylandServerBuffer *buffer) - : m_buffer(buffer), m_tex(nullptr) -{ -} - -int SharedTexture::textureId() const -{ - updateGLTexture(); - return m_tex ? m_tex->textureId() : 0; -} - -qint64 SharedTexture::comparisonKey() const -{ - return m_tex ? qint64(m_tex->textureId()) : qint64(this); -} - -QSize SharedTexture::textureSize() const -{ - updateGLTexture(); - return m_tex ? QSize(m_tex->width(), m_tex->height()) : QSize(); -} - -bool SharedTexture::hasAlphaChannel() const -{ - return true; -} - -bool SharedTexture::hasMipmaps() const -{ - updateGLTexture(); - return m_tex ? (m_tex->mipLevels() > 1) : false; -} - -void SharedTexture::bind() -{ - updateGLTexture(); - if (m_tex) - m_tex->bind(); -} - -inline void SharedTexture::updateGLTexture() const -{ - if (!m_tex && m_buffer) - m_tex = m_buffer->toOpenGlTexture(); -} - class SharedTextureFactory : public QQuickTextureFactory { public: @@ -133,9 +88,16 @@ public: return m_buffer ? (m_buffer->size().width() * m_buffer->size().height() * 4) : 0; } - QSGTexture *createTexture(QQuickWindow *) const override + QSGTexture *createTexture(QQuickWindow *window) const override { - return new SharedTexture(const_cast<QtWaylandClient::QWaylandServerBuffer *>(m_buffer)); + if (m_buffer != nullptr) { + QOpenGLTexture *texture = const_cast<QtWaylandClient::QWaylandServerBuffer *>(m_buffer)->toOpenGlTexture(); + return QNativeInterface::QSGOpenGLTexture::fromNative(texture->textureId(), + window, + m_buffer->size(), + QQuickWindow::TextureHasAlphaChannel); + } + return nullptr; } private: @@ -189,6 +151,11 @@ void SharedTextureRegistry::handleExtensionActive() bool SharedTextureRegistry::preinitialize() { + if (QSGRhiSupport::instance()->rhiBackend() != QRhi::OpenGLES2) { + qWarning() << "The shared-texture extension is only supported on OpenGL. Use QQuickWindow::setSceneGraphBackend() to override the default."; + return false; + } + auto *serverBufferIntegration = QGuiApplicationPrivate::platformIntegration()->nativeInterface()->nativeResourceForIntegration("server_buffer_integration"); if (!serverBufferIntegration) { diff --git a/src/imports/texture-sharing/sharedtextureprovider.h b/src/imports/texture-sharing/sharedtextureprovider.h index d200315e..7eaf9e0d 100644 --- a/src/imports/texture-sharing/sharedtextureprovider.h +++ b/src/imports/texture-sharing/sharedtextureprovider.h @@ -93,27 +93,6 @@ private: bool m_sharingAvailable = false; }; -class SharedTexture : public QSGTexture -{ - Q_OBJECT -public: - SharedTexture(QtWaylandClient::QWaylandServerBuffer *buffer); - - int textureId() const; //###### override; - qint64 comparisonKey() const override; - QSize textureSize() const override; - bool hasAlphaChannel() const override; - bool hasMipmaps() const override; - - void bind(); //######## override; - -private: - void updateGLTexture() const; - QtWaylandClient::QWaylandServerBuffer *m_buffer = nullptr; - mutable QOpenGLTexture *m_tex = nullptr; -}; - - QT_END_NAMESPACE #endif // SHAREDTEXTUREPROVIDER_H |