lottie: update LOTNode with the gradient stop value. 36/192736/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 9 Nov 2018 01:50:00 +0000 (10:50 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Fri, 9 Nov 2018 01:52:07 +0000 (10:52 +0900)
Change-Id: I85f882418d66341f2667428e293364e2cd916a9e

inc/lottiecommon.h
src/lottie/lottieitem.cpp

index 22400e6a397c0edc5d44d6b7ee55f2e8b132379e..dd65f9b7fdb931b16153262c088ee678386ee19d 100644 (file)
@@ -71,6 +71,12 @@ typedef enum
     GradientRadial
 } LOTGradientType;
 
+typedef struct
+{
+    float         pos;
+    unsigned char r, g, b, a;
+}GradientStop;
+
 typedef struct LOTNode {
 
 #define ChangeFlagNone 0x0000
@@ -101,6 +107,8 @@ typedef struct LOTNode {
 
     struct {
         LOTGradientType type;
+        GradientStop *stopPtr;
+        unsigned int stopCount;
         struct {
             float x, y;
         } start, end, center, focal;
index cb7a2ad8e843ceb8e074adc0e8127bcf47c1f7ee..bf9ffac63bbcdefd18bc4f98893f0abcc25fae16 100644 (file)
@@ -992,9 +992,34 @@ void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
 
 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
 
+static void updateGStops(LOTNode *n, const VGradient *grad)
+{
+    if (grad->mStops.size() != n->mGradient.stopCount) {
+        if (n->mGradient.stopCount)
+            free(n->mGradient.stopPtr);
+        n->mGradient.stopCount = grad->mStops.size();
+        n->mGradient.stopPtr = (GradientStop *) malloc(n->mGradient.stopCount * sizeof(GradientStop));
+    }
+
+    GradientStop *ptr = n->mGradient.stopPtr;
+    for (const auto &i : grad->mStops) {
+        ptr->pos = i.first;
+        ptr->a = i.second.alpha() * grad->alpha();
+        ptr->r = i.second.red();
+        ptr->g = i.second.green();
+        ptr->b = i.second.blue();
+        ptr++;
+    }
+
+}
+
 void LOTDrawable::sync()
 {
-    if (!mCNode) mCNode = std::make_unique<LOTNode>();
+    if (!mCNode) {
+        mCNode = std::make_unique<LOTNode>();
+        mCNode->mGradient.stopPtr = nullptr;
+        mCNode->mGradient.stopCount = 0;
+    }
 
     mCNode->mFlag = ChangeFlagNone;
     if (mFlag & DirtyState::None) return;
@@ -1077,6 +1102,7 @@ void LOTDrawable::sync()
         mCNode->mGradient.start.y = mBrush.mGradient->linear.y1;
         mCNode->mGradient.end.x = mBrush.mGradient->linear.x2;
         mCNode->mGradient.end.y = mBrush.mGradient->linear.y2;
+        updateGStops(mCNode.get(), mBrush.mGradient);
         break;
     case VBrush::Type::RadialGradient:
         mCNode->mType = LOTBrushType::BrushGradient;
@@ -1087,6 +1113,7 @@ void LOTDrawable::sync()
         mCNode->mGradient.focal.y = mBrush.mGradient->radial.fy;
         mCNode->mGradient.cradius = mBrush.mGradient->radial.cradius;
         mCNode->mGradient.fradius = mBrush.mGradient->radial.fradius;
+        updateGStops(mCNode.get(), mBrush.mGradient);
         break;
     default:
         break;