Expanded PropertyObserver interface to include Node Type

Change-Id: I86b0ab3445f8fe4790492fa1b942c97e3053af9e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/417264
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
This commit is contained in:
Kyle Carlstrom 2021-06-09 17:12:46 -04:00 committed by Skia Commit-Bot
parent bc215ba3bb
commit 1907f9051e
9 changed files with 33 additions and 17 deletions

View File

@ -119,6 +119,8 @@ using TransformPropertyHandle = PropertyHandle<TransformPropertyValue,
*/
class SK_API PropertyObserver : public SkRefCnt {
public:
enum class NodeType {COMPOSITION, LAYER, EFFECT, OTHER};
template <typename T>
using LazyHandle = std::function<std::unique_ptr<T>()>;
@ -130,8 +132,8 @@ public:
const LazyHandle<TextPropertyHandle>&);
virtual void onTransformProperty(const char node_name[],
const LazyHandle<TransformPropertyHandle>&);
virtual void onEnterNode(const char node_name[]);
virtual void onLeavingNode(const char node_name[]);
virtual void onEnterNode(const char node_name[], NodeType node_type);
virtual void onLeavingNode(const char node_name[], NodeType node_type);
};
} // namespace skottie

View File

@ -344,7 +344,7 @@ sk_sp<sksg::Transform> LayerBuilder::getTransform(const AnimationBuilder& abuild
// Set valid flag upfront to break cycles.
fFlags |= cache_valid_mask;
const AnimationBuilder::AutoPropertyTracker apt(&abuilder, fJlayer);
const AnimationBuilder::AutoPropertyTracker apt(&abuilder, fJlayer, PropertyObserver::NodeType::LAYER);
AnimationBuilder::AutoScope ascope(&abuilder, std::move(fLayerScope));
fTransformCache[ttype] = this->doAttachTransform(abuilder, cbuilder, ttype);
fLayerScope = ascope.release();
@ -410,7 +410,7 @@ bool LayerBuilder::hasMotionBlur(const CompositionBuilder* cbuilder) const {
sk_sp<sksg::RenderNode> LayerBuilder::buildRenderTree(const AnimationBuilder& abuilder,
CompositionBuilder* cbuilder,
const LayerBuilder* prev_layer) {
const AnimationBuilder::AutoPropertyTracker apt(&abuilder, fJlayer);
const AnimationBuilder::AutoPropertyTracker apt(&abuilder, fJlayer, PropertyObserver::NodeType::LAYER);
using LayerBuilder =
sk_sp<sksg::RenderNode> (AnimationBuilder::*)(const skjson::ObjectValue&,

View File

@ -184,6 +184,7 @@ AnimationBuilder::AnimationInfo AnimationBuilder::parse(const skjson::ObjectValu
this->parseFonts(jroot["fonts"], jroot["chars"]);
AutoScope ascope(this);
AutoPropertyTracker apt(this, jroot, PropertyObserver::NodeType::COMPOSITION);
auto root = CompositionBuilder(*this, fCompSize, jroot).build(*this);
auto animators = ascope.release();

View File

@ -146,19 +146,19 @@ public:
class AutoPropertyTracker {
public:
AutoPropertyTracker(const AnimationBuilder* builder, const skjson::ObjectValue& obj)
AutoPropertyTracker(const AnimationBuilder* builder, const skjson::ObjectValue& obj, const PropertyObserver::NodeType node_type)
: fBuilder(builder)
, fPrevContext(builder->fPropertyObserverContext) {
, fPrevContext(builder->fPropertyObserverContext), fNodeType(node_type) {
if (fBuilder->fPropertyObserver) {
auto observer = builder->fPropertyObserver.get();
this->updateContext(observer, obj);
observer->onEnterNode(fBuilder->fPropertyObserverContext);
observer->onEnterNode(fBuilder->fPropertyObserverContext, fNodeType);
}
}
~AutoPropertyTracker() {
if (fBuilder->fPropertyObserver) {
fBuilder->fPropertyObserver->onLeavingNode(fBuilder->fPropertyObserverContext);
fBuilder->fPropertyObserver->onLeavingNode(fBuilder->fPropertyObserverContext, fNodeType);
fBuilder->fPropertyObserverContext = fPrevContext;
}
}
@ -167,6 +167,7 @@ public:
const AnimationBuilder* fBuilder;
const char* fPrevContext;
const PropertyObserver::NodeType fNodeType;
};
bool dispatchColorProperty(const sk_sp<sksg::Color>&) const;

View File

@ -128,8 +128,8 @@ void PropertyObserver::onTextProperty(const char[],
void PropertyObserver::onTransformProperty(const char[],
const LazyHandle<TransformPropertyHandle>&) {}
void PropertyObserver::onEnterNode(const char node_name[]) {}
void PropertyObserver::onEnterNode(const char node_name[], NodeType) {}
void PropertyObserver::onLeavingNode(const char node_name[]) {}
void PropertyObserver::onLeavingNode(const char node_name[], NodeType) {}
} // namespace skottie

View File

@ -173,11 +173,17 @@ DEF_TEST(Skottie_Properties, reporter) {
fTransforms.push_back({SkString(node_name), lh()});
}
void onEnterNode(const char node_name[]) override {
void onEnterNode(const char node_name[], PropertyObserver::NodeType node_type) override {
if (node_name == nullptr) {
return;
}
fCurrentNode = fCurrentNode.empty() ? node_name : fCurrentNode + "." + node_name;
}
void onLeavingNode(const char node_name[]) override {
void onLeavingNode(const char node_name[], PropertyObserver::NodeType node_type) override {
if (node_name == nullptr) {
return;
}
auto length = strlen(node_name);
fCurrentNode =
fCurrentNode.length() > length

View File

@ -115,7 +115,7 @@ sk_sp<sksg::RenderNode> EffectBuilder::attachEffects(const skjson::ArrayValue& j
continue;
}
const AnimationBuilder::AutoPropertyTracker apt(fBuilder, *jeffect);
const AnimationBuilder::AutoPropertyTracker apt(fBuilder, *jeffect, PropertyObserver::NodeType::EFFECT);
layer = (this->*builder)(*jprops, std::move(layer));
if (!layer) {

View File

@ -233,7 +233,7 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachShape(const skjson::ArrayValue*
};
for (auto rec = recs.rbegin(); rec != recs.rend(); ++rec) {
const AutoPropertyTracker apt(this, rec->fJson);
const AutoPropertyTracker apt(this, rec->fJson, PropertyObserver::NodeType::OTHER);
switch (rec->fInfo.fShapeType) {
case ShapeType::kGeometry: {
@ -328,7 +328,7 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachShape(const skjson::ArrayValue*
sk_sp<sksg::Transform> shape_transform;
if (jtransform) {
const AutoPropertyTracker apt(this, *jtransform);
const AutoPropertyTracker apt(this, *jtransform, PropertyObserver::NodeType::OTHER);
// This is tricky due to the interaction with ctx->fCommittedAnimators: we want any
// animators related to tranform/opacity to be committed => they must be inserted in front

View File

@ -45,12 +45,18 @@ public:
}
}
void onEnterNode(const char node_name[]) override {
void onEnterNode(const char node_name[], PropertyObserver::NodeType node_type) override {
if (node_name == nullptr) {
return;
}
fMgr->fCurrentNode =
fMgr->fCurrentNode.empty() ? node_name : fMgr->fCurrentNode + "." + node_name;
}
void onLeavingNode(const char node_name[]) override {
void onLeavingNode(const char node_name[], PropertyObserver::NodeType node_type) override {
if (node_name == nullptr) {
return;
}
auto length = strlen(node_name);
fMgr->fCurrentNode =
fMgr->fCurrentNode.length() > length