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 // 1. create layer item
320 for (auto &i : mLayerData->mChildren) {
321 LOTLayerData *layerModel = static_cast<LOTLayerData *>(i.get());
322 auto layerItem = LOTCompItem::createLayerItem(layerModel);
323 if (layerItem) mLayers.push_back(std::move(layerItem));
326 // 2. update parent layer
327 for (const auto &layer : mLayers) {
328 int id = layer->parentId();
330 auto search = std::find_if(mLayers.begin(), mLayers.end(),
331 [id](const auto& val){ return val->id() == id;});
332 if (search != mLayers.end()) layer->setParentLayer((*search).get());
334 // update the precomp layer if its not the root layer.
335 if (!layerModel->root()) layer->setPrecompLayer(this);
338 // 3. keep the layer in back-to-front order.
339 // as lottie model keeps the data in front-toback-order.
340 std::reverse(mLayers.begin(), mLayers.end());
343 void LOTCompLayerItem::updateStaticProperty()
345 LOTLayerItem::updateStaticProperty();
347 for (const auto &layer : mLayers) {
348 layer->updateStaticProperty();
352 void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, const VRle &inheritMatte, LOTLayerItem *matteSource)
356 mDrawableList.clear();
357 matteSource->renderList(mDrawableList);
358 for (auto &i : mDrawableList) {
359 matteRle = matteRle + i->rle();
362 if (!inheritMatte.isEmpty())
363 matteRle = matteRle & inheritMatte;
365 matteRle = inheritMatte;
370 mask = maskRle(painter->clipBoundingRect());
371 if (!inheritMask.isEmpty())
372 mask = mask & inheritMask;
373 // if resulting mask is empty then return.
380 LOTLayerItem *matteLayer = nullptr;
381 for (const auto &layer : mLayers) {
382 if (!matteLayer && layer->hasMatte()) {
383 matteLayer = layer.get();
388 if (matteLayer->visible() && layer->visible())
389 matteLayer->render(painter, mask, matteRle, layer.get());
390 matteLayer = nullptr;
392 if (layer->visible())
393 layer->render(painter, mask, matteRle, nullptr);
398 void LOTCompLayerItem::updateContent()
400 for (const auto &layer : mLayers) {
401 layer->update(frameNo(), combinedMatrix(), combinedAlpha());
405 void LOTCompLayerItem::renderList(std::vector<VDrawable *> &list)
407 if (!visible()) return;
409 for (const auto &layer : mLayers) {
410 layer->renderList(list);
414 LOTSolidLayerItem::LOTSolidLayerItem(LOTLayerData *layerData)
415 : LOTLayerItem(layerData)
419 void LOTSolidLayerItem::updateContent()
422 mRenderNode = std::make_unique<LOTDrawable>();
423 mRenderNode->mType = VDrawable::Type::Fill;
424 mRenderNode->mFlag |= VDrawable::DirtyState::All;
427 if (flag() & DirtyFlagBit::Matrix) {
430 VRectF(0, 0, mLayerData->solidWidth(), mLayerData->solidHeight()));
431 path.transform(combinedMatrix());
432 mRenderNode->mFlag |= VDrawable::DirtyState::Path;
433 mRenderNode->mPath = path;
435 if (flag() & DirtyFlagBit::Alpha) {
436 LottieColor color = mLayerData->solidColor();
437 VBrush brush(color.toColor(combinedAlpha()));
438 mRenderNode->setBrush(brush);
439 mRenderNode->mFlag |= VDrawable::DirtyState::Brush;
443 void LOTSolidLayerItem::renderList(std::vector<VDrawable *> &list)
445 if (!visible()) return;
447 list.push_back(mRenderNode.get());
450 LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
451 : LOTLayerItem(layerData)
454 void LOTNullLayerItem::updateContent() {}
456 LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
457 : LOTLayerItem(layerData)
459 mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
460 mRoot->addChildren(layerData);
462 std::vector<LOTPathDataItem *> list;
463 mRoot->processPaintItems(list);
465 if (layerData->hasPathOperator()) {
467 mRoot->processTrimItems(list);
471 std::unique_ptr<LOTContentItem>
472 LOTShapeLayerItem::createContentItem(LOTData *contentData)
474 switch (contentData->type()) {
475 case LOTData::Type::ShapeGroup: {
476 return std::make_unique<LOTContentGroupItem>(
477 static_cast<LOTShapeGroupData *>(contentData));
480 case LOTData::Type::Rect: {
481 return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
484 case LOTData::Type::Ellipse: {
485 return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
488 case LOTData::Type::Shape: {
489 return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
492 case LOTData::Type::Polystar: {
493 return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
496 case LOTData::Type::Fill: {
497 return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
500 case LOTData::Type::GFill: {
501 return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
504 case LOTData::Type::Stroke: {
505 return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
508 case LOTData::Type::GStroke: {
509 return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
512 case LOTData::Type::Repeater: {
513 return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
516 case LOTData::Type::Trim: {
517 return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
526 void LOTShapeLayerItem::updateContent()
528 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
530 if (mLayerData->hasPathOperator()) {
535 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
537 if (!visible()) return;
538 mRoot->renderList(list);
541 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
546 void LOTContentGroupItem::addChildren(LOTGroupData *data)
550 for (auto &i : data->mChildren) {
551 auto content = LOTShapeLayerItem::createContentItem(i.get());
553 content->setParent(this);
554 mContents.push_back(std::move(content));
558 // keep the content in back-to-front order.
559 std::reverse(mContents.begin(), mContents.end());
562 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
563 float parentAlpha, const DirtyFlag &flag)
565 VMatrix m = parentMatrix;
566 float alpha = parentAlpha;
567 DirtyFlag newFlag = flag;
570 // update the matrix and the flag
571 if ((flag & DirtyFlagBit::Matrix) ||
572 !mData->mTransform->staticMatrix()) {
573 newFlag |= DirtyFlagBit::Matrix;
575 m = mData->mTransform->matrix(frameNo);
577 alpha *= mData->mTransform->opacity(frameNo);
579 if (!vCompare(alpha, parentAlpha)) {
580 newFlag |= DirtyFlagBit::Alpha;
586 for (const auto &content : mContents) {
587 content->update(frameNo, m, alpha, newFlag);
591 void LOTContentGroupItem::applyTrim()
593 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
594 auto content = (*i).get();
595 if (auto trim = dynamic_cast<LOTTrimItem *>(content)) {
597 } else if (auto group = dynamic_cast<LOTContentGroupItem *>(content)) {
603 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
605 for (const auto &content : mContents) {
606 content->renderList(list);
610 void LOTContentGroupItem::processPaintItems(
611 std::vector<LOTPathDataItem *> &list)
613 int curOpCount = list.size();
614 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
615 auto content = (*i).get();
616 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(content)) {
617 // add it to the list
618 list.push_back(pathNode);
619 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(content)) {
620 // the node is a paint data node update the path list of the paint item.
621 paintNode->addPathItems(list, curOpCount);
622 } else if (auto groupNode =
623 dynamic_cast<LOTContentGroupItem *>(content)) {
624 // update the groups node with current list
625 groupNode->processPaintItems(list);
630 void LOTContentGroupItem::processTrimItems(
631 std::vector<LOTPathDataItem *> &list)
633 int curOpCount = list.size();
634 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
635 auto content = (*i).get();
636 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(content)) {
637 // add it to the list
638 list.push_back(pathNode);
639 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(content)) {
640 // the node is a paint data node update the path list of the paint item.
641 trimNode->addPathItems(list, curOpCount);
642 } else if (auto groupNode =
643 dynamic_cast<LOTContentGroupItem *>(content)) {
644 // update the groups node with current list
645 groupNode->processTrimItems(list);
650 void LOTPathDataItem::update(int frameNo, const VMatrix &,
651 float, const DirtyFlag &flag)
653 mPathChanged = false;
655 // 1. update the local path if needed
656 if (hasChanged(frameNo)) {
657 updatePath(mLocalPath, frameNo);
664 // 3. compute the final path with parentMatrix
665 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
670 const VPath & LOTPathDataItem::finalPath()
672 if (mPathChanged || mNeedUpdate) {
673 mFinalPath.clone(mTemp);
674 mFinalPath.transform(static_cast<LOTContentGroupItem *>(parent())->matrix());
679 LOTRectItem::LOTRectItem(LOTRectData *data)
680 : LOTPathDataItem(data->isStatic()), mData(data)
684 void LOTRectItem::updatePath(VPath& path, int frameNo)
686 VPointF pos = mData->mPos.value(frameNo);
687 VPointF size = mData->mSize.value(frameNo);
688 float roundness = mData->mRound.value(frameNo);
689 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
693 path.addRoundRect(r, roundness, roundness, mData->direction());
694 updateCache(frameNo, pos, size, roundness);
697 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
698 : LOTPathDataItem(data->isStatic()), mData(data)
702 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
704 VPointF pos = mData->mPos.value(frameNo);
705 VPointF size = mData->mSize.value(frameNo);
706 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
710 path.addOval(r, mData->direction());
711 updateCache(frameNo, pos, size);
714 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
715 : LOTPathDataItem(data->isStatic()), mData(data)
719 void LOTShapeItem::updatePath(VPath& path, int frameNo)
721 mData->mShape.value(frameNo).toPath(path);
724 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
725 : LOTPathDataItem(data->isStatic()), mData(data)
729 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
731 VPointF pos = mData->mPos.value(frameNo);
732 float points = mData->mPointCount.value(frameNo);
733 float innerRadius = mData->mInnerRadius.value(frameNo);
734 float outerRadius = mData->mOuterRadius.value(frameNo);
735 float innerRoundness = mData->mInnerRoundness.value(frameNo);
736 float outerRoundness = mData->mOuterRoundness.value(frameNo);
737 float rotation = mData->mRotation.value(frameNo);
742 if (mData->mType == LOTPolystarData::PolyType::Star) {
743 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
744 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
746 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
750 m.translate(pos.x(), pos.y()).rotate(rotation);
753 updateCache(frameNo, pos, points, innerRadius, outerRadius,
754 innerRoundness, outerRoundness, rotation);
758 * PaintData Node handling
761 LOTPaintDataItem::LOTPaintDataItem(bool staticContent):mDrawable(std::make_unique<LOTDrawable>()),
762 mStaticContent(staticContent){}
764 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
765 float parentAlpha, const DirtyFlag &flag)
767 mRenderNodeUpdate = true;
768 mParentAlpha = parentAlpha;
772 updateContent(frameNo);
775 void LOTPaintDataItem::updateRenderNode()
778 for (auto &i : mPathItems) {
788 for (auto &i : mPathItems) {
789 mPath.addPath(i->finalPath());
791 mDrawable->setPath(mPath);
793 if (mDrawable->mFlag & VDrawable::DirtyState::Path)
794 mDrawable->mPath = mPath;
798 void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
800 if (mRenderNodeUpdate) {
802 LOTPaintDataItem::updateRenderNode();
803 mRenderNodeUpdate = false;
805 list.push_back(mDrawable.get());
809 void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
811 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
815 LOTFillItem::LOTFillItem(LOTFillData *data)
816 : LOTPaintDataItem(data->isStatic()), mData(data)
820 void LOTFillItem::updateContent(int frameNo)
822 LottieColor c = mData->mColor.value(frameNo);
823 float opacity = mData->opacity(frameNo);
824 mColor = c.toColor(opacity);
825 mFillRule = mData->fillRule();
828 void LOTFillItem::updateRenderNode()
830 VColor color = mColor;
832 color.setAlpha(color.a * parentAlpha());
834 mDrawable->setBrush(brush);
835 mDrawable->setFillRule(mFillRule);
838 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
839 : LOTPaintDataItem(data->isStatic()), mData(data)
843 void LOTGFillItem::updateContent(int frameNo)
845 mData->update(mGradient, frameNo);
846 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
847 mFillRule = mData->fillRule();
850 void LOTGFillItem::updateRenderNode()
852 mDrawable->setBrush(VBrush(mGradient.get()));
853 mDrawable->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()) / 2.0;
888 void LOTStrokeItem::updateRenderNode()
890 VColor color = mColor;
892 color.setAlpha(color.a * parentAlpha());
894 mDrawable->setBrush(brush);
895 float scale = getScale(static_cast<LOTContentGroupItem *>(parent())->matrix());
896 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
898 if (mDashArraySize) {
899 for (int i = 0 ; i < mDashArraySize ; i++)
900 mDashArray[i] *= scale;
901 mDrawable->setDashInfo(mDashArray, mDashArraySize);
905 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
906 : LOTPaintDataItem(data->isStatic()), mData(data)
911 void LOTGStrokeItem::updateContent(int frameNo)
913 mData->update(mGradient, frameNo);
914 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
915 mCap = mData->capStyle();
916 mJoin = mData->joinStyle();
917 mMiterLimit = mData->meterLimit();
918 mWidth = mData->width(frameNo);
919 if (mData->hasDashInfo()) {
920 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
924 void LOTGStrokeItem::updateRenderNode()
926 float scale = getScale(mGradient->mMatrix);
927 mDrawable->setBrush(VBrush(mGradient.get()));
928 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
930 if (mDashArraySize) {
931 for (int i = 0 ; i < mDashArraySize ; i++)
932 mDashArray[i] *= scale;
933 mDrawable->setDashInfo(mDashArray, mDashArraySize);
937 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
939 void LOTTrimItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
940 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
944 if (mCache.mFrameNo == frameNo) return;
946 float start = mData->start(frameNo);
947 float end = mData->end(frameNo);
948 float offset = mData->offset(frameNo);
950 if (!(vCompare(mCache.mStart, start) && vCompare(mCache.mEnd, end) &&
951 vCompare(mCache.mOffset, offset))) {
953 mCache.mStart = start;
955 mCache.mOffset = offset;
957 mCache.mFrameNo = frameNo;
960 void LOTTrimItem::update()
962 // when both path and trim are not dirty
963 if (!(mDirty || pathDirty())) return;
965 //@TODO take the offset and trim type into account.
966 for (auto &i : mPathItems) {
968 pm.setStart(mCache.mStart);
969 pm.setEnd(mCache.mEnd);
970 pm.setOffset(mCache.mOffset);
971 i->updatePath(pm.trim(i->localPath()));
976 void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
978 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
982 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
984 void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
985 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
989 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
991 void LOTDrawable::sync()
993 mCNode.mFlag = ChangeFlagNone;
994 if (mFlag & DirtyState::None) return;
996 if (mFlag & DirtyState::Path) {
997 const std::vector<VPath::Element> &elm = mPath.elements();
998 const std::vector<VPointF> & pts = mPath.points();
999 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
1000 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
1001 mCNode.mPath.elmPtr = elmPtr;
1002 mCNode.mPath.elmCount = elm.size();
1003 mCNode.mPath.ptPtr = ptPtr;
1004 mCNode.mPath.ptCount = 2 * pts.size();
1005 mCNode.mFlag |= ChangeFlagPath;
1008 if (mStroke.enable) {
1009 mCNode.mStroke.width = mStroke.width;
1010 mCNode.mStroke.meterLimit = mStroke.meterLimit;
1011 mCNode.mStroke.enable = 1;
1013 switch (mFillRule) {
1014 case FillRule::EvenOdd:
1015 mCNode.mFillRule = LOTFillRule::FillEvenOdd;
1018 mCNode.mFillRule = LOTFillRule::FillWinding;
1022 switch (mStroke.cap) {
1023 case CapStyle::Flat:
1024 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1026 case CapStyle::Square:
1027 mCNode.mStroke.cap = LOTCapStyle::CapSquare;
1029 case CapStyle::Round:
1030 mCNode.mStroke.cap = LOTCapStyle::CapRound;
1033 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1037 switch (mStroke.join) {
1038 case JoinStyle::Miter:
1039 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1041 case JoinStyle::Bevel:
1042 mCNode.mStroke.join = LOTJoinStyle::JoinBevel;
1044 case JoinStyle::Round:
1045 mCNode.mStroke.join = LOTJoinStyle::JoinRound;
1048 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1052 mCNode.mStroke.dashArray = mStroke.mDash.data();
1053 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1056 mCNode.mStroke.enable = 0;
1059 switch (mBrush.type()) {
1060 case VBrush::Type::Solid:
1061 mCNode.mType = LOTBrushType::BrushSolid;
1062 mCNode.mColor.r = mBrush.mColor.r;
1063 mCNode.mColor.g = mBrush.mColor.g;
1064 mCNode.mColor.b = mBrush.mColor.b;
1065 mCNode.mColor.a = mBrush.mColor.a;
1067 case VBrush::Type::LinearGradient:
1068 mCNode.mType = LOTBrushType::BrushGradient;
1069 mCNode.mGradient.type = LOTGradientType::GradientLinear;
1070 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1071 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1072 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1073 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1075 case VBrush::Type::RadialGradient:
1076 mCNode.mType = LOTBrushType::BrushGradient;
1077 mCNode.mGradient.type = LOTGradientType::GradientRadial;
1078 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1079 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1080 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1081 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1082 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1083 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;