Skip to content

Commit 8391a58

Browse files
author
Isaac
committed
Refactoring
1 parent bb095f3 commit 8391a58

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎Tests/LottieMetalTest/SoftwareLottieRenderer/Sources/SoftwareLottieRenderer.mm‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,18 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
661661
needsTempContext = layerAlpha != 1.0 || node->renderData.layer.masksToBounds();
662662
}
663663

664-
auto testGlobalRect = lottie::getRenderNodeGlobalRect(node, globalSize, bezierPathsBoundingBoxContext);
665-
auto actualGlobalRect = node->renderData.globalRect;
666-
if (testGlobalRect != actualGlobalRect) {
667-
//printf("getRenderNodeGlobalRect!\n");
668-
}
669-
664+
std::optional<lottie::CGRect> globalRect;
670665
if (needsTempContext) {
666+
globalRect = lottie::getRenderNodeGlobalRect(node, globalSize, bezierPathsBoundingBoxContext);
667+
if (!globalRect) {
668+
parentContext->restoreState();
669+
return;
670+
}
671+
671672
if ((node->mask() && node->mask()->renderData.isValid) || node->renderData.layer.masksToBounds()) {
672-
auto maskBackingStorage = parentContext->makeLayer((int)(node->renderData.globalRect.width), (int)(node->renderData.globalRect.height));
673+
auto maskBackingStorage = parentContext->makeLayer((int)(globalRect->width), (int)(globalRect->height));
673674

674-
maskBackingStorage->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-node->renderData.globalRect.x, -node->renderData.globalRect.y)));
675+
maskBackingStorage->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
675676
maskBackingStorage->concatenate(node->renderData.globalTransform);
676677

677678
if (node->renderData.layer.masksToBounds()) {
@@ -684,11 +685,11 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
684685
maskContext = maskBackingStorage;
685686
}
686687

687-
auto tempContextValue = parentContext->makeLayer((int)(node->renderData.globalRect.width), (int)(node->renderData.globalRect.height));
688+
auto tempContextValue = parentContext->makeLayer((int)(globalRect->width), (int)(globalRect->height));
688689
tempContext = tempContextValue;
689690

690691
currentContext = tempContextValue;
691-
currentContext->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-node->renderData.globalRect.x, -node->renderData.globalRect.y)));
692+
currentContext->concatenate(lottie::CATransform3D::identity().translated(lottie::Vector2D(-globalRect->x, -globalRect->y)));
692693

693694
currentContext->saveState();
694695
currentContext->concatenate(node->renderData.globalTransform);
@@ -727,12 +728,12 @@ static void renderLottieRenderNode(std::shared_ptr<lottie::RenderTreeNode> node,
727728

728729
if (maskContext) {
729730
tempContext->setBlendMode(lottieRendering::BlendMode::DestinationIn);
730-
tempContext->draw(maskContext, lottie::CGRect(node->renderData.globalRect.x, node->renderData.globalRect.y, node->renderData.globalRect.width, node->renderData.globalRect.height));
731+
tempContext->draw(maskContext, lottie::CGRect(globalRect->x, globalRect->y, globalRect->width, globalRect->height));
731732
}
732733

733734
parentContext->concatenate(node->renderData.globalTransform.inverted());
734735
parentContext->setAlpha(layerAlpha);
735-
parentContext->draw(tempContext, node->renderData.globalRect);
736+
parentContext->draw(tempContext, globalRect.value());
736737
}
737738

738739
parentContext->restoreState();

0 commit comments

Comments
 (0)