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)
}
var continueFromName: String? = "5138957708585599529.json"
var continueFromName: String?
//continueFromName = "1258816259754282.json"
let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in
if let continueFromNameValue = continueFromName {

View File

@ -102,19 +102,6 @@ public:
virtual std::shared_ptr<RenderTreeNode> renderTreeNode() override {
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>(
CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0),
@ -127,11 +114,9 @@ public:
nullptr,
false
);
}
if (_contentsLayer->isHidden()) {
return nullptr;
}
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
subnodes.push_back(_contentsTreeNode);
std::shared_ptr<RenderTreeNode> maskNode;
bool invertMask = false;
@ -142,58 +127,20 @@ public:
}
}
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue;
auto renderTreeContentItem = renderTree();
if (renderTreeContentItem) {
renderTreeValue.push_back(renderTreeContentItem);
}
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
_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(),
_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,
renderTreeValue,
nullptr,
false
));*/
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;
subnodes,
maskNode,
invertMask
);
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeSubnodes;
for (const auto &animationLayer : _animationLayers) {
bool found = false;
for (const auto &sublayer : contentsLayer()->sublayers()) {
@ -205,13 +152,13 @@ public:
if (found) {
auto node = animationLayer->renderTreeNode();
if (node) {
result.push_back(node);
renderTreeSubnodes.push_back(node);
}
}
}
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
return std::make_shared<RenderTreeNode>(
std::vector<std::shared_ptr<RenderTreeNode>> renderTreeValue;
auto renderTreeContentItem = std::make_shared<RenderTreeNode>(
CGRect(0.0, 0.0, 0.0, 0.0),
Vector2D(0.0, 0.0),
CATransform3D::identity(),
@ -219,10 +166,18 @@ public:
false,
false,
nullptr,
result,
renderTreeSubnodes,
nullptr,
false
);
if (renderTreeContentItem) {
renderTreeValue.push_back(renderTreeContentItem);
}
_contentsTreeNode->_subnodes = renderTreeValue;
}
return _renderTreeNode;
}
virtual void updateRenderTree() override {
@ -242,6 +197,26 @@ public:
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:

View File

@ -1295,19 +1295,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::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;
renderTreeValue.push_back(_contentTree->itemTree->renderTree());
@ -1323,7 +1310,9 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
nullptr,
false
);
}
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
subnodes.push_back(_contentsTreeNode);
std::shared_ptr<RenderTreeNode> maskNode;
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->_position = _contentsLayer->position();
_contentsTreeNode->_transform = _contentsLayer->transform();
@ -1341,9 +1352,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
_contentsTreeNode->_masksToBounds = _contentsLayer->masksToBounds();
_contentsTreeNode->_isHidden = _contentsLayer->isHidden();
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
subnodes.push_back(_contentsTreeNode);
assert(position() == Vector2D::Zero());
assert(transform().isIdentity());
assert(opacity() == 1.0);
@ -1359,14 +1367,6 @@ std::shared_ptr<RenderTreeNode> ShapeCompositionLayer::renderTreeNode() {
_renderTreeNode->_alpha = opacity();
_renderTreeNode->_masksToBounds = masksToBounds();
_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() {
if (!_renderTreeNode) {
std::vector<std::shared_ptr<RenderTreeNode>> subnodes;
for (const auto &animationLayer : _animationLayers) {
bool found = false;
@ -235,8 +236,7 @@ public:
}
}
}
return std::make_shared<RenderTreeNode>(
_renderTreeNode = std::make_shared<RenderTreeNode>(
bounds(),
position(),
CATransform3D::identity(),
@ -250,7 +250,12 @@ public:
);
}
virtual void updateRenderTree() {
updateRenderTree();
return _renderTreeNode;
}
void updateRenderTree() {
for (const auto &animationLayer : _animationLayers) {
bool found = false;
for (const auto &sublayer : sublayers()) {
@ -282,6 +287,8 @@ private:
std::shared_ptr<LayerImageProvider> _layerImageProvider;
std::shared_ptr<LayerTextProvider> _layerTextProvider;
std::shared_ptr<LayerFontProvider> _layerFontProvider;
std::shared_ptr<RenderTreeNode> _renderTreeNode;
};
}