4 #include<lottiemodel.h>
11 #include"vpathmesure.h"
12 #include"lottieplayer.h"
18 enum class DirtyFlagBit : uchar
23 All = (Matrix | Alpha)
33 LOTCompItem(LOTModel *model);
34 static LOTLayerItem * createLayerItem(LOTLayerData *layerData);
35 bool update(int frameNo);
36 void resize(const VSize &size);
38 const std::vector<LOTNode *>& renderList()const;
39 void buildRenderList();
40 bool render(const LOTBuffer &buffer);
45 LOTCompositionData *mCompData;
46 std::unique_ptr<LOTLayerItem> mRootLayer;
49 std::vector<LOTNode *> mRenderList;
50 std::vector<VDrawable *> mDrawableList;
53 typedef vFlag<DirtyFlagBit> DirtyFlag;
57 LOTLayerItem(LOTLayerData *layerData);
58 virtual ~LOTLayerItem(){}
59 int id() const {return mLayerData->id();}
60 int parentId() const {return mLayerData->parentId();}
61 void setParentLayer(LOTLayerItem *parent){mParentLayer = parent;}
62 void setPrecompLayer(LOTLayerItem *precomp){mPrecompLayer = precomp;}
63 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha);
64 VMatrix matrix(int frameNo) const;
65 virtual void renderList(std::vector<VDrawable *> &list){}
66 virtual void updateStaticProperty();
67 virtual void render(VPainter *painter, const VRle &mask, LOTLayerItem *matteSource);
68 bool hasMatte() { if (mLayerData->mMatteType == MatteType::None) return false; return true; }
71 virtual void updateContent() = 0;
72 inline VMatrix combinedMatrix() const {return mCombinedMatrix;}
73 inline int frameNo() const {return mFrameNo;}
74 inline float combinedAlpha() const {return mCombinedAlpha;}
75 inline bool isStatic() const {return mStatic;}
76 float opacity(int frameNo) const;
78 inline DirtyFlag flag() const {return mDirtyFlag;}
79 VRle maskRle(const VRect &clipRect);
80 bool hasMask() const {return !mMasks.empty();}
82 std::vector<std::unique_ptr<LOTMaskItem>> mMasks;
83 LOTLayerData *mLayerData;
84 LOTLayerItem *mParentLayer;
85 LOTLayerItem *mPrecompLayer;
86 VMatrix mCombinedMatrix;
94 class LOTCompLayerItem: public LOTLayerItem
98 LOTCompLayerItem(LOTLayerData *layerData);
99 void renderList(std::vector<VDrawable *> &list)final;
100 void updateStaticProperty() final;
101 void render(VPainter *painter, const VRle &mask, LOTLayerItem *matteSource) final;
103 void updateContent() final;
105 std::vector<LOTLayerItem *> mLayers;
106 std::unordered_map<int, LOTLayerItem *> mLayerMap;
110 class LOTSolidLayerItem: public LOTLayerItem
113 LOTSolidLayerItem(LOTLayerData *layerData);
115 void updateContent() final;
116 void renderList(std::vector<VDrawable *> &list) final;
118 std::unique_ptr<VDrawable> mRenderNode;
121 class LOTContentItem;
122 class LOTContentGroupItem;
123 class LOTShapeLayerItem: public LOTLayerItem
126 ~LOTShapeLayerItem();
127 LOTShapeLayerItem(LOTLayerData *layerData);
128 static LOTContentItem * createContentItem(LOTData *contentData);
129 void renderList(std::vector<VDrawable *> &list)final;
131 void updateContent() final;
132 LOTContentGroupItem *mRoot;
135 class LOTNullLayerItem: public LOTLayerItem
138 LOTNullLayerItem(LOTLayerData *layerData);
140 void updateContent() final;
146 LOTMaskItem(LOTMaskData *data): mData(data), mCombinedAlpha(0){}
147 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
148 LOTMaskData::Mode maskMode() const { return mData->mMode;}
152 float mCombinedAlpha;
153 VMatrix mCombinedMatrix;
155 std::future<VRle> mRleTask;
159 class LOTDrawable : public VDrawable
168 class LOTPathDataItem;
169 class LOTPaintDataItem;
173 LOTRenderNode(LOTPathDataItem *path, LOTPaintDataItem *paint, VDrawable *render, bool sameG)
174 :pathNodeRef(path), paintNodeRef(paint), drawable(render), sameGroup(sameG){}
175 LOTPathDataItem *pathNodeRef;
176 LOTPaintDataItem *paintNodeRef;
185 virtual ~LOTContentItem(){}
186 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) = 0;
187 virtual void renderList(std::vector<VDrawable *> &list){}
190 class LOTContentGroupItem: public LOTContentItem
193 ~LOTContentGroupItem();
194 LOTContentGroupItem(LOTShapeGroupData *data);
195 void addChildren(LOTGroupData *data);
196 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
197 void processPaintOperation();
198 void processTrimOperation();
199 void renderList(std::vector<VDrawable *> &list) final;
201 void paintOperationHelper(std::vector<LOTPaintDataItem *> &list);
202 void trimOperationHelper(std::vector<LOTTrimItem *> &list);
203 LOTShapeGroupData *mData;
204 std::vector<LOTContentItem *> mContents;
207 class LOTPathDataItem : public LOTContentItem
210 LOTPathDataItem(bool staticPath):mInit(false), mStaticPath(staticPath){}
211 void addPaintOperation(std::vector<LOTPaintDataItem *> &list, int externalCount);
212 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
214 void addTrimOperation(std::vector<LOTTrimItem *> &list);
215 inline float combinedAlpha() const{ return mCombinedAlpha;}
216 void renderList(std::vector<VDrawable *> &list) final;
218 std::vector<LOTTrimItem *> mTrimNodeRefs;
219 std::vector<LOTRenderNode> mRenderList;
220 std::vector<std::unique_ptr<VDrawable>> mNodeList;
226 float mCombinedAlpha;
228 virtual void updatePath(VPath& path, int frameNo) = 0;
229 virtual bool hasChanged(int frameNo) = 0;
232 class LOTRectItem: public LOTPathDataItem
235 LOTRectItem(LOTRectData *data);
237 void updatePath(VPath& path, int frameNo) final;
248 void updateCache(int frameNo, VPointF pos, VPointF size, float roundness) {
249 mCache.mFrameNo = frameNo;
252 mCache.mRoundness = roundness;
254 bool hasChanged(int frameNo) final {
255 if (mCache.mFrameNo == frameNo) return false;
257 VPointF pos = mData->mPos.value(frameNo);
258 VPointF size = mData->mSize.value(frameNo);
259 float roundness = mData->mRound.value(frameNo);
261 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
262 vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()) &&
263 vCompare(mCache.mRoundness, roundness))
270 class LOTEllipseItem: public LOTPathDataItem
273 LOTEllipseItem(LOTEllipseData *data);
275 void updatePath(VPath& path, int frameNo) final;
276 LOTEllipseData *mData;
285 void updateCache(int frameNo, VPointF pos, VPointF size) {
286 mCache.mFrameNo = frameNo;
290 bool hasChanged(int frameNo) final {
291 if (mCache.mFrameNo == frameNo) return false;
293 VPointF pos = mData->mPos.value(frameNo);
294 VPointF size = mData->mSize.value(frameNo);
296 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
297 vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()))
304 class LOTShapeItem: public LOTPathDataItem
307 LOTShapeItem(LOTShapeData *data);
309 void updatePath(VPath& path, int frameNo) final;
311 bool hasChanged(int frameNo) final { return true; }
314 class LOTPolystarItem: public LOTPathDataItem
317 LOTPolystarItem(LOTPolystarData *data);
319 void updatePath(VPath& path, int frameNo) final;
320 LOTPolystarData *mData;
326 float mInnerRadius{0};
327 float mOuterRadius{0};
328 float mInnerRoundness{0};
329 float mOuterRoundness{0};
334 void updateCache(int frameNo, VPointF pos, float points, float innerRadius, float outerRadius,
335 float innerRoundness, float outerRoundness, float rotation) {
336 mCache.mFrameNo = frameNo;
338 mCache.mPoints = points;
339 mCache.mInnerRadius = innerRadius;
340 mCache.mOuterRadius = outerRadius;
341 mCache.mInnerRoundness = innerRoundness;
342 mCache.mOuterRoundness = outerRoundness;
343 mCache.mRotation = rotation;
345 bool hasChanged(int frameNo) final {
346 if (mCache.mFrameNo == frameNo) return false;
348 VPointF pos = mData->mPos.value(frameNo);
349 float points = mData->mPointCount.value(frameNo);
350 float innerRadius = mData->mInnerRadius.value(frameNo);
351 float outerRadius = mData->mOuterRadius.value(frameNo);
352 float innerRoundness = mData->mInnerRoundness.value(frameNo);
353 float outerRoundness = mData->mOuterRoundness.value(frameNo);
354 float rotation = mData->mRotation.value(frameNo);
356 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
357 vCompare(mCache.mPoints, points) && vCompare(mCache.mRotation, rotation) &&
358 vCompare(mCache.mInnerRadius, innerRadius) && vCompare(mCache.mOuterRadius, outerRadius) &&
359 vCompare(mCache.mInnerRoundness, innerRoundness) && vCompare(mCache.mOuterRoundness, outerRoundness))
368 class LOTPaintDataItem : public LOTContentItem
371 LOTPaintDataItem(bool staticContent):mInit(false), mStaticContent(staticContent){}
372 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
373 virtual void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) = 0;
375 virtual void updateContent(int frameNo) = 0;
376 inline float parentAlpha() const {return mParentAlpha;}
377 inline bool contentChanged() const{return mContentChanged;}
380 VMatrix mParentMatrix;
385 bool mContentChanged;
388 class LOTFillItem : public LOTPaintDataItem
391 LOTFillItem(LOTFillData *data);
393 void updateContent(int frameNo) final;
394 void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
401 class LOTGFillItem : public LOTPaintDataItem
404 LOTGFillItem(LOTGFillData *data);
406 void updateContent(int frameNo) final;
407 void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
410 std::unique_ptr<VGradient> mGradient;
414 class LOTStrokeItem : public LOTPaintDataItem
417 LOTStrokeItem(LOTStrokeData *data);
419 void updateContent(int frameNo) final;
420 void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
422 LOTStrokeData *mData;
432 class LOTGStrokeItem : public LOTPaintDataItem
435 LOTGStrokeItem(LOTGStrokeData *data);
437 void updateContent(int frameNo) final;
438 void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
440 LOTGStrokeData *mData;
441 std::unique_ptr<VGradient> mGradient;
454 class LOTTrimItem : public LOTContentItem
457 LOTTrimItem(LOTTrimData *data);
458 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
459 float getStart(int frameNo) {return mData->mStart.value(frameNo);}
460 float getEnd(int frameNo) {return mData->mEnd.value(frameNo);}
465 class LOTRepeaterItem : public LOTContentItem
468 LOTRepeaterItem(LOTRepeaterData *data);
469 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
470 virtual void renderList(std::vector<VDrawable *> &list) final;
472 LOTRepeaterData *mData;
476 #endif // LOTTIEITEM_H