Lottie optimization

This commit is contained in:
Isaac 2024-05-14 23:05:11 +04:00
parent 920de21020
commit ea4a203285
3 changed files with 15 additions and 78 deletions

View File

@ -38,55 +38,27 @@ static void processRenderTree(std::shared_ptr<RenderTreeNode> const &node, Vecto
double alpha = node->alpha(); double alpha = node->alpha();
/*if (node->_contentItem) { if (node->_contentItem) {
RenderTreeNodeContentItem *contentItem = node->_contentItem.get(); RenderTreeNodeContentItem *contentItem = node->_contentItem.get();
for (const auto &shadingVariant : contentItem->shadings) { for (const auto &shadingVariant : contentItem->shadings) {
CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value());
if (shadingVariant->stroke) { if (shadingVariant->stroke) {
CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value());
shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0); shapeBounds = shapeBounds.insetBy(-shadingVariant->stroke->lineWidth / 2.0, -shadingVariant->stroke->lineWidth / 2.0);
effectiveLocalBounds = shapeBounds; if (effectiveLocalBounds) {
effectiveLocalBounds = effectiveLocalBounds->unionWith(shapeBounds);
switch (shadingVariant->stroke->shading->type()) { } else {
case RenderTreeNodeContent::ShadingType::Solid: { effectiveLocalBounds = shapeBounds;
RenderTreeNodeContent::SolidShading *solidShading = (RenderTreeNodeContent::SolidShading *)shadingVariant->stroke->shading.get();
alpha *= solidShading->opacity;
break;
}
case RenderTreeNodeContent::ShadingType::Gradient: {
break;
}
default:
break;
} }
} else if (shadingVariant->fill) { } else if (shadingVariant->fill) {
CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shadingVariant->explicitPath.value()); if (effectiveLocalBounds) {
effectiveLocalBounds = shapeBounds; effectiveLocalBounds = effectiveLocalBounds->unionWith(shapeBounds);
} else {
switch (shadingVariant->fill->shading->type()) { effectiveLocalBounds = shapeBounds;
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 (node->content()) { /*if (node->content()) {
RenderTreeNodeContent *shapeContent = node->content().get(); RenderTreeNodeContent *shapeContent = node->content().get();
CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shapeContent->paths); CGRect shapeBounds = bezierPathsBoundingBoxParallel(bezierPathsBoundingBoxContext, shapeContent->paths);
@ -94,45 +66,10 @@ static void processRenderTree(std::shared_ptr<RenderTreeNode> const &node, Vecto
if (shapeContent->stroke) { if (shapeContent->stroke) {
shapeBounds = shapeBounds.insetBy(-shapeContent->stroke->lineWidth / 2.0, -shapeContent->stroke->lineWidth / 2.0); shapeBounds = shapeBounds.insetBy(-shapeContent->stroke->lineWidth / 2.0, -shapeContent->stroke->lineWidth / 2.0);
effectiveLocalBounds = shapeBounds; 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) { } else if (shapeContent->fill) {
effectiveLocalBounds = shapeBounds; 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; bool isInvertedMatte = isInvertedMask;
if (isInvertedMatte) { if (isInvertedMatte) {

View File

@ -78,7 +78,7 @@ private final class ReferenceCompareTest {
} }
var continueFromName: String? var continueFromName: String?
//continueFromName = "35707580709863498.json" //continueFromName = "778160933443732778.json"
let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in let _ = await processAnimationFolderAsync(basePath: bundlePath, path: "", stopOnFailure: true, process: { path, name, alwaysDraw in
if let continueFromNameValue = continueFromName { if let continueFromNameValue = continueFromName {

View File

@ -1011,7 +1011,7 @@ public:
false false
); );
shadingVariant.renderTree = shadingRenderTree; shadingVariant.renderTree = shadingRenderTree;
_renderTree->_subnodes.push_back(shadingRenderTree); //_renderTree->_subnodes.push_back(shadingRenderTree);
auto itemShadingVariant = std::make_shared<RenderTreeNodeContentShadingVariant>(); auto itemShadingVariant = std::make_shared<RenderTreeNodeContentShadingVariant>();
if (shadingVariant.fill) { if (shadingVariant.fill) {