{
mRoot = std::make_unique<LOTContentGroupItem>(nullptr);
mRoot->addChildren(layerData);
- mRoot->processPaintOperation();
+
+ std::vector<LOTPathDataItem *> list;
+ mRoot->processPathItems(list);
+
if (layerData->hasPathOperator()) mRoot->processTrimOperation();
}
}
}
-void LOTContentGroupItem::processPaintOperation()
-{
- std::vector<LOTPaintDataItem *> list;
- paintOperationHelper(list);
-}
-
-void LOTContentGroupItem::paintOperationHelper(
- std::vector<LOTPaintDataItem *> &list)
+void LOTContentGroupItem::processPathItems(
+ std::vector<LOTPathDataItem *> &list)
{
int curOpCount = list.size();
- for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
- auto child = (*i).get();
- if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
- // the node is a path data node add the paint operation list to it.
- pathNode->addPaintOperation(list, curOpCount);
- } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(child)) {
- // add it to the paint operation list
- list.push_back(paintNode);
+ for (auto &i : mContents) {
+ if (auto pathNode = dynamic_cast<LOTPathDataItem *>(i.get())) {
+ // add it to the list
+ list.push_back(pathNode);
+ } else if (auto paintNode = dynamic_cast<LOTPaintDataItem *>(i.get())) {
+ // the node is a paint data node update the path list of the paint item.
+ paintNode->addPathItems(list);
} else if (auto groupNode =
- dynamic_cast<LOTContentGroupItem *>(child)) {
+ dynamic_cast<LOTContentGroupItem *>(i.get())) {
// update the groups node with current list
- groupNode->paintOperationHelper(list);
+ groupNode->processPathItems(list);
}
}
list.erase(list.begin() + curOpCount, list.end());
}
-void LOTPathDataItem::addPaintOperation(std::vector<LOTPaintDataItem *> &list,
- int externalCount)
-{
- for (auto paintItem : list) {
- bool sameGroup = (externalCount-- > 0) ? false : true;
- mNodeList.push_back(std::make_unique<LOTDrawable>());
- mRenderList.push_back(
- LOTRenderNode(this, paintItem, mNodeList.back().get(), sameGroup));
- }
-}
-
void LOTContentGroupItem::processTrimOperation()
{
std::vector<LOTTrimItem *> list;
mFinalPath.transform(parentMatrix);
mPathChanged = true;
}
-
- // 2. update the rendernode list
- for (const auto &i : mRenderList) {
- i.drawable->mFlag = VDrawable::DirtyState::None;
- i.paintNodeRef->updateRenderNode(i.pathNodeRef, i.drawable,
- i.sameGroup);
- if (mPathChanged)
- i.drawable->mFlag |= VDrawable::DirtyState::Path;
-
- if (i.drawable->mFlag & VDrawable::DirtyState::Path)
- i.drawable->mPath = mFinalPath;
- }
-}
-
-void LOTPathDataItem::renderList(std::vector<VDrawable *> &list)
-{
- for (const auto &i : mRenderList) {
- list.push_back(i.drawable);
- }
-}
-
-VPath LOTPathDataItem::path() const
-{
- return mFinalPath;
}
LOTRectItem::LOTRectItem(LOTRectData *data)
* PaintData Node handling
*
*/
+LOTPaintDataItem::LOTPaintDataItem(bool staticContent):mDrawable(std::make_unique<LOTDrawable>()),
+ mStaticContent(staticContent){}
void LOTPaintDataItem::update(int frameNo, const VMatrix &parentMatrix,
float parentAlpha, const DirtyFlag &flag)
{
- mContentChanged = false;
+ mRenderNodeUpdate = true;
mParentAlpha = parentAlpha;
mParentMatrix = parentMatrix;
mFlag = flag;
mFrameNo = frameNo;
- // 1. update the local content if needed
- // if (!(mInit && mStaticContent)) {
- mInit = true;
+
updateContent(frameNo);
- mContentChanged = true;
- // }
}
+void LOTPaintDataItem::updateRenderNode()
+{
+ bool dirty = false;
+ for (auto &i : mPathItems) {
+ if (i->dirty()) {
+ dirty = true;
+ break;
+ }
+ }
+
+ if (dirty) {
+ mPath.reset();
+
+ for (auto &i : mPathItems) {
+ mPath.addPath(i->path());
+ }
+ mDrawable->setPath(mPath);
+ } else {
+ if (mDrawable->mFlag & VDrawable::DirtyState::Path)
+ mDrawable->mPath = mPath;
+ }
+}
+
+void LOTPaintDataItem::renderList(std::vector<VDrawable *> &list)
+{
+ if (mRenderNodeUpdate) {
+ updateRenderNode();
+ LOTPaintDataItem::updateRenderNode();
+ mRenderNodeUpdate = false;
+ }
+ list.push_back(mDrawable.get());
+}
+
+
+void LOTPaintDataItem::addPathItems(std::vector<LOTPathDataItem *> &list)
+{
+ mPathItems = list;
+}
+
+
LOTFillItem::LOTFillItem(LOTFillData *data)
: LOTPaintDataItem(data->isStatic()), mData(data)
{
mFillRule = mData->fillRule();
}
-void LOTFillItem::updateRenderNode(LOTPathDataItem *pathNode,
- VDrawable *drawable, bool sameParent)
+void LOTFillItem::updateRenderNode()
{
VColor color = mColor;
color.setAlpha(color.a * parentAlpha());
VBrush brush(color);
- drawable->setBrush(brush);
- drawable->setFillRule(mFillRule);
+ mDrawable->setBrush(brush);
+ mDrawable->setFillRule(mFillRule);
}
LOTGFillItem::LOTGFillItem(LOTGFillData *data)
mFillRule = mData->fillRule();
}
-void LOTGFillItem::updateRenderNode(LOTPathDataItem */*pathNode*/,
- VDrawable *drawable, bool /*sameParent*/)
+void LOTGFillItem::updateRenderNode()
{
- drawable->setBrush(VBrush(mGradient.get()));
- drawable->setFillRule(mFillRule);
+ mDrawable->setBrush(VBrush(mGradient.get()));
+ mDrawable->setFillRule(mFillRule);
}
LOTStrokeItem::LOTStrokeItem(LOTStrokeData *data)
return std::sqrt(final.x() * final.x() + final.y() * final.y());
}
-void LOTStrokeItem::updateRenderNode(LOTPathDataItem *pathNode,
- VDrawable *drawable, bool sameParent)
+void LOTStrokeItem::updateRenderNode()
{
VColor color = mColor;
color.setAlpha(color.a * parentAlpha());
VBrush brush(color);
- drawable->setBrush(brush);
+ mDrawable->setBrush(brush);
float scale = getScale(mParentMatrix);
- drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
+ mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
mWidth * scale);
if (mDashArraySize) {
for (int i = 0 ; i < mDashArraySize ; i++)
mDashArray[i] *= scale;
- drawable->setDashInfo(mDashArray, mDashArraySize);
+ mDrawable->setDashInfo(mDashArray, mDashArraySize);
}
}
}
}
-void LOTGStrokeItem::updateRenderNode(LOTPathDataItem */*pathNode*/,
- VDrawable *drawable, bool /*sameParent*/)
+void LOTGStrokeItem::updateRenderNode()
{
float scale = getScale(mParentMatrix);
- drawable->setBrush(VBrush(mGradient.get()));
- drawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
+ mDrawable->setBrush(VBrush(mGradient.get()));
+ mDrawable->setStrokeInfo(mCap, mJoin, mMiterLimit,
mWidth * scale);
if (mDashArraySize) {
for (int i = 0 ; i < mDashArraySize ; i++)
mDashArray[i] *= scale;
- drawable->setDashInfo(mDashArray, mDashArraySize);
+ mDrawable->setDashInfo(mDashArray, mDashArraySize);
}
}
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
void processPaintOperation();
void processTrimOperation();
+ void processPathItems(std::vector<LOTPathDataItem *> &list);
void renderList(std::vector<VDrawable *> &list) final;
private:
void paintOperationHelper(std::vector<LOTPaintDataItem *> &list);
LOTPathDataItem(bool staticPath):mInit(false), mStaticPath(staticPath){}
void addPaintOperation(std::vector<LOTPaintDataItem *> &list, int externalCount);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
- VPath path() const;
void addTrimOperation(std::vector<LOTTrimItem *> &list);
- void renderList(std::vector<VDrawable *> &list) final;
+ bool dirty() const {return mPathChanged;}
+ const VPath &path()const {return mFinalPath;}
private:
std::vector<LOTTrimItem *> mTrimNodeRefs;
- std::vector<LOTRenderNode> mRenderList;
- std::vector<std::unique_ptr<VDrawable>> mNodeList;
bool mInit;
bool mStaticPath;
- VPath mLocalPath;
- VPath mFinalPath;
- bool mPathChanged;
+ VPath mLocalPath;
+ VPath mFinalPath;
+ bool mPathChanged{true};
protected:
virtual void updatePath(VPath& path, int frameNo) = 0;
virtual bool hasChanged(int frameNo) = 0;
class LOTPaintDataItem : public LOTContentItem
{
public:
- LOTPaintDataItem(bool staticContent):mInit(false), mStaticContent(staticContent){}
+ LOTPaintDataItem(bool staticContent);
+ void addPathItems(std::vector<LOTPathDataItem *> &list);
virtual void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
- virtual void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) = 0;
+ void renderList(std::vector<VDrawable *> &list) final;
protected:
virtual void updateContent(int frameNo) = 0;
+ virtual void updateRenderNode();
inline float parentAlpha() const {return mParentAlpha;}
- inline bool contentChanged() const{return mContentChanged;}
public:
- float mParentAlpha;
- VMatrix mParentMatrix;
- DirtyFlag mFlag;
- int mFrameNo;
- bool mInit;
- bool mStaticContent;
- bool mContentChanged;
+ float mParentAlpha;
+ VMatrix mParentMatrix;
+ VPath mPath;
+ DirtyFlag mFlag;
+ int mFrameNo;
+ std::vector<LOTPathDataItem *> mPathItems;
+ std::unique_ptr<VDrawable> mDrawable;
+ bool mStaticContent;
+ bool mRenderNodeUpdate{true};
};
class LOTFillItem : public LOTPaintDataItem
LOTFillItem(LOTFillData *data);
protected:
void updateContent(int frameNo) final;
- void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
+ void updateRenderNode() final;
private:
LOTFillData *mData;
VColor mColor;
LOTGFillItem(LOTGFillData *data);
protected:
void updateContent(int frameNo) final;
- void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
+ void updateRenderNode() final;
private:
LOTGFillData *mData;
std::unique_ptr<VGradient> mGradient;
LOTStrokeItem(LOTStrokeData *data);
protected:
void updateContent(int frameNo) final;
- void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
+ void updateRenderNode() final;
private:
LOTStrokeData *mData;
CapStyle mCap;
LOTGStrokeItem(LOTGStrokeData *data);
protected:
void updateContent(int frameNo) final;
- void updateRenderNode(LOTPathDataItem *pathNode, VDrawable *renderer, bool sameParent) final;
+ void updateRenderNode() final;
private:
LOTGStrokeData *mData;
std::unique_ptr<VGradient> mGradient;