[skottie] De-dupe sequential cubic mappers

Detect and de-dupe repeating/sequential cubic mapers.

Also improve linear keyframe detection.

Change-Id: Ic7cc757ba9369416d4f1e5639e1c9fdf9e1e2c6e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228117
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Florin Malita 2019-07-17 12:46:12 -04:00 committed by Skia Commit-Bot
parent 009ad250fe
commit 7a15a6e2c7
2 changed files with 27 additions and 12 deletions

View File

@ -22,6 +22,10 @@ class SK_API SkCubicMap {
public:
SkCubicMap(SkPoint p1, SkPoint p2);
static bool IsLinear(SkPoint p1, SkPoint p2) {
return SkScalarNearlyEqual(p1.fX, p1.fY) && SkScalarNearlyEqual(p2.fX, p2.fY);
}
float computeYFromX(float x) const;
SkPoint computeFromT(float t) const;

View File

@ -90,6 +90,9 @@ protected:
// and the last frame is not discarded (its t1 is assumed -> inf)
//
SkPoint prev_c0 = { 0, 0 },
prev_c1 = prev_c0;
for (const skjson::ObjectValue* jframe : jframes) {
if (!jframe) continue;
@ -130,20 +133,28 @@ protected:
continue;
}
// default is linear lerp
static constexpr SkPoint kDefaultC0 = { 0, 0 },
kDefaultC1 = { 1, 1 };
const auto c0 = ParseDefault<SkPoint>((*jframe)["o"], kDefaultC0),
c1 = ParseDefault<SkPoint>((*jframe)["i"], kDefaultC1);
const auto cubic_mapper_index = [&]() -> int {
// Do we have non-linear control points?
SkPoint c0, c1;
if (!Parse((*jframe)["o"], &c0) ||
!Parse((*jframe)["i"], &c1) ||
SkCubicMap::IsLinear(c0, c1)) {
// No need for a cubic mapper.
return -1;
}
int cm_idx = -1;
if (c0 != kDefaultC0 || c1 != kDefaultC1) {
// TODO: is it worth de-duping these?
cm_idx = SkToInt(fCubicMaps.size());
fCubicMaps.emplace_back(c0, c1);
}
// De-dupe sequential cubic mappers.
if (c0 != prev_c0 || c1 != prev_c1) {
fCubicMaps.emplace_back(c0, c1);
prev_c0 = c0;
prev_c1 = c1;
}
fRecs.push_back({t0, t0, v0_idx, v1_idx, cm_idx });
SkASSERT(!fCubicMaps.empty());
return SkToInt(fCubicMaps.size()) - 1;
};
fRecs.push_back({t0, t0, v0_idx, v1_idx, cubic_mapper_index()});
}
if (!fRecs.empty()) {