6#include <private/qqmlglobal_p.h>
7#include <private/qsgmaterialshader_p.h>
8#include <private/qsgrenderer_p.h>
9#include <private/qquickitem_p.h>
10#include <private/qquickwindow_p.h>
11#include <QtCore/private/qnativeinterface_p.h>
14#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && defined(__GLIBC__)
15#define CAN_BACKTRACE_EXECINFO
19#define CAN_BACKTRACE_EXECINFO
22#if defined(QT_NO_DEBUG)
23#undef CAN_BACKTRACE_EXECINFO
26#if defined(CAN_BACKTRACE_EXECINFO)
42 return a.filtering ==
b.filtering
43 &&
a.mipmapFiltering ==
b.mipmapFiltering
44 &&
a.horizontalWrap ==
b.horizontalWrap
45 &&
a.verticalWrap ==
b.verticalWrap
46 &&
a.anisotropylevel ==
b.anisotropylevel;
56 const int f =
s.filtering;
57 const int m =
s.mipmapFiltering;
58 const int w =
s.horizontalWrap;
59 const int a =
s.anisotropylevel;
60 return (((
f & 7) << 24) | ((
m & 7) << 16) | ((
w & 7) << 8) | (
a & 7)) ^
seed;
67 s.mipmapFiltering =
t->mipmapFiltering();
68 s.horizontalWrap =
t->horizontalWrapMode();
69 s.verticalWrap =
t->verticalWrapMode();
70 s.anisotropylevel =
t->anisotropyLevel();
76 , filteringChanged(
false)
77 , anisotropyChanged(
false)
84 , m_openglTextureAccessor(
t)
87 , m_d3d11TextureAccessor(
t)
88 , m_d3d12TextureAccessor(
t)
91 , m_metalTextureAccessor(
t)
94 , m_vulkanTextureAccessor(
t)
106#if (defined(Q_OS_LINUX) || defined (Q_OS_MAC)) && !defined(Q_OS_ANDROID)
109#define BACKTRACE_SIZE 20
110class SGTextureTraceItem
113 void *backTrace[BACKTRACE_SIZE];
114 size_t backTraceSize;
117static QHash<QSGTexture*, SGTextureTraceItem*> qt_debug_allocated_textures;
125#if defined(CAN_BACKTRACE_EXECINFO)
126 if (qmlDebugLeakBacktrace()) {
127 while (!qt_debug_allocated_textures.isEmpty()) {
130 SGTextureTraceItem*
item =
it.value();
132 qt_debug_allocated_textures.
erase(
it);
137 char** symbols = backtrace_symbols(
item->backTrace,
item->backTraceSize);
140 for (
int i=0;
i<(int)
item->backTraceSize;
i++)
141 qDebug(
"Backtrace <%02d>: %s",
i, symbols[
i]);
155#if defined(CAN_BACKTRACE_EXECINFO)
156 if (qmlDebugLeakBacktrace()) {
157 SGTextureTraceItem*
item =
new SGTextureTraceItem;
158 item->backTraceSize = backtrace(
item->backTrace, BACKTRACE_SIZE);
167 static bool atexit_registered =
false;
168 if (!atexit_registered) {
170 atexit_registered =
true;
176#if defined(CAN_BACKTRACE_EXECINFO)
177 if (qmlDebugLeakBacktrace()) {
178 SGTextureTraceItem*
item = qt_debug_allocated_textures.value(
texture, 0);
180 qt_debug_allocated_textures.remove(
texture);
191 qDebug(
"Texture destroyed after qt_debug_print_texture_count() was called.");
308 if (lcQsgLeak().isDebugEnabled())
312 qsg_valid_texture_set()->insert(
this);
323 if (lcQsgLeak().isDebugEnabled())
327 qsg_valid_texture_set()->insert(
this);
337 if (lcQsgLeak().isDebugEnabled())
341 qsg_valid_texture_set()->remove(
this);
436 return QRectF(0, 0, 1, 1);
464 d->filteringChanged =
true;
485 d->filteringChanged =
true;
511 d->anisotropyLevel =
level;
512 d->anisotropyChanged =
true;
535 if ((
uint) hwrap !=
d->horizontalWrap) {
536 d->horizontalWrap = hwrap;
537 d->wrapChanged =
true;
557 if ((
uint) vwrap !=
d->verticalWrap) {
558 d->verticalWrap = vwrap;
559 d->wrapChanged =
true;
679#if QT_CONFIG(opengl) || defined(Q_QDOC)
727 QQuickWindow::CreateTextureOptions options)
762 QQuickWindow::CreateTextureOptions options)
772GLuint QSGTexturePlatformOpenGL::nativeTexture()
const
774 if (
auto *tex = m_texture->rhiTexture())
775 return GLuint(tex->nativeTexture().object);
780#if defined(Q_OS_WIN) || defined(Q_QDOC)
827 QQuickWindow::CreateTextureOptions options)
833void *QSGTexturePlatformD3D11::nativeTexture()
const
835 if (
auto *tex = m_texture->rhiTexture())
836 return reinterpret_cast<void *
>(
quintptr(tex->nativeTexture().object));
891 QQuickWindow::CreateTextureOptions options)
897int QSGTexturePlatformD3D12::nativeResourceState()
const
899 if (
auto *tex = m_texture->rhiTexture())
900 return tex->nativeTexture().layout;
904void *QSGTexturePlatformD3D12::nativeTexture()
const
906 if (
auto *tex = m_texture->rhiTexture())
907 return reinterpret_cast<void *
>(
quintptr(tex->nativeTexture().object));
913#if defined(__OBJC__) || defined(Q_QDOC)
961#if QT_CONFIG(vulkan) || defined(Q_QDOC)
1016 QQuickWindow::CreateTextureOptions options)
1022VkImage QSGTexturePlatformVulkan::nativeImage()
const
1024 if (
auto *tex = m_texture->rhiTexture())
1025 return VkImage(tex->nativeTexture().object);
1026 return VK_NULL_HANDLE;
1029VkImageLayout QSGTexturePlatformVulkan::nativeImageLayout()
const
1031 if (
auto *tex = m_texture->rhiTexture())
1032 return VkImageLayout(tex->nativeTexture().layout);
1033 return VK_IMAGE_LAYOUT_UNDEFINED;
1037void *QSGTexture::resolveInterface(
const char *
name,
int revision)
const
1047#if QT_CONFIG(vulkan)
1053#if defined(Q_OS_WIN)
1057#if QT_CONFIG(opengl)
1066#include "moc_qsgtexture.cpp"
static QQuickWindowPrivate * get(QQuickWindow *c)
@ NativeTextureIsExternalOES
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
~QSGDynamicTexture() override
QSGDynamicTexture()=default
void resetDirtySamplerOptions()
bool hasDirtySamplerOptions() const
QSGTexturePrivate(QSGTexture *t)
virtual void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
Call this function to enqueue image upload operations to resourceUpdates, in case there are any pendi...
void setAnisotropyLevel(AnisotropyLevel level)
Sets the level of anisotropic filtering to level.
QSGTexture::Filtering mipmapFiltering() const
Returns whether mipmapping should be used when sampling from this texture.
virtual QRectF normalizedTextureSubRect() const
Returns the rectangle inside textureSize() that this texture represents in normalized coordinates.
void setHorizontalWrapMode(WrapMode hwrap)
Sets the horizontal wrap mode to hwrap.
virtual QSGTexture * removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates=nullptr) const
This function returns a copy of the current texture which is removed from its atlas.
void setFiltering(Filtering filter)
Sets the sampling mode to filter.
QSGTexture::WrapMode verticalWrapMode() const
Returns the vertical wrap mode to be used for this texture.
QSGTexture::Filtering filtering() const
Returns the sampling mode to be used for this texture.
QSGTexture::AnisotropyLevel anisotropyLevel() const
Returns the anisotropy level in use for filtering this texture.
void setMipmapFiltering(Filtering filter)
Sets the mipmap sampling mode to filter.
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
WrapMode
Specifies how the sampler should treat texture coordinates.
~QSGTexture() override
Destroys the QSGTexture.
QSGTexture()
Constructs the QSGTexture base class.
virtual bool isAtlasTexture() const
Returns whether this texture is part of an atlas or not.
AnisotropyLevel
Specifies the anisotropic filtering level to be used when the texture is not screen aligned.
QSGTexture::WrapMode horizontalWrapMode() const
Returns the horizontal wrap mode to be used for this texture.
virtual QRhiTexture * rhiTexture() const
void setVerticalWrapMode(WrapMode vwrap)
Sets the vertical wrap mode to vwrap.
iterator erase(const_iterator i)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
#define QT_NATIVE_INTERFACE_RETURN_IF(NativeInterface, baseType)
#define QT_DEFINE_NATIVE_INTERFACE(...)
GLboolean GLboolean GLboolean b
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
#define DEFINE_BOOL_CONFIG_OPTION(name, var)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
#define Q_ASSERT_X(cond, x, msg)
size_t qHash(const QSGSamplerDescription &s, size_t seed) noexcept
static void qt_debug_print_texture_count()
static void qt_debug_remove_texture(QSGTexture *texture)
static int qt_debug_texture_count
bool operator!=(const QSGSamplerDescription &a, const QSGSamplerDescription &b) noexcept
static void qt_debug_add_texture(QSGTexture *texture)
#define QT_CONFIG(feature)
unsigned long long quint64
if(qFloatDistance(a, b)<(1<< 7))
[0]
static QSGSamplerDescription fromTexture(QSGTexture *t)
QSGTexture::Filtering filtering