LOTCompItem::LOTCompItem(LOTModel *model)
: mRootModel(model), mUpdateViewBox(false), mCurFrameNo(-1)
{
- // 1. build layer item list
mCompData = model->mRoot.get();
- for (auto &i : mCompData->mChildren) {
- LOTLayerData *layerData = dynamic_cast<LOTLayerData *>(i.get());
- if (layerData) {
- LOTLayerItem *layerItem = LOTCompItem::createLayerItem(layerData);
- if (layerItem) {
- mLayers.push_back(layerItem);
- mLayerMap[layerItem->id()] = layerItem;
- }
- }
- }
-
- // 2. update parent layer
- for (auto &i : mLayers) {
- int id = i->parentId();
- if (id >= 0) {
- auto search = mLayerMap.find(id);
- if (search != mLayerMap.end()) {
- LOTLayerItem *parentLayer = search->second;
- i->setParentLayer(parentLayer);
- }
- }
- }
- // 3. update static property of each layer
- for (auto &i : mLayers) {
- i->updateStaticProperty();
- }
-
+ mRootLayer = std::unique_ptr<LOTLayerItem>(createLayerItem(mCompData->mRootLayer.get()));
+ mRootLayer->updateStaticProperty();
mViewSize = mCompData->size();
}
-LOTCompItem::~LOTCompItem()
-{
- for (auto &i : mLayers) {
- delete i;
- }
-}
-
LOTLayerItem *LOTCompItem::createLayerItem(LOTLayerData *layerData)
{
switch (layerData->mLayerType) {
VMatrix m;
m.scale(scale, scale).translate(tx, ty);
+ mRootLayer->update(frameNo, m, 1.0);
- // update the layer from back to front
- for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
- LOTLayerItem *layer = *i;
- layer->update(frameNo, m, 1.0);
- }
buildRenderList();
mCurFrameNo = frameNo;
mUpdateViewBox = false;
void LOTCompItem::buildRenderList()
{
mDrawableList.clear();
- for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
- LOTLayerItem *layer = *i;
- layer->renderList(mDrawableList);
- }
+ mRootLayer->renderList(mDrawableList);
mRenderList.clear();
for (auto &i : mDrawableList) {
VPainter painter(&bitmap);
VRle mask;
- for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
- LOTLayerItem *layer = *i;
- layer->render(&painter, mask);
- }
+ mRootLayer->render(&painter, mask);
return true;
}
{
public:
LOTCompItem(LOTModel *model);
- ~LOTCompItem();
static LOTLayerItem * createLayerItem(LOTLayerData *layerData);
bool update(int frameNo);
void resize(const VSize &size);
VSize mViewSize;
LOTModel *mRootModel;
LOTCompositionData *mCompData;
- std::vector<LOTLayerItem *> mLayers;
- std::unordered_map<int, LOTLayerItem *> mLayerMap;
+ std::unique_ptr<LOTLayerItem> mRootLayer;
bool mUpdateViewBox;
int mCurFrameNo;
std::vector<LOTNode *> mRenderList;
}
}
resolveLayerRefs();
- // update the static property of Composition
- bool staticFlag = true;
- for (auto child : comp->mChildren) {
- staticFlag &= child.get()->isStatic();
- }
- comp->setStatic(staticFlag);
+ comp->setStatic(comp->mRootLayer->isStatic());
+ comp->mRootLayer->mInFrame = comp->mStartFrame;
+ comp->mRootLayer->mOutFrame = comp->mEndFrame;
mComposition = sharedComposition;
}
return sharedAsset;
}
-void LottieParserImpl::parseLayers(LOTCompositionData *composition)
+void LottieParserImpl::parseLayers(LOTCompositionData *comp)
{
+ comp->mRootLayer = std::make_shared<LOTLayerData>();
+ comp->mRootLayer->mLayerType = LayerType::Precomp;
+ comp->mRootLayer->mTransform = std::make_shared<LOTTransformData>();
+ bool staticFlag = true;
RAPIDJSON_ASSERT(PeekType() == kArrayType);
EnterArray();
while (NextArrayValue()) {
std::shared_ptr<LOTData> layer = parseLayer();
- composition->mChildren.push_back(layer);
+ staticFlag &= layer->isStatic();
+ comp->mRootLayer->mChildren.push_back(layer);
}
+ comp->mRootLayer->setStatic(staticFlag);
}
LottieColor LottieParserImpl::toColor(const char *str)