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::instance().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();
234 LOTLayerItem::LOTLayerItem(LOTLayerData *layerData)
235 : mLayerData(layerData),
236 mParentLayer(nullptr),
237 mPrecompLayer(nullptr),
238 mCombinedAlpha(0.0f),
240 mDirtyFlag(DirtyFlagBit::All)
242 if (mLayerData->mHasMask) {
243 for (auto &i : mLayerData->mMasks) {
244 mMasks.push_back(std::make_unique<LOTMaskItem>(i.get()));
249 void LOTLayerItem::updateStaticProperty()
251 if (mParentLayer) mParentLayer->updateStaticProperty();
253 mStatic = mLayerData->isStatic();
254 mStatic = mParentLayer ? (mStatic & mParentLayer->isStatic()) : mStatic;
255 mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic;
258 void LOTLayerItem::update(int frameNo, const VMatrix &parentMatrix,
262 // 1. check if the layer is part of the current frame
263 if (!visible()) return;
265 // 2. calculate the parent matrix and alpha
266 VMatrix m = matrix(frameNo);
268 float alpha = parentAlpha * opacity(frameNo);
270 // 6. update the mask
272 for (auto &i : mMasks) i->update(frameNo, m, alpha, mDirtyFlag);
275 // 3. update the dirty flag based on the change
276 if (!mCombinedMatrix.fuzzyCompare(m)) {
277 mDirtyFlag |= DirtyFlagBit::Matrix;
279 if (!vCompare(mCombinedAlpha, alpha)) {
280 mDirtyFlag |= DirtyFlagBit::Alpha;
283 mCombinedAlpha = alpha;
285 // 4. if no parent property change and layer is static then nothing to do.
286 if ((flag() & DirtyFlagBit::None) && isStatic()) return;
288 // 5. update the content of the layer
291 // 6. reset the dirty flag
292 mDirtyFlag = DirtyFlagBit::None;
295 float LOTLayerItem::opacity(int frameNo) const
297 return mLayerData->mTransform->opacity(frameNo);
300 VMatrix LOTLayerItem::matrix(int frameNo) const
303 return mLayerData->mTransform->matrix(frameNo) *
304 mParentLayer->matrix(frameNo);
306 return mLayerData->mTransform->matrix(frameNo);
309 bool LOTLayerItem::visible() const
311 if (frameNo() >= mLayerData->inFrame() &&
312 frameNo() < mLayerData->outFrame())
318 LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
319 : LOTLayerItem(layerModel)
321 for (auto &i : mLayerData->mChildren) {
322 LOTLayerData *layerModel = dynamic_cast<LOTLayerData *>(i.get());
324 auto layerItem = LOTCompItem::createLayerItem(layerModel);
325 if (layerItem) mLayers.push_back(std::move(layerItem));
329 // 2. update parent layer
330 for (auto &i : mLayers) {
331 int id = i->parentId();
333 auto search = std::find_if(mLayers.begin(), mLayers.end(),
334 [id](const auto& val){ return val->id() == id;});
335 if (search != mLayers.end()) i->setParentLayer((*search).get());
337 // update the precomp layer if its not the root layer.
338 if (!layerModel->root()) i->setPrecompLayer(this);
342 void LOTCompLayerItem::updateStaticProperty()
344 LOTLayerItem::updateStaticProperty();
346 for (auto &i : mLayers) {
347 i->updateStaticProperty();
351 void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &inheritMatte, LOTLayerItem *matteSource)
355 mDrawableList.clear();
356 matteSource->renderList(mDrawableList);
357 for (auto &i : mDrawableList) {
358 matteRle = matteRle + i->rle();
361 if (!inheritMatte.isEmpty())
362 matteRle = matteRle & inheritMatte;
364 matteRle = inheritMatte;
369 mask = maskRle(painter->clipBoundingRect());
370 if (!inheritMask.isEmpty())
371 mask = mask & inheritMask;
372 // if resulting mask is empty then return.
379 LOTLayerItem *matteLayer = nullptr;
380 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
381 LOTLayerItem *layer = (*i).get();
383 if (!matteLayer && layer->hasMatte()) {
389 matteLayer->render(painter, mask, matteRle, layer);
390 matteLayer = nullptr;
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 = new LOTContentGroupItem(nullptr);
461 mRoot->addChildren(layerData);
462 mRoot->processPaintOperation();
463 if (layerData->hasPathOperator()) mRoot->processTrimOperation();
466 LOTShapeLayerItem::~LOTShapeLayerItem()
471 LOTContentItem *LOTShapeLayerItem::createContentItem(LOTData *contentData)
473 switch (contentData->type()) {
474 case LOTData::Type::ShapeGroup: {
475 return new LOTContentGroupItem(
476 static_cast<LOTShapeGroupData *>(contentData));
479 case LOTData::Type::Rect: {
480 return new LOTRectItem(static_cast<LOTRectData *>(contentData));
483 case LOTData::Type::Ellipse: {
484 return new LOTEllipseItem(static_cast<LOTEllipseData *>(contentData));
487 case LOTData::Type::Shape: {
488 return new LOTShapeItem(static_cast<LOTShapeData *>(contentData));
491 case LOTData::Type::Polystar: {
492 return new LOTPolystarItem(static_cast<LOTPolystarData *>(contentData));
495 case LOTData::Type::Fill: {
496 return new LOTFillItem(static_cast<LOTFillData *>(contentData));
499 case LOTData::Type::GFill: {
500 return new LOTGFillItem(static_cast<LOTGFillData *>(contentData));
503 case LOTData::Type::Stroke: {
504 return new LOTStrokeItem(static_cast<LOTStrokeData *>(contentData));
507 case LOTData::Type::GStroke: {
508 return new LOTGStrokeItem(static_cast<LOTGStrokeData *>(contentData));
511 case LOTData::Type::Repeater: {
512 return new LOTRepeaterItem(static_cast<LOTRepeaterData *>(contentData));
515 case LOTData::Type::Trim: {
516 return new LOTTrimItem(static_cast<LOTTrimData *>(contentData));
525 void LOTShapeLayerItem::updateContent()
527 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
530 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
532 if (!visible()) return;
533 mRoot->renderList(list);
536 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
541 void LOTContentGroupItem::addChildren(LOTGroupData *data)
545 for (auto i : data->mChildren) {
546 LOTData * data = i.get();
547 LOTContentItem *content = LOTShapeLayerItem::createContentItem(data);
548 if (content) mContents.push_back(content);
552 LOTContentGroupItem::~LOTContentGroupItem()
554 for (auto i : mContents) {
559 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
560 float parentAlpha, const DirtyFlag &flag)
562 VMatrix m = parentMatrix;
563 float alpha = parentAlpha;
564 DirtyFlag newFlag = flag;
567 // update the matrix and the flag
568 if ((flag & DirtyFlagBit::Matrix) ||
569 !mData->mTransform->staticMatrix()) {
570 newFlag |= DirtyFlagBit::Matrix;
572 m = mData->mTransform->matrix(frameNo);
574 alpha *= mData->mTransform->opacity(frameNo);
576 if (!vCompare(alpha, parentAlpha)) {
577 newFlag |= DirtyFlagBit::Alpha;
581 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
582 (*i)->update(frameNo, m, alpha, newFlag);
586 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
588 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
589 (*i)->renderList(list);
593 void LOTContentGroupItem::processPaintOperation()
595 std::vector<LOTPaintDataItem *> list;
596 paintOperationHelper(list);
599 void LOTContentGroupItem::paintOperationHelper(
600 std::vector<LOTPaintDataItem *> &list)
602 int curOpCount = list.size();
603 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
605 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
606 // the node is a path data node add the paint operation list to it.
607 pathNode->addPaintOperation(list, curOpCount);
608 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(child)) {
609 // add it to the paint operation list
610 list.push_back(paintNode);
611 } else if (auto groupNode =
612 dynamic_cast<LOTContentGroupItem *>(child)) {
613 // update the groups node with current list
614 groupNode->paintOperationHelper(list);
617 list.erase(list.begin() + curOpCount, list.end());
620 void LOTPathDataItem::addPaintOperation(std::vector<LOTPaintDataItem *> &list,
623 for (auto paintItem : list) {
624 bool sameGroup = (externalCount-- > 0) ? false : true;
625 mNodeList.push_back(std::make_unique<LOTDrawable>());
626 mRenderList.push_back(
627 LOTRenderNode(this, paintItem, mNodeList.back().get(), sameGroup));
631 void LOTContentGroupItem::processTrimOperation()
633 std::vector<LOTTrimItem *> list;
634 trimOperationHelper(list);
637 void LOTContentGroupItem::trimOperationHelper(std::vector<LOTTrimItem *> &list)
639 int curOpCount = list.size();
640 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
642 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
643 // the node is a path data node add the trim operation list to it.
644 pathNode->addTrimOperation(list);
645 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(child)) {
646 // add it to the trim operation list
647 list.push_back(trimNode);
648 } else if (auto groupNode =
649 dynamic_cast<LOTContentGroupItem *>(child)) {
650 // update the groups node with current list
651 groupNode->trimOperationHelper(list);
654 list.erase(list.begin() + curOpCount, list.end());
657 void LOTPathDataItem::addTrimOperation(std::vector<LOTTrimItem *> &list)
659 for (auto trimItem : list) {
660 mTrimNodeRefs.push_back(trimItem);
664 void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix,
665 float parentAlpha, const DirtyFlag &flag)
669 mPathChanged = false;
670 mCombinedAlpha = parentAlpha;
672 // 1. update the local path if needed
673 if (!(mInit && mStaticPath) && hasChanged(frameNo)) {
674 updatePath(mLocalPath, frameNo);
679 tempPath = mLocalPath;
681 // 2. apply path operation if needed
682 if (mTrimNodeRefs.size() > 0) {
683 // TODO apply more than one trim path if necessary
685 float s = mTrimNodeRefs.front()->getStart(frameNo) / 100.0f;
686 float e = mTrimNodeRefs.front()->getEnd(frameNo) / 100.0f;
689 tempPath = pm.trim(tempPath);
693 // 3. compute the final path with parentMatrix
695 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
696 mFinalPath.clone(tempPath);
697 mFinalPath.transform(parentMatrix);
701 // 2. update the rendernode list
702 for (const auto &i : mRenderList) {
703 i.drawable->mFlag = VDrawable::DirtyState::None;
704 i.paintNodeRef->updateRenderNode(i.pathNodeRef, i.drawable,
707 i.drawable->mFlag |= VDrawable::DirtyState::Path;
709 if (i.drawable->mFlag & VDrawable::DirtyState::Path)
710 i.drawable->mPath = mFinalPath;
714 void LOTPathDataItem::renderList(std::vector<VDrawable *> &list)
716 for (const auto &i : mRenderList) {
717 list.push_back(i.drawable);
721 VPath LOTPathDataItem::path() const
726 LOTRectItem::LOTRectItem(LOTRectData *data)
727 : LOTPathDataItem(data->isStatic()), mData(data)
731 void LOTRectItem::updatePath(VPath& path, int frameNo)
733 VPointF pos = mData->mPos.value(frameNo);
734 VPointF size = mData->mSize.value(frameNo);
735 float roundness = mData->mRound.value(frameNo);
736 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
740 path.addRoundRect(r, roundness, roundness, mData->direction());
741 updateCache(frameNo, pos, size, roundness);
744 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
745 : LOTPathDataItem(data->isStatic()), mData(data)
749 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
751 VPointF pos = mData->mPos.value(frameNo);
752 VPointF size = mData->mSize.value(frameNo);
753 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
757 path.addOval(r, mData->direction());
758 updateCache(frameNo, pos, size);
761 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
762 : LOTPathDataItem(data->isStatic()), mData(data)
766 void LOTShapeItem::updatePath(VPath& path, int frameNo)
768 mData->mShape.value(frameNo).toPath(path);
771 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
772 : LOTPathDataItem(data->isStatic()), mData(data)
776 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
778 VPointF pos = mData->mPos.value(frameNo);
779 float points = mData->mPointCount.value(frameNo);
780 float innerRadius = mData->mInnerRadius.value(frameNo);
781 float outerRadius = mData->mOuterRadius.value(frameNo);
782 float innerRoundness = mData->mInnerRoundness.value(frameNo);
783 float outerRoundness = mData->mOuterRoundness.value(frameNo);
784 float rotation = mData->mRotation.value(frameNo);
789 if (mData->mType == LOTPolystarData::PolyType::Star) {
790 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
791 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
793 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
797 m.translate(pos.x(), pos.y()).rotate(rotation);
800 updateCache(frameNo, pos, points, innerRadius, outerRadius,
801 innerRoundness, outerRoundness, rotation);
805 * PaintData Node handling
809 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
810 float parentAlpha, const DirtyFlag &flag)
812 mContentChanged = false;
813 mParentAlpha = parentAlpha;
814 mParentMatrix = parentMatrix;
817 // 1. update the local content if needed
818 // if (!(mInit && mStaticContent)) {
820 updateContent(frameNo);
821 mContentChanged = true;
825 LOTFillItem::LOTFillItem(LOTFillData *data)
826 : LOTPaintDataItem(data->isStatic()), mData(data)
830 void LOTFillItem::updateContent(int frameNo)
832 LottieColor c = mData->mColor.value(frameNo);
833 float opacity = mData->opacity(frameNo);
834 mColor = c.toColor(opacity);
835 mFillRule = mData->fillRule();
838 void LOTFillItem::updateRenderNode(LOTPathDataItem *pathNode,
839 VDrawable *drawable, bool sameParent)
841 VColor color = mColor;
843 color.setAlpha(color.a * pathNode->combinedAlpha());
845 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
847 drawable->setBrush(brush);
848 drawable->setFillRule(mFillRule);
851 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
852 : LOTPaintDataItem(data->isStatic()), mData(data)
856 void LOTGFillItem::updateContent(int frameNo)
858 mData->update(mGradient, frameNo);
859 mGradient->mMatrix = mParentMatrix;
860 mFillRule = mData->fillRule();
863 void LOTGFillItem::updateRenderNode(LOTPathDataItem *pathNode,
864 VDrawable *drawable, bool sameParent)
866 drawable->setBrush(VBrush(mGradient.get()));
867 drawable->setFillRule(mFillRule);
870 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
871 : LOTPaintDataItem(data->isStatic()), mData(data)
876 void LOTStrokeItem::updateContent(int frameNo)
878 LottieColor c = mData->mColor.value(frameNo);
879 float opacity = mData->opacity(frameNo);
880 mColor = c.toColor(opacity);
881 mCap = mData->capStyle();
882 mJoin = mData->joinStyle();
883 mMiterLimit = mData->meterLimit();
884 mWidth = mData->width(frameNo);
885 if (mData->hasDashInfo()) {
886 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
890 static float getScale(const VMatrix &matrix)
892 constexpr float SQRT_2 = 1.41421;
894 VPointF p2(SQRT_2, SQRT_2);
897 VPointF final = p2 - p1;
899 return std::sqrt(final.x() * final.x() + final.y() * final.y());
902 void LOTStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
903 VDrawable *drawable, bool sameParent)
905 VColor color = mColor;
907 color.setAlpha(color.a * pathNode->combinedAlpha());
909 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
912 drawable->setBrush(brush);
913 float scale = getScale(mParentMatrix);
914 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
916 if (mDashArraySize) {
917 for (int i = 0 ; i < mDashArraySize ; i++)
918 mDashArray[i] *= scale;
919 drawable->setDashInfo(mDashArray, mDashArraySize);
923 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
924 : LOTPaintDataItem(data->isStatic()), mData(data)
929 void LOTGStrokeItem::updateContent(int frameNo)
931 mData->update(mGradient, frameNo);
932 mGradient->mMatrix = mParentMatrix;
933 mCap = mData->capStyle();
934 mJoin = mData->joinStyle();
935 mMiterLimit = mData->meterLimit();
936 mWidth = mData->width(frameNo);
937 if (mData->hasDashInfo()) {
938 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
942 void LOTGStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
943 VDrawable *drawable, bool sameParent)
945 float scale = getScale(mParentMatrix);
946 drawable->setBrush(VBrush(mGradient.get()));
947 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
949 if (mDashArraySize) {
950 for (int i = 0 ; i < mDashArraySize ; i++)
951 mDashArray[i] *= scale;
952 drawable->setDashInfo(mDashArray, mDashArraySize);
956 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
958 void LOTTrimItem::update(int frameNo, const VMatrix &parentMatrix,
959 float parentAlpha, const DirtyFlag &flag)
963 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
965 void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix,
966 float parentAlpha, const DirtyFlag &flag)
970 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &list) {}
972 void LOTDrawable::sync()
974 mCNode.mFlag = ChangeFlagNone;
975 if (mFlag & DirtyState::None) return;
977 if (mFlag & DirtyState::Path) {
978 const std::vector<VPath::Element> &elm = mPath.elements();
979 const std::vector<VPointF> & pts = mPath.points();
980 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
981 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
982 mCNode.mPath.elmPtr = elmPtr;
983 mCNode.mPath.elmCount = elm.size();
984 mCNode.mPath.ptPtr = ptPtr;
985 mCNode.mPath.ptCount = 2 * pts.size();
986 mCNode.mFlag |= ChangeFlagPath;
989 if (mStroke.enable) {
990 mCNode.mStroke.width = mStroke.width;
991 mCNode.mStroke.meterLimit = mStroke.meterLimit;
992 mCNode.mStroke.enable = 1;
995 case FillRule::EvenOdd:
996 mCNode.mFillRule = LOTNode::EvenOdd;
999 mCNode.mFillRule = LOTNode::Winding;
1003 switch (mStroke.cap) {
1004 case CapStyle::Flat:
1005 mCNode.mStroke.cap = LOTNode::FlatCap;
1007 case CapStyle::Square:
1008 mCNode.mStroke.cap = LOTNode::SquareCap;
1010 case CapStyle::Round:
1011 mCNode.mStroke.cap = LOTNode::RoundCap;
1014 mCNode.mStroke.cap = LOTNode::FlatCap;
1018 switch (mStroke.join) {
1019 case JoinStyle::Miter:
1020 mCNode.mStroke.join = LOTNode::MiterJoin;
1022 case JoinStyle::Bevel:
1023 mCNode.mStroke.join = LOTNode::BevelJoin;
1025 case JoinStyle::Round:
1026 mCNode.mStroke.join = LOTNode::RoundJoin;
1029 mCNode.mStroke.join = LOTNode::MiterJoin;
1033 mCNode.mStroke.dashArray = mStroke.mDash.data();
1034 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1037 mCNode.mStroke.enable = 0;
1040 switch (mBrush.type()) {
1041 case VBrush::Type::Solid:
1042 mCNode.mType = LOTNode::BrushSolid;
1043 mCNode.mColor.r = mBrush.mColor.r;
1044 mCNode.mColor.g = mBrush.mColor.g;
1045 mCNode.mColor.b = mBrush.mColor.b;
1046 mCNode.mColor.a = mBrush.mColor.a;
1048 case VBrush::Type::LinearGradient:
1049 mCNode.mType = LOTNode::BrushGradient;
1050 mCNode.mGradient.type = LOTNode::Gradient::Linear;
1051 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1052 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1053 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1054 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1056 case VBrush::Type::RadialGradient:
1057 mCNode.mType = LOTNode::BrushGradient;
1058 mCNode.mGradient.type = LOTNode::Gradient::Radial;
1059 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1060 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1061 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1062 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1063 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1064 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;