1 #include "lottieitem.h"
9 * 1. time stretch is pre calculated and applied to all the properties of the
10 * lottilayer model and all its children
11 * 2. The frame property could be reversed using,time-reverse layer property in
12 * AE. which means (start frame > endFrame) 3.
15 LOTCompItem::LOTCompItem(LOTModel *model)
16 : mRootModel(model), mUpdateViewBox(false), mCurFrameNo(-1)
18 // 1. build layer item list
19 mCompData = model->mRoot.get();
20 for (auto &i : mCompData->mChildren) {
21 LOTLayerData *layerData = dynamic_cast<LOTLayerData *>(i.get());
23 LOTLayerItem *layerItem = LOTCompItem::createLayerItem(layerData);
25 mLayers.push_back(layerItem);
26 mLayerMap[layerItem->id()] = layerItem;
31 // 2. update parent layer
32 for (auto &i : mLayers) {
33 int id = i->parentId();
35 auto search = mLayerMap.find(id);
36 if (search != mLayerMap.end()) {
37 LOTLayerItem *parentLayer = search->second;
38 i->setParentLayer(parentLayer);
42 // 3. update static property of each layer
43 for (auto &i : mLayers) {
44 i->updateStaticProperty();
47 mViewSize = mCompData->size();
50 LOTCompItem::~LOTCompItem()
52 for (auto &i : mLayers) {
57 LOTLayerItem *LOTCompItem::createLayerItem(LOTLayerData *layerData)
59 switch (layerData->mLayerType) {
60 case LayerType::Precomp: {
61 return new LOTCompLayerItem(layerData);
64 case LayerType::Solid: {
65 return new LOTSolidLayerItem(layerData);
68 case LayerType::Shape: {
69 return new LOTShapeLayerItem(layerData);
72 case LayerType::Null: {
73 return new LOTNullLayerItem(layerData);
82 void LOTCompItem::resize(const VSize &size)
84 if (mViewSize == size) return;
86 mUpdateViewBox = true;
89 VSize LOTCompItem::size() const
94 bool LOTCompItem::update(int frameNo)
96 // check if cached frame is same as requested frame.
97 if (!mUpdateViewBox && (mCurFrameNo == frameNo)) return false;
100 * if viewbox dosen't scale exactly to the viewport
101 * we scale the viewbox keeping AspectRatioPreserved and then align the
102 * viewbox to the viewport using AlignCenter rule.
104 VSize viewPort = mViewSize;
105 VSize viewBox = mCompData->size();
107 float sx = float(viewPort.width()) / viewBox.width();
108 float sy = float(viewPort.height()) / viewBox.height();
109 float scale = fmin(sx, sy);
110 float tx = (viewPort.width() - viewBox.width() * scale) * 0.5;
111 float ty = (viewPort.height() - viewBox.height() * scale) * 0.5;
114 m.scale(scale, scale).translate(tx, ty);
116 // update the layer from back to front
117 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
118 LOTLayerItem *layer = *i;
119 layer->update(frameNo, m, 1.0);
122 mCurFrameNo = frameNo;
123 mUpdateViewBox = false;
127 void LOTCompItem::buildRenderList()
129 mDrawableList.clear();
130 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
131 LOTLayerItem *layer = *i;
132 layer->renderList(mDrawableList);
136 for (auto &i : mDrawableList) {
137 LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
139 mRenderList.push_back(&lotDrawable->mCNode);
143 const std::vector<LOTNode *> &LOTCompItem::renderList() const
148 bool LOTCompItem::render(const LOTBuffer &buffer)
150 VBitmap bitmap((uchar *)buffer.buffer, buffer.width, buffer.height,
151 buffer.bytesPerLine, VBitmap::Format::ARGB32_Premultiplied,
154 /* schedule all preprocess task for this frame at once.
156 for (auto &e : mDrawableList) {
160 VPainter painter(&bitmap);
162 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
163 LOTLayerItem *layer = *i;
164 layer->render(&painter, mask);
170 void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
171 float parentAlpha, const DirtyFlag &flag)
173 if (mData->mShape.isStatic()) {
174 if (mLocalPath.isEmpty()) {
175 mData->mShape.value(frameNo).toPath(mLocalPath);
178 mData->mShape.value(frameNo).toPath(mLocalPath);
180 float opacity = mData->opacity(frameNo);
181 opacity = opacity * parentAlpha;
182 mCombinedAlpha = opacity;
184 VPath path = mLocalPath;
185 path.transform(parentMatrix);
187 mRleTask = VRaster::instance().generateFillInfo(std::move(path), std::move(mRle));
190 VRle LOTMaskItem::rle()
192 if (mRleTask.valid()) {
193 mRle = mRleTask.get();
194 if (!vCompare(mCombinedAlpha, 1.0f))
195 mRle = mRle * (mCombinedAlpha * 255);
196 if (mData->mInv) mRle = ~mRle;
201 void LOTLayerItem::render(VPainter *painter, const VRle &inheritMask)
203 std::vector<VDrawable *> list;
205 VRle mask = inheritMask;
208 mask = maskRle(painter->clipBoundingRect());
210 mask = mask & inheritMask;
213 for (auto &i : list) {
214 painter->setBrush(i->mBrush);
215 if (!mask.isEmpty()) {
216 VRle rle = i->rle() & mask;
217 painter->drawRle(VPoint(), rle);
219 painter->drawRle(VPoint(), i->rle());
224 VRle LOTLayerItem::maskRle(const VRect &clipRect)
227 for (auto &i : mMasks) {
228 switch (i->maskMode()) {
229 case LOTMaskData::Mode::Add: {
230 rle = rle + i->rle();
233 case LOTMaskData::Mode::Substarct: {
234 if (rle.isEmpty() && !clipRect.isEmpty())
235 rle = VRle::toRle(clipRect);
236 rle = rle - i->rle();
239 case LOTMaskData::Mode::Intersect: {
240 rle = rle & i->rle();
250 LOTLayerItem::LOTLayerItem(LOTLayerData *layerData)
251 : mLayerData(layerData),
252 mParentLayer(nullptr),
253 mPrecompLayer(nullptr),
254 mCombinedAlpha(0.0f),
256 mDirtyFlag(DirtyFlagBit::All)
258 if (mLayerData->mHasMask) {
259 for (auto &i : mLayerData->mMasks) {
260 mMasks.push_back(std::make_unique<LOTMaskItem>(i.get()));
265 void LOTLayerItem::updateStaticProperty()
267 if (mParentLayer) mParentLayer->updateStaticProperty();
269 mStatic = mLayerData->isStatic();
270 mStatic = mParentLayer ? (mStatic & mParentLayer->isStatic()) : mStatic;
271 mStatic = mPrecompLayer ? (mStatic & mPrecompLayer->isStatic()) : mStatic;
274 void LOTLayerItem::update(int frameNo, const VMatrix &parentMatrix,
278 // 1. check if the layer is part of the current frame
279 if (!visible()) return;
281 // 2. calculate the parent matrix and alpha
282 VMatrix m = matrix(frameNo);
284 float alpha = parentAlpha * opacity(frameNo);
286 // 6. update the mask
288 for (auto &i : mMasks) i->update(frameNo, m, alpha, mDirtyFlag);
291 // 3. update the dirty flag based on the change
292 if (!mCombinedMatrix.fuzzyCompare(m)) {
293 mDirtyFlag |= DirtyFlagBit::Matrix;
295 if (!vCompare(mCombinedAlpha, alpha)) {
296 mDirtyFlag |= DirtyFlagBit::Alpha;
299 mCombinedAlpha = alpha;
301 // 4. if no parent property change and layer is static then nothing to do.
302 if ((flag() & DirtyFlagBit::None) && isStatic()) return;
304 // 5. update the content of the layer
307 // 6. reset the dirty flag
308 mDirtyFlag = DirtyFlagBit::None;
311 float LOTLayerItem::opacity(int frameNo) const
313 return mLayerData->mTransform->opacity(frameNo);
316 VMatrix LOTLayerItem::matrix(int frameNo) const
319 return mLayerData->mTransform->matrix(frameNo) *
320 mParentLayer->matrix(frameNo);
322 return mLayerData->mTransform->matrix(frameNo);
325 bool LOTLayerItem::visible() const
327 if (frameNo() >= mLayerData->inFrame() &&
328 frameNo() < mLayerData->outFrame())
334 LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
335 : LOTLayerItem(layerModel)
337 for (auto &i : mLayerData->mChildren) {
338 LOTLayerData *layerModel = dynamic_cast<LOTLayerData *>(i.get());
340 LOTLayerItem *layerItem = LOTCompItem::createLayerItem(layerModel);
342 mLayers.push_back(layerItem);
343 mLayerMap[layerItem->id()] = layerItem;
348 // 2. update parent layer
349 for (auto &i : mLayers) {
350 int id = i->parentId();
352 auto search = mLayerMap.find(id);
353 if (search != mLayerMap.end()) {
354 LOTLayerItem *parentLayer = search->second;
355 i->setParentLayer(parentLayer);
358 i->setPrecompLayer(this);
362 void LOTCompLayerItem::updateStaticProperty()
364 LOTLayerItem::updateStaticProperty();
366 for (auto &i : mLayers) {
367 i->updateStaticProperty();
371 void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask)
373 VRle mask = inheritMask;
377 mask = maskRle(painter->clipBoundingRect());
379 mask = mask & inheritMask;
382 for (auto &i : mLayers) {
383 i->render(painter, mask);
387 LOTCompLayerItem::~LOTCompLayerItem()
389 for (auto &i : mLayers) {
394 void LOTCompLayerItem::updateContent()
396 // update the layer from back to front
397 for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
398 LOTLayerItem *layer = *i;
399 layer->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 LOTLayerItem *layer = *i;
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 = new LOTContentGroupItem(nullptr);
460 mRoot->addChildren(layerData);
461 mRoot->processPaintOperation();
462 if (layerData->hasPathOperator()) mRoot->processTrimOperation();
465 LOTShapeLayerItem::~LOTShapeLayerItem()
470 LOTContentItem *LOTShapeLayerItem::createContentItem(LOTData *contentData)
472 switch (contentData->type()) {
473 case LOTData::Type::ShapeGroup: {
474 return new LOTContentGroupItem(
475 static_cast<LOTShapeGroupData *>(contentData));
478 case LOTData::Type::Rect: {
479 return new LOTRectItem(static_cast<LOTRectData *>(contentData));
482 case LOTData::Type::Ellipse: {
483 return new LOTEllipseItem(static_cast<LOTEllipseData *>(contentData));
486 case LOTData::Type::Shape: {
487 return new LOTShapeItem(static_cast<LOTShapeData *>(contentData));
490 case LOTData::Type::Polystar: {
491 return new LOTPolystarItem(static_cast<LOTPolystarData *>(contentData));
494 case LOTData::Type::Fill: {
495 return new LOTFillItem(static_cast<LOTFillData *>(contentData));
498 case LOTData::Type::GFill: {
499 return new LOTGFillItem(static_cast<LOTGFillData *>(contentData));
502 case LOTData::Type::Stroke: {
503 return new LOTStrokeItem(static_cast<LOTStrokeData *>(contentData));
506 case LOTData::Type::GStroke: {
507 return new LOTGStrokeItem(static_cast<LOTGStrokeData *>(contentData));
510 case LOTData::Type::Repeater: {
511 return new LOTRepeaterItem(static_cast<LOTRepeaterData *>(contentData));
514 case LOTData::Type::Trim: {
515 return new LOTTrimItem(static_cast<LOTTrimData *>(contentData));
524 void LOTShapeLayerItem::updateContent()
526 mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
529 void LOTShapeLayerItem::renderList(std::vector<VDrawable *> &list)
531 if (!visible()) return;
532 mRoot->renderList(list);
535 LOTContentGroupItem::LOTContentGroupItem(LOTShapeGroupData *data) : mData(data)
540 void LOTContentGroupItem::addChildren(LOTGroupData *data)
544 for (auto i : data->mChildren) {
545 LOTData * data = i.get();
546 LOTContentItem *content = LOTShapeLayerItem::createContentItem(data);
547 if (content) mContents.push_back(content);
551 LOTContentGroupItem::~LOTContentGroupItem()
553 for (auto i : mContents) {
558 void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
559 float parentAlpha, const DirtyFlag &flag)
561 VMatrix m = parentMatrix;
562 float alpha = parentAlpha;
563 DirtyFlag newFlag = flag;
566 // update the matrix and the flag
567 if ((flag & DirtyFlagBit::Matrix) ||
568 !mData->mTransform->staticMatrix()) {
569 newFlag |= DirtyFlagBit::Matrix;
571 m = mData->mTransform->matrix(frameNo);
573 alpha *= mData->mTransform->opacity(frameNo);
575 if (!vCompare(alpha, parentAlpha)) {
576 newFlag |= DirtyFlagBit::Alpha;
580 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
581 (*i)->update(frameNo, m, alpha, newFlag);
585 void LOTContentGroupItem::renderList(std::vector<VDrawable *> &list)
587 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
588 (*i)->renderList(list);
592 void LOTContentGroupItem::processPaintOperation()
594 std::vector<LOTPaintDataItem *> list;
595 paintOperationHelper(list);
598 void LOTContentGroupItem::paintOperationHelper(
599 std::vector<LOTPaintDataItem *> &list)
601 int curOpCount = list.size();
602 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
604 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
605 // the node is a path data node add the paint operation list to it.
606 pathNode->addPaintOperation(list, curOpCount);
607 } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(child)) {
608 // add it to the paint operation list
609 list.push_back(paintNode);
610 } else if (auto groupNode =
611 dynamic_cast<LOTContentGroupItem *>(child)) {
612 // update the groups node with current list
613 groupNode->paintOperationHelper(list);
616 list.erase(list.begin() + curOpCount, list.end());
619 void LOTPathDataItem::addPaintOperation(std::vector<LOTPaintDataItem *> &list,
622 for (auto paintItem : list) {
623 bool sameGroup = (externalCount-- > 0) ? false : true;
624 mNodeList.push_back(std::make_unique<LOTDrawable>());
625 mRenderList.push_back(
626 LOTRenderNode(this, paintItem, mNodeList.back().get(), sameGroup));
630 void LOTContentGroupItem::processTrimOperation()
632 std::vector<LOTTrimItem *> list;
633 trimOperationHelper(list);
636 void LOTContentGroupItem::trimOperationHelper(std::vector<LOTTrimItem *> &list)
638 int curOpCount = list.size();
639 for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
641 if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
642 // the node is a path data node add the trim operation list to it.
643 pathNode->addTrimOperation(list);
644 } else if (auto trimNode = dynamic_cast<LOTTrimItem *>(child)) {
645 // add it to the trim operation list
646 list.push_back(trimNode);
647 } else if (auto groupNode =
648 dynamic_cast<LOTContentGroupItem *>(child)) {
649 // update the groups node with current list
650 groupNode->trimOperationHelper(list);
653 list.erase(list.begin() + curOpCount, list.end());
656 void LOTPathDataItem::addTrimOperation(std::vector<LOTTrimItem *> &list)
658 for (auto trimItem : list) {
659 mTrimNodeRefs.push_back(trimItem);
663 void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix,
664 float parentAlpha, const DirtyFlag &flag)
668 mPathChanged = false;
669 mCombinedAlpha = parentAlpha;
671 // 1. update the local path if needed
672 if (!(mInit && mStaticPath)) {
673 updatePath(mLocalPath, frameNo);
678 tempPath = mLocalPath;
680 // 2. apply path operation if needed
681 if (mTrimNodeRefs.size() > 0) {
682 // TODO apply more than one trim path if necessary
684 float s = mTrimNodeRefs.front()->getStart(frameNo) / 100.0f;
685 float e = mTrimNodeRefs.front()->getEnd(frameNo) / 100.0f;
688 tempPath = pm.trim(tempPath);
692 // 3. compute the final path with parentMatrix
694 if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
695 mFinalPath.clone(tempPath);
696 mFinalPath.transform(parentMatrix);
700 // 2. update the rendernode list
701 for (const auto &i : mRenderList) {
702 i.drawable->mFlag = VDrawable::DirtyState::None;
703 i.paintNodeRef->updateRenderNode(i.pathNodeRef, i.drawable,
706 i.drawable->mFlag |= VDrawable::DirtyState::Path;
708 if (i.drawable->mFlag & VDrawable::DirtyState::Path)
709 i.drawable->mPath = mFinalPath;
713 void LOTPathDataItem::renderList(std::vector<VDrawable *> &list)
715 for (const auto &i : mRenderList) {
716 list.push_back(i.drawable);
720 VPath LOTPathDataItem::path() const
725 LOTRectItem::LOTRectItem(LOTRectData *data)
726 : LOTPathDataItem(data->isStatic()), mData(data)
730 void LOTRectItem::updatePath(VPath& path, int frameNo)
732 VPointF pos = mData->mPos.value(frameNo);
733 VPointF size = mData->mSize.value(frameNo);
734 float radius = mData->mRound.value(frameNo);
735 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
739 path.addRoundRect(r, radius, radius, mData->direction());
742 LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
743 : LOTPathDataItem(data->isStatic()), mData(data)
747 void LOTEllipseItem::updatePath(VPath& path, int frameNo)
749 VPointF pos = mData->mPos.value(frameNo);
750 VPointF size = mData->mSize.value(frameNo);
751 VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
755 path.addOval(r, mData->direction());
758 LOTShapeItem::LOTShapeItem(LOTShapeData *data)
759 : LOTPathDataItem(data->isStatic()), mData(data)
763 void LOTShapeItem::updatePath(VPath& path, int frameNo)
765 mData->mShape.value(frameNo).toPath(path);
768 LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
769 : LOTPathDataItem(data->isStatic()), mData(data)
773 void LOTPolystarItem::updatePath(VPath& path, int frameNo)
775 VPointF pos = mData->mPos.value(frameNo);
776 float points = mData->mPointCount.value(frameNo);
777 float innerRadius = mData->mInnerRadius.value(frameNo);
778 float outerRadius = mData->mOuterRadius.value(frameNo);
779 float innerRoundness = mData->mInnerRoundness.value(frameNo);
780 float outerRoundness = mData->mOuterRoundness.value(frameNo);
781 float rotation = mData->mRotation.value(frameNo);
786 if (mData->mType == LOTPolystarData::PolyType::Star) {
787 path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
788 outerRoundness, 0.0, 0.0, 0.0, mData->direction());
790 path.addPolygon(points, outerRadius, outerRoundness, 0.0, 0.0, 0.0,
794 m.translate(pos.x(), pos.y()).rotate(rotation);
800 * PaintData Node handling
804 void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
805 float parentAlpha, const DirtyFlag &flag)
807 mContentChanged = false;
808 mParentAlpha = parentAlpha;
809 mParentMatrix = parentMatrix;
812 // 1. update the local content if needed
813 // if (!(mInit && mStaticContent)) {
815 updateContent(frameNo);
816 mContentChanged = true;
820 LOTFillItem::LOTFillItem(LOTFillData *data)
821 : LOTPaintDataItem(data->isStatic()), mData(data)
825 void LOTFillItem::updateContent(int frameNo)
827 LottieColor c = mData->mColor.value(frameNo);
828 float opacity = mData->opacity(frameNo);
829 mColor = c.toColor(opacity);
830 mFillRule = mData->fillRule();
833 void LOTFillItem::updateRenderNode(LOTPathDataItem *pathNode,
834 VDrawable *drawable, bool sameParent)
836 VColor color = mColor;
838 color.setAlpha(color.a * pathNode->combinedAlpha());
840 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
842 drawable->setBrush(brush);
843 drawable->setFillRule(mFillRule);
846 LOTGFillItem::LOTGFillItem(LOTGFillData *data)
847 : LOTPaintDataItem(data->isStatic()), mData(data)
851 void LOTGFillItem::updateContent(int frameNo)
853 mData->update(mGradient, frameNo);
854 mGradient->mMatrix = mParentMatrix;
855 mFillRule = mData->fillRule();
858 void LOTGFillItem::updateRenderNode(LOTPathDataItem *pathNode,
859 VDrawable *drawable, bool sameParent)
861 drawable->setBrush(VBrush(mGradient.get()));
862 drawable->setFillRule(mFillRule);
865 LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
866 : LOTPaintDataItem(data->isStatic()), mData(data)
871 void LOTStrokeItem::updateContent(int frameNo)
873 LottieColor c = mData->mColor.value(frameNo);
874 float opacity = mData->opacity(frameNo);
875 mColor = c.toColor(opacity);
876 mCap = mData->capStyle();
877 mJoin = mData->joinStyle();
878 mMiterLimit = mData->meterLimit();
879 mWidth = mData->width(frameNo);
880 if (mData->hasDashInfo()) {
881 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
885 static float getScale(const VMatrix &matrix)
887 constexpr float SQRT_2 = 1.41421;
889 VPointF p2(SQRT_2, SQRT_2);
892 VPointF final = p2 - p1;
894 return std::sqrt(final.x() * final.x() + final.y() * final.y());
897 void LOTStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
898 VDrawable *drawable, bool sameParent)
900 VColor color = mColor;
902 color.setAlpha(color.a * pathNode->combinedAlpha());
904 color.setAlpha(color.a * parentAlpha() * pathNode->combinedAlpha());
907 drawable->setBrush(brush);
909 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
910 mWidth * getScale(mParentMatrix));
911 if (mDashArraySize) {
912 drawable->setDashInfo(mDashArray, mDashArraySize);
916 LOTGStrokeItem::LOTGStrokeItem(LOTGStrokeData *data)
917 : LOTPaintDataItem(data->isStatic()), mData(data)
922 void LOTGStrokeItem::updateContent(int frameNo)
924 mData->update(mGradient, frameNo);
925 mGradient->mMatrix = mParentMatrix;
926 mCap = mData->capStyle();
927 mJoin = mData->joinStyle();
928 mMiterLimit = mData->meterLimit();
929 mWidth = mData->width(frameNo);
930 if (mData->hasDashInfo()) {
931 mDashArraySize = mData->getDashInfo(frameNo, mDashArray);
935 void LOTGStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
936 VDrawable *drawable, bool sameParent)
938 drawable->setBrush(VBrush(mGradient.get()));
939 drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
940 mWidth * getScale(mParentMatrix));
941 if (mDashArraySize) {
942 drawable->setDashInfo(mDashArray, mDashArraySize);
946 LOTTrimItem::LOTTrimItem(LOTTrimData *data) : mData(data) {}
948 void LOTTrimItem::update(int frameNo, const VMatrix &parentMatrix,
949 float parentAlpha, const DirtyFlag &flag)
953 LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data) {}
955 void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix,
956 float parentAlpha, const DirtyFlag &flag)
960 void LOTRepeaterItem::renderList(std::vector<VDrawable *> &list) {}
962 void LOTDrawable::sync()
964 mCNode.mFlag = ChangeFlagNone;
965 if (mFlag & DirtyState::None) return;
967 if (mFlag & DirtyState::Path) {
968 const std::vector<VPath::Element> &elm = mPath.elements();
969 const std::vector<VPointF> & pts = mPath.points();
970 const float *ptPtr = reinterpret_cast<const float *>(pts.data());
971 const char * elmPtr = reinterpret_cast<const char *>(elm.data());
972 mCNode.mPath.elmPtr = elmPtr;
973 mCNode.mPath.elmCount = elm.size();
974 mCNode.mPath.ptPtr = ptPtr;
975 mCNode.mPath.ptCount = 2 * pts.size();
976 mCNode.mFlag |= ChangeFlagPath;
979 if (mStroke.enable) {
980 mCNode.mStroke.width = mStroke.width;
981 mCNode.mStroke.meterLimit = mStroke.meterLimit;
982 mCNode.mStroke.enable = 1;
985 case FillRule::EvenOdd:
986 mCNode.mFillRule = LOTNode::EvenOdd;
989 mCNode.mFillRule = LOTNode::Winding;
993 switch (mStroke.cap) {
995 mCNode.mStroke.cap = LOTNode::FlatCap;
997 case CapStyle::Square:
998 mCNode.mStroke.cap = LOTNode::SquareCap;
1000 case CapStyle::Round:
1001 mCNode.mStroke.cap = LOTNode::RoundCap;
1004 mCNode.mStroke.cap = LOTNode::FlatCap;
1008 switch (mStroke.join) {
1009 case JoinStyle::Miter:
1010 mCNode.mStroke.join = LOTNode::MiterJoin;
1012 case JoinStyle::Bevel:
1013 mCNode.mStroke.join = LOTNode::BevelJoin;
1015 case JoinStyle::Round:
1016 mCNode.mStroke.join = LOTNode::RoundJoin;
1019 mCNode.mStroke.join = LOTNode::MiterJoin;
1023 mCNode.mStroke.dashArray = mStroke.dashArray;
1024 mCNode.mStroke.dashArraySize = mStroke.dashArraySize;
1027 mCNode.mStroke.enable = 0;
1030 switch (mBrush.type()) {
1031 case VBrush::Type::Solid:
1032 mCNode.mType = LOTNode::BrushSolid;
1033 mCNode.mColor.r = mBrush.mColor.r;
1034 mCNode.mColor.g = mBrush.mColor.g;
1035 mCNode.mColor.b = mBrush.mColor.b;
1036 mCNode.mColor.a = mBrush.mColor.a;
1038 case VBrush::Type::LinearGradient:
1039 mCNode.mType = LOTNode::BrushGradient;
1040 mCNode.mGradient.type = LOTNode::Gradient::Linear;
1041 mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
1042 mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
1043 mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
1044 mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
1046 case VBrush::Type::RadialGradient:
1047 mCNode.mType = LOTNode::BrushGradient;
1048 mCNode.mGradient.type = LOTNode::Gradient::Radial;
1049 mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
1050 mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
1051 mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
1052 mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
1053 mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
1054 mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;