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);
460 mRoot->processPaintOperation();
461 if (layerData->hasPathOperator()) mRoot->processTrimOperation();
464 std::unique_ptr<LOTContentItem>
465 LOTShapeLayerItem::createContentItem(LOTData *contentData)
467 switch (contentData->type()) {
468 case LOTData::Type::ShapeGroup: {
469 return std::make_unique<LOTContentGroupItem>(
470 static_cast<LOTShapeGroupData *>(contentData));
473 case LOTData::Type::Rect: {
474 return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
477 case LOTData::Type::Ellipse: {
478 return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
481 case LOTData::Type::Shape: {
482 return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
485 case LOTData::Type::Polystar: {
486 return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
489 case LOTData::Type::Fill: {
490 return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
493 case LOTData::Type::GFill: {
494 return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
497 case LOTData::Type::Stroke: {
498 return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
501 case LOTData::Type::GStroke: {
502 return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
505 case LOTData::Type::Repeater: {
506 return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
509 case LOTData::Type::Trim: {
510 return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
519 void LOTShapeLayerItem::updateContent()
521 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
524 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
526 if (!visible()) return;
527 mRoot->renderList(list);
530 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
535 void LOTContentGroupItem::addChildren(LOTGroupData *data)
539 for (auto &i : data->mChildren) {
540 auto content = LOTShapeLayerItem::createContentItem(i.get());
541 if (content) mContents.push_back(std::move(content));
545 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
546 float parentAlpha, const DirtyFlag &flag)
548 VMatrix m = parentMatrix;
549 float alpha = parentAlpha;
550 DirtyFlag newFlag = flag;
553 // update the matrix and the flag
554 if ((flag & DirtyFlagBit::Matrix) ||
555 !mData->mTransform->staticMatrix()) {
556 newFlag |= DirtyFlagBit::Matrix;
558 m = mData->mTransform->matrix(frameNo);
560 alpha *= mData->mTransform->opacity(frameNo);
562 if (!vCompare(alpha, parentAlpha)) {
563 newFlag |= DirtyFlagBit::Alpha;
567 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
568 (*i)->update(frameNo, m, alpha, newFlag);
572 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
574 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
575 (*i)->renderList(list);
579 void LOTContentGroupItem::processPaintOperation()
581 std::vector<LOTPaintDataItem *> list;
582 paintOperationHelper(list);
585 void LOTContentGroupItem::paintOperationHelper(
586 std::vector<LOTPaintDataItem *> &list)
588 int curOpCount = list.size();
589 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
590 auto child = (*i).get();
591 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
592 // the node is a path data node add the paint operation list to it.
593 pathNode->addPaintOperation(list, curOpCount);
594 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(child)) {
595 // add it to the paint operation list
596 list.push_back(paintNode);
597 } else if (auto groupNode =
598 dynamic_cast<LOTContentGroupItem *>(child)) {
599 // update the groups node with current list
600 groupNode->paintOperationHelper(list);
603 list.erase(list.begin() + curOpCount, list.end());
606 void LOTPathDataItem::addPaintOperation(std::vector<LOTPaintDataItem *> &list,
609 for (auto paintItem : list) {
610 bool sameGroup = (externalCount-- > 0) ? false : true;
611 mNodeList.push_back(std::make_unique<LOTDrawable>());
612 mRenderList.push_back(
613 LOTRenderNode(this, paintItem, mNodeList.back().get(), sameGroup));
617 void LOTContentGroupItem::processTrimOperation()
619 std::vector<LOTTrimItem *> list;
620 trimOperationHelper(list);
623 void LOTContentGroupItem::trimOperationHelper(std::vector<LOTTrimItem *> &list)
625 int curOpCount = list.size();
626 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
627 auto child = (*i).get();
628 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
629 // the node is a path data node add the trim operation list to it.
630 pathNode->addTrimOperation(list);
631 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(child)) {
632 // add it to the trim operation list
633 list.push_back(trimNode);
634 } else if (auto groupNode =
635 dynamic_cast<LOTContentGroupItem *>(child)) {
636 // update the groups node with current list
637 groupNode->trimOperationHelper(list);
640 list.erase(list.begin() + curOpCount, list.end());
643 void LOTPathDataItem::addTrimOperation(std::vector<LOTTrimItem *> &list)
645 for (auto trimItem : list) {
646 mTrimNodeRefs.push_back(trimItem);
650 void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix,
651 float parentAlpha, const DirtyFlag &flag)
655 mPathChanged = false;
656 mCombinedAlpha = parentAlpha;
658 // 1. update the local path if needed
659 if (!(mInit && mStaticPath) && hasChanged(frameNo)) {
660 updatePath(mLocalPath, frameNo);
665 tempPath = mLocalPath;
667 // 2. apply path operation if needed
668 if (mTrimNodeRefs.size() > 0) {
669 // TODO apply more than one trim path if necessary
671 float s = mTrimNodeRefs.front()->getStart(frameNo) / 100.0f;
672 float e = mTrimNodeRefs.front()->getEnd(frameNo) / 100.0f;
675 tempPath = pm.trim(tempPath);
679 // 3. compute the final path with parentMatrix
681 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
682 mFinalPath.clone(tempPath);
683 mFinalPath.transform(parentMatrix);
687 // 2. update the rendernode list
688 for (const auto &i : mRenderList) {
689 i.drawable->mFlag = VDrawable::DirtyState::None;
690 i.paintNodeRef->updateRenderNode(i.pathNodeRef, i.drawable,
693 i.drawable->mFlag |= VDrawable::DirtyState::Path;
695 if (i.drawable->mFlag & VDrawable::DirtyState::Path)
696 i.drawable->mPath = mFinalPath;
700 void LOTPathDataItem::renderList(std::vector<VDrawable *> &list)
702 for (const auto &i : mRenderList) {
703 list.push_back(i.drawable);
707 VPath LOTPathDataItem::path() const
712 LOTRectItem::LOTRectItem(LOTRectData *data)
713 : LOTPathDataItem(data->isStatic()), mData(data)
717 void LOTRectItem::updatePath(VPath& path, int frameNo)
719 VPointF pos = mData->mPos.value(frameNo);
720 VPointF size = mData->mSize.value(frameNo);
721 float roundness = mData->mRound.value(frameNo);
722 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
726 path.addRoundRect(r, roundness, roundness, mData->direction());
727 updateCache(frameNo, pos, size, roundness);
730 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
731 : LOTPathDataItem(data->isStatic()), mData(data)
735 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
737 VPointF pos = mData->mPos.value(frameNo);
738 VPointF size = mData->mSize.value(frameNo);
739 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
743 path.addOval(r, mData->direction());
744 updateCache(frameNo, pos, size);
747 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
748 : LOTPathDataItem(data->isStatic()), mData(data)
752 void LOTShapeItem::updatePath(VPath& path, int frameNo)
754 mData->mShape.value(frameNo).toPath(path);
757 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
758 : LOTPathDataItem(data->isStatic()), mData(data)
762 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
764 VPointF pos = mData->mPos.value(frameNo);
765 float points = mData->mPointCount.value(frameNo);
766 float innerRadius = mData->mInnerRadius.value(frameNo);
767 float outerRadius = mData->mOuterRadius.value(frameNo);
768 float innerRoundness = mData->mInnerRoundness.value(frameNo);
769 float outerRoundness = mData->mOuterRoundness.value(frameNo);
770 float rotation = mData->mRotation.value(frameNo);
775 if (mData->mType == LOTPolystarData::PolyType::Star) {
776 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
777 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
779 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
783 m.translate(pos.x(), pos.y()).rotate(rotation);
786 updateCache(frameNo, pos, points, innerRadius, outerRadius,
787 innerRoundness, outerRoundness, rotation);
791 * PaintData Node handling
795 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
796 float parentAlpha, const DirtyFlag &flag)
798 mContentChanged = false;
799 mParentAlpha = parentAlpha;
800 mParentMatrix = parentMatrix;
803 // 1. update the local content if needed
804 // if (!(mInit && mStaticContent)) {
806 updateContent(frameNo);
807 mContentChanged = true;
811 LOTFillItem::LOTFillItem(LOTFillData *data)
812 : LOTPaintDataItem(data->isStatic()), mData(data)
816 void LOTFillItem::updateContent(int frameNo)
818 LottieColor c = mData->mColor.value(frameNo);
819 float opacity = mData->opacity(frameNo);
820 mColor = c.toColor(opacity);
821 mFillRule = mData->fillRule();
824 void LOTFillItem::updateRenderNode(LOTPathDataItem *pathNode,
825 VDrawable *drawable, bool sameParent)
827 VColor color = mColor;
829 color.setAlpha(color.a * pathNode->combinedAlpha());
831 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
833 drawable->setBrush(brush);
834 drawable->setFillRule(mFillRule);
837 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
838 : LOTPaintDataItem(data->isStatic()), mData(data)
842 void LOTGFillItem::updateContent(int frameNo)
844 mData->update(mGradient, frameNo);
845 mGradient->mMatrix = mParentMatrix;
846 mFillRule = mData->fillRule();
849 void LOTGFillItem::updateRenderNode(LOTPathDataItem */*pathNode*/,
850 VDrawable *drawable, bool /*sameParent*/)
852 drawable->setBrush(VBrush(mGradient.get()));
853 drawable->setFillRule(mFillRule);
856 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
857 : LOTPaintDataItem(data->isStatic()), mData(data)
862 void LOTStrokeItem::updateContent(int frameNo)
864 LottieColor c = mData->mColor.value(frameNo);
865 float opacity = mData->opacity(frameNo);
866 mColor = c.toColor(opacity);
867 mCap = mData->capStyle();
868 mJoin = mData->joinStyle();
869 mMiterLimit = mData->meterLimit();
870 mWidth = mData->width(frameNo);
871 if (mData->hasDashInfo()) {
872 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
876 static float getScale(const VMatrix &matrix)
878 constexpr float SQRT_2 = 1.41421;
880 VPointF p2(SQRT_2, SQRT_2);
883 VPointF final = p2 - p1;
885 return std::sqrt(final.x() * final.x() + final.y() * final.y());
888 void LOTStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
889 VDrawable *drawable, bool sameParent)
891 VColor color = mColor;
893 color.setAlpha(color.a * pathNode->combinedAlpha());
895 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
898 drawable->setBrush(brush);
899 float scale = getScale(mParentMatrix);
900 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
902 if (mDashArraySize) {
903 for (int i = 0 ; i < mDashArraySize ; i++)
904 mDashArray[i] *= scale;
905 drawable->setDashInfo(mDashArray, mDashArraySize);
909 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
910 : LOTPaintDataItem(data->isStatic()), mData(data)
915 void LOTGStrokeItem::updateContent(int frameNo)
917 mData->update(mGradient, frameNo);
918 mGradient->mMatrix = mParentMatrix;
919 mCap = mData->capStyle();
920 mJoin = mData->joinStyle();
921 mMiterLimit = mData->meterLimit();
922 mWidth = mData->width(frameNo);
923 if (mData->hasDashInfo()) {
924 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
928 void LOTGStrokeItem::updateRenderNode(LOTPathDataItem */*pathNode*/,
929 VDrawable *drawable, bool /*sameParent*/)
931 float scale = getScale(mParentMatrix);
932 drawable->setBrush(VBrush(mGradient.get()));
933 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
935 if (mDashArraySize) {
936 for (int i = 0 ; i < mDashArraySize ; i++)
937 mDashArray[i] *= scale;
938 drawable->setDashInfo(mDashArray, mDashArraySize);
942 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
944 void LOTTrimItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
945 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
949 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
951 void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
952 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
956 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
958 void LOTDrawable::sync()
960 mCNode.mFlag = ChangeFlagNone;
961 if (mFlag & DirtyState::None) return;
963 if (mFlag & DirtyState::Path) {
964 const std::vector<VPath::Element> &elm = mPath.elements();
965 const std::vector<VPointF> & pts = mPath.points();
966 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
967 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
968 mCNode.mPath.elmPtr = elmPtr;
969 mCNode.mPath.elmCount = elm.size();
970 mCNode.mPath.ptPtr = ptPtr;
971 mCNode.mPath.ptCount = 2 * pts.size();
972 mCNode.mFlag |= ChangeFlagPath;
975 if (mStroke.enable) {
976 mCNode.mStroke.width = mStroke.width;
977 mCNode.mStroke.meterLimit = mStroke.meterLimit;
978 mCNode.mStroke.enable = 1;
981 case FillRule::EvenOdd:
982 mCNode.mFillRule = LOTNode::EvenOdd;
985 mCNode.mFillRule = LOTNode::Winding;
989 switch (mStroke.cap) {
991 mCNode.mStroke.cap = LOTNode::FlatCap;
993 case CapStyle::Square:
994 mCNode.mStroke.cap = LOTNode::SquareCap;
996 case CapStyle::Round:
997 mCNode.mStroke.cap = LOTNode::RoundCap;
1000 mCNode.mStroke.cap = LOTNode::FlatCap;
1004 switch (mStroke.join) {
1005 case JoinStyle::Miter:
1006 mCNode.mStroke.join = LOTNode::MiterJoin;
1008 case JoinStyle::Bevel:
1009 mCNode.mStroke.join = LOTNode::BevelJoin;
1011 case JoinStyle::Round:
1012 mCNode.mStroke.join = LOTNode::RoundJoin;
1015 mCNode.mStroke.join = LOTNode::MiterJoin;
1019 mCNode.mStroke.dashArray = mStroke.mDash.data();
1020 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1023 mCNode.mStroke.enable = 0;
1026 switch (mBrush.type()) {
1027 case VBrush::Type::Solid:
1028 mCNode.mType = LOTNode::BrushSolid;
1029 mCNode.mColor.r = mBrush.mColor.r;
1030 mCNode.mColor.g = mBrush.mColor.g;
1031 mCNode.mColor.b = mBrush.mColor.b;
1032 mCNode.mColor.a = mBrush.mColor.a;
1034 case VBrush::Type::LinearGradient:
1035 mCNode.mType = LOTNode::BrushGradient;
1036 mCNode.mGradient.type = LOTNode::Gradient::Linear;
1037 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1038 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1039 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1040 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1042 case VBrush::Type::RadialGradient:
1043 mCNode.mType = LOTNode::BrushGradient;
1044 mCNode.mGradient.type = LOTNode::Gradient::Radial;
1045 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1046 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1047 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1048 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1049 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1050 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;