4 #include<lottiemodel.h>
11 #include"vpathmesure.h"
12 #include"lottiecommon.h"
13 #include"lottieanimation.h"
19 enum class DirtyFlagBit : uchar
24 All = (Matrix | Alpha)
34 LOTCompItem(LOTModel *model);
35 static std::unique_ptr<LOTLayerItem> createLayerItem(LOTLayerData *layerData);
36 bool update(int frameNo);
37 void resize(const VSize &size);
39 const std::vector<LOTNode *>& renderList()const;
40 void buildRenderList();
41 bool render(const lottie::Surface &surface);
46 LOTCompositionData *mCompData;
47 std::unique_ptr<LOTLayerItem> mRootLayer;
50 std::vector<LOTNode *> mRenderList;
51 std::vector<VDrawable *> mDrawableList;
54 typedef vFlag<DirtyFlagBit> DirtyFlag;
58 LOTLayerItem(LOTLayerData *layerData);
59 virtual ~LOTLayerItem()= default;
60 int id() const {return mLayerData->id();}
61 int parentId() const {return mLayerData->parentId();}
62 void setParentLayer(LOTLayerItem *parent){mParentLayer = parent;}
63 void setPrecompLayer(LOTLayerItem *precomp){mPrecompLayer = precomp;}
64 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha);
65 VMatrix matrix(int frameNo) const;
66 virtual void renderList(std::vector<VDrawable *> &){}
67 virtual void updateStaticProperty();
68 virtual void render(VPainter *painter, const VRle &mask, const VRle &inheritMatte, LOTLayerItem *matteSource);
69 bool hasMatte() { if (mLayerData->mMatteType == MatteType::None) return false; return true; }
73 virtual void updateContent() = 0;
74 inline VMatrix combinedMatrix() const {return mCombinedMatrix;}
75 inline int frameNo() const {return mFrameNo;}
76 inline float combinedAlpha() const {return mCombinedAlpha;}
77 inline bool isStatic() const {return mStatic;}
78 float opacity(int frameNo) const;
79 inline DirtyFlag flag() const {return mDirtyFlag;}
80 VRle maskRle(const VRect &clipRect);
81 bool hasMask() const {return !mMasks.empty();}
83 std::vector<VDrawable *> mDrawableList;
84 std::vector<std::unique_ptr<LOTMaskItem>> mMasks;
85 LOTLayerData *mLayerData{nullptr};
86 LOTLayerItem *mParentLayer{nullptr};
87 LOTLayerItem *mPrecompLayer{nullptr};
88 VMatrix mCombinedMatrix;
89 float mCombinedAlpha{0.0};
91 DirtyFlag mDirtyFlag{DirtyFlagBit::All};
95 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, const VRle &inheritMatte, LOTLayerItem *matteSource) final;
103 void updateContent() final;
105 std::vector<std::unique_ptr<LOTLayerItem>> mLayers;
109 class LOTSolidLayerItem: public LOTLayerItem
112 LOTSolidLayerItem(LOTLayerData *layerData);
114 void updateContent() final;
115 void renderList(std::vector<VDrawable *> &list) final;
117 std::unique_ptr<VDrawable> mRenderNode;
120 class LOTContentItem;
121 class LOTContentGroupItem;
122 class LOTShapeLayerItem: public LOTLayerItem
125 LOTShapeLayerItem(LOTLayerData *layerData);
126 static std::unique_ptr<LOTContentItem> createContentItem(LOTData *contentData);
127 void renderList(std::vector<VDrawable *> &list)final;
129 void updateContent() final;
130 std::unique_ptr<LOTContentGroupItem> mRoot;
133 class LOTNullLayerItem: public LOTLayerItem
136 LOTNullLayerItem(LOTLayerData *layerData);
138 void updateContent() final;
144 LOTMaskItem(LOTMaskData *data): mData(data), mCombinedAlpha(0){}
145 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
146 LOTMaskData::Mode maskMode() const { return mData->mMode;}
150 float mCombinedAlpha;
151 VMatrix mCombinedMatrix;
153 std::future<VRle> mRleTask;
157 class LOTDrawable : public VDrawable
162 std::unique_ptr<LOTNode> mCNode;
165 if (mCNode && mCNode->mGradient.stopPtr)
166 free(mCNode->mGradient.stopPtr);
170 class LOTPathDataItem;
171 class LOTPaintDataItem;
177 virtual ~LOTContentItem()= default;
178 virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) = 0;
179 virtual void renderList(std::vector<VDrawable *> &){}
180 void setParent(LOTContentItem *parent) {mParent = parent;}
181 LOTContentItem *parent() const {return mParent;}
183 LOTContentItem *mParent{nullptr};
186 class LOTContentGroupItem: public LOTContentItem
189 LOTContentGroupItem(LOTShapeGroupData *data);
190 void addChildren(LOTGroupData *data);
191 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
193 void processTrimItems(std::vector<LOTPathDataItem *> &list);
194 void processPaintItems(std::vector<LOTPathDataItem *> &list);
195 void renderList(std::vector<VDrawable *> &list) final;
196 const VMatrix & matrix() const { return mMatrix;}
198 LOTShapeGroupData *mData;
199 std::vector<std::unique_ptr<LOTContentItem>> mContents;
203 class LOTPathDataItem : public LOTContentItem
206 LOTPathDataItem(bool staticPath): mStaticPath(staticPath){}
207 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
208 bool dirty() const {return mPathChanged;}
209 const VPath &localPath() const {return mTemp;}
210 const VPath &finalPath();
211 void updatePath(const VPath &path) {mTemp.clone(path); mPathChanged = true; mNeedUpdate = true;}
212 bool staticPath() const { return mStaticPath; }
214 virtual void updatePath(VPath& path, int frameNo) = 0;
215 virtual bool hasChanged(int frameNo) = 0;
220 bool mPathChanged{true};
221 bool mNeedUpdate{true};
225 class LOTRectItem: public LOTPathDataItem
228 LOTRectItem(LOTRectData *data);
230 void updatePath(VPath& path, int frameNo) final;
241 void updateCache(int frameNo, VPointF pos, VPointF size, float roundness) {
242 mCache.mFrameNo = frameNo;
245 mCache.mRoundness = roundness;
247 bool hasChanged(int frameNo) final {
248 if (mCache.mFrameNo != -1 && staticPath()) return false;
249 if (mCache.mFrameNo == frameNo) return false;
251 VPointF pos = mData->mPos.value(frameNo);
252 VPointF size = mData->mSize.value(frameNo);
253 float roundness = mData->mRound.value(frameNo);
255 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
256 vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()) &&
257 vCompare(mCache.mRoundness, roundness))
264 class LOTEllipseItem: public LOTPathDataItem
267 LOTEllipseItem(LOTEllipseData *data);
269 void updatePath(VPath& path, int frameNo) final;
270 LOTEllipseData *mData;
279 void updateCache(int frameNo, VPointF pos, VPointF size) {
280 mCache.mFrameNo = frameNo;
284 bool hasChanged(int frameNo) final {
285 if (mCache.mFrameNo != -1 && staticPath()) return false;
286 if (mCache.mFrameNo == frameNo) return false;
288 VPointF pos = mData->mPos.value(frameNo);
289 VPointF size = mData->mSize.value(frameNo);
291 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
292 vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()))
299 class LOTShapeItem: public LOTPathDataItem
302 LOTShapeItem(LOTShapeData *data);
304 void updatePath(VPath& path, int frameNo) final;
306 bool hasChanged(int) final { return true; }
309 class LOTPolystarItem: public LOTPathDataItem
312 LOTPolystarItem(LOTPolystarData *data);
314 void updatePath(VPath& path, int frameNo) final;
315 LOTPolystarData *mData;
321 float mInnerRadius{0};
322 float mOuterRadius{0};
323 float mInnerRoundness{0};
324 float mOuterRoundness{0};
329 void updateCache(int frameNo, VPointF pos, float points, float innerRadius, float outerRadius,
330 float innerRoundness, float outerRoundness, float rotation) {
331 mCache.mFrameNo = frameNo;
333 mCache.mPoints = points;
334 mCache.mInnerRadius = innerRadius;
335 mCache.mOuterRadius = outerRadius;
336 mCache.mInnerRoundness = innerRoundness;
337 mCache.mOuterRoundness = outerRoundness;
338 mCache.mRotation = rotation;
340 bool hasChanged(int frameNo) final {
341 if (mCache.mFrameNo != -1 && staticPath()) return false;
342 if (mCache.mFrameNo == frameNo) return false;
344 VPointF pos = mData->mPos.value(frameNo);
345 float points = mData->mPointCount.value(frameNo);
346 float innerRadius = mData->mInnerRadius.value(frameNo);
347 float outerRadius = mData->mOuterRadius.value(frameNo);
348 float innerRoundness = mData->mInnerRoundness.value(frameNo);
349 float outerRoundness = mData->mOuterRoundness.value(frameNo);
350 float rotation = mData->mRotation.value(frameNo);
352 if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
353 vCompare(mCache.mPoints, points) && vCompare(mCache.mRotation, rotation) &&
354 vCompare(mCache.mInnerRadius, innerRadius) && vCompare(mCache.mOuterRadius, outerRadius) &&
355 vCompare(mCache.mInnerRoundness, innerRoundness) && vCompare(mCache.mOuterRoundness, outerRoundness))
364 class LOTPaintDataItem : public LOTContentItem
367 LOTPaintDataItem(bool staticContent);
368 void addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset);
369 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) override;
370 void renderList(std::vector<VDrawable *> &list) final;
372 virtual void updateContent(int frameNo) = 0;
373 virtual void updateRenderNode();
374 inline float parentAlpha() const {return mParentAlpha;}
380 std::vector<LOTPathDataItem *> mPathItems;
381 std::unique_ptr<VDrawable> mDrawable;
383 bool mRenderNodeUpdate{true};
386 class LOTFillItem : public LOTPaintDataItem
389 LOTFillItem(LOTFillData *data);
391 void updateContent(int frameNo) final;
392 void updateRenderNode() final;
399 class LOTGFillItem : public LOTPaintDataItem
402 LOTGFillItem(LOTGFillData *data);
404 void updateContent(int frameNo) final;
405 void updateRenderNode() final;
408 std::unique_ptr<VGradient> mGradient;
412 class LOTStrokeItem : public LOTPaintDataItem
415 LOTStrokeItem(LOTStrokeData *data);
417 void updateContent(int frameNo) final;
418 void updateRenderNode() final;
420 LOTStrokeData *mData;
430 class LOTGStrokeItem : public LOTPaintDataItem
433 LOTGStrokeItem(LOTGStrokeData *data);
435 void updateContent(int frameNo) final;
436 void updateRenderNode() final;
438 LOTGStrokeData *mData;
439 std::unique_ptr<VGradient> mGradient;
452 class LOTTrimItem : public LOTContentItem
455 LOTTrimItem(LOTTrimData *data);
456 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
458 void addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset);
460 bool pathDirty() const {
461 for (auto &i : mPathItems) {
469 LOTTrimData::Segment mSegment{};
472 std::vector<LOTPathDataItem *> mPathItems;
477 class LOTRepeaterItem : public LOTContentItem
480 LOTRepeaterItem(LOTRepeaterData *data);
481 void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
482 void renderList(std::vector<VDrawable *> &list) final;
484 LOTRepeaterData *mData;
488 #endif // LOTTIEITEM_H