Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsggradientcache_p.h
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
ifndef
QSGGRADIENTCACHE_P_H
5
#
define
QSGGRADIENTCACHE_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists for the convenience
12
// of a number of Qt sources files. This header file may change from
13
// version to version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtCore
/
qhash
.
h
>
19
#
include
<
QtCore
/
qcache
.
h
>
20
#
include
<
QtGui
/
qbrush
.
h
>
21
22
#
include
<
QtQuick
/
qtquickexports
.
h
>
23
24
QT_BEGIN_NAMESPACE
25
26
class
QSGTexture;
27
class
QSGPlainTexture;
28
class
QRhi;
29
30
struct
Q_QUICK_EXPORT
QSGGradientCacheKey
31
{
32
QSGGradientCacheKey(
const
QGradientStops &stops, QGradient::Spread spread)
33
: stops(stops), spread(spread)
34
{ }
35
QGradientStops stops;
36
QGradient
::
Spread
spread
;
37
bool
operator
==(
const
QSGGradientCacheKey &other)
const
38
{
39
return
spread == other.spread && stops == other.stops;
40
}
41
};
42
43
inline
size_t
qHash
(
const
QSGGradientCacheKey &v, size_t seed = 0)
44
{
45
size_t h = qHash(size_t(v.spread), seed);
46
for
(
int
i = 0; i < 2 && i < v.stops.size(); ++i)
47
h = qHash(v.stops[i].first, qHash(v.stops[i].second.rgba64(), h));
48
return
h;
49
}
50
51
class
Q_QUICK_EXPORT
QSGGradientCache
52
{
53
public
:
54
struct
GradientDesc {
// can fully describe a linear/radial/conical gradient
55
QGradientStops stops;
56
QGradient::Spread spread = QGradient::PadSpread;
57
QPointF a;
// start (L) or center point (R/C)
58
QPointF b;
// end (L) or focal point (R)
59
qreal v0;
// center radius (R) or start angle (C)
60
qreal v1;
// focal radius (R)
61
62
int
compare(
const
GradientDesc &other)
const
{
63
if
(
int
d = a.x() - other.a.x())
64
return
d;
65
if
(
int
d = a.y() - other.a.y())
66
return
d;
67
if
(
int
d = b.x() - other.b.x())
68
return
d;
69
if
(
int
d = b.y() - other.b.y())
70
return
d;
71
72
if
(
int
d = v0 - other.v0)
73
return
d;
74
if
(
int
d = v1 - other.v1)
75
return
d;
76
77
if
(
int
d = spread - other.spread)
78
return
d;
79
80
if
(
int
d = stops.size() - other.stops.size())
81
return
d;
82
83
for
(
int
i = 0; i < stops.size(); ++i) {
84
if
(
int
d = stops[i].first - other.stops[i].first)
85
return
d;
86
if
(
int
d = stops[i].second.rgba() - other.stops[i].second.rgba())
87
return
d;
88
}
89
90
return
0;
91
}
92
};
93
94
QSGGradientCache();
95
~QSGGradientCache();
96
static
QSGGradientCache *cacheForRhi(QRhi *rhi);
97
QSGTexture *get(
const
QSGGradientCacheKey &grad);
98
99
private
:
100
void
setTextureData(QSGPlainTexture *tx,
const
QSGGradientCacheKey &grad);
101
102
struct
IndexHolder {
103
~IndexHolder() {
if
(freeIndex && idx >= 0) *freeIndex = idx; }
104
qsizetype idx = -1;
105
qsizetype *freeIndex =
nullptr
;
106
};
107
QList<QSGPlainTexture *> m_textures;
108
QCache<QSGGradientCacheKey, IndexHolder> m_cache;
109
qsizetype m_freeIndex = -1;
110
};
111
112
QT_END_NAMESPACE
113
114
#
endif
// QSGGRADIENTCACHE_P_H
QSGGradientCache
Definition
qsggradientcache_p.h:52
QT_BEGIN_NAMESPACE::QSGCurveFillMaterialShader
Definition
qsgcurvefillnode_p.cpp:17
QT_BEGIN_NAMESPACE::QSGCurveFillMaterialShader::updateSampledImage
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
Definition
qsgcurvefillnode_p.cpp:53
QT_BEGIN_NAMESPACE::QSGCurveFillMaterialShader::QSGCurveFillMaterialShader
QSGCurveFillMaterialShader(QGradient::Type gradientType, bool useTextureFill, bool useDerivatives, int viewCount)
Definition
qsgcurvefillnode_p.cpp:29
QT_BEGIN_NAMESPACE::QSGCurveFillMaterialShader::updateUniformData
bool updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
Definition
qsgcurvefillnode_p.cpp:104
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qHash
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition
qsize.h:192
QSGGradientCacheKey
Definition
qsggradientcache_p.h:31
QSGGradientCacheKey::spread
QGradient::Spread spread
Definition
qsggradientcache_p.h:36
QSGGradientCacheKey::operator==
bool operator==(const QSGGradientCacheKey &other) const
Definition
qsggradientcache_p.h:37
qtdeclarative
src
quick
scenegraph
util
qsggradientcache_p.h
Generated on
for Qt by
1.18.0