vector: keep a shared reference to cached color table
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 31 May 2019 00:40:08 +0000 (09:40 +0900)
committerHermet Park <hermetpark@gmail.com>
Wed, 19 Jun 2019 04:34:12 +0000 (13:34 +0900)
src/vector/vdrawhelper.cpp
src/vector/vdrawhelper.h

index 9c793726bd81f1caab36a95a0faf0e167c0a5440..ebe4e38d1b5da0c6185c9a552fc2e9473f3ac6a8 100644 (file)
 
 class VGradientCache {
 public:
-    struct CacheInfo : public VSpanData::Pinnable {
+    struct CacheInfo : public VColorTable {
         inline CacheInfo(VGradientStops s) : stops(std::move(s)) {}
-        uint32_t       buffer32[VGradient::colorTableSize];
         VGradientStops stops;
-        bool           alpha{true};
     };
 
-    typedef std::unordered_multimap<uint64_t, std::shared_ptr<const CacheInfo>>
-         VGradientColorTableHash;
+    using VGradientColorTableHash = std::unordered_multimap<uint64_t, std::shared_ptr<const CacheInfo>>;
+
     bool generateGradientColorTable(const VGradientStops &stops, float alpha,
                                     uint32_t *colorTable, int size);
-    inline const std::shared_ptr<const CacheInfo> getBuffer(
+    inline const std::shared_ptr<const VColorTable> getBuffer(
         const VGradient &gradient)
     {
         uint64_t                         hash_val = 0;
@@ -748,9 +746,9 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
         break;
     case VBrush::Type::LinearGradient: {
         mType = VSpanData::Type::LinearGradient;
-        auto cacheInfo = VGradientCacheInstance.getBuffer(*brush.mGradient);
-        mGradient.mColorTable = cacheInfo->buffer32;
-        mGradient.mColorTableAlpha = cacheInfo->alpha;
+        mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
+        mGradient.mColorTable = mColorTable->buffer32;
+        mGradient.mColorTableAlpha = mColorTable->alpha;
         mGradient.linear.x1 = brush.mGradient->linear.x1;
         mGradient.linear.y1 = brush.mGradient->linear.y1;
         mGradient.linear.x2 = brush.mGradient->linear.x2;
@@ -761,9 +759,9 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
     }
     case VBrush::Type::RadialGradient: {
         mType = VSpanData::Type::RadialGradient;
-        auto cacheInfo = VGradientCacheInstance.getBuffer(*brush.mGradient);
-        mGradient.mColorTable = cacheInfo->buffer32;
-        mGradient.mColorTableAlpha = cacheInfo->alpha;
+        mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
+        mGradient.mColorTable = mColorTable->buffer32;
+        mGradient.mColorTableAlpha = mColorTable->alpha;
         mGradient.radial.cx = brush.mGradient->radial.cx;
         mGradient.radial.cy = brush.mGradient->radial.cy;
         mGradient.radial.fx = brush.mGradient->radial.fx;
index 065377201f999b01ace260822a5df9b02e0253c7..93710bbaff89cae3a263aa1be1d9c6b5c809b2c0 100644 (file)
@@ -138,11 +138,13 @@ struct VBitmapData
     int const_alpha;
 };
 
+struct VColorTable
+{
+    uint32_t buffer32[VGradient::colorTableSize];
+    bool     alpha{true};
+};
+
 struct VSpanData {
-    class Pinnable {
-    protected:
-        ~Pinnable() = default;
-    };
     enum class Type { None, Solid, LinearGradient, RadialGradient, Texture };
 
     void  updateSpanFunc();
@@ -174,7 +176,7 @@ struct VSpanData {
     ProcessRleSpan                       mBlendFunc;
     ProcessRleSpan                       mUnclippedBlendFunc;
     VSpanData::Type                      mType;
-    std::shared_ptr<VSpanData::Pinnable> mCachedGradient;
+    std::shared_ptr<const VColorTable>   mColorTable{nullptr};
     VPoint                               mOffset; // offset to the subsurface
     VSize                                mDrawableSize;// suburface size
     union {