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)
162 if (!visible()) return;
166 mDrawableList.clear();
167 matteSource->renderList(mDrawableList);
168 for (auto &i : mDrawableList) {
169 matteRle = matteRle + i->rle();
172 if (!inheritMatte.isEmpty())
173 matteRle = matteRle & inheritMatte;
175 matteRle = inheritMatte;
177 mDrawableList.clear();
178 renderList(mDrawableList);
182 mask = maskRle(painter->clipBoundingRect());
183 if (!inheritMask.isEmpty())
184 mask = mask & inheritMask;
185 // if resulting mask is empty then return.
192 for (auto &i : mDrawableList) {
193 painter->setBrush(i->mBrush);
195 if (!mask.isEmpty()) rle = rle & mask;
197 if (rle.isEmpty()) continue;
199 if (!matteRle.isEmpty()) {
200 if (mLayerData->mMatteType == MatteType::AlphaInv) {
201 rle = rle - matteRle;
203 rle = rle & matteRle;
206 painter->drawRle(VPoint(), rle);
210 VRle LOTLayerItem::maskRle(const VRect &clipRect)
213 for (auto &i : mMasks) {
214 switch (i->maskMode()) {
215 case LOTMaskData::Mode::Add: {
216 rle = rle + i->rle();
219 case LOTMaskData::Mode::Substarct: {
220 if (rle.isEmpty() && !clipRect.isEmpty())
221 rle = VRle::toRle(clipRect);
222 rle = rle - i->rle();
225 case LOTMaskData::Mode::Intersect: {
226 rle = rle & i->rle();
229 case LOTMaskData::Mode::Difference: {
230 rle = rle ^ i->rle();
240 LOTLayerItem::LOTLayerItem(LOTLayerData *layerData): mLayerData(layerData)
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)
353 if (!visible()) return;
357 mDrawableList.clear();
358 matteSource->renderList(mDrawableList);
359 for (auto &i : mDrawableList) {
360 matteRle = matteRle + i->rle();
363 if (!inheritMatte.isEmpty())
364 matteRle = matteRle & inheritMatte;
366 matteRle = inheritMatte;
371 mask = maskRle(painter->clipBoundingRect());
372 if (!inheritMask.isEmpty())
373 mask = mask & inheritMask;
374 // if resulting mask is empty then return.
381 LOTLayerItem *matteLayer = nullptr;
382 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
383 LOTLayerItem *layer = (*i).get();
385 if (!matteLayer && layer->hasMatte()) {
391 matteLayer->render(painter, mask, matteRle, layer);
392 matteLayer = nullptr;
394 layer->render(painter, mask, matteRle, nullptr);
399 void LOTCompLayerItem::updateContent()
401 // update the layer from back to front
402 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
403 (*i)->update(frameNo(), combinedMatrix(), combinedAlpha());
407 void LOTCompLayerItem::renderList(std::vector<VDrawable *> &list)
409 if (!visible()) return;
411 // update the layer from back to front
412 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
413 (*i)->renderList(list);
417 LOTSolidLayerItem::LOTSolidLayerItem(LOTLayerData *layerData)
418 : LOTLayerItem(layerData)
422 void LOTSolidLayerItem::updateContent()
425 mRenderNode = std::make_unique<LOTDrawable>();
426 mRenderNode->mType = VDrawable::Type::Fill;
427 mRenderNode->mFlag |= VDrawable::DirtyState::All;
430 if (flag() & DirtyFlagBit::Matrix) {
433 VRectF(0, 0, mLayerData->solidWidth(), mLayerData->solidHeight()));
434 path.transform(combinedMatrix());
435 mRenderNode->mFlag |= VDrawable::DirtyState::Path;
436 mRenderNode->mPath = path;
438 if (flag() & DirtyFlagBit::Alpha) {
439 LottieColor color = mLayerData->solidColor();
440 VBrush brush(color.toColor(combinedAlpha()));
441 mRenderNode->setBrush(brush);
442 mRenderNode->mFlag |= VDrawable::DirtyState::Brush;
446 void LOTSolidLayerItem::renderList(std::vector<VDrawable *> &list)
448 if (!visible()) return;
450 list.push_back(mRenderNode.get());
453 LOTNullLayerItem::LOTNullLayerItem(LOTLayerData *layerData)
454 : LOTLayerItem(layerData)
457 void LOTNullLayerItem::updateContent() {}
459 LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
460 : LOTLayerItem(layerData)
462 mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
463 mRoot->addChildren(layerData);
465 std::vector<LOTPathDataItem *> list;
466 mRoot->processPaintItems(list);
468 if (layerData->hasPathOperator()) {
470 mRoot->processTrimItems(list);
474 std::unique_ptr<LOTContentItem>
475 LOTShapeLayerItem::createContentItem(LOTData *contentData)
477 switch (contentData->type()) {
478 case LOTData::Type::ShapeGroup: {
479 return std::make_unique<LOTContentGroupItem>(
480 static_cast<LOTShapeGroupData *>(contentData));
483 case LOTData::Type::Rect: {
484 return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
487 case LOTData::Type::Ellipse: {
488 return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
491 case LOTData::Type::Shape: {
492 return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
495 case LOTData::Type::Polystar: {
496 return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
499 case LOTData::Type::Fill: {
500 return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
503 case LOTData::Type::GFill: {
504 return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
507 case LOTData::Type::Stroke: {
508 return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
511 case LOTData::Type::GStroke: {
512 return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
515 case LOTData::Type::Repeater: {
516 return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
519 case LOTData::Type::Trim: {
520 return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(contentData));
529 void LOTShapeLayerItem::updateContent()
531 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
533 if (mLayerData->hasPathOperator()) {
538 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
540 if (!visible()) return;
541 mRoot->renderList(list);
544 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
549 void LOTContentGroupItem::addChildren(LOTGroupData *data)
553 for (auto &i : data->mChildren) {
554 auto content = LOTShapeLayerItem::createContentItem(i.get());
556 content->setParent(this);
557 mContents.push_back(std::move(content));
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 (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
587 (*i)->update(frameNo, m, alpha, newFlag);
591 void LOTContentGroupItem::applyTrim()
593 for (auto &i : mContents) {
594 if (auto trim = dynamic_cast<LOTTrimItem *>(i.get())) {
596 } else if (auto group = dynamic_cast<LOTContentGroupItem *>(i.get())) {
602 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
604 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
605 (*i)->renderList(list);
609 void LOTContentGroupItem::processPaintItems(
610 std::vector<LOTPathDataItem *> &list)
612 int curOpCount = list.size();
613 for (auto &i : mContents) {
614 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
615 // add it to the list
616 list.push_back(pathNode);
617 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(i.get())) {
618 // the node is a paint data node update the path list of the paint item.
619 paintNode->addPathItems(list, curOpCount);
620 } else if (auto groupNode =
621 dynamic_cast<LOTContentGroupItem *>(i.get())) {
622 // update the groups node with current list
623 groupNode->processPaintItems(list);
628 void LOTContentGroupItem::processTrimItems(
629 std::vector<LOTPathDataItem *> &list)
631 int curOpCount = list.size();
632 for (auto &i : mContents) {
633 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
634 // add it to the list
635 list.push_back(pathNode);
636 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(i.get())) {
637 // the node is a paint data node update the path list of the paint item.
638 trimNode->addPathItems(list, curOpCount);
639 } else if (auto groupNode =
640 dynamic_cast<LOTContentGroupItem *>(i.get())) {
641 // update the groups node with current list
642 groupNode->processTrimItems(list);
647 void LOTPathDataItem::update(int frameNo, const VMatrix &,
648 float, const DirtyFlag &flag)
650 mPathChanged = false;
652 // 1. update the local path if needed
653 if (hasChanged(frameNo)) {
654 updatePath(mLocalPath, frameNo);
661 // 3. compute the final path with parentMatrix
662 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
667 const VPath & LOTPathDataItem::finalPath()
669 if (mPathChanged || mNeedUpdate) {
670 mFinalPath.clone(mTemp);
671 mFinalPath.transform(static_cast<LOTContentGroupItem *>(parent())->matrix());
676 LOTRectItem::LOTRectItem(LOTRectData *data)
677 : LOTPathDataItem(data->isStatic()), mData(data)
681 void LOTRectItem::updatePath(VPath& path, int frameNo)
683 VPointF pos = mData->mPos.value(frameNo);
684 VPointF size = mData->mSize.value(frameNo);
685 float roundness = mData->mRound.value(frameNo);
686 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
690 path.addRoundRect(r, roundness, roundness, mData->direction());
691 updateCache(frameNo, pos, size, roundness);
694 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
695 : LOTPathDataItem(data->isStatic()), mData(data)
699 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
701 VPointF pos = mData->mPos.value(frameNo);
702 VPointF size = mData->mSize.value(frameNo);
703 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
707 path.addOval(r, mData->direction());
708 updateCache(frameNo, pos, size);
711 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
712 : LOTPathDataItem(data->isStatic()), mData(data)
716 void LOTShapeItem::updatePath(VPath& path, int frameNo)
718 mData->mShape.value(frameNo).toPath(path);
721 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
722 : LOTPathDataItem(data->isStatic()), mData(data)
726 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
728 VPointF pos = mData->mPos.value(frameNo);
729 float points = mData->mPointCount.value(frameNo);
730 float innerRadius = mData->mInnerRadius.value(frameNo);
731 float outerRadius = mData->mOuterRadius.value(frameNo);
732 float innerRoundness = mData->mInnerRoundness.value(frameNo);
733 float outerRoundness = mData->mOuterRoundness.value(frameNo);
734 float rotation = mData->mRotation.value(frameNo);
739 if (mData->mType == LOTPolystarData::PolyType::Star) {
740 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
741 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
743 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
747 m.translate(pos.x(), pos.y()).rotate(rotation);
750 updateCache(frameNo, pos, points, innerRadius, outerRadius,
751 innerRoundness, outerRoundness, rotation);
755 * PaintData Node handling
758 LOTPaintDataItem::LOTPaintDataItem(bool staticContent):mDrawable(std::make_unique<LOTDrawable>()),
759 mStaticContent(staticContent){}
761 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
762 float parentAlpha, const DirtyFlag &flag)
764 mRenderNodeUpdate = true;
765 mParentAlpha = parentAlpha;
769 updateContent(frameNo);
772 void LOTPaintDataItem::updateRenderNode()
775 for (auto &i : mPathItems) {
785 for (auto &i : mPathItems) {
786 mPath.addPath(i->finalPath());
788 mDrawable->setPath(mPath);
790 if (mDrawable->mFlag & VDrawable::DirtyState::Path)
791 mDrawable->mPath = mPath;
795 void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
797 if (mRenderNodeUpdate) {
799 LOTPaintDataItem::updateRenderNode();
800 mRenderNodeUpdate = false;
802 list.push_back(mDrawable.get());
806 void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
808 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
812 LOTFillItem::LOTFillItem(LOTFillData *data)
813 : LOTPaintDataItem(data->isStatic()), mData(data)
817 void LOTFillItem::updateContent(int frameNo)
819 LottieColor c = mData->mColor.value(frameNo);
820 float opacity = mData->opacity(frameNo);
821 mColor = c.toColor(opacity);
822 mFillRule = mData->fillRule();
825 void LOTFillItem::updateRenderNode()
827 VColor color = mColor;
829 color.setAlpha(color.a * parentAlpha());
831 mDrawable->setBrush(brush);
832 mDrawable->setFillRule(mFillRule);
835 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
836 : LOTPaintDataItem(data->isStatic()), mData(data)
840 void LOTGFillItem::updateContent(int frameNo)
842 mData->update(mGradient, frameNo);
843 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
844 mFillRule = mData->fillRule();
847 void LOTGFillItem::updateRenderNode()
849 mDrawable->setBrush(VBrush(mGradient.get()));
850 mDrawable->setFillRule(mFillRule);
853 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
854 : LOTPaintDataItem(data->isStatic()), mData(data)
859 void LOTStrokeItem::updateContent(int frameNo)
861 LottieColor c = mData->mColor.value(frameNo);
862 float opacity = mData->opacity(frameNo);
863 mColor = c.toColor(opacity);
864 mCap = mData->capStyle();
865 mJoin = mData->joinStyle();
866 mMiterLimit = mData->meterLimit();
867 mWidth = mData->width(frameNo);
868 if (mData->hasDashInfo()) {
869 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
873 static float getScale(const VMatrix &matrix)
875 constexpr float SQRT_2 = 1.41421;
877 VPointF p2(SQRT_2, SQRT_2);
880 VPointF final = p2 - p1;
882 return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0;
885 void LOTStrokeItem::updateRenderNode()
887 VColor color = mColor;
889 color.setAlpha(color.a * parentAlpha());
891 mDrawable->setBrush(brush);
892 float scale = getScale(static_cast<LOTContentGroupItem *>(parent())->matrix());
893 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
895 if (mDashArraySize) {
896 for (int i = 0 ; i < mDashArraySize ; i++)
897 mDashArray[i] *= scale;
898 mDrawable->setDashInfo(mDashArray, mDashArraySize);
902 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
903 : LOTPaintDataItem(data->isStatic()), mData(data)
908 void LOTGStrokeItem::updateContent(int frameNo)
910 mData->update(mGradient, frameNo);
911 mGradient->mMatrix = static_cast<LOTContentGroupItem *>(parent())->matrix();
912 mCap = mData->capStyle();
913 mJoin = mData->joinStyle();
914 mMiterLimit = mData->meterLimit();
915 mWidth = mData->width(frameNo);
916 if (mData->hasDashInfo()) {
917 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
921 void LOTGStrokeItem::updateRenderNode()
923 float scale = getScale(mGradient->mMatrix);
924 mDrawable->setBrush(VBrush(mGradient.get()));
925 mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
927 if (mDashArraySize) {
928 for (int i = 0 ; i < mDashArraySize ; i++)
929 mDashArray[i] *= scale;
930 mDrawable->setDashInfo(mDashArray, mDashArraySize);
934 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
936 void LOTTrimItem::update(int frameNo, const VMatrix &/*parentMatrix*/,
937 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
941 if (mCache.mFrameNo == frameNo) return;
943 float start = mData->start(frameNo);
944 float end = mData->end(frameNo);
945 float offset = mData->offset(frameNo);
947 if (!(vCompare(mCache.mStart, start) && vCompare(mCache.mEnd, end) &&
948 vCompare(mCache.mOffset, offset))) {
950 mCache.mStart = start;
952 mCache.mOffset = offset;
954 mCache.mFrameNo = frameNo;
957 void LOTTrimItem::update()
959 // when both path and trim are not dirty
960 if (!(mDirty || pathDirty())) return;
962 //@TODO take the offset and trim type into account.
963 for (auto &i : mPathItems) {
965 pm.setStart(mCache.mStart);
966 pm.setEnd(mCache.mEnd);
967 pm.setOffset(mCache.mOffset);
968 i->updatePath(pm.trim(i->localPath()));
973 void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOffset)
975 std::copy(list.begin() + startOffset, list.end(), back_inserter(mPathItems));
979 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
981 void LOTRepeaterItem::update(int /*frameNo*/, const VMatrix &/*parentMatrix*/,
982 float /*parentAlpha*/, const DirtyFlag &/*flag*/)
986 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
988 void LOTDrawable::sync()
990 mCNode.mFlag = ChangeFlagNone;
991 if (mFlag & DirtyState::None) return;
993 if (mFlag & DirtyState::Path) {
994 const std::vector<VPath::Element> &elm = mPath.elements();
995 const std::vector<VPointF> & pts = mPath.points();
996 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
997 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
998 mCNode.mPath.elmPtr = elmPtr;
999 mCNode.mPath.elmCount = elm.size();
1000 mCNode.mPath.ptPtr = ptPtr;
1001 mCNode.mPath.ptCount = 2 * pts.size();
1002 mCNode.mFlag |= ChangeFlagPath;
1005 if (mStroke.enable) {
1006 mCNode.mStroke.width = mStroke.width;
1007 mCNode.mStroke.meterLimit = mStroke.meterLimit;
1008 mCNode.mStroke.enable = 1;
1010 switch (mFillRule) {
1011 case FillRule::EvenOdd:
1012 mCNode.mFillRule = LOTFillRule::FillEvenOdd;
1015 mCNode.mFillRule = LOTFillRule::FillWinding;
1019 switch (mStroke.cap) {
1020 case CapStyle::Flat:
1021 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1023 case CapStyle::Square:
1024 mCNode.mStroke.cap = LOTCapStyle::CapSquare;
1026 case CapStyle::Round:
1027 mCNode.mStroke.cap = LOTCapStyle::CapRound;
1030 mCNode.mStroke.cap = LOTCapStyle::CapFlat;
1034 switch (mStroke.join) {
1035 case JoinStyle::Miter:
1036 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1038 case JoinStyle::Bevel:
1039 mCNode.mStroke.join = LOTJoinStyle::JoinBevel;
1041 case JoinStyle::Round:
1042 mCNode.mStroke.join = LOTJoinStyle::JoinRound;
1045 mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
1049 mCNode.mStroke.dashArray = mStroke.mDash.data();
1050 mCNode.mStroke.dashArraySize = mStroke.mDash.size();
1053 mCNode.mStroke.enable = 0;
1056 switch (mBrush.type()) {
1057 case VBrush::Type::Solid:
1058 mCNode.mType = LOTBrushType::BrushSolid;
1059 mCNode.mColor.r = mBrush.mColor.r;
1060 mCNode.mColor.g = mBrush.mColor.g;
1061 mCNode.mColor.b = mBrush.mColor.b;
1062 mCNode.mColor.a = mBrush.mColor.a;
1064 case VBrush::Type::LinearGradient:
1065 mCNode.mType = LOTBrushType::BrushGradient;
1066 mCNode.mGradient.type = LOTGradientType::GradientLinear;
1067 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1068 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1069 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1070 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1072 case VBrush::Type::RadialGradient:
1073 mCNode.mType = LOTBrushType::BrushGradient;
1074 mCNode.mGradient.type = LOTGradientType::GradientRadial;
1075 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1076 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1077 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1078 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1079 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1080 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;