}
}
-LOTCompItem::LOTCompItem(LOTModel *model)
- : mCurFrameNo(-1)
-{
- mCompData = model->mRoot.get();
- mRootLayer = createLayerItem(mCompData->mRootLayer.get());
- mRootLayer->setComplexContent(false);
- mViewSize = mCompData->size();
-}
-
-void LOTCompItem::setValue(const std::string &keypath, LOTVariant &value)
-{
- LOTKeyPath key(keypath);
- mRootLayer->resolveKeyPath(key, 0, value);
-}
-
-std::unique_ptr<LOTLayerItem> LOTCompItem::createLayerItem(
- LOTLayerData *layerData)
+static LOTLayerItem*
+createLayerItem(LOTLayerData *layerData, VArenaAlloc *allocator)
{
switch (layerData->mLayerType) {
case LayerType::Precomp: {
- return std::make_unique<LOTCompLayerItem>(layerData);
+ return allocator->make<LOTCompLayerItem>(layerData, allocator);
}
case LayerType::Solid: {
- return std::make_unique<LOTSolidLayerItem>(layerData);
+ return allocator->make<LOTSolidLayerItem>(layerData);
}
case LayerType::Shape: {
- return std::make_unique<LOTShapeLayerItem>(layerData);
+ return allocator->make<LOTShapeLayerItem>(layerData, allocator);
}
case LayerType::Null: {
- return std::make_unique<LOTNullLayerItem>(layerData);
+ return allocator->make<LOTNullLayerItem>(layerData);
}
case LayerType::Image: {
- return std::make_unique<LOTImageLayerItem>(layerData);
+ return allocator->make<LOTImageLayerItem>(layerData);
}
default:
return nullptr;
}
}
+LOTCompItem::LOTCompItem(LOTModel *model)
+ : mCurFrameNo(-1)
+{
+ mCompData = model->mRoot.get();
+ mRootLayer = createLayerItem(mCompData->mRootLayer.get(), &mAllocator);
+ mRootLayer->setComplexContent(false);
+ mViewSize = mCompData->size();
+}
+
+void LOTCompItem::setValue(const std::string &keypath, LOTVariant &value)
+{
+ LOTKeyPath key(keypath);
+ mRootLayer->resolveKeyPath(key, 0, value);
+}
+
bool LOTCompItem::update(int frameNo, const VSize &size, bool keepAspectRatio)
{
// check if cached frame is same as requested frame.
preprocessStage(clip);
}
-LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
+LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel, VArenaAlloc* allocator)
: LOTLayerItem(layerModel)
{
if (!mLayerData->mChildren.empty())
for (auto it = mLayerData->mChildren.crbegin();
it != mLayerData->mChildren.rend(); ++it ) {
auto model = static_cast<LOTLayerData *>((*it).get());
- auto item = LOTCompItem::createLayerItem(model);
- if (item) mLayers.push_back(std::move(item));
+ auto item = createLayerItem(model, allocator);
+ if (item) mLayers.push_back(item);
}
// 2. update parent layer
auto search =
std::find_if(mLayers.begin(), mLayers.end(),
[id](const auto &val) { return val->id() == id; });
- if (search != mLayers.end()) layer->setParentLayer((*search).get());
+ if (search != mLayers.end()) layer->setParentLayer(*search);
}
}
LOTLayerItem *matte = nullptr;
for (const auto &layer : mLayers) {
if (layer->hasMatte()) {
- matte = layer.get();
+ matte = layer;
} else {
if (layer->visible()) {
if (matte) {
if (matte->visible())
renderMatteLayer(painter, mask, matteRle, matte,
- layer.get());
+ layer);
} else {
layer->render(painter, mask, matteRle);
}
LOTLayerItem *matte = nullptr;
for (const auto &layer : mLayers) {
if (layer->hasMatte()) {
- matte = layer.get();
+ matte = layer;
} else {
if (layer->visible()) {
if (matte) {
}
void LOTNullLayerItem::updateContent() {}
-LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData)
- : LOTLayerItem(layerData),
- mRoot(std::make_unique<LOTContentGroupItem>(nullptr))
-{
- mRoot->addChildren(layerData);
-
- std::vector<LOTPathDataItem *> list;
- mRoot->processPaintItems(list);
-
- if (layerData->hasPathOperator()) {
- list.clear();
- mRoot->processTrimItems(list);
- }
-}
-
-std::unique_ptr<LOTContentItem> LOTShapeLayerItem::createContentItem(
- LOTData *contentData)
+static LOTContentItem*
+createContentItem(LOTData *contentData, VArenaAlloc* allocator)
{
switch (contentData->type()) {
case LOTData::Type::ShapeGroup: {
- return std::make_unique<LOTContentGroupItem>(
- static_cast<LOTGroupData *>(contentData));
+ return allocator->make<LOTContentGroupItem>(
+ static_cast<LOTGroupData *>(contentData), allocator);
}
case LOTData::Type::Rect: {
- return std::make_unique<LOTRectItem>(
+ return allocator->make<LOTRectItem>(
static_cast<LOTRectData *>(contentData));
}
case LOTData::Type::Ellipse: {
- return std::make_unique<LOTEllipseItem>(
+ return allocator->make<LOTEllipseItem>(
static_cast<LOTEllipseData *>(contentData));
}
case LOTData::Type::Shape: {
- return std::make_unique<LOTShapeItem>(
+ return allocator->make<LOTShapeItem>(
static_cast<LOTShapeData *>(contentData));
}
case LOTData::Type::Polystar: {
- return std::make_unique<LOTPolystarItem>(
+ return allocator->make<LOTPolystarItem>(
static_cast<LOTPolystarData *>(contentData));
}
case LOTData::Type::Fill: {
- return std::make_unique<LOTFillItem>(
+ return allocator->make<LOTFillItem>(
static_cast<LOTFillData *>(contentData));
}
case LOTData::Type::GFill: {
- return std::make_unique<LOTGFillItem>(
+ return allocator->make<LOTGFillItem>(
static_cast<LOTGFillData *>(contentData));
}
case LOTData::Type::Stroke: {
- return std::make_unique<LOTStrokeItem>(
+ return allocator->make<LOTStrokeItem>(
static_cast<LOTStrokeData *>(contentData));
}
case LOTData::Type::GStroke: {
- return std::make_unique<LOTGStrokeItem>(
+ return allocator->make<LOTGStrokeItem>(
static_cast<LOTGStrokeData *>(contentData));
}
case LOTData::Type::Repeater: {
- return std::make_unique<LOTRepeaterItem>(
- static_cast<LOTRepeaterData *>(contentData));
+ return allocator->make<LOTRepeaterItem>(
+ static_cast<LOTRepeaterData *>(contentData), allocator);
}
case LOTData::Type::Trim: {
- return std::make_unique<LOTTrimItem>(
+ return allocator->make<LOTTrimItem>(
static_cast<LOTTrimData *>(contentData));
}
default:
}
}
+LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData, VArenaAlloc* allocator)
+ : LOTLayerItem(layerData),
+ mRoot(allocator->make<LOTContentGroupItem>(nullptr, allocator))
+{
+ mRoot->addChildren(layerData, allocator);
+
+ std::vector<LOTPathDataItem *> list;
+ mRoot->processPaintItems(list);
+
+ if (layerData->hasPathOperator()) {
+ list.clear();
+ mRoot->processTrimItems(list);
+ }
+}
+
void LOTShapeLayerItem::updateContent()
{
mRoot->update(frameNo(), combinedMatrix(), combinedAlpha(), flag());
return false;
}
-LOTContentGroupItem::LOTContentGroupItem(LOTGroupData *data)
+LOTContentGroupItem::LOTContentGroupItem(LOTGroupData *data, VArenaAlloc* allocator)
: mData(data)
{
- addChildren(mData);
+ addChildren(mData, allocator);
}
-void LOTContentGroupItem::addChildren(LOTGroupData *data)
+void LOTContentGroupItem::addChildren(LOTGroupData *data, VArenaAlloc* allocator)
{
if (!data) return;
// as lottie model keeps it in front-to-back order.
for (auto it = data->mChildren.crbegin(); it != data->mChildren.rend();
++it ) {
- auto content = LOTShapeLayerItem::createContentItem((*it).get());
+ auto content = createContentItem((*it).get(), allocator);
if (content) {
- mContents.push_back(std::move(content));
+ mContents.push_back(content);
}
}
}
void LOTContentGroupItem::applyTrim()
{
for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
- auto content = (*i).get();
+ auto content = (*i);
switch (content->type()) {
case ContentType::Trim: {
static_cast<LOTTrimItem *>(content)->update();
{
size_t curOpCount = list.size();
for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
- auto content = (*i).get();
+ auto content = (*i);
switch (content->type()) {
case ContentType::Path: {
auto pathItem = static_cast<LOTPathDataItem *>(content);
{
size_t curOpCount = list.size();
for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
- auto content = (*i).get();
+ auto content = (*i);
switch (content->type()) {
case ContentType::Path: {
back_inserter(mPathItems));
}
-LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mRepeaterData(data)
+LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data, VArenaAlloc* allocator) : mRepeaterData(data)
{
assert(mRepeaterData->content());
for (int i = 0; i < mCopies; i++) {
auto content =
- std::make_unique<LOTContentGroupItem>(mRepeaterData->content());
+ allocator->make<LOTContentGroupItem>(mRepeaterData->content(), allocator);
//content->setParent(this);
- mContents.push_back(std::move(content));
+ mContents.push_back(content);
}
}
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include"vpainter.h"
#include"vdrawable.h"
#include"lottiekeypath.h"
+#include"varenaalloc.h"
V_USE_NAMESPACE
{
public:
explicit LOTCompItem(LOTModel *model);
- static std::unique_ptr<LOTLayerItem> createLayerItem(LOTLayerData *layerData);
bool update(int frameNo, const VSize &size, bool keepAspectRatio);
VSize size() const { return mViewSize;}
void buildRenderTree();
VMatrix mScaleMatrix;
VSize mViewSize;
LOTCompositionData *mCompData;
- std::unique_ptr<LOTLayerItem> mRootLayer;
+ LOTLayerItem *mRootLayer;
+ VArenaAlloc mAllocator{2048};
int mCurFrameNo;
bool mKeepAspectRatio{true};
};
class LOTCompLayerItem: public LOTLayerItem
{
public:
- explicit LOTCompLayerItem(LOTLayerData *layerData);
+ explicit LOTCompLayerItem(LOTLayerData *layerData, VArenaAlloc* allocator);
void render(VPainter *painter, const VRle &mask, const VRle &matteRle) final;
void buildLayerNode() final;
void renderMatteLayer(VPainter *painter, const VRle &inheritMask, const VRle &matteRle,
LOTLayerItem *layer, LOTLayerItem *src);
private:
- std::vector<std::unique_ptr<LOTLayerItem>> mLayers;
- std::unique_ptr<LOTClipperItem> mClipper;
+ std::vector<LOTLayerItem*> mLayers;
+ std::unique_ptr<LOTClipperItem> mClipper;
};
class LOTSolidLayerItem: public LOTLayerItem
class LOTShapeLayerItem: public LOTLayerItem
{
public:
- explicit LOTShapeLayerItem(LOTLayerData *layerData);
- static std::unique_ptr<LOTContentItem> createContentItem(LOTData *contentData);
+ explicit LOTShapeLayerItem(LOTLayerData *layerData, VArenaAlloc* allocator);
DrawableList renderList() final;
void buildLayerNode() final;
bool resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value) override;
void preprocessStage(const VRect& clip) final;
void updateContent() final;
std::vector<VDrawable *> mDrawableList;
- std::unique_ptr<LOTContentGroupItem> mRoot;
+ LOTContentGroupItem *mRoot;
};
class LOTNullLayerItem: public LOTLayerItem
class LOTContentGroupItem: public LOTContentItem
{
public:
- explicit LOTContentGroupItem(LOTGroupData *data=nullptr);
- void addChildren(LOTGroupData *data);
+ LOTContentGroupItem() = default;
+ explicit LOTContentGroupItem(LOTGroupData *data, VArenaAlloc* allocator);
+ void addChildren(LOTGroupData *data, VArenaAlloc* allocator);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) override;
void applyTrim();
void processTrimItems(std::vector<LOTPathDataItem *> &list);
bool resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value) override;
protected:
LOTGroupData *mData{nullptr};
- std::vector<std::unique_ptr<LOTContentItem>> mContents;
+ std::vector<LOTContentItem*> mContents;
VMatrix mMatrix;
};
class LOTRepeaterItem : public LOTContentGroupItem
{
public:
- explicit LOTRepeaterItem(LOTRepeaterData *data);
+ explicit LOTRepeaterItem(LOTRepeaterData *data, VArenaAlloc* allocator);
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
void renderList(std::vector<VDrawable *> &list) final;
private: