diff options
Diffstat (limited to 'src/quickshapes/qquickshape_p_p.h')
-rw-r--r-- | src/quickshapes/qquickshape_p_p.h | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/src/quickshapes/qquickshape_p_p.h b/src/quickshapes/qquickshape_p_p.h index bc06c8fde8..bfeb0d2f9f 100644 --- a/src/quickshapes/qquickshape_p_p.h +++ b/src/quickshapes/qquickshape_p_p.h @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE class QSGPlainTexture; +class QRhi; class QQuickAbstractPathRenderer { @@ -186,45 +187,57 @@ public: bool syncTimingActive = false; }; -#if QT_CONFIG(opengl) +struct QQuickShapeGradientCacheKey +{ + QQuickShapeGradientCacheKey(const QGradientStops &stops, QQuickShapeGradient::SpreadMode spread) + : stops(stops), spread(spread) + { } + QGradientStops stops; + QQuickShapeGradient::SpreadMode spread; + bool operator==(const QQuickShapeGradientCacheKey &other) const + { + return spread == other.spread && stops == other.stops; + } +}; -class QQuickShapeGradientCache : public QOpenGLSharedResource +inline uint qHash(const QQuickShapeGradientCacheKey &v, uint seed = 0) { -public: - struct Key { - Key(const QGradientStops &stops, QQuickShapeGradient::SpreadMode spread) - : stops(stops), spread(spread) - { } - QGradientStops stops; - QQuickShapeGradient::SpreadMode spread; - bool operator==(const Key &other) const - { - return spread == other.spread && stops == other.stops; - } - }; + uint h = seed + v.spread; + for (int i = 0; i < 3 && i < v.stops.count(); ++i) + h += v.stops[i].second.rgba(); + return h; +} - QQuickShapeGradientCache(QOpenGLContext *context) : QOpenGLSharedResource(context->shareGroup()) { } +class QQuickShapeGradientCache +{ +public: ~QQuickShapeGradientCache(); + static QQuickShapeGradientCache *cacheForRhi(QRhi *rhi); + QSGTexture *get(const QQuickShapeGradientCacheKey &grad); + +private: + QHash<QQuickShapeGradientCacheKey, QSGPlainTexture *> m_textures; +}; + +#if QT_CONFIG(opengl) + +class QQuickShapeGradientOpenGLCache : public QOpenGLSharedResource +{ +public: + QQuickShapeGradientOpenGLCache(QOpenGLContext *context) : QOpenGLSharedResource(context->shareGroup()) { } + ~QQuickShapeGradientOpenGLCache(); void invalidateResource() override; void freeResource(QOpenGLContext *) override; - QSGTexture *get(const Key &grad); + QSGTexture *get(const QQuickShapeGradientCacheKey &grad); - static QQuickShapeGradientCache *currentCache(); + static QQuickShapeGradientOpenGLCache *currentCache(); private: - QHash<Key, QSGPlainTexture *> m_cache; + QHash<QQuickShapeGradientCacheKey, QSGPlainTexture *> m_cache; }; -inline uint qHash(const QQuickShapeGradientCache::Key &v, uint seed = 0) -{ - uint h = seed + v.spread; - for (int i = 0; i < 3 && i < v.stops.count(); ++i) - h += v.stops[i].second.rgba(); - return h; -} - #endif // QT_CONFIG(opengl) QT_END_NAMESPACE |