vector: refactor code to remove a global instance. submit/tizen/20190917.012523 submit/tizen/20190917.040942 submit/tizen/20190917.043123
authorHermet Park <hermetpark@gmail.com>
Mon, 16 Sep 2019 11:05:55 +0000 (20:05 +0900)
committerHermet Park <hermetpark@gmail.com>
Tue, 17 Sep 2019 01:24:36 +0000 (10:24 +0900)
This kind of global static instance is really dangerous in c++ because
We have no idea when the instance will be initalization exactly.

This might interrupt the program sequence, more worsely, it could break the program
while That breakage is totally up to the member instances of the class.

Very poor design.

Change-Id: I9d7dd12dc72a2936be95478d26aefc982e4eeeb9

src/vector/vdrawhelper.cpp

index 78a4519..d6fa3d1 100644 (file)
@@ -111,6 +111,12 @@ public:
         return info;
     }
 
+    static VGradientCache &instance()
+      {
+         static VGradientCache CACHE;
+         return CACHE;
+      }
+
 protected:
     uint       maxCacheSize() const { return 60; }
     VCacheData addCacheElement(VCacheKey hash_val, const VGradient &gradient)
@@ -187,8 +193,6 @@ bool VGradientCache::generateGradientColorTable(const VGradientStops &stops,
     return alpha;
 }
 
-//static VGradientCache VGradientCacheInstance;
-
 void VRasterBuffer::clear()
 {
     memset(mBuffer, 0, mHeight * mBytesPerLine);
@@ -758,9 +762,8 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
         mSolid = brush.mColor.premulARGB();
         break;
     case VBrush::Type::LinearGradient: {
-#if 0
         mType = VSpanData::Type::LinearGradient;
-        mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
+        mColorTable = VGradientCache::instance().getBuffer(*brush.mGradient);
         mGradient.mColorTable = mColorTable->buffer32;
         mGradient.mColorTableAlpha = mColorTable->alpha;
         mGradient.linear.x1 = brush.mGradient->linear.x1;
@@ -770,12 +773,10 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
         mGradient.mSpread = brush.mGradient->mSpread;
         setupMatrix(brush.mGradient->mMatrix);
         break;
-#endif
     }
     case VBrush::Type::RadialGradient: {
-#if 0
         mType = VSpanData::Type::RadialGradient;
-        mColorTable = VGradientCacheInstance.getBuffer(*brush.mGradient);
+        mColorTable = VGradientCache::instance().getBuffer(*brush.mGradient);
         mGradient.mColorTable = mColorTable->buffer32;
         mGradient.mColorTableAlpha = mColorTable->alpha;
         mGradient.radial.cx = brush.mGradient->radial.cx;
@@ -787,7 +788,6 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/,
         mGradient.mSpread = brush.mGradient->mSpread;
         setupMatrix(brush.mGradient->mMatrix);
         break;
-#endif
     }
     case VBrush::Type::Texture: {
         mType = VSpanData::Type::Texture;