From c0ef6478f75c3bd13d548306c39c92c6e97cce66 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Sat, 18 May 2024 22:14:10 +0400 Subject: [PATCH] Refactoring --- .../Sources/SoftwareLottieRenderer.mm | 90 +------------------ .../Sources/ViewController.swift | 2 +- .../PublicHeaders/LottieCpp/RenderTreeNode.h | 2 - .../Sources/LottieAnimationContainer.mm | 1 - 4 files changed, 3 insertions(+), 92 deletions(-) diff --git a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm index 3b198fae47..e56e5bb349 100644 --- a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm +++ b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm @@ -189,28 +189,15 @@ static void processRenderContentItem(std::shared_ptr return; } - std::optional globalRect; - int drawContentDescendants = 0; - for (const auto &shadingVariant : contentItem->shadings) { - lottie::CGRect shapeBounds = collectPathBoundingBoxes(contentItem, shadingVariant->subItemLimit, lottie::CATransform3D::identity(), true, bezierPathsBoundingBoxContext); - if (shadingVariant->stroke) { - shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0); } else if (shadingVariant->fill) { } else { continue; } drawContentDescendants += 1; - - CGRect shapeGlobalBounds = shapeBounds.applyingTransform(currentTransform); - if (globalRect) { - globalRect = globalRect->unionWith(shapeGlobalBounds); - } else { - globalRect = shapeGlobalBounds; - } } if (contentItem->isGroup) { @@ -220,11 +207,6 @@ static void processRenderContentItem(std::shared_ptr if (subItem->renderData.isValid) { drawContentDescendants += subItem->renderData.drawContentDescendants; - if (globalRect) { - globalRect = globalRect->unionWith(subItem->renderData.globalRect); - } else { - globalRect = subItem->renderData.globalRect; - } } } } else { @@ -233,28 +215,6 @@ static void processRenderContentItem(std::shared_ptr } } - if (!globalRect) { - contentItem->renderData.isValid = false; - return; - } - - CGRect integralGlobalRect( - std::floor(globalRect->x), - std::floor(globalRect->y), - std::ceil(globalRect->width + globalRect->x - floor(globalRect->x)), - std::ceil(globalRect->height + globalRect->y - floor(globalRect->y)) - ); - integralGlobalRect = integralGlobalRect.intersection(CGRect(0.0, 0.0, globalSize.x, globalSize.y)); - - if (!CGRect(0.0, 0.0, globalSize.x, globalSize.y).intersects(integralGlobalRect)) { - contentItem->renderData.isValid = false; - return; - } - if (integralGlobalRect.width <= 0.0 || integralGlobalRect.height <= 0.0) { - contentItem->renderData.isValid = false; - return; - } - contentItem->renderData.isValid = true; contentItem->renderData.layer._bounds = CGRect(0.0, 0.0, 0.0, 0.0); @@ -264,7 +224,6 @@ static void processRenderContentItem(std::shared_ptr contentItem->renderData.layer._masksToBounds = false; contentItem->renderData.layer._isHidden = false; - contentItem->renderData.globalRect = integralGlobalRect; contentItem->renderData.globalTransform = currentTransform; contentItem->renderData.drawContentDescendants = drawContentDescendants; contentItem->renderData.isInvertedMatte = false; @@ -297,56 +256,22 @@ static void processRenderTree(std::shared_ptr const &node, Vecto } int drawContentDescendants = 0; - std::optional globalRect; if (node->_contentItem) { processRenderContentItem(node->_contentItem, globalSize, currentTransform, bezierPathsBoundingBoxContext); if (node->_contentItem->renderData.isValid) { drawContentDescendants += node->_contentItem->renderData.drawContentDescendants; - globalRect = node->_contentItem->renderData.globalRect; } } bool isInvertedMatte = isInvertedMask; - if (isInvertedMatte) { - CGRect globalBounds = node->bounds().applyingTransform(currentTransform); - if (globalRect) { - globalRect = globalRect->unionWith(globalBounds); - } else { - globalRect = globalBounds; - } - } for (const auto &item : node->subnodes()) { processRenderTree(item, globalSize, currentTransform, false, bezierPathsBoundingBoxContext); if (item->renderData.isValid) { drawContentDescendants += item->renderData.drawContentDescendants; - - if (globalRect) { - globalRect = globalRect->unionWith(item->renderData.globalRect); - } else { - globalRect = item->renderData.globalRect; - } } } - if (!globalRect) { - node->renderData.isValid = false; - return; - } - - CGRect integralGlobalRect( - std::floor(globalRect->x), - std::floor(globalRect->y), - std::ceil(globalRect->width + globalRect->x - floor(globalRect->x)), - std::ceil(globalRect->height + globalRect->y - floor(globalRect->y)) - ); - integralGlobalRect = integralGlobalRect.intersection(CGRect(0.0, 0.0, globalSize.x, globalSize.y)); - - if (!CGRect(0.0, 0.0, globalSize.x, globalSize.y).intersects(integralGlobalRect)) { - node->renderData.isValid = false; - return; - } - bool masksToBounds = node->masksToBounds(); if (masksToBounds) { CGRect effectiveGlobalBounds = node->bounds().applyingTransform(currentTransform); @@ -357,22 +282,12 @@ static void processRenderTree(std::shared_ptr const &node, Vecto if (node->mask()) { processRenderTree(node->mask(), globalSize, currentTransform, node->invertMask(), bezierPathsBoundingBoxContext); - if (node->mask()->renderData.isValid) { - if (!node->mask()->renderData.globalRect.intersects(integralGlobalRect)) { - node->renderData.isValid = false; - return; - } - } else { + if (!node->mask()->renderData.isValid) { node->renderData.isValid = false; return; } } - if (integralGlobalRect.width <= 0.0 || integralGlobalRect.height <= 0.0) { - node->renderData.isValid = false; - return; - } - node->renderData.isValid = true; node->renderData.layer._bounds = node->bounds(); @@ -382,7 +297,6 @@ static void processRenderTree(std::shared_ptr const &node, Vecto node->renderData.layer._masksToBounds = masksToBounds; node->renderData.layer._isHidden = node->isHidden(); - node->renderData.globalRect = integralGlobalRect; node->renderData.globalTransform = currentTransform; node->renderData.drawContentDescendants = drawContentDescendants; node->renderData.isInvertedMatte = isInvertedMatte; @@ -664,7 +578,7 @@ static void renderLottieRenderNode(std::shared_ptr node, std::optional globalRect; if (needsTempContext) { globalRect = lottie::getRenderNodeGlobalRect(node, globalSize, bezierPathsBoundingBoxContext); - if (!globalRect) { + if (!globalRect || globalRect->width <= 0.0f || globalRect->height <= 0.0f) { parentContext->restoreState(); return; } diff --git a/Tests/LottieMetalTest/Sources/ViewController.swift b/Tests/LottieMetalTest/Sources/ViewController.swift index da7d22c2b2..b8464a9117 100644 --- a/Tests/LottieMetalTest/Sources/ViewController.swift +++ b/Tests/LottieMetalTest/Sources/ViewController.swift @@ -78,7 +78,7 @@ private final class ReferenceCompareTest { } var continueFromName: String? - //continueFromName = "569118802063655905.json" + //continueFromName = "1471004892762996754.json" let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in if let continueFromNameValue = continueFromName { diff --git a/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h b/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h index e504de3175..9b26390a23 100644 --- a/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h +++ b/submodules/TelegramUI/Components/LottieCpp/PublicHeaders/LottieCpp/RenderTreeNode.h @@ -74,7 +74,6 @@ public: false, false ), - globalRect(CGRect(0.0, 0.0, 0.0, 0.0)), globalTransform(CATransform3D::identity()), drawContentDescendants(false), isInvertedMatte(false) { @@ -83,7 +82,6 @@ public: bool isValid = false; LayerParams layer; - CGRect globalRect; CATransform3D globalTransform; int drawContentDescendants; bool isInvertedMatte; diff --git a/submodules/TelegramUI/Components/LottieCpp/Sources/LottieAnimationContainer.mm b/submodules/TelegramUI/Components/LottieCpp/Sources/LottieAnimationContainer.mm index d155af122e..283a1cdf0f 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/LottieAnimationContainer.mm +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/LottieAnimationContainer.mm @@ -64,7 +64,6 @@ result.layer.masksToBounds = node->renderData.layer._masksToBounds; result.layer.isHidden = node->renderData.layer._isHidden; - result.globalRect = CGRectMake(node->renderData.globalRect.x, node->renderData.globalRect.y, node->renderData.globalRect.width, node->renderData.globalRect.height); result.globalTransform = lottie::nativeTransform(node->renderData.globalTransform); result.hasSimpleContents = node->renderData.drawContentDescendants <= 1; result.drawContentDescendants = node->renderData.drawContentDescendants;