From: subhransu mohanty Date: Thu, 16 Aug 2018 01:36:37 +0000 (+0900) Subject: lottie/parser: refactor lottie model objects. X-Git-Tag: submit/tizen/20180917.042405~111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=308d8cf4baacde817df1206611b3c761cd3d7f40;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/parser: refactor lottie model objects. Change-Id: I89160d918b36300b4f98a8059106c356e96643d0 --- diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index d130d96..69523b1 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -268,15 +268,14 @@ public: Trim, Repeater }; + LOTData(LOTData::Type type): mType(type){} + virtual ~LOTData(){} inline LOTData::Type type() const {return mType;} virtual void accept(LOTDataVisitor *){} - virtual ~LOTData(){} - LOTData(LOTData::Type type): mStatic(true), mType(type){} bool isStatic() const{return mStatic;} void setStatic(bool value) {mStatic = value;} - virtual bool hasChildren() {return false;} public: - bool mStatic; + bool mStatic{true}; LOTData::Type mType; }; @@ -284,7 +283,6 @@ class LOTGroupData: public LOTData { public: LOTGroupData(LOTData::Type type):LOTData(type){} - virtual bool hasChildren() {return true;} public: std::vector> mChildren; std::shared_ptr mTransform; @@ -293,17 +291,14 @@ public: class LOTShapeGroupData : public LOTGroupData { public: + LOTShapeGroupData():LOTGroupData(LOTData::Type::ShapeGroup){} void accept(LOTDataVisitor *visitor) override {visitor->visit(this); visitor->visitChildren(this);} - - LOTShapeGroupData():LOTGroupData(LOTData::Type::ShapeGroup){} }; class LOTLayerData; -class LOTAsset +struct LOTAsset { -public: - LOTAsset(){} int mAssetType; //lottie asset type (precomp/char/image) std::string mRefId; // ref id std::vector> mLayers; @@ -312,65 +307,65 @@ public: class LOTLayerData : public LOTGroupData { public: + LOTLayerData():LOTGroupData(LOTData::Type::Layer){} + bool hasPathOperator() const noexcept {return mHasPathOperator;} + bool hasGradient() const noexcept {return mHasGradient;} + bool hasMask() const noexcept {return mHasMask;} + bool hasRepeater() const noexcept {return mHasRepeater;} + int id() const noexcept{ return mId;} + int parentId() const noexcept{ return mParentId;} + int inFrame() const noexcept{return mInFrame;} + int outFrame() const noexcept{return mOutFrame;} + int startFrame() const noexcept{return mStartFrame;} + int solidWidth() const noexcept{return mSolidLayer.mWidth;} + int solidHeight() const noexcept{return mSolidLayer.mHeight;} + LottieColor solidColor() const noexcept{return mSolidLayer.mColor;} void accept(LOTDataVisitor *visitor) override {visitor->visit(this); visitor->visitChildren(this);} - LOTLayerData():LOTGroupData(LOTData::Type::Layer), - mMatteType(MatteType::None), - mParentId(-1), - mId(-1), - mHasPathOperator(false), mHasMask(false){} - inline bool hasPathOperator() const noexcept {return mHasPathOperator;} - inline int id() const noexcept{ return mId;} - inline int parentId() const noexcept{ return mParentId;} - inline int inFrame() const noexcept{return mInFrame;} - inline int outFrame() const noexcept{return mOutFrame;} - inline int startFrame() const noexcept{return mOutFrame;} - inline int solidWidth() const noexcept{return mSolidLayer.mWidth;} - inline int solidHeight() const noexcept{return mSolidLayer.mHeight;} - inline LottieColor solidColor() const noexcept{return mSolidLayer.mColor;} -public: - MatteType mMatteType; - VRect mBound; - LayerType mLayerType; //lottie layer type (solid/shape/precomp) - int mParentId; // Lottie the id of the parent in the composition - int mId; // Lottie the group id used for parenting. - long mInFrame = 0; - long mOutFrame = 0; - long mStartFrame = 0; - LottieBlendMode mBlendMode; - float mTimeStreatch; - std::string mPreCompRefId; - LOTAnimatable mTimeRemap; /* "tm" */ +public: struct SolidLayer { - int mWidth; - int mHeight; + int mWidth{0}; + int mHeight{0}; LottieColor mColor; }; - SolidLayer mSolidLayer; - bool mHasPathOperator; - bool mHasMask; + + MatteType mMatteType{MatteType::None}; + VRect mBound; + LayerType mLayerType; //lottie layer type (solid/shape/precomp) + int mParentId{-1}; // Lottie the id of the parent in the composition + int mId{-1}; // Lottie the group id used for parenting. + long mInFrame{0}; + long mOutFrame{0}; + long mStartFrame{0}; + LottieBlendMode mBlendMode; + float mTimeStreatch{1.0f}; + std::string mPreCompRefId; + LOTAnimatable mTimeRemap; /* "tm" */ + SolidLayer mSolidLayer; + bool mHasPathOperator{false}; + bool mHasMask{false}; + bool mHasRepeater{false}; + bool mHasGradient{false}; std::vector> mMasks; }; class LOTCompositionData : public LOTData { public: + LOTCompositionData():LOTData(LOTData::Type::Composition){} + long frameDuration()const{return mEndFrame - mStartFrame -1;} + long frameRate()const{return mFrameRate;} + long startFrame() const {return mStartFrame;} + long endFrame() const {return mEndFrame;} + VSize size() const { return mSize;} void processRepeaterObjects(); void accept(LOTDataVisitor *visitor) override {visitor->visit(this); mRootLayer->accept(visitor);} - LOTCompositionData():LOTData(LOTData::Type::Composition){} - inline long frameDuration()const{return mEndFrame - mStartFrame -1;} - inline long frameRate()const{return mFrameRate;} - inline long startFrame() const {return mStartFrame;} - inline long endFrame() const {return mEndFrame;} - inline VSize size() const { return mSize;} - public: std::string mVersion; - VSize mSize; - bool mAnimation = false; - long mStartFrame = 0; - long mEndFrame = 0; + VSize mSize; + long mStartFrame{0}; + long mEndFrame{0}; float mFrameRate; LottieBlendMode mBlendMode; std::shared_ptr mRootLayer; @@ -384,80 +379,71 @@ public: class LOTTransformData : public LOTData { public: - void accept(LOTDataVisitor *visitor) final - {visitor->visit(this);} - LOTTransformData():LOTData(LOTData::Type::Transform), - mRotation(0), - mScale(VPointF(100, 100)), - mPosition(VPointF(0, 0)), - mAnchor(VPointF(0, 0)), - mOpacity(100), - mSkew(0), - mSkewAxis(0), - mStaticMatrix(true){} + LOTTransformData():LOTData(LOTData::Type::Transform),mScale({100, 100}){} VMatrix matrix(int frameNo) const; float opacity(int frameNo) const; void cacheMatrix(); - inline bool staticMatrix() const {return mStaticMatrix;} + bool staticMatrix() const {return mStaticMatrix;} + void accept(LOTDataVisitor *visitor) final + {visitor->visit(this);} private: VMatrix computeMatrix(int frameNo) const; public: - LOTAnimatable mRotation; /* "r" */ - LOTAnimatable mScale; /* "s" */ - LOTAnimatable mPosition; /* "p" */ - LOTAnimatable mAnchor; /* "a" */ - LOTAnimatable mOpacity; /* "o" */ - LOTAnimatable mSkew; /* "sk" */ - LOTAnimatable mSkewAxis; /* "sa" */ - bool mStaticMatrix; - VMatrix mCachedMatrix; + LOTAnimatable mRotation{0}; /* "r" */ + LOTAnimatable mScale; /* "s" */ + LOTAnimatable mPosition; /* "p" */ + LOTAnimatable mAnchor; /* "a" */ + LOTAnimatable mOpacity{100}; /* "o" */ + LOTAnimatable mSkew{0}; /* "sk" */ + LOTAnimatable mSkewAxis{0}; /* "sa" */ + bool mStaticMatrix{true}; + VMatrix mCachedMatrix; }; class LOTFillData : public LOTData { public: + LOTFillData():LOTData(LOTData::Type::Fill){} + float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} + FillRule fillRule() const {return mFillRule;} void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - LOTFillData():LOTData(LOTData::Type::Fill), mFillRule(FillRule::Winding){} - inline float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} - inline FillRule fillRule() const {return mFillRule;} public: - FillRule mFillRule; /* "r" */ + FillRule mFillRule{FillRule::Winding}; /* "r" */ LOTAnimatable mColor; /* "c" */ - LOTAnimatable mOpacity; /* "o" */ - bool mEnabled = true; /* "fillEnabled" */ + LOTAnimatable mOpacity{100}; /* "o" */ + bool mEnabled{true}; /* "fillEnabled" */ }; struct LOTDashProperty { - LOTDashProperty():mDashCount(0), mStatic(true){} LOTAnimatable mDashArray[5]; /* "d" "g" "o"*/ - int mDashCount; - bool mStatic; + int mDashCount{0}; + bool mStatic{true}; }; class LOTStrokeData : public LOTData { public: - void accept(LOTDataVisitor *visitor) final - {visitor->visit(this);} LOTStrokeData():LOTData(LOTData::Type::Stroke){} - inline float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} - inline float width(int frameNo) const {return mWidth.value(frameNo);} - inline CapStyle capStyle() const {return mCapStyle;} - inline JoinStyle joinStyle() const {return mJoinStyle;} - inline float meterLimit() const{return mMeterLimit;} - inline bool hasDashInfo() const { return !(mDash.mDashCount == 0);} + float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} + float width(int frameNo) const {return mWidth.value(frameNo);} + CapStyle capStyle() const {return mCapStyle;} + JoinStyle joinStyle() const {return mJoinStyle;} + float meterLimit() const{return mMeterLimit;} + bool hasDashInfo() const { return !(mDash.mDashCount == 0);} int getDashInfo(int frameNo, float *array) const; + void accept(LOTDataVisitor *visitor) final + {visitor->visit(this);} public: LOTAnimatable mColor; /* "c" */ - LOTAnimatable mOpacity; /* "o" */ - LOTAnimatable mWidth; /* "w" */ + LOTAnimatable mOpacity{100}; /* "o" */ + LOTAnimatable mWidth{0}; /* "w" */ CapStyle mCapStyle; /* "lc" */ JoinStyle mJoinStyle; /* "lj" */ float mMeterLimit{0}; /* "ml" */ LOTDashProperty mDash; - bool mEnabled = true; /* "fillEnabled" */ + bool mEnabled{true}; /* "fillEnabled" */ }; class LottieGradient @@ -519,7 +505,7 @@ inline LottieGradient operator*(float m, const LottieGradient &g) class LOTGradient : public LOTData { public: - LOTGradient(LOTData::Type type):LOTData(type), mColorPoints(-1){} + LOTGradient(LOTData::Type type):LOTData(type){} inline float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} void update(std::unique_ptr &grad, int frameNo); @@ -529,37 +515,37 @@ public: int mGradientType; /* "t" Linear=1 , Radial = 2*/ LOTAnimatable mStartPoint; /* "s" */ LOTAnimatable mEndPoint; /* "e" */ - LOTAnimatable mHighlightLength; /* "h" */ - LOTAnimatable mHighlightAngle; /* "a" */ - LOTAnimatable mOpacity; /* "o" */ + LOTAnimatable mHighlightLength{0}; /* "h" */ + LOTAnimatable mHighlightAngle{0}; /* "a" */ + LOTAnimatable mOpacity{0}; /* "o" */ LOTAnimatable mGradient; /* "g" */ - int mColorPoints; - bool mEnabled = true; /* "fillEnabled" */ + int mColorPoints{-1}; + bool mEnabled{true}; /* "fillEnabled" */ }; class LOTGFillData : public LOTGradient { public: + LOTGFillData():LOTGradient(LOTData::Type::GFill){} + FillRule fillRule() const {return mFillRule;} void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - LOTGFillData():LOTGradient(LOTData::Type::GFill), mFillRule(FillRule::Winding){} - inline FillRule fillRule() const {return mFillRule;} public: - FillRule mFillRule; /* "r" */ + FillRule mFillRule{FillRule::Winding}; /* "r" */ }; class LOTGStrokeData : public LOTGradient { public: - void accept(LOTDataVisitor *visitor) final - {visitor->visit(this);} LOTGStrokeData():LOTGradient(LOTData::Type::GStroke){} - inline float width(int frameNo) const {return mWidth.value(frameNo);} - inline CapStyle capStyle() const {return mCapStyle;} - inline JoinStyle joinStyle() const {return mJoinStyle;} - inline float meterLimit() const{return mMeterLimit;} - inline bool hasDashInfo() const { return !(mDash.mDashCount == 0);} + float width(int frameNo) const {return mWidth.value(frameNo);} + CapStyle capStyle() const {return mCapStyle;} + JoinStyle joinStyle() const {return mJoinStyle;} + float meterLimit() const{return mMeterLimit;} + bool hasDashInfo() const { return !(mDash.mDashCount == 0);} int getDashInfo(int frameNo, float *array) const; + void accept(LOTDataVisitor *visitor) final + {visitor->visit(this);} public: LOTAnimatable mWidth; /* "w" */ CapStyle mCapStyle; /* "lc" */ @@ -571,20 +557,20 @@ public: class LOTPath : public LOTData { public: - LOTPath(LOTData::Type type):LOTData(type), mDirection(1){} + LOTPath(LOTData::Type type):LOTData(type){} VPath::Direction direction() { if (mDirection == 3) return VPath::Direction::CCW; else return VPath::Direction::CW;} public: - int mDirection; + int mDirection{1}; }; class LOTShapeData : public LOTPath { public: + LOTShapeData():LOTPath(LOTData::Type::Shape){} + void process(); void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - void process(); - LOTShapeData():LOTPath(LOTData::Type::Shape){} public: LOTAnimatable mShape; }; @@ -598,30 +584,26 @@ public: Substarct, Intersect }; - LOTMaskData():mInv(false), mIsStatic(true){} - inline float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} - inline bool isStatic() const {return mIsStatic;} + float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} + bool isStatic() const {return mIsStatic;} public: LOTAnimatable mShape; LOTAnimatable mOpacity; - bool mInv; - bool mIsStatic; + bool mInv{false}; + bool mIsStatic{true}; LOTMaskData::Mode mMode; }; class LOTRectData : public LOTPath { public: + LOTRectData():LOTPath(LOTData::Type::Rect){} void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - LOTRectData():LOTPath(LOTData::Type::Rect), - mPos(VPointF(0,0)), - mSize(VPointF(0,0)), - mRound(0){} public: LOTAnimatable mPos; LOTAnimatable mSize; - LOTAnimatable mRound; + LOTAnimatable mRound{0}; }; class LOTEllipseData : public LOTPath @@ -629,9 +611,7 @@ class LOTEllipseData : public LOTPath public: void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - LOTEllipseData():LOTPath(LOTData::Type::Ellipse), - mPos(VPointF(0,0)), - mSize(VPointF(0,0)){} + LOTEllipseData():LOTPath(LOTData::Type::Ellipse){} public: LOTAnimatable mPos; LOTAnimatable mSize; @@ -644,60 +624,46 @@ public: Star = 1, Polygon = 2 }; + LOTPolystarData():LOTPath(LOTData::Type::Polystar){} void accept(LOTDataVisitor *visitor) final {visitor->visit(this);} - LOTPolystarData():LOTPath(LOTData::Type::Polystar), - mType(PolyType::Polygon), - mPos(VPointF(0,0)), - mPointCount(0), - mInnerRadius(0), - mOuterRadius(0), - mInnerRoundness(0), - mOuterRoundness(0), - mRotation(0){} -public: - LOTPolystarData::PolyType mType; - LOTAnimatable mPos; - LOTAnimatable mPointCount; - LOTAnimatable mInnerRadius; - LOTAnimatable mOuterRadius; - LOTAnimatable mInnerRoundness; - LOTAnimatable mOuterRoundness; - LOTAnimatable mRotation; +public: + LOTPolystarData::PolyType mType{PolyType::Polygon}; + LOTAnimatable mPos; + LOTAnimatable mPointCount{0}; + LOTAnimatable mInnerRadius{0}; + LOTAnimatable mOuterRadius{0}; + LOTAnimatable mInnerRoundness{0}; + LOTAnimatable mOuterRoundness{0}; + LOTAnimatable mRotation{0}; }; class LOTTrimData : public LOTData { public: - void accept(LOTDataVisitor *visitor) final - {visitor->visit(this);} enum class TrimType { Simultaneously, Individually }; - LOTTrimData():LOTData(LOTData::Type::Trim), - mStart(0), - mEnd(0), - mOffset(0), - mTrimType(TrimType::Simultaneously){} + LOTTrimData():LOTData(LOTData::Type::Trim){} + void accept(LOTDataVisitor *visitor) final + {visitor->visit(this);} public: - LOTAnimatable mStart; - LOTAnimatable mEnd; - LOTAnimatable mOffset; - LOTTrimData::TrimType mTrimType; + LOTAnimatable mStart{0}; + LOTAnimatable mEnd{0}; + LOTAnimatable mOffset{0}; + LOTTrimData::TrimType mTrimType{TrimType::Simultaneously}; }; class LOTRepeaterData : public LOTGroupData { public: + LOTRepeaterData():LOTGroupData(LOTData::Type::Repeater){} void accept(LOTDataVisitor *visitor) final {visitor->visit(this); visitor->visitChildren(this);} - LOTRepeaterData():LOTGroupData(LOTData::Type::Repeater), - mCopies(0), - mOffset(0){} public: - LOTAnimatable mCopies; - LOTAnimatable mOffset; + LOTAnimatable mCopies{0}; + LOTAnimatable mOffset{0}; }; class LOTModel diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 822cfa4..39cad49 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -748,6 +748,7 @@ std::shared_ptr LottieParserImpl::parseLayer() } else if (0 == strcmp(key, "refId")) { /*preComp Layer reference id*/ RAPIDJSON_ASSERT(PeekType() == kStringType); layer->mPreCompRefId = std::string(GetString()); + layer->mHasGradient = true; mLayersToUpdate.push_back(sharedLayer); hasLayerRef = true; } else if (0 == strcmp(key, "sr")) { // "Layer Time Stretching" @@ -887,16 +888,20 @@ std::shared_ptr LottieParserImpl::parseObjectTypeAttr() } else if (0 == strcmp(type, "st")) { return parseStrokeObject(); } else if (0 == strcmp(type, "gf")) { + curLayerRef->mHasGradient = true; return parseGFillObject(); } else if (0 == strcmp(type, "gs")) { + curLayerRef->mHasGradient = true; return parseGStrokeObject(); } else if (0 == strcmp(type, "sh")) { return parseShapeObject(); } else if (0 == strcmp(type, "sr")) { return parsePolystarObject(); } else if (0 == strcmp(type, "tm")) { + curLayerRef->mHasPathOperator = true; return parseTrimObject(); } else if (0 == strcmp(type, "rp")) { + curLayerRef->mHasRepeater = true; return parseReapeaterObject(); } else { #ifdef DEBUG_PARSER @@ -1117,7 +1122,6 @@ std::shared_ptr LottieParserImpl::parseTrimObject() } obj->setStatic(obj->mStart.isStatic() && obj->mEnd.isStatic() && obj->mOffset.isStatic()); - curLayerRef->mHasPathOperator = true; return sharedTrim; }