Lottie: optimization

This commit is contained in:
Isaac 2024-05-09 01:15:45 +04:00
parent 58a1caf9df
commit 99e93aadd1
4 changed files with 145 additions and 162 deletions

View File

@ -77,7 +77,8 @@ private final class ReferenceCompareTest {
let _ = await cacheReferenceAnimation(baseCachePath: baseCachePath, width: sizeMapping[fileName] ?? defaultSize, path: filePath, name: fileName) let _ = await cacheReferenceAnimation(baseCachePath: baseCachePath, width: sizeMapping[fileName] ?? defaultSize, path: filePath, name: fileName)
} }
var continueFromName: String? = "5138957708585599529.json" var continueFromName: String?
//continueFromName = "1258816259754282.json"
let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in
if let continueFromNameValue = continueFromName { if let continueFromNameValue = continueFromName {

View File

@ -102,19 +102,6 @@ public:
virtual std::shared_ptr<RenderTreeNode> renderTreeNode() override { virtual std::shared_ptr<RenderTreeNode> renderTreeNode() override {
if (!_renderTreeNode) { if (!_renderTreeNode) {
_renderTreeNode = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0),
CATransform3D::identity(),
1.0,
false,
false,
nullptr,
std::vector<std::shared_ptr<RenderTreeNode>>(),
nullptr,
false
);
_contentsTreeNode = std::make_shared<RenderTreeNode>( _contentsTreeNode = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0), CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0), Vector2D(0.0, 0.0),
@ -127,11 +114,9 @@ public:
nullptr, nullptr,
false false
); );
}
if (_contentsLayer->isHidden()) { std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
return nullptr; subnodes.push_back(_contentsTreeNode);
}
std::shared_ptr<RenderTreeNode> maskNode; std::shared_ptr<RenderTreeNode> maskNode;
bool invertMask = false; bool invertMask = false;
@ -142,58 +127,20 @@ public:
} }
} }
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue; _renderTreeNode = std::make_shared<RenderTreeNode>(
auto renderTreeContentItem = renderTree(); CGRect(0.0, 0.0, 0.0, 0.0),
if (renderTreeContentItem) { Vector2D(0.0, 0.0),
renderTreeValue.push_back(renderTreeContentItem); CATransform3D::identity(),
} 1.0,
false,
std::vector<std::shared_ptr<RenderTreeNode>> subnodes; false,
_contentsTreeNode->_bounds = _contentsLayer->bounds();
_contentsTreeNode->_position = _contentsLayer->position();
_contentsTreeNode->_transform = _contentsLayer->transform();
_contentsTreeNode->_alpha = _contentsLayer->opacity();
_contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds();
_contentsTreeNode->_isHidden = _contentsLayer->isHidden();
_contentsTreeNode->_subnodes = renderTreeValue;
subnodes.push_back(_contentsTreeNode);
/*subnodes.push_back(std::make_shared<RenderTreeNode>(
_contentsLayer->bounds(),
_contentsLayer->position(),
_contentsLayer->transform(),
_contentsLayer->opacity(),
_contentsLayer->masksToBounds(),
_contentsLayer->isHidden(),
nullptr, nullptr,
renderTreeValue, subnodes,
nullptr, maskNode,
false invertMask
));*/ );
assert(opacity() == 1.0);
assert(!isHidden());
assert(!masksToBounds());
assert(transform().isIdentity());
assert(position() == Vector2D::Zero());
_renderTreeNode->_bounds = bounds();
_renderTreeNode->_position = position();
_renderTreeNode->_transform = transform();
_renderTreeNode->_alpha = opacity();
_renderTreeNode->_masksToBounds = masksToBounds();
_renderTreeNode->_isHidden = isHidden();
_renderTreeNode->_subnodes = subnodes;
_renderTreeNode->_mask = maskNode;
_renderTreeNode->_invertMask = invertMask;
return _renderTreeNode;
}
std::shared_ptr<RenderTreeNode> renderTree() {
std::vector<std::shared_ptr<RenderTreeNode>> result;
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeSubnodes;
for (const auto &animationLayer : _animationLayers) { for (const auto &animationLayer : _animationLayers) {
bool found = false; bool found = false;
for (const auto &sublayer : contentsLayer()->sublayers()) { for (const auto &sublayer : contentsLayer()->sublayers()) {
@ -205,13 +152,13 @@ public:
if (found) { if (found) {
auto node = animationLayer->renderTreeNode(); auto node = animationLayer->renderTreeNode();
if (node) { if (node) {
result.push_back(node); renderTreeSubnodes.push_back(node);
} }
} }
} }
std::vector<std::shared_ptr<RenderTreeNode>> subnodes; std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue;
return std::make_shared<RenderTreeNode>( auto renderTreeContentItem = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0), CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0), Vector2D(0.0, 0.0),
CATransform3D::identity(), CATransform3D::identity(),
@ -219,10 +166,18 @@ public:
false, false,
false, false,
nullptr, nullptr,
result, renderTreeSubnodes,
nullptr, nullptr,
false false
); );
if (renderTreeContentItem) {
renderTreeValue.push_back(renderTreeContentItem);
}
_contentsTreeNode->_subnodes = renderTreeValue;
}
return _renderTreeNode;
} }
virtual void updateRenderTree() override { virtual void updateRenderTree() override {
@ -242,6 +197,26 @@ public:
animationLayer->updateRenderTree(); animationLayer->updateRenderTree();
} }
} }
assert(opacity() == 1.0);
assert(!isHidden());
assert(!masksToBounds());
assert(transform().isIdentity());
assert(position() == Vector2D::Zero());
_contentsTreeNode->_bounds = _contentsLayer->bounds();
_contentsTreeNode->_position = _contentsLayer->position();
_contentsTreeNode->_transform = _contentsLayer->transform();
_contentsTreeNode->_alpha = _contentsLayer->opacity();
_contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds();
_contentsTreeNode->_isHidden = _contentsLayer->isHidden();
_renderTreeNode->_bounds = bounds();
_renderTreeNode->_position = position();
_renderTreeNode->_transform = transform();
_renderTreeNode->_alpha = opacity();
_renderTreeNode->_masksToBounds = masksToBounds();
_renderTreeNode->_isHidden = isHidden();
} }
private: private:

