From ea4a2032856420f4fd852bbed67a50a6ed22921c Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Tue, 14 May 2024 23:05:11 +0400 Subject: [PATCH] Lottie optimization --- .../Sources/SoftwareLottieRenderer.mm | 89 +++---------------- .../Sources/ViewController.swift | 2 +- .../CompLayers/ShapeCompositionLayer.cpp | 2 +- 3 files changed, 15 insertions(+), 78 deletions(-) diff --git a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm index 9b2842b96b..dfe2fbafbf 100644 --- a/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm +++ b/Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm @@ -38,55 +38,27 @@ static void processRenderTree(std::shared_ptr const &node, Vecto double alpha = node->alpha(); - /*if (node->_contentItem) { + if (node->_contentItem) { RenderTreeNodeContentItem *contentItem = node->_contentItem.get(); for (const auto &shadingVariant : contentItem->shadings) { + CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value()); if (shadingVariant->stroke) { - CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value()); shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0); - effectiveLocalBounds = shapeBounds; - - switch (shadingVariant->stroke->shading->type()) { - case RenderTreeNodeContent::ShadingType::Solid: { - RenderTreeNodeContent::SolidShading *solidShading = (RenderTreeNodeContent::SolidShading *)shadingVariant->stroke->shading.get(); - - alpha *= solidShading->opacity; - - break; - } - case RenderTreeNodeContent::ShadingType::Gradient: { - - break; - } - default: - break; + if (effectiveLocalBounds) { + effectiveLocalBounds = effectiveLocalBounds->unionWith(shapeBounds); + } else { + effectiveLocalBounds = shapeBounds; } } else if (shadingVariant->fill) { - CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value()); - effectiveLocalBounds = shapeBounds; - - switch (shadingVariant->fill->shading->type()) { - case RenderTreeNodeContent::ShadingType::Solid: { - RenderTreeNodeContent::SolidShading *solidShading = (RenderTreeNodeContent::SolidShading *)shadingVariant->fill->shading.get(); - - alpha *= solidShading->opacity; - - break; - } - case RenderTreeNodeContent::ShadingType::Gradient: { - RenderTreeNodeContent::GradientShading *gradientShading = (RenderTreeNodeContent::GradientShading *)shadingVariant->fill->shading.get(); - - alpha *= gradientShading->opacity; - - break; - } - default: - break; + if (effectiveLocalBounds) { + effectiveLocalBounds = effectiveLocalBounds->unionWith(shapeBounds); + } else { + effectiveLocalBounds = shapeBounds; } } } - }*/ - if (node->content()) { + } + /*if (node->content()) { RenderTreeNodeContent *shapeContent = node->content().get(); CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shapeContent->paths); @@ -94,45 +66,10 @@ static void processRenderTree(std::shared_ptr const &node, Vecto if (shapeContent->stroke) { shapeBounds = shapeBounds.insetBy(-shapeContent->stroke->lineWidth / 2.0, -shapeContent->stroke->lineWidth / 2.0); effectiveLocalBounds = shapeBounds; - - /*switch (shapeContent->stroke->shading->type()) { - case RenderTreeNodeContent::ShadingType::Solid: { - RenderTreeNodeContent::SolidShading *solidShading = (RenderTreeNodeContent::SolidShading *)shapeContent->stroke->shading.get(); - - alpha *= solidShading->opacity; - - break; - } - case RenderTreeNodeContent::ShadingType::Gradient: { - - break; - } - default: - break; - }*/ } else if (shapeContent->fill) { effectiveLocalBounds = shapeBounds; - - /*switch (shapeContent->fill->shading->type()) { - case RenderTreeNodeContent::ShadingType::Solid: { - RenderTreeNodeContent::SolidShading *solidShading = (RenderTreeNodeContent::SolidShading *)shapeContent->fill->shading.get(); - - alpha *= solidShading->opacity; - - break; - } - case RenderTreeNodeContent::ShadingType::Gradient: { - RenderTreeNodeContent::GradientShading *gradientShading = (RenderTreeNodeContent::GradientShading *)shapeContent->fill->shading.get(); - - alpha *= gradientShading->opacity; - - break; - } - default: - break; - }*/ } - } + }*/ bool isInvertedMatte = isInvertedMask; if (isInvertedMatte) { diff --git a/Tests/LottieMetalTest/Sources/ViewController.swift b/Tests/LottieMetalTest/Sources/ViewController.swift index d164f4d680..599c888d16 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 = "35707580709863498.json" + //continueFromName = "778160933443732778.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/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp index f6bbb25a76..bd638add70 100644 --- a/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp +++ b/submodules/TelegramUI/Components/LottieCpp/Sources/Lottie/Private/MainThread/LayerContainers/CompLayers/ShapeCompositionLayer.cpp @@ -1011,7 +1011,7 @@ public: false ); shadingVariant.renderTree = shadingRenderTree; - _renderTree->_subnodes.push_back(shadingRenderTree); + //_renderTree->_subnodes.push_back(shadingRenderTree); auto itemShadingVariant = std::make_shared(); if (shadingVariant.fill) {