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 matteLayer->render(painter, mask, matteRle, layer);
388 matteLayer = nullptr;
390 layer->render(painter, mask, matteRle, nullptr);
395 void LOTCompLayerItem::updateContent()
397 // update the layer from back to front
398 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
399 (*i)->update(frameNo(), combinedMatrix(), combinedAlpha());
403 void LOTCompLayerItem::renderList(std::vector<VDrawable *> &list)
405 if (!visible()) return;
407 // update the layer from back to front
408 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
409 (*i)->renderList(list);
413 LOTSolidLayerItem::LOTSolidLayerItem(LOTLayerData *layerData)
414 : LOTLayerItem(layerData)
418 void LOTSolidLayerItem::updateContent()
421 mRenderNode = std::make_unique<LOTDrawable>();
422 mRenderNode->mType = VDrawable::Type::Fill;
423 mRenderNode->mFlag |= VDrawable::DirtyState::All;
426 if (flag() & DirtyFlagBit::Matrix) {
429 VRectF(0, 0, mLayerData->solidWidth(), mLayerData->solidHeight()));
430 path.transform(combinedMatrix());
431 mRenderNode->mFlag |= VDrawable::DirtyState::Path;
432 mRenderNode->mPath = path;
434 if (flag() & DirtyFlagBit::Alpha) {
435 LottieColor color = mLayerData->solidColor();
436 VBrush brush(color.toColor(combinedAlpha()));
437 mRenderNode->setBrush(brush);
438 mRenderNode->mFlag |= VDrawable::DirtyState::Brush;
442 void LOTSolidLayerItem::renderList(std::vector<VDrawable *> &list)
444 if (!visible()) return;
446 list.push_back(mRenderNode.get());
449 LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
450 : LOTLayerItem(layerData)
453 void LOTNullLayerItem::updateContent() {}
455 LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
456 : LOTLayerItem(layerData)
458 mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
459 mRoot->addChildren(layerData);
461 std::vector<LOTPathDataItem *> list;
462 mRoot->processPaintItems(list);
464 if (layerData->hasPathOperator()) {
466 mRoot->processTrimItems(list);
470 std::unique_ptr<LOTContentItem>
471 LOTShapeLayerItem::createContentItem(LOTData *contentData)
473 switch (contentData->type()) {
474 case LOTData::Type::ShapeGroup: {
475 return std::make_unique<LOTContentGroupItem>(
476 static_cast<LOTShapeGroupData *>(contentData));
479 case LOTData::Type::Rect: {
480 return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
483 case LOTData::Type::Ellipse: {
484 return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
487 case LOTData::Type::Shape: {
488 return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
491 case LOTData::Type::Polystar: {
492 return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
495 case LOTData::Type::Fill: {
496 return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
499 case LOTData::Type::GFill: {
500 return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
503 case LOTData::Type::Stroke: {
504 return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
507 case LOTData::Type::GStroke: {
508 return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
511 case LOTData::Type::Repeater: {
512 return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
515 case LOTData::Type::Trim: {
516 return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
525 void LOTShapeLayerItem::updateContent()
527 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
529 if (mLayerData->hasPathOperator()) {
534 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
536 if (!visible()) return;
537 mRoot->renderList(list);
540 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
545 void LOTContentGroupItem::addChildren(LOTGroupData *data)
549 for (auto &i : data->mChildren) {
550 auto content = LOTShapeLayerItem::createContentItem(i.get());
551 if (content) mContents.push_back(std::move(content));
555 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
556 float parentAlpha, const DirtyFlag &flag)
558 VMatrix m = parentMatrix;
559 float alpha = parentAlpha;
560 DirtyFlag newFlag = flag;
563 // update the matrix and the flag
564 if ((flag & DirtyFlagBit::Matrix) ||
565 !mData->mTransform->staticMatrix()) {
566 newFlag |= DirtyFlagBit::Matrix;
568 m = mData->mTransform->matrix(frameNo);
570 alpha *= mData->mTransform->opacity(frameNo);
572 if (!vCompare(alpha, parentAlpha)) {
573 newFlag |= DirtyFlagBit::Alpha;
577 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
578 (*i)->update(frameNo, m, alpha, newFlag);
582 void LOTContentGroupItem::applyTrim()
584 for (auto &i : mContents) {
585 if (auto trim = dynamic_cast<LOTTrimItem *>(i.get())) {
587 } else if (auto group = dynamic_cast<LOTContentGroupItem *>(i.get())) {
593 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
595 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
596 (*i)->renderList(list);
600 void LOTContentGroupItem::processPaintItems(
601 std::vector<LOTPathDataItem *> &list)
603 int curOpCount = list.size();
604 for (auto &i : mContents) {
605 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
606 // add it to the list
607 list.push_back(pathNode);
608 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(i.get())) {
609 // the node is a paint data node update the path list of the paint item.
610 paintNode->addPathItems(list, curOpCount);
611 } else if (auto groupNode =
612 dynamic_cast<LOTContentGroupItem *>(i.get())) {
613 // update the groups node with current list
614 groupNode->processPaintItems(list);
619 void LOTContentGroupItem::processTrimItems(
620 std::vector<LOTPathDataItem *> &list)
622 int curOpCount = list.size();
623 for (auto &i : mContents) {
624 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
625 // add it to the list
626 list.push_back(pathNode);
627 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(i.get())) {
628 // the node is a paint data node update the path list of the paint item.
629 trimNode->addPathItems(list, curOpCount);
630 } else if (auto groupNode =
631 dynamic_cast<LOTContentGroupItem *>(i.get())) {
632 // update the groups node with current list
633 groupNode->processTrimItems(list);
638 void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix,
639 float, const DirtyFlag &flag)
641 mPathChanged = false;
643 // 1. update the local path if needed
644 if (!(mInit && mStaticPath) && hasChanged(frameNo)) {
645 updatePath(mLocalPath, frameNo);
652 // 3. compute the final path with parentMatrix
654 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
655 mMatrix = parentMatrix;
660 const VPath & LOTPathDataItem::finalPath()
663 mFinalPath.clone(mTemp);
664 mFinalPath.transform(mMatrix);
665 mPathChanged = false;
669 LOTRectItem::LOTRectItem(LOTRectData *data)
670 : LOTPathDataItem(data->isStatic()), mData(data)
674 void LOTRectItem::updatePath(VPath& path, int frameNo)
676 VPointF pos = mData->mPos.value(frameNo);
677 VPointF size = mData->mSize.value(frameNo);
678 float roundness = mData->mRound.value(frameNo);
679 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
683 path.addRoundRect(r, roundness, roundness, mData->direction());
684 updateCache(frameNo, pos, size, roundness);
687 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
688 : LOTPathDataItem(data->isStatic()), mData(data)
692 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
694 VPointF pos = mData->mPos.value(frameNo);
695 VPointF size = mData->mSize.value(frameNo);
696 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
700 path.addOval(r, mData->direction());
701 updateCache(frameNo, pos, size);
704 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
705 : LOTPathDataItem(data->isStatic()), mData(data)
709 void LOTShapeItem::updatePath(VPath& path, int frameNo)
711 mData->mShape.value(frameNo).toPath(path);
714 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
715 : LOTPathDataItem(data->isStatic()), mData(data)
719 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
721 VPointF pos = mData->mPos.value(frameNo);
722 float points = mData->mPointCount.value(frameNo);
723 float innerRadius = mData->mInnerRadius.value(frameNo);
724 float outerRadius = mData->mOuterRadius.value(frameNo);
725 float innerRoundness = mData->mInnerRoundness.value(frameNo);
726 float outerRoundness = mData->mOuterRoundness.value(frameNo);
727 float rotation = mData->mRotation.value(frameNo);
732 if (mData->mType == LOTPolystarData::PolyType::Star) {
733 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
734 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
736 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
740 m.translate(pos.x(), pos.y()).rotate(rotation);
743 updateCache(frameNo, pos, points, innerRadius, outerRadius,
744 innerRoundness, outerRoundness, rotation);
748 * PaintData Node handling
751 LOTPaintDataItem::LOTPaintDataItem(bool staticContent):mDrawable(std::make_unique<LOTDrawable>()),
752 mStaticContent(staticContent){}
754 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
755 float parentAlpha, const DirtyFlag &flag)
757 mRenderNodeUpdate = true;
758 mParentAlpha = parentAlpha;
759 mParentMatrix = parentMatrix;
763 updateContent(frameNo);
766 void LOTPaintDataItem::updateRenderNode()
769 for (auto &i : mPathItems) {
779 for (auto &i : mPathItems) {
780 mPath.addPath(i->finalPath());
782 mDrawable->setPath(mPath);
784 if (mDrawable->mFlag & VDrawable::DirtyState::Path)
785 mDrawable->mPath = mPath;
789 void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
791 if (mRenderNodeUpdate) {
793 LOTPaintDataItem::updateRenderNode();
794 mRenderNodeUpdate = false;
796 list.push_back(mDrawable.get());
800 void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
802 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
806 LOTFillItem::LOTFillItem(LOTFillData *data)
807 : LOTPaintDataItem(data->isStatic()), mData(data)
811 void LOTFillItem::updateContent(int frameNo)
813 LottieColor c = mData->mColor.value(frameNo);
814 float opacity = mData->opacity(frameNo);
815 mColor = c.toColor(opacity);
816 mFillRule = mData->fillRule();
819 void LOTFillItem::updateRenderNode()
821 VColor color = mColor;
823 color.setAlpha(color.a * parentAlpha());
825 mDrawable->setBrush(brush);
826 mDrawable->setFillRule(mFillRule);
829 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
830 : LOTPaintDataItem(data->isStatic()), mData(data)
834 void LOTGFillItem::updateContent(int frameNo)
836 mData->update(mGradient, frameNo);
837 mGradient->mMatrix = mParentMatrix;
838 mFillRule = mData->fillRule();
841 void LOTGFillItem::updateRenderNode()
843 mDrawable->setBrush(VBrush(mGradient.get()));
844 mDrawable->setFillRule(mFillRule);
847 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
848 : LOTPaintDataItem(data->isStatic()), mData(data)
853 void LOTStrokeItem::updateContent(int frameNo)
855 LottieColor c = mData->mColor.value(frameNo);
856 float opacity = mData->opacity(frameNo);
857 mColor = c.toColor(opacity);
858 mCap = mData->capStyle();
859 mJoin = mData->joinStyle();
860 mMiterLimit = mData->meterLimit();
861 mWidth = mData->width(frameNo);
862 if (mData->hasDashInfo()) {
863 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
867 static float getScale(const VMatrix &matrix)
869 constexpr float SQRT_2 = 1.41421;
871 VPointF p2(SQRT_2, SQRT_2);
874 VPointF final = p2 - p1;
876 return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0;
879 void LOTStrokeItem::updateRenderNode()
881 VColor color = mColor;
883 color.setAlpha(color.a * parentAlpha());
885 mDrawable->setBrush(brush);
886 float scale = getScale(mParentMatrix);
887 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
889 if (mDashArraySize) {
890 for (int i = 0 ; i < mDashArraySize ; i++)
891 mDashArray[i] *= scale;
892 mDrawable->setDashInfo(mDashArray, mDashArraySize);
896 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
897 : LOTPaintDataItem(data->isStatic()), mData(data)
902 void LOTGStrokeItem::updateContent(int frameNo)
904 mData->update(mGradient, frameNo);
905 mGradient->mMatrix = mParentMatrix;
906 mCap = mData->capStyle();
907 mJoin = mData->joinStyle();
908 mMiterLimit = mData->meterLimit();
909 mWidth = mData->width(frameNo);
910 if (mData->hasDashInfo()) {
911 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
915 void LOTGStrokeItem::updateRenderNode()
917 float scale = getScale(mParentMatrix);
918 mDrawable->setBrush(VBrush(mGradient.get()));
919 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
921 if (mDashArraySize) {
922 for (int i = 0 ; i < mDashArraySize ; i++)
923 mDashArray[i] *= scale;
924 mDrawable->setDashInfo(mDashArray, mDashArraySize);
928 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
930 void LOTTrimItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
931 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
935 if (mCache.mFrameNo == frameNo) return;
937 float start = mData->start(frameNo);
938 float end = mData->end(frameNo);
939 float offset = mData->offset(frameNo);
941 if (!(vCompare(mCache.mStart, start) && vCompare(mCache.mEnd, end) &&
942 vCompare(mCache.mOffset, offset))) {
944 mCache.mStart = start;
946 mCache.mOffset = offset;
948 mCache.mFrameNo = frameNo;
951 void LOTTrimItem::update()
953 // when both path and trim are not dirty
954 if (!(mDirty || pathDirty())) return;
956 //@TODO take the offset and trim type into account.
957 for (auto &i : mPathItems) {
959 pm.setOffset(mCache.mStart, mCache.mEnd);
960 i->updatePath(pm.trim(i->localPath()));
965 void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
967 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
971 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
973 void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
974 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
978 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
980 void LOTDrawable::sync()
982 mCNode.mFlag = ChangeFlagNone;
983 if (mFlag & DirtyState::None) return;
985 if (mFlag & DirtyState::Path) {
986 const std::vector<VPath::Element> &elm = mPath.elements();
987 const std::vector<VPointF> & pts = mPath.points();
988 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
989 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
990 mCNode.mPath.elmPtr = elmPtr;
991 mCNode.mPath.elmCount = elm.size();
992 mCNode.mPath.ptPtr = ptPtr;
993 mCNode.mPath.ptCount = 2 * pts.size();
994 mCNode.mFlag |= ChangeFlagPath;
997 if (mStroke.enable) {
998 mCNode.mStroke.width = mStroke.width;
999 mCNode.mStroke.meterLimit = mStroke.meterLimit;
1000 mCNode.mStroke.enable = 1;
1002 switch (mFillRule) {
1003 case FillRule::EvenOdd:
1004 mCNode.mFillRule = LOTFillRule::FillEvenOdd;
1007 mCNode.mFillRule = LOTFillRule::FillWinding;
1011 switch (mStroke.cap) {
1012 case CapStyle::Flat:
1013 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1015 case CapStyle::Square:
1016 mCNode.mStroke.cap = LOTCapStyle::CapSquare;
1018 case CapStyle::Round:
1019 mCNode.mStroke.cap = LOTCapStyle::CapRound;
1022 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1026 switch (mStroke.join) {
1027 case JoinStyle::Miter:
1028 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1030 case JoinStyle::Bevel:
1031 mCNode.mStroke.join = LOTJoinStyle::JoinBevel;
1033 case JoinStyle::Round:
1034 mCNode.mStroke.join = LOTJoinStyle::JoinRound;
1037 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1041 mCNode.mStroke.dashArray = mStroke.mDash.data();
1042 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1045 mCNode.mStroke.enable = 0;
1048 switch (mBrush.type()) {
1049 case VBrush::Type::Solid:
1050 mCNode.mType = LOTBrushType::BrushSolid;
1051 mCNode.mColor.r = mBrush.mColor.r;
1052 mCNode.mColor.g = mBrush.mColor.g;
1053 mCNode.mColor.b = mBrush.mColor.b;
1054 mCNode.mColor.a = mBrush.mColor.a;
1056 case VBrush::Type::LinearGradient:
1057 mCNode.mType = LOTBrushType::BrushGradient;
1058 mCNode.mGradient.type = LOTGradientType::GradientLinear;
1059 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1060 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1061 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1062 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1064 case VBrush::Type::RadialGradient:
1065 mCNode.mType = LOTBrushType::BrushGradient;
1066 mCNode.mGradient.type = LOTGradientType::GradientRadial;
1067 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1068 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1069 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1070 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1071 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1072 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;