summaryrefslogtreecommitdiffstats
path: root/src/compositor/extensions/qwltexturesharingextension.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compositor/extensions/qwltexturesharingextension.cpp')
-rw-r--r--src/compositor/extensions/qwltexturesharingextension.cpp134
1 files changed, 24 insertions, 110 deletions
diff --git a/src/compositor/extensions/qwltexturesharingextension.cpp b/src/compositor/extensions/qwltexturesharingextension.cpp
index cf9fd0116..c474176d2 100644
--- a/src/compositor/extensions/qwltexturesharingextension.cpp
+++ b/src/compositor/extensions/qwltexturesharingextension.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qwltexturesharingextension_p.h"
@@ -50,7 +14,8 @@
#include <QTimer>
#include <QtGui/private/qtexturefilereader_p.h>
-#include <QtGui/QOpenGLTexture>
+
+#include <QtOpenGL/QOpenGLTexture>
#include <QtGui/QImageReader>
#include <QtQuick/QSGTexture>
@@ -59,66 +24,6 @@
QT_BEGIN_NAMESPACE
-class SharedTexture : public QSGTexture
-{
- Q_OBJECT
-public:
- SharedTexture(QtWayland::ServerBuffer *buffer);
-
- int textureId() 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;
-}
-
-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:
@@ -143,9 +48,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:
@@ -186,7 +99,7 @@ public:
return m_errorString;
}
-public slots:
+public Q_SLOTS:
void doResponse(const QString &key, QtWayland::ServerBuffer *buffer)
{
if (key != m_id)
@@ -231,7 +144,7 @@ QQuickImageResponse *QWaylandSharedTextureProvider::requestImageResponse(const Q
void QWaylandSharedTextureProvider::setExtensionReady(QWaylandTextureSharingExtension *extension)
{
- for (auto *response : qAsConst(m_pendingResponses))
+ for (auto *response : std::as_const(m_pendingResponses))
response->doRequest(extension);
m_pendingResponses.clear();
m_pendingResponses.squeeze();
@@ -286,7 +199,7 @@ void QWaylandTextureSharingExtension::initialize()
auto suffixes = QTextureFileReader::supportedFileFormats();
suffixes.append(QImageReader::supportedImageFormats());
- for (auto ext : qAsConst(suffixes))
+ for (auto ext : std::as_const(suffixes))
m_image_suffixes << QLatin1Char('.') + QString::fromLatin1(ext);
//qDebug() << "m_image_suffixes" << m_image_suffixes << "m_image_dirs" << m_image_dirs;
@@ -311,13 +224,13 @@ QString QWaylandTextureSharingExtension::getExistingFilePath(const QString &key)
if (key.contains(QLatin1String("../")))
return QString();
- for (auto dir : m_image_dirs) {
+ for (auto dir : std::as_const(m_image_dirs)) {
QString path = dir + key;
if (QFileInfo::exists(path))
return path;
}
- for (auto dir : m_image_dirs) {
+ for (auto dir : std::as_const(m_image_dirs)) {
for (auto ext : m_image_suffixes) {
QString fp = dir + key + ext;
//qDebug() << "trying" << fp;
@@ -465,9 +378,8 @@ QtWayland::ServerBuffer *QWaylandTextureSharingExtension::getCompressedBuffer(co
return nullptr;
}
- QByteArray pixelData = QByteArray::fromRawData(td.data().constData() + td.dataOffset(), td.dataLength());
-
- return m_server_buffer_integration->createServerBufferFromData(pixelData, td.size(), td.glInternalFormat());
+ return m_server_buffer_integration->createServerBufferFromData(td.getDataView(), td.size(),
+ td.glInternalFormat());
}
void QWaylandTextureSharingExtension::cleanupBuffers()
@@ -487,11 +399,13 @@ void QWaylandTextureSharingExtension::cleanupBuffers()
void QWaylandTextureSharingExtension::dumpBufferInfo()
{
- qDebug() << "shared buffers:" << m_server_buffers.count();
+ qDebug() << "shared buffers:" << m_server_buffers.size();
for (auto it = m_server_buffers.cbegin(); it != m_server_buffers.cend(); ++it)
qDebug() << " " << it.key() << ":" << it.value().buffer << "in use" << it.value().buffer->bufferInUse() << "usedLocally" << it.value().usedLocally ;
}
QT_END_NAMESPACE
+#include "moc_qwltexturesharingextension_p.cpp"
+
#include "qwltexturesharingextension.moc"