| 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 <QtGui/qbrush.h> |
| 20 | |
| 21 | #include <QtQuick/qtquickexports.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | class QSGTexture; |
| 26 | class QSGPlainTexture; |
| 27 | class QRhi; |
| 28 | |
| 29 | struct Q_QUICK_EXPORT QSGGradientCacheKey |
| 30 | { |
| 31 | QSGGradientCacheKey(const QGradientStops &stops, QGradient::Spread spread) |
| 32 | : stops(stops), spread(spread) |
| 33 | { } |
| 34 | QGradientStops stops; |
| 35 | QGradient::Spread spread; |
| 36 | bool operator==(const QSGGradientCacheKey &other) const |
| 37 | { |
| 38 | return spread == other.spread && stops == other.stops; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | inline size_t qHash(const QSGGradientCacheKey &v, size_t seed = 0) |
| 43 | { |
| 44 | size_t h = seed + v.spread; |
| 45 | for (int i = 0; i < 3 && i < v.stops.size(); ++i) |
| 46 | h += v.stops[i].second.rgba(); |
| 47 | return h; |
| 48 | } |
| 49 | |
| 50 | class Q_QUICK_EXPORT QSGGradientCache |
| 51 | { |
| 52 | public: |
| 53 | struct GradientDesc { // can fully describe a linear/radial/conical gradient |
| 54 | QGradientStops stops; |
| 55 | QGradient::Spread spread = QGradient::PadSpread; |
| 56 | QPointF a; // start (L) or center point (R/C) |
| 57 | QPointF b; // end (L) or focal point (R) |
| 58 | qreal v0; // center radius (R) or start angle (C) |
| 59 | qreal v1; // focal radius (R) |
| 60 | }; |
| 61 | |
| 62 | ~QSGGradientCache(); |
| 63 | static QSGGradientCache *cacheForRhi(QRhi *rhi); |
| 64 | QSGTexture *get(const QSGGradientCacheKey &grad); |
| 65 | |
| 66 | private: |
| 67 | QHash<QSGGradientCacheKey, QSGPlainTexture *> m_textures; |
| 68 | }; |
| 69 | |
| 70 | QT_END_NAMESPACE |
| 71 | |
| 72 | #endif // QSGGRADIENTCACHE_P_H |
| 73 |
