aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/coreapi/qsgtexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsgtexture.cpp')
-rw-r--r--src/quick/scenegraph/coreapi/qsgtexture.cpp206
1 files changed, 125 insertions, 81 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp
index f09ff9ad85..57111e9e5f 100644
--- a/src/quick/scenegraph/coreapi/qsgtexture.cpp
+++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp
@@ -1,49 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick 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 LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsgtexture_p.h"
#include "qsgtexture_platform.h"
#include <private/qqmlglobal_p.h>
#include <private/qsgmaterialshader_p.h>
+#include <private/qsgrenderer_p.h>
#include <private/qquickitem_p.h> // qquickwindow_p.h cannot be included on its own due to template nonsense
#include <private/qquickwindow_p.h>
-#include <QtGui/private/qrhi_p.h>
+#include <QtCore/private/qnativeinterface_p.h>
+#include <rhi/qrhi.h>
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && defined(__GLIBC__)
#define CAN_BACKTRACE_EXECINFO
@@ -65,11 +31,12 @@
#ifndef QT_NO_DEBUG
Q_GLOBAL_STATIC(QSet<QSGTexture *>, qsg_valid_texture_set)
Q_GLOBAL_STATIC(QMutex, qsg_valid_texture_mutex)
-static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
#endif
QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(lcQsgLeak)
+
bool operator==(const QSGSamplerDescription &a, const QSGSamplerDescription &b) noexcept
{
return a.filtering == b.filtering
@@ -118,8 +85,9 @@ QSGTexturePrivate::QSGTexturePrivate(QSGTexture *t)
#endif
#ifdef Q_OS_WIN
, m_d3d11TextureAccessor(t)
+ , m_d3d12TextureAccessor(t)
#endif
-#if defined(__OBJC__)
+#if QT_CONFIG(metal)
, m_metalTextureAccessor(t)
#endif
#if QT_CONFIG(vulkan)
@@ -151,7 +119,7 @@ static QHash<QSGTexture*, SGTextureTraceItem*> qt_debug_allocated_textures;
inline static void qt_debug_print_texture_count()
{
- qDebug("Number of leaked textures: %i", qt_debug_texture_count);
+ qCDebug(lcQsgLeak, "Number of leaked textures: %i", qt_debug_texture_count);
qt_debug_texture_count = -1;
#if defined(CAN_BACKTRACE_EXECINFO)
@@ -278,8 +246,6 @@ static void qt_debug_remove_texture(QSGTexture* texture)
\note All classes with QSG prefix should be used solely on the scene graph's
rendering thread. See \l {Scene Graph and Rendering} for more information.
-
- \sa {Scene Graph - Rendering FBOs}
*/
/*!
@@ -339,7 +305,7 @@ QSGTexture::QSGTexture()
: QObject(*(new QSGTexturePrivate(this)))
{
#ifndef QT_NO_DEBUG
- if (qsg_leak_check)
+ if (lcQsgLeak().isDebugEnabled())
qt_debug_add_texture(this);
QMutexLocker locker(qsg_valid_texture_mutex());
@@ -354,7 +320,7 @@ QSGTexture::QSGTexture(QSGTexturePrivate &dd)
: QObject(dd)
{
#ifndef QT_NO_DEBUG
- if (qsg_leak_check)
+ if (lcQsgLeak().isDebugEnabled())
qt_debug_add_texture(this);
QMutexLocker locker(qsg_valid_texture_mutex());
@@ -368,7 +334,7 @@ QSGTexture::QSGTexture(QSGTexturePrivate &dd)
QSGTexture::~QSGTexture()
{
#ifndef QT_NO_DEBUG
- if (qsg_leak_check)
+ if (lcQsgLeak().isDebugEnabled())
qt_debug_remove_texture(this);
QMutexLocker locker(qsg_valid_texture_mutex());
@@ -455,7 +421,7 @@ bool QSGTexture::isAtlasTexture() const
/*!
\fn QSize QSGTexture::textureSize() const
- Returns the size of the texture.
+ Returns the size of the texture in pixels.
*/
/*!
@@ -615,8 +581,6 @@ QSGTexture::WrapMode QSGTexture::verticalWrapMode() const
\warning This function can only be called from the rendering thread.
\since 6.0
-
- \internal
*/
QRhiTexture *QSGTexture::rhiTexture() const
{
@@ -637,8 +601,6 @@ QRhiTexture *QSGTexture::rhiTexture() const
\warning This function can only be called from the rendering thread.
\since 6.0
-
- \internal
*/
void QSGTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
{
@@ -692,6 +654,12 @@ QSGDynamicTexture::QSGDynamicTexture(QSGTexturePrivate &dd)
}
/*!
+ \internal
+ */
+QSGDynamicTexture::~QSGDynamicTexture()
+ = default;
+
+/*!
\fn template <typename QNativeInterface> NativeInterface *QSGTexture::nativeInterface() const
Returns a native interface of the given type for the texture.
@@ -708,13 +676,14 @@ QSGDynamicTexture::QSGDynamicTexture(QSGTexturePrivate &dd)
*/
-#if QT_CONFIG(opengl) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(opengl) || defined(Q_QDOC)
namespace QNativeInterface {
/*!
\class QNativeInterface::QSGOpenGLTexture
\inmodule QtQuick
\ingroup native-interfaces
\ingroup native-interfaces-qsgtexture
+ \inheaderfile QSGTexture
\brief Provides access to and enables adopting OpenGL texture objects.
\since 6.0
*/
@@ -761,7 +730,7 @@ QSGTexture *QSGOpenGLTexture::fromNative(GLuint textureId,
}
/*!
- Creates a new QSGTexture wrapping an existing OpenGL texture object for
+ Creates a new QSGTexture wrapping an existing OpenGL ES texture object for
\a window.
The native object specified in \a textureId is wrapped, but not owned, by
@@ -770,7 +739,8 @@ QSGTexture *QSGOpenGLTexture::fromNative(GLuint textureId,
native object.
This function is suitable only for textures that are meant to be
- used with the \c{GL_TEXTURE_EXTERNAL_OES} target.
+ used with the \c{GL_TEXTURE_EXTERNAL_OES} target: usually textures
+ to which another device (such as a camera) writes data.
\warning This function will return null if the scenegraph has not yet been
initialized.
@@ -805,22 +775,16 @@ GLuint QSGTexturePlatformOpenGL::nativeTexture() const
return GLuint(tex->nativeTexture().object);
return 0;
}
-
-template<> Q_QUICK_EXPORT
-QNativeInterface::QSGOpenGLTexture *QSGTexture::nativeInterface<QNativeInterface::QSGOpenGLTexture>() const
-{
- Q_D(const QSGTexture);
- return &const_cast<QSGTexturePrivate*>(d)->m_openglTextureAccessor;
-}
#endif // opengl
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
namespace QNativeInterface {
/*!
\class QNativeInterface::QSGD3D11Texture
\inmodule QtQuick
\ingroup native-interfaces
\ingroup native-interfaces-qsgtexture
+ \inheaderfile QSGTexture
\brief Provides access to and enables adopting Direct3D 11 texture objects.
\since 6.0
*/
@@ -873,21 +837,87 @@ void *QSGTexturePlatformD3D11::nativeTexture() const
return 0;
}
-template<> Q_QUICK_EXPORT
-QNativeInterface::QSGD3D11Texture *QSGTexture::nativeInterface<QNativeInterface::QSGD3D11Texture>() const
+namespace QNativeInterface {
+/*!
+ \class QNativeInterface::QSGD3D12Texture
+ \inmodule QtQuick
+ \ingroup native-interfaces
+ \ingroup native-interfaces-qsgtexture
+ \inheaderfile QSGTexture
+ \brief Provides access to and enables adopting Direct3D 12 texture objects.
+ \since 6.6
+*/
+
+/*!
+ \fn void *QNativeInterface::QSGD3D12Texture::nativeTexture() const
+ \return the ID3D12Texture object.
+ */
+
+QT_DEFINE_NATIVE_INTERFACE(QSGD3D12Texture);
+
+/*!
+ Creates a new QSGTexture wrapping an existing Direct 3D 12 \a texture object
+ for \a window.
+
+ The native object is wrapped, but not owned, by the resulting QSGTexture.
+ The caller of the function is responsible for deleting the returned
+ QSGTexture, but that will not destroy the underlying native object.
+
+ This function is currently suitable for 2D RGBA textures only.
+
+ \warning This function will return null if the scene graph has not yet been
+ initialized.
+
+ Use \a options to customize the texture attributes. Only the
+ TextureHasAlphaChannel and TextureHasMipmaps are taken into account here.
+
+ \a size specifies the size in pixels.
+
+ \a resourceState must specify the
+ \l{https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_states}{current state}
+ of the texture resource.
+
+ \note This function must be called on the scene graph rendering thread.
+
+ \sa QQuickWindow::sceneGraphInitialized(), QSGTexture,
+ {Scene Graph - Metal Texture Import}, {Scene Graph - Vulkan Texture Import}
+
+ \since 6.6
+ */
+QSGTexture *QSGD3D12Texture::fromNative(void *texture,
+ int resourceState,
+ QQuickWindow *window,
+ const QSize &size,
+ QQuickWindow::CreateTextureOptions options)
+{
+ return QQuickWindowPrivate::get(window)->createTextureFromNativeTexture(quint64(texture), resourceState, size, options);
+}
+} // QNativeInterface
+
+int QSGTexturePlatformD3D12::nativeResourceState() const
+{
+ if (auto *tex = m_texture->rhiTexture())
+ return tex->nativeTexture().layout;
+ return 0;
+}
+
+void *QSGTexturePlatformD3D12::nativeTexture() const
{
- Q_D(const QSGTexture);
- return &const_cast<QSGTexturePrivate*>(d)->m_d3d11TextureAccessor;
+ if (auto *tex = m_texture->rhiTexture())
+ return reinterpret_cast<void *>(quintptr(tex->nativeTexture().object));
+ return 0;
}
+
#endif // win
-#if defined(__OBJC__) || defined(Q_CLANG_QDOC)
+#if defined(__OBJC__) || defined(Q_QDOC)
namespace QNativeInterface {
/*!
\class QNativeInterface::QSGMetalTexture
\inmodule QtQuick
\ingroup native-interfaces
\ingroup native-interfaces-qsgtexture
+ \inheaderfile QSGTexture
\brief Provides access to and enables adopting Metal texture objects.
\since 6.0
*/
@@ -926,22 +956,16 @@ namespace QNativeInterface {
*/
} // QNativeInterface
+#endif // OBJC
-template<> Q_QUICK_EXPORT
-QNativeInterface::QSGMetalTexture *QSGTexture::nativeInterface<QNativeInterface::QSGMetalTexture>() const
-{
- Q_D(const QSGTexture);
- return &const_cast<QSGTexturePrivate*>(d)->m_metalTextureAccessor;
-}
-#endif // win
-
-#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
+#if QT_CONFIG(vulkan) || defined(Q_QDOC)
namespace QNativeInterface {
/*!
\class QNativeInterface::QSGVulkanTexture
\inmodule QtQuick
\ingroup native-interfaces
\ingroup native-interfaces-qsgtexture
+ \inheaderfile QSGTexture
\brief Provides access to and enables adopting Vulkan image objects.
\since 6.0
*/
@@ -1008,14 +1032,34 @@ VkImageLayout QSGTexturePlatformVulkan::nativeImageLayout() const
return VkImageLayout(tex->nativeTexture().layout);
return VK_IMAGE_LAYOUT_UNDEFINED;
}
+#endif // vulkan
-template<> Q_QUICK_EXPORT
-QNativeInterface::QSGVulkanTexture *QSGTexture::nativeInterface<QNativeInterface::QSGVulkanTexture>() const
+void *QSGTexture::resolveInterface(const char *name, int revision) const
{
+ using namespace QNativeInterface;
+ Q_UNUSED(name);
+ Q_UNUSED(revision);
+
Q_D(const QSGTexture);
- return &const_cast<QSGTexturePrivate*>(d)->m_vulkanTextureAccessor;
+ auto *dd = const_cast<QSGTexturePrivate *>(d);
+ Q_UNUSED(dd);
+
+#if QT_CONFIG(vulkan)
+ QT_NATIVE_INTERFACE_RETURN_IF(QSGVulkanTexture, &dd->m_vulkanTextureAccessor);
+#endif
+#if QT_CONFIG(metal)
+ QT_NATIVE_INTERFACE_RETURN_IF(QSGMetalTexture, &dd->m_metalTextureAccessor);
+#endif
+#if defined(Q_OS_WIN)
+ QT_NATIVE_INTERFACE_RETURN_IF(QSGD3D11Texture, &dd->m_d3d11TextureAccessor);
+ QT_NATIVE_INTERFACE_RETURN_IF(QSGD3D12Texture, &dd->m_d3d12TextureAccessor);
+#endif
+#if QT_CONFIG(opengl)
+ QT_NATIVE_INTERFACE_RETURN_IF(QSGOpenGLTexture, &dd->m_openglTextureAccessor);
+#endif
+
+ return nullptr;
}
-#endif // vulkan
QT_END_NAMESPACE