Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
25
26class QSGTexture;
27class QSGPlainTexture;
28class QRhi;
29
30struct Q_QUICK_EXPORT QSGGradientCacheKey
31{
32 QSGGradientCacheKey(const QGradientStops &stops, QGradient::Spread spread)
33 : stops(stops), spread(spread)
34 { }
35 QGradientStops stops;
37 bool operator==(const QSGGradientCacheKey &other) const
38 {
39 return spread == other.spread && stops == other.stops;
40 }
41};
42
43inline 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
51class Q_QUICK_EXPORT QSGGradientCache
52{
53public:
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
63 QSGGradientCache();
64 ~QSGGradientCache();
65 static QSGGradientCache *cacheForRhi(QRhi *rhi);
66 QSGTexture *get(const QSGGradientCacheKey &grad);
67
68private:
69 void setTextureData(QSGPlainTexture *tx, const QSGGradientCacheKey &grad);
70
71 struct IndexHolder {
72 ~IndexHolder() { if (freeIndex && idx >= 0) *freeIndex = idx; }
73 qsizetype idx = -1;
74 qsizetype *freeIndex = nullptr;
75 };
76 QList<QSGPlainTexture *> m_textures;
77 QCache<QSGGradientCacheKey, IndexHolder> m_cache;
78 qsizetype m_freeIndex = -1;
79};
80
81QT_END_NAMESPACE
82
83#endif // QSGGRADIENTCACHE_P_H
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,...
QSGCurveFillMaterialShader(QGradient::Type gradientType, bool useTextureFill, bool useDerivatives, int viewCount)
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...
Combined button and popup list for selecting options.
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192
QGradient::Spread spread
bool operator==(const QSGGradientCacheKey &other) const