Refactoring

This commit is contained in:
Isaac 2024-05-18 22:14:10 +04:00
parent 7346583939
commit c0ef6478f7
4 changed files with 3 additions and 92 deletions

View File

@ -189,28 +189,15 @@ static void processRenderContentItem(std::shared_ptr<RenderTreeNodeContentItem>
return;
}
std::optional<CGRect> 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<RenderTreeNodeContentItem>
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<RenderTreeNodeContentItem>
}
}
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<RenderTreeNodeContentItem>
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<RenderTreeNode> const &node, Vecto
}
int drawContentDescendants = 0;
std::optional<CGRect> 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<RenderTreeNode> 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<RenderTreeNode> 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<lottie::RenderTreeNode> node,
std::optional<lottie::CGRect> globalRect;
if (needsTempContext) {
globalRect = lottie::getRenderNodeGlobalRect(node, globalSize, bezierPathsBoundingBoxContext);
if (!globalRect) {
if (!globalRect || globalRect->width <= 0.0f || globalRect->height <= 0.0f) {
parentContext->restoreState();
return;
}

View File

@ -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 {

View File

@ -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;

View File

@ -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;