View File

@ -1295,19 +1295,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
} }
if (!_renderTreeNode) { if (!_renderTreeNode) {
_renderTreeNode = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0),
CATransform3D::identity(),
1.0,
false,
false,
nullptr,
std::vector<std::shared_ptr<RenderTreeNode>>(),
nullptr,
false
);
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue; std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue;
renderTreeValue.push_back(_contentTree->itemTree->renderTree()); renderTreeValue.push_back(_contentTree->itemTree->renderTree());
@ -1323,7 +1310,9 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
nullptr, nullptr,
false false
); );
}
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
subnodes.push_back(_contentsTreeNode);
std::shared_ptr<RenderTreeNode> maskNode; std::shared_ptr<RenderTreeNode> maskNode;
bool invertMask = false; bool invertMask = false;
@ -1334,6 +1323,28 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
} }
} }
_renderTreeNode = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0),
CATransform3D::identity(),
1.0,
false,
false,
nullptr,
subnodes,
maskNode,
invertMask
);
}
return _renderTreeNode;
}
void ShapeCompositionLayer::updateRenderTree() {
if (_matteLayer) {
_matteLayer->updateRenderTree();
}
_contentsTreeNode->_bounds = _contentsLayer->bounds(); _contentsTreeNode->_bounds = _contentsLayer->bounds();
_contentsTreeNode->_position = _contentsLayer->position(); _contentsTreeNode->_position = _contentsLayer->position();
_contentsTreeNode->_transform = _contentsLayer->transform(); _contentsTreeNode->_transform = _contentsLayer->transform();
@ -1341,9 +1352,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
_contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds(); _contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds();
_contentsTreeNode->_isHidden = _contentsLayer->isHidden(); _contentsTreeNode->_isHidden = _contentsLayer->isHidden();
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
subnodes.push_back(_contentsTreeNode);
assert(position() == Vector2D::Zero()); assert(position() == Vector2D::Zero());
assert(transform().isIdentity()); assert(transform().isIdentity());
assert(opacity() == 1.0); assert(opacity() == 1.0);
@ -1359,14 +1367,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
_renderTreeNode->_alpha = opacity(); _renderTreeNode->_alpha = opacity();
_renderTreeNode->_masksToBounds = masksToBounds(); _renderTreeNode->_masksToBounds = masksToBounds();
_renderTreeNode->_isHidden = isHidden(); _renderTreeNode->_isHidden = isHidden();
_renderTreeNode->_subnodes = subnodes;
_renderTreeNode->_mask = maskNode;
_renderTreeNode->_invertMask = invertMask;
return _renderTreeNode;
}
void ShapeCompositionLayer::updateRenderTree() {
} }
} }

View File

@ -219,6 +219,7 @@ public:
} }
virtual std::shared_ptr<RenderTreeNode> renderTreeNode() { virtual std::shared_ptr<RenderTreeNode> renderTreeNode() {
if (!_renderTreeNode) {
std::vector<std::shared_ptr<RenderTreeNode>> subnodes; std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
for (const auto &animationLayer : _animationLayers) { for (const auto &animationLayer : _animationLayers) {
bool found = false; bool found = false;
@ -235,8 +236,7 @@ public:
} }
} }
} }
_renderTreeNode = std::make_shared<RenderTreeNode>(
return std::make_shared<RenderTreeNode>(
bounds(), bounds(),
position(), position(),
CATransform3D::identity(), CATransform3D::identity(),
@ -250,7 +250,12 @@ public:
); );
} }
virtual void updateRenderTree() { updateRenderTree();
return _renderTreeNode;
}
void updateRenderTree() {
for (const auto &animationLayer : _animationLayers) { for (const auto &animationLayer : _animationLayers) {
bool found = false; bool found = false;
for (const auto &sublayer : sublayers()) { for (const auto &sublayer : sublayers()) {
@ -282,6 +287,8 @@ private:
std::shared_ptr<LayerImageProvider> _layerImageProvider; std::shared_ptr<LayerImageProvider> _layerImageProvider;
std::shared_ptr<LayerTextProvider> _layerTextProvider; std::shared_ptr<LayerTextProvider> _layerTextProvider;
std::shared_ptr<LayerFontProvider> _layerFontProvider; std::shared_ptr<LayerFontProvider> _layerFontProvider;
std::shared_ptr<RenderTreeNode> _renderTreeNode;
}; };
} }