1 #include "lottieitem.h"
10 * 1. time stretch is pre calculated and applied to all the properties of the
11 * lottilayer model and all its children
12 * 2. The frame property could be reversed using,time-reverse layer property in
13 * AE. which means (start frame > endFrame) 3.
16 LOTCompItem::LOTCompItem(LOTModel *model)
17 : mRootModel(model), mUpdateViewBox(false), mCurFrameNo(-1)
19 mCompData = model->mRoot.get();
20 mRootLayer = createLayerItem(mCompData->mRootLayer.get());
21 mRootLayer->updateStaticProperty();
22 mViewSize = mCompData->size();
25 std::unique_ptr<LOTLayerItem>
26 LOTCompItem::createLayerItem(LOTLayerData *layerData)
28 switch (layerData->mLayerType) {
29 case LayerType::Precomp: {
30 return std::make_unique<LOTCompLayerItem>(layerData);
33 case LayerType::Solid: {
34 return std::make_unique<LOTSolidLayerItem>(layerData);
37 case LayerType::Shape: {
38 return std::make_unique<LOTShapeLayerItem>(layerData);
41 case LayerType::Null: {
42 return std::make_unique<LOTNullLayerItem>(layerData);
51 void LOTCompItem::resize(const VSize &size)
53 if (mViewSize == size) return;
55 mUpdateViewBox = true;
58 VSize LOTCompItem::size() const
63 bool LOTCompItem::update(int frameNo)
65 // check if cached frame is same as requested frame.
66 if (!mUpdateViewBox && (mCurFrameNo == frameNo)) return false;
69 * if viewbox dosen't scale exactly to the viewport
70 * we scale the viewbox keeping AspectRatioPreserved and then align the
71 * viewbox to the viewport using AlignCenter rule.
73 VSize viewPort = mViewSize;
74 VSize viewBox = mCompData->size();
76 float sx = float(viewPort.width()) / viewBox.width();
77 float sy = float(viewPort.height()) / viewBox.height();
78 float scale = fmin(sx, sy);
79 float tx = (viewPort.width() - viewBox.width() * scale) * 0.5;
80 float ty = (viewPort.height() - viewBox.height() * scale) * 0.5;
83 m.scale(scale, scale).translate(tx, ty);
84 mRootLayer->update(frameNo, m, 1.0);
87 mCurFrameNo = frameNo;
88 mUpdateViewBox = false;
92 void LOTCompItem::buildRenderList()
94 mDrawableList.clear();
95 mRootLayer->renderList(mDrawableList);
98 for (auto &i : mDrawableList) {
99 LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
101 mRenderList.push_back(&lotDrawable->mCNode);
105 const std::vector<LOTNode *> &LOTCompItem::renderList() const
110 bool LOTCompItem::render(const LOTBuffer &buffer)
112 VBitmap bitmap((uchar *)buffer.buffer, buffer.width, buffer.height,
113 buffer.bytesPerLine, VBitmap::Format::ARGB32_Premultiplied,
116 /* schedule all preprocess task for this frame at once.
118 for (auto &e : mDrawableList) {
122 VPainter painter(&bitmap);
123 mRootLayer->render(&painter, {}, {}, nullptr);
128 void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
129 float parentAlpha, const DirtyFlag &/*flag*/)
131 if (mData->mShape.isStatic()) {
132 if (mLocalPath.isEmpty()) {
133 mData->mShape.value(frameNo).toPath(mLocalPath);
136 mData->mShape.value(frameNo).toPath(mLocalPath);
138 float opacity = mData->opacity(frameNo);
139 opacity = opacity * parentAlpha;
140 mCombinedAlpha = opacity;
142 VPath path = mLocalPath;
143 path.transform(parentMatrix);
145 mRleTask = VRaster::generateFillInfo(std::move(path), std::move(mRle));
149 VRle LOTMaskItem::rle()
151 if (mRleTask.valid()) {
152 mRle = mRleTask.get();
153 if (!vCompare(mCombinedAlpha, 1.0f))
154 mRle *= (mCombinedAlpha * 255);
155 if (mData->mInv) mRle.invert();
160 void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &inheritMatte, LOTLayerItem *matteSource)
164 mDrawableList.clear();
165 matteSource->renderList(mDrawableList);
166 for (auto &i : mDrawableList) {
167 matteRle = matteRle + i->rle();
170 if (!inheritMatte.isEmpty())
171 matteRle = matteRle & inheritMatte;
173 matteRle = inheritMatte;
175 mDrawableList.clear();
176 renderList(mDrawableList);
180 mask = maskRle(painter->clipBoundingRect());
181 if (!inheritMask.isEmpty())
182 mask = mask & inheritMask;
183 // if resulting mask is empty then return.
190 for (auto &i : mDrawableList) {
191 painter->setBrush(i->mBrush);
193 if (!mask.isEmpty()) rle = rle & mask;
195 if (rle.isEmpty()) continue;
197 if (!matteRle.isEmpty()) {
198 if (mLayerData->mMatteType == MatteType::AlphaInv) {
199 rle = rle - matteRle;
201 rle = rle & matteRle;
204 painter->drawRle(VPoint(), rle);
208 VRle LOTLayerItem::maskRle(const VRect &clipRect)
211 for (auto &i : mMasks) {
212 switch (i->maskMode()) {
213 case LOTMaskData::Mode::Add: {
214 rle = rle + i->rle();
217 case LOTMaskData::Mode::Substarct: {
218 if (rle.isEmpty() && !clipRect.isEmpty())
219 rle = VRle::toRle(clipRect);
220 rle = rle - i->rle();
223 case LOTMaskData::Mode::Intersect: {
224 rle = rle & i->rle();
227 case LOTMaskData::Mode::Difference: {
228 rle = rle ^ i->rle();
238 LOTLayerItem::LOTLayerItem(LOTLayerData *layerData): mLayerData(layerData)
240 if (mLayerData->mHasMask) {
241 for (auto &i : mLayerData->mMasks) {
242 mMasks.push_back(std::make_unique<LOTMaskItem>(i.get()));
247 void LOTLayerItem::updateStaticProperty()
249 if (mParentLayer) mParentLayer->updateStaticProperty();
251 mStatic = mLayerData->isStatic();
252 mStatic = mParentLayer ? (mStatic & mParentLayer->isStatic()) : mStatic;
253 mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic;
256 void LOTLayerItem::update(int frameNo, const VMatrix &parentMatrix,
260 // 1. check if the layer is part of the current frame
261 if (!visible()) return;
263 // 2. calculate the parent matrix and alpha
264 VMatrix m = matrix(frameNo);
266 float alpha = parentAlpha * opacity(frameNo);
268 // 6. update the mask
270 for (auto &i : mMasks) i->update(frameNo, m, alpha, mDirtyFlag);
273 // 3. update the dirty flag based on the change
274 if (!mCombinedMatrix.fuzzyCompare(m)) {
275 mDirtyFlag |= DirtyFlagBit::Matrix;
277 if (!vCompare(mCombinedAlpha, alpha)) {
278 mDirtyFlag |= DirtyFlagBit::Alpha;
281 mCombinedAlpha = alpha;
283 // 4. if no parent property change and layer is static then nothing to do.
284 if ((flag() & DirtyFlagBit::None) && isStatic()) return;
286 // 5. update the content of the layer
289 // 6. reset the dirty flag
290 mDirtyFlag = DirtyFlagBit::None;
293 float LOTLayerItem::opacity(int frameNo) const
295 return mLayerData->mTransform->opacity(frameNo);
298 VMatrix LOTLayerItem::matrix(int frameNo) const
301 return mLayerData->mTransform->matrix(frameNo) *
302 mParentLayer->matrix(frameNo);
304 return mLayerData->mTransform->matrix(frameNo);
307 bool LOTLayerItem::visible() const
309 if (frameNo() >= mLayerData->inFrame() &&
310 frameNo() < mLayerData->outFrame())
316 LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
317 : LOTLayerItem(layerModel)
319 for (auto &i : mLayerData->mChildren) {
320 LOTLayerData *layerModel = dynamic_cast<LOTLayerData *>(i.get());
322 auto layerItem = LOTCompItem::createLayerItem(layerModel);
323 if (layerItem) mLayers.push_back(std::move(layerItem));
327 // 2. update parent layer
328 for (auto &i : mLayers) {
329 int id = i->parentId();
331 auto search = std::find_if(mLayers.begin(), mLayers.end(),
332 [id](const auto& val){ return val->id() == id;});
333 if (search != mLayers.end()) i->setParentLayer((*search).get());
335 // update the precomp layer if its not the root layer.
336 if (!layerModel->root()) i->setPrecompLayer(this);
340 void LOTCompLayerItem::updateStaticProperty()
342 LOTLayerItem::updateStaticProperty();
344 for (auto &i : mLayers) {
345 i->updateStaticProperty();
349 void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &inheritMatte, LOTLayerItem *matteSource)
353 mDrawableList.clear();
354 matteSource->renderList(mDrawableList);
355 for (auto &i : mDrawableList) {
356 matteRle = matteRle + i->rle();
359 if (!inheritMatte.isEmpty())
360 matteRle = matteRle & inheritMatte;
362 matteRle = inheritMatte;
367 mask = maskRle(painter->clipBoundingRect());
368 if (!inheritMask.isEmpty())
369 mask = mask & inheritMask;
370 // if resulting mask is empty then return.
377 LOTLayerItem *matteLayer = nullptr;
378 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
379 LOTLayerItem *layer = (*i).get();
381 if (!matteLayer && layer->hasMatte()) {
387 if (matteLayer->visible() && layer->visible())
388 matteLayer->render(painter, mask, matteRle, layer);
389 matteLayer = nullptr;
391 if (layer->visible())
392 layer->render(painter, mask, matteRle, nullptr);
397 void LOTCompLayerItem::updateContent()
399 // update the layer from back to front
400 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
401 (*i)->update(frameNo(), combinedMatrix(), combinedAlpha());
405 void LOTCompLayerItem::renderList(std::vector<VDrawable *> &list)
407 if (!visible()) return;
409 // update the layer from back to front
410 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
411 (*i)->renderList(list);
415 LOTSolidLayerItem::LOTSolidLayerItem(LOTLayerData *layerData)
416 : LOTLayerItem(layerData)
420 void LOTSolidLayerItem::updateContent()
423 mRenderNode = std::make_unique<LOTDrawable>();
424 mRenderNode->mType = VDrawable::Type::Fill;
425 mRenderNode->mFlag |= VDrawable::DirtyState::All;
428 if (flag() & DirtyFlagBit::Matrix) {
431 VRectF(0, 0, mLayerData->solidWidth(), mLayerData->solidHeight()));
432 path.transform(combinedMatrix());
433 mRenderNode->mFlag |= VDrawable::DirtyState::Path;
434 mRenderNode->mPath = path;
436 if (flag() & DirtyFlagBit::Alpha) {
437 LottieColor color = mLayerData->solidColor();
438 VBrush brush(color.toColor(combinedAlpha()));
439 mRenderNode->setBrush(brush);
440 mRenderNode->mFlag |= VDrawable::DirtyState::Brush;
444 void LOTSolidLayerItem::renderList(std::vector<VDrawable *> &list)
446 if (!visible()) return;
448 list.push_back(mRenderNode.get());
451 LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
452 : LOTLayerItem(layerData)
455 void LOTNullLayerItem::updateContent() {}
457 LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
458 : LOTLayerItem(layerData)
460 mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
461 mRoot->addChildren(layerData);
463 std::vector<LOTPathDataItem *> list;
464 mRoot->processPaintItems(list);
466 if (layerData->hasPathOperator()) {
468 mRoot->processTrimItems(list);
472 std::unique_ptr<LOTContentItem>
473 LOTShapeLayerItem::createContentItem(LOTData *contentData)
475 switch (contentData->type()) {
476 case LOTData::Type::ShapeGroup: {
477 return std::make_unique<LOTContentGroupItem>(
478 static_cast<LOTShapeGroupData *>(contentData));
481 case LOTData::Type::Rect: {
482 return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
485 case LOTData::Type::Ellipse: {
486 return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
489 case LOTData::Type::Shape: {
490 return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
493 case LOTData::Type::Polystar: {
494 return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
497 case LOTData::Type::Fill: {
498 return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
501 case LOTData::Type::GFill: {
502 return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
505 case LOTData::Type::Stroke: {
506 return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
509 case LOTData::Type::GStroke: {
510 return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
513 case LOTData::Type::Repeater: {
514 return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
517 case LOTData::Type::Trim: {
518 return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
527 void LOTShapeLayerItem::updateContent()
529 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
531 if (mLayerData->hasPathOperator()) {
536 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
538 if (!visible()) return;
539 mRoot->renderList(list);
542 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
547 void LOTContentGroupItem::addChildren(LOTGroupData *data)
551 for (auto &i : data->mChildren) {
552 auto content = LOTShapeLayerItem::createContentItem(i.get());
554 content->setParent(this);
555 mContents.push_back(std::move(content));
560 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
561 float parentAlpha, const DirtyFlag &flag)
563 VMatrix m = parentMatrix;
564 float alpha = parentAlpha;
565 DirtyFlag newFlag = flag;
568 // update the matrix and the flag
569 if ((flag & DirtyFlagBit::Matrix) ||
570 !mData->mTransform->staticMatrix()) {
571 newFlag |= DirtyFlagBit::Matrix;
573 m = mData->mTransform->matrix(frameNo);
575 alpha *= mData->mTransform->opacity(frameNo);
577 if (!vCompare(alpha, parentAlpha)) {
578 newFlag |= DirtyFlagBit::Alpha;
584 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
585 (*i)->update(frameNo, m, alpha, newFlag);
589 void LOTContentGroupItem::applyTrim()
591 for (auto &i : mContents) {
592 if (auto trim = dynamic_cast<LOTTrimItem *>(i.get())) {
594 } else if (auto group = dynamic_cast<LOTContentGroupItem *>(i.get())) {
600 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
602 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
603 (*i)->renderList(list);
607 void LOTContentGroupItem::processPaintItems(
608 std::vector<LOTPathDataItem *> &list)
610 int curOpCount = list.size();
611 for (auto &i : mContents) {
612 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
613 // add it to the list
614 list.push_back(pathNode);
615 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(i.get())) {
616 // the node is a paint data node update the path list of the paint item.
617 paintNode->addPathItems(list, curOpCount);
618 } else if (auto groupNode =
619 dynamic_cast<LOTContentGroupItem *>(i.get())) {
620 // update the groups node with current list
621 groupNode->processPaintItems(list);
626 void LOTContentGroupItem::processTrimItems(
627 std::vector<LOTPathDataItem *> &list)
629 int curOpCount = list.size();
630 for (auto &i : mContents) {
631 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
632 // add it to the list
633 list.push_back(pathNode);
634 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(i.get())) {
635 // the node is a paint data node update the path list of the paint item.
636 trimNode->addPathItems(list, curOpCount);
637 } else if (auto groupNode =
638 dynamic_cast<LOTContentGroupItem *>(i.get())) {
639 // update the groups node with current list
640 groupNode->processTrimItems(list);
645 void LOTPathDataItem::update(int frameNo, const VMatrix &,
646 float, const DirtyFlag &flag)
648 mPathChanged = false;
650 // 1. update the local path if needed
651 if (hasChanged(frameNo)) {
652 updatePath(mLocalPath, frameNo);
659 // 3. compute the final path with parentMatrix
660 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
665 const VPath & LOTPathDataItem::finalPath()
667 if (mPathChanged || mNeedUpdate) {
668 mFinalPath.clone(mTemp);
669 mFinalPath.transform(static_cast<LOTContentGroupItem *>(parent())->matrix());
674 LOTRectItem::LOTRectItem(LOTRectData *data)
675 : LOTPathDataItem(data->isStatic()), mData(data)
679 void LOTRectItem::updatePath(VPath& path, int frameNo)
681 VPointF pos = mData->mPos.value(frameNo);
682 VPointF size = mData->mSize.value(frameNo);
683 float roundness = mData->mRound.value(frameNo);
684 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
688 path.addRoundRect(r, roundness, roundness, mData->direction());
689 updateCache(frameNo, pos, size, roundness);
692 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
693 : LOTPathDataItem(data->isStatic()), mData(data)
697 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
699 VPointF pos = mData->mPos.value(frameNo);
700 VPointF size = mData->mSize.value(frameNo);
701 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
705 path.addOval(r, mData->direction());
706 updateCache(frameNo, pos, size);
709 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
710 : LOTPathDataItem(data->isStatic()), mData(data)
714 void LOTShapeItem::updatePath(VPath& path, int frameNo)
716 mData->mShape.value(frameNo).toPath(path);
719 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
720 : LOTPathDataItem(data->isStatic()), mData(data)
724 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
726 VPointF pos = mData->mPos.value(frameNo);
727 float points = mData->mPointCount.value(frameNo);
728 float innerRadius = mData->mInnerRadius.value(frameNo);
729 float outerRadius = mData->mOuterRadius.value(frameNo);
730 float innerRoundness = mData->mInnerRoundness.value(frameNo);
731 float outerRoundness = mData->mOuterRoundness.value(frameNo);
732 float rotation = mData->mRotation.value(frameNo);
737 if (mData->mType == LOTPolystarData::PolyType::Star) {
738 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
739 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
741 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
745 m.translate(pos.x(), pos.y()).rotate(rotation);
748 updateCache(frameNo, pos, points, innerRadius, outerRadius,
749 innerRoundness, outerRoundness, rotation);
753 * PaintData Node handling
756 LOTPaintDataItem::LOTPaintDataItem(bool staticContent):mDrawable(std::make_unique<LOTDrawable>()),
757 mStaticContent(staticContent){}
759 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
760 float parentAlpha, const DirtyFlag &flag)
762 mRenderNodeUpdate = true;
763 mParentAlpha = parentAlpha;
767 updateContent(frameNo);
770 void LOTPaintDataItem::updateRenderNode()
773 for (auto &i : mPathItems) {
783 for (auto &i : mPathItems) {
784 mPath.addPath(i->finalPath());
786 mDrawable->setPath(mPath);
788 if (mDrawable->mFlag & VDrawable::DirtyState::Path)
789 mDrawable->mPath = mPath;
793 void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
795 if (mRenderNodeUpdate) {
797 LOTPaintDataItem::updateRenderNode();
798 mRenderNodeUpdate = false;
800 list.push_back(mDrawable.get());
804 void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
806 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
810 LOTFillItem::LOTFillItem(LOTFillData *data)
811 : LOTPaintDataItem(data->isStatic()), mData(data)
815 void LOTFillItem::updateContent(int frameNo)
817 LottieColor c = mData->mColor.value(frameNo);
818 float opacity = mData->opacity(frameNo);
819 mColor = c.toColor(opacity);
820 mFillRule = mData->fillRule();
823 void LOTFillItem::updateRenderNode()
825 VColor color = mColor;
827 color.setAlpha(color.a * parentAlpha());
829 mDrawable->setBrush(brush);
830 mDrawable->setFillRule(mFillRule);
833 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
834 : LOTPaintDataItem(data->isStatic()), mData(data)
838 void LOTGFillItem::updateContent(int frameNo)
840 mData->update(mGradient, frameNo);
841 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
842 mFillRule = mData->fillRule();
845 void LOTGFillItem::updateRenderNode()
847 mDrawable->setBrush(VBrush(mGradient.get()));
848 mDrawable->setFillRule(mFillRule);
851 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
852 : LOTPaintDataItem(data->isStatic()), mData(data)
857 void LOTStrokeItem::updateContent(int frameNo)
859 LottieColor c = mData->mColor.value(frameNo);
860 float opacity = mData->opacity(frameNo);
861 mColor = c.toColor(opacity);
862 mCap = mData->capStyle();
863 mJoin = mData->joinStyle();
864 mMiterLimit = mData->meterLimit();
865 mWidth = mData->width(frameNo);
866 if (mData->hasDashInfo()) {
867 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
871 static float getScale(const VMatrix &matrix)
873 constexpr float SQRT_2 = 1.41421;
875 VPointF p2(SQRT_2, SQRT_2);
878 VPointF final = p2 - p1;
880 return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0;
883 void LOTStrokeItem::updateRenderNode()
885 VColor color = mColor;
887 color.setAlpha(color.a * parentAlpha());
889 mDrawable->setBrush(brush);
890 float scale = getScale(static_cast<LOTContentGroupItem *>(parent())->matrix());
891 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
893 if (mDashArraySize) {
894 for (int i = 0 ; i < mDashArraySize ; i++)
895 mDashArray[i] *= scale;
896 mDrawable->setDashInfo(mDashArray, mDashArraySize);
900 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
901 : LOTPaintDataItem(data->isStatic()), mData(data)
906 void LOTGStrokeItem::updateContent(int frameNo)
908 mData->update(mGradient, frameNo);
909 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
910 mCap = mData->capStyle();
911 mJoin = mData->joinStyle();
912 mMiterLimit = mData->meterLimit();
913 mWidth = mData->width(frameNo);
914 if (mData->hasDashInfo()) {
915 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
919 void LOTGStrokeItem::updateRenderNode()
921 float scale = getScale(mGradient->mMatrix);
922 mDrawable->setBrush(VBrush(mGradient.get()));
923 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
925 if (mDashArraySize) {
926 for (int i = 0 ; i < mDashArraySize ; i++)
927 mDashArray[i] *= scale;
928 mDrawable->setDashInfo(mDashArray, mDashArraySize);
932 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
934 void LOTTrimItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
935 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
939 if (mCache.mFrameNo == frameNo) return;
941 float start = mData->start(frameNo);
942 float end = mData->end(frameNo);
943 float offset = mData->offset(frameNo);
945 if (!(vCompare(mCache.mStart, start) && vCompare(mCache.mEnd, end) &&
946 vCompare(mCache.mOffset, offset))) {
948 mCache.mStart = start;
950 mCache.mOffset = offset;
952 mCache.mFrameNo = frameNo;
955 void LOTTrimItem::update()
957 // when both path and trim are not dirty
958 if (!(mDirty || pathDirty())) return;
960 //@TODO take the offset and trim type into account.
961 for (auto &i : mPathItems) {
963 pm.setStart(mCache.mStart);
964 pm.setEnd(mCache.mEnd);
965 pm.setOffset(mCache.mOffset);
966 i->updatePath(pm.trim(i->localPath()));
971 void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
973 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
977 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
979 void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
980 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
984 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
986 void LOTDrawable::sync()
988 mCNode.mFlag = ChangeFlagNone;
989 if (mFlag & DirtyState::None) return;
991 if (mFlag & DirtyState::Path) {
992 const std::vector<VPath::Element> &elm = mPath.elements();
993 const std::vector<VPointF> & pts = mPath.points();
994 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
995 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
996 mCNode.mPath.elmPtr = elmPtr;
997 mCNode.mPath.elmCount = elm.size();
998 mCNode.mPath.ptPtr = ptPtr;
999 mCNode.mPath.ptCount = 2 * pts.size();
1000 mCNode.mFlag |= ChangeFlagPath;
1003 if (mStroke.enable) {
1004 mCNode.mStroke.width = mStroke.width;
1005 mCNode.mStroke.meterLimit = mStroke.meterLimit;
1006 mCNode.mStroke.enable = 1;
1008 switch (mFillRule) {
1009 case FillRule::EvenOdd:
1010 mCNode.mFillRule = LOTFillRule::FillEvenOdd;
1013 mCNode.mFillRule = LOTFillRule::FillWinding;
1017 switch (mStroke.cap) {
1018 case CapStyle::Flat:
1019 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1021 case CapStyle::Square:
1022 mCNode.mStroke.cap = LOTCapStyle::CapSquare;
1024 case CapStyle::Round:
1025 mCNode.mStroke.cap = LOTCapStyle::CapRound;
1028 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1032 switch (mStroke.join) {
1033 case JoinStyle::Miter:
1034 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1036 case JoinStyle::Bevel:
1037 mCNode.mStroke.join = LOTJoinStyle::JoinBevel;
1039 case JoinStyle::Round:
1040 mCNode.mStroke.join = LOTJoinStyle::JoinRound;
1043 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1047 mCNode.mStroke.dashArray = mStroke.mDash.data();
1048 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1051 mCNode.mStroke.enable = 0;
1054 switch (mBrush.type()) {
1055 case VBrush::Type::Solid:
1056 mCNode.mType = LOTBrushType::BrushSolid;
1057 mCNode.mColor.r = mBrush.mColor.r;
1058 mCNode.mColor.g = mBrush.mColor.g;
1059 mCNode.mColor.b = mBrush.mColor.b;
1060 mCNode.mColor.a = mBrush.mColor.a;
1062 case VBrush::Type::LinearGradient:
1063 mCNode.mType = LOTBrushType::BrushGradient;
1064 mCNode.mGradient.type = LOTGradientType::GradientLinear;
1065 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1066 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1067 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1068 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1070 case VBrush::Type::RadialGradient:
1071 mCNode.mType = LOTBrushType::BrushGradient;
1072 mCNode.mGradient.type = LOTGradientType::GradientRadial;
1073 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1074 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1075 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1076 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1077 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1078 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;