summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compositor/extensions/qwltexturesharingextension.cpp80
-rw-r--r--src/imports/texture-sharing/sharedtextureprovider.cpp63
-rw-r--r--src/imports/texture-sharing/sharedtextureprovider.h21
3 files changed, 25 insertions, 139 deletions
diff --git a/src/compositor/extensions/qwltexturesharingextension.cpp b/src/compositor/extensions/qwltexturesharingextension.cpp
index ef1d82fe2..c90fde1ec 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 a7d61d519..45da33330 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 d200315e0..7eaf9e0d5 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