From 5ba25903882222a556a3e7558e6455e2a203569d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Dec 2022 15:57:59 +0100 Subject: QPaintEngineRaster: port from QSharedPointer to std::shared_ptr Compared to std::shared_ptr, QSharedPointer requires 2x the atomic operations per copy, and does not support QSharedPointer. Port to std::shared_ptr, and drop the Pinnable kludge. Add an optimistic std::move() when we insert into QMultiHash. Pick-to: 6.5 Change-Id: I2ab004b7e8fa36d9e777cd787ffded4076d2880f Reviewed-by: Ahmad Samir Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qdrawhelper_p.h | 8 ++------ src/gui/painting/qpaintengine_raster.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 85b073bfde..5f58d55dd0 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -29,7 +29,7 @@ #include "private/qrasterdefs_p.h" #include -#include +#include QT_BEGIN_NAMESPACE @@ -330,11 +330,7 @@ struct QSpanData QGradientData gradient; QTextureData texture; }; - class Pinnable { - protected: - ~Pinnable() {} - }; // QSharedPointer is not supported - QSharedPointer cachedGradient; + std::shared_ptr cachedGradient; void init(QRasterBuffer *rb, const QRasterPaintEngine *pe); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index a26467e72b..9cabef4a95 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -4206,7 +4206,7 @@ static void qt_span_clip(int count, const QT_FT_Span *spans, void *userData) class QGradientCache { public: - struct CacheInfo : QSpanData::Pinnable + struct CacheInfo { inline CacheInfo(QGradientStops s, int op, QGradient::InterpolationMode mode) : stops(std::move(s)), opacity(op), interpolationMode(mode) {} @@ -4217,9 +4217,9 @@ public: QGradient::InterpolationMode interpolationMode; }; - typedef QMultiHash> QGradientColorTableHash; + using QGradientColorTableHash = QMultiHash>; - inline QSharedPointer getBuffer(const QGradient &gradient, int opacity) { + std::shared_ptr getBuffer(const QGradient &gradient, int opacity) { quint64 hash_val = 0; const QGradientStops stops = gradient.stops(); @@ -4249,16 +4249,16 @@ protected: inline void generateGradientColorTable(const QGradient& g, QRgba64 *colorTable, int size, int opacity) const; - QSharedPointer addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) { + std::shared_ptr addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) { if (cache.size() == maxCacheSize()) { // may remove more than 1, but OK cache.erase(std::next(cache.begin(), QRandomGenerator::global()->bounded(maxCacheSize()))); } - auto cache_entry = QSharedPointer::create(gradient.stops(), opacity, gradient.interpolationMode()); + auto cache_entry = std::make_shared(gradient.stops(), opacity, gradient.interpolationMode()); generateGradientColorTable(gradient, cache_entry->buffer64, paletteSize(), opacity); for (int i = 0; i < GRADIENT_STOPTABLE_SIZE; ++i) cache_entry->buffer32[i] = cache_entry->buffer64[i].toArgb32(); - return cache.insert(hash_val, cache_entry).value(); + return cache.insert(hash_val, std::move(cache_entry)).value(); } QGradientColorTableHash cache; -- cgit v1.2.3