0147de41c4
Expand the core animator logic to return whether the computed value is changing on each tick. Also rename tick/onTick -> seek/onSeek to better reflect Skottie semantics. This information allows us to skip adapter updates for static/hold animation segments. This effectively hoists some of the scene graph lazy-update logic to the Skottie model level, and culls unneeded conversions (e.g. we were converting ShapeValue -> SkPath on every tick, even when the shape was not changing). TBR= Change-Id: I1ea4e19ae8f993d659826269de6b0465fec70189 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/279816 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
137 lines
5.7 KiB
C++
137 lines
5.7 KiB
C++
/*
|
|
* Copyright 2020 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "modules/skottie/src/SkottiePriv.h"
|
|
#include "modules/skottie/src/SkottieValue.h"
|
|
#include "modules/skottie/src/animator/Animator.h"
|
|
#include "src/utils/SkJSON.h"
|
|
#include "tests/Test.h"
|
|
|
|
#include <cmath>
|
|
|
|
using namespace skottie;
|
|
using namespace skottie::internal;
|
|
|
|
namespace {
|
|
|
|
template <typename T>
|
|
class MockProperty final : public AnimatablePropertyContainer {
|
|
public:
|
|
explicit MockProperty(const char* jprop) {
|
|
AnimationBuilder abuilder(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
|
{100, 100}, 10, 1, 0);
|
|
skjson::DOM json_dom(jprop, strlen(jprop));
|
|
|
|
fDidBind = this->bind(abuilder, json_dom.root(), &fValue);
|
|
}
|
|
|
|
operator bool() const { return fDidBind; }
|
|
|
|
const T& operator()(float t) { this->seek(t); return fValue; }
|
|
|
|
private:
|
|
void onSync() override {}
|
|
|
|
T fValue = T();
|
|
bool fDidBind;
|
|
};
|
|
|
|
}
|
|
|
|
DEF_TEST(Skottie_Keyframe, reporter) {
|
|
{
|
|
MockProperty<ScalarValue> prop(R"({})");
|
|
REPORTER_ASSERT(reporter, !prop);
|
|
}
|
|
{
|
|
MockProperty<ScalarValue> prop(R"({ "a": 1, "k": [] })");
|
|
REPORTER_ASSERT(reporter, !prop);
|
|
}
|
|
{
|
|
// New style
|
|
MockProperty<ScalarValue> prop(R"({
|
|
"a": 1,
|
|
"k": [
|
|
{ "t": 1, "s": 1 },
|
|
{ "t": 2, "s": 2 },
|
|
{ "t": 3, "s": 4 }
|
|
]
|
|
})");
|
|
REPORTER_ASSERT(reporter, prop);
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( -1), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 0), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 1), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(1.5), 1.5f));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 2), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(2.5), 3));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 3), 4));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 4), 4));
|
|
}
|
|
{
|
|
// New style hold (hard stops)
|
|
MockProperty<ScalarValue> prop(R"({
|
|
"a": 1,
|
|
"k": [
|
|
{ "t": 1, "s": 1, "h": true },
|
|
{ "t": 2, "s": 2, "h": true },
|
|
{ "t": 3, "s": 4, "h": true }
|
|
]
|
|
})");
|
|
REPORTER_ASSERT(reporter, prop);
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(0 ), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(1 ), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(1.5), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(std::nextafter(2.f, 0.f)), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(2 ), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(2.5), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(std::nextafter(3.f, 0.f)), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(3 ), 4));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(4 ), 4));
|
|
}
|
|
{
|
|
// Legacy style
|
|
MockProperty<ScalarValue> prop(R"({
|
|
"a": 1,
|
|
"k": [
|
|
{ "t": 1, "s": 1, "e": 2 },
|
|
{ "t": 2, "s": 2, "e": 4 },
|
|
{ "t": 3 }
|
|
]
|
|
})");
|
|
REPORTER_ASSERT(reporter, prop);
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(-1), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 0), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 1 ), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 1.5), 1.5f));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 2 ), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 2.5), 3));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 3 ), 4));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop( 4 ), 4));
|
|
}
|
|
{
|
|
// Legacy style hold (hard stops)
|
|
MockProperty<ScalarValue> prop(R"({
|
|
"a": 1,
|
|
"k": [
|
|
{ "t": 1, "s": 1, "e": 2, "h": true },
|
|
{ "t": 2, "s": 2, "e": 4, "h": true },
|
|
{ "t": 3 }
|
|
]
|
|
})");
|
|
REPORTER_ASSERT(reporter, prop);
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(0 ), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(1 ), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(1.5), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(std::nextafter(2.f, 0.f)), 1));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(2 ), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(2.5), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(std::nextafter(3.f, 0.f)), 2));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(3 ), 4));
|
|
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(prop(4 ), 4));
|
|
}
|
|
}
|