Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 40c7c64

Browse files
fmalitaSkia Commit-Bot
authored andcommitted
[skottie] Skip group nodes for single-draw shapes
Pulling this off requires deferring the group creation until after we've resolved all the draws. Doable, but somewhat tricky due to the interaction with the dangling/uncommitted animator logic. TBR= Bug: skia:8340 Change-Id: Id00c841152bd80330751db45f6b26462efc844a5 Reviewed-on: https://skia-review.googlesource.com/152860 Reviewed-by: Florin Malita <[email protected]> Commit-Queue: Florin Malita <[email protected]>
1 parent a3dc329 commit 40c7c64

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

modules/skottie/src/SkottieShapeLayer.cpp

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "SkSGTransform.h"
2525
#include "SkSGTrimEffect.h"
2626

27+
#include <iterator>
28+
2729
namespace skottie {
2830
namespace internal {
2931

@@ -452,9 +454,7 @@ sk_sp<sksg::RenderNode> AttachShape(const skjson::ArrayValue* jshape, AttachShap
452454

453455
SkDEBUGCODE(const auto initialGeometryEffects = ctx->fGeometryEffectStack->size();)
454456

455-
sk_sp<sksg::Group> shape_group = sksg::Group::Make();
456-
sk_sp<sksg::RenderNode> shape_wrapper = shape_group;
457-
sk_sp<sksg::Matrix> shape_matrix;
457+
const skjson::ObjectValue* jtransform = nullptr;
458458

459459
struct ShapeRec {
460460
const skjson::ObjectValue& fJson;
@@ -482,11 +482,8 @@ sk_sp<sksg::RenderNode> AttachShape(const skjson::ArrayValue* jshape, AttachShap
482482

483483
switch (info->fShapeType) {
484484
case ShapeType::kTransform:
485-
if ((shape_matrix = ctx->fBuilder->attachMatrix(*shape, ctx->fScope, nullptr))) {
486-
shape_wrapper = sksg::Transform::Make(std::move(shape_wrapper), shape_matrix);
487-
}
488-
shape_wrapper = ctx->fBuilder->attachOpacity(*shape, ctx->fScope,
489-
std::move(shape_wrapper));
485+
// Just track the transform property for now -- we'll deal with it later.
486+
jtransform = shape;
490487
break;
491488
case ShapeType::kGeometryEffect:
492489
SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGeometryEffectAttachers));
@@ -575,20 +572,50 @@ sk_sp<sksg::RenderNode> AttachShape(const skjson::ArrayValue* jshape, AttachShap
575572
// By now we should have popped all local geometry effects.
576573
SkASSERT(ctx->fGeometryEffectStack->size() == initialGeometryEffects);
577574

575+
sk_sp<sksg::RenderNode> shape_wrapper;
576+
if (draws.size() == 1) {
577+
// For a single draw, we don't need a group.
578+
shape_wrapper = std::move(draws.front());
579+
} else if (!draws.empty()) {
580+
// We need a group to dispatch multiple draws.
581+
auto group = sksg::Group::Make();
582+
583+
// Emit local draws reversed (bottom->top, per spec).
584+
for (auto it = draws.rbegin(); it != draws.rend(); ++it) {
585+
group->addChild(std::move(*it));
586+
}
587+
group->shrink_to_fit();
588+
589+
shape_wrapper = std::move(group);
590+
}
591+
592+
sk_sp<sksg::Matrix> shape_matrix;
593+
if (jtransform) {
594+
// This is tricky due to the interaction with ctx->fCommittedAnimators: we want any
595+
// animators related to tranform/opacity to be committed => they must be inserted in front
596+
// of the dangling/uncommitted ones.
597+
AnimatorScope local_scope;
598+
599+
if ((shape_matrix = ctx->fBuilder->attachMatrix(*jtransform, &local_scope, nullptr))) {
600+
shape_wrapper = sksg::Transform::Make(std::move(shape_wrapper), shape_matrix);
601+
}
602+
shape_wrapper = ctx->fBuilder->attachOpacity(*jtransform, &local_scope,
603+
std::move(shape_wrapper));
604+
605+
ctx->fScope->insert(ctx->fScope->begin() + ctx->fCommittedAnimators,
606+
std::make_move_iterator(local_scope.begin()),
607+
std::make_move_iterator(local_scope.end()));
608+
ctx->fCommittedAnimators += local_scope.size();
609+
}
610+
578611
// Push transformed local geometries to parent list, for subsequent paints.
579612
for (const auto& geo : geos) {
580613
ctx->fGeometryStack->push_back(shape_matrix
581614
? sksg::GeometryTransform::Make(std::move(geo), shape_matrix)
582615
: std::move(geo));
583616
}
584617

585-
// Emit local draws reversed (bottom->top, per spec).
586-
for (auto it = draws.rbegin(); it != draws.rend(); ++it) {
587-
shape_group->addChild(std::move(*it));
588-
}
589-
shape_group->shrink_to_fit();
590-
591-
return draws.empty() ? nullptr : shape_wrapper;
618+
return shape_wrapper;
592619
}
593620

594621
} // namespace

0 commit comments

Comments
 (0)