Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
skottie::internal::AnimatorBuilder Class Referenceabstract

#include <KeyframeAnimator.h>

Inheritance diagram for skottie::internal::AnimatorBuilder:
SkNoncopyable skottie::internal::VectorAnimatorBuilder

Public Member Functions

virtual ~AnimatorBuilder ()
 
virtual sk_sp< KeyframeAnimatormakeFromKeyframes (const AnimationBuilder &, const skjson::ArrayValue &)=0
 
virtual sk_sp< AnimatormakeFromExpression (ExpressionManager &, const char *)=0
 
virtual bool parseValue (const AnimationBuilder &, const skjson::Value &) const =0
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Protected Member Functions

 AnimatorBuilder (Keyframe::Value::Type ty)
 
virtual bool parseKFValue (const AnimationBuilder &, const skjson::ObjectValue &, const skjson::Value &, Keyframe::Value *)=0
 
bool parseKeyframes (const AnimationBuilder &, const skjson::ArrayValue &)
 

Protected Attributes

std::vector< KeyframefKFs
 
std::vector< SkCubicMapfCMs
 

Detailed Description

Definition at line 118 of file KeyframeAnimator.h.

Constructor & Destructor Documentation

◆ ~AnimatorBuilder()

skottie::internal::AnimatorBuilder::~AnimatorBuilder ( )
virtualdefault

◆ AnimatorBuilder()

skottie::internal::AnimatorBuilder::AnimatorBuilder ( Keyframe::Value::Type  ty)
inlineexplicitprotected

Definition at line 130 of file KeyframeAnimator.h.

131 : keyframe_type(ty) {}

Member Function Documentation

◆ makeFromExpression()

virtual sk_sp< Animator > skottie::internal::AnimatorBuilder::makeFromExpression ( ExpressionManager ,
const char *   
)
pure virtual

◆ makeFromKeyframes()

virtual sk_sp< KeyframeAnimator > skottie::internal::AnimatorBuilder::makeFromKeyframes ( const AnimationBuilder ,
const skjson::ArrayValue  
)
pure virtual

◆ parseKeyframes()

bool skottie::internal::AnimatorBuilder::parseKeyframes ( const AnimationBuilder abuilder,
const skjson::ArrayValue jkfs 
)
protected

Definition at line 94 of file KeyframeAnimator.cpp.

95 {
96 // Keyframe format:
97 //
98 // [ // array of
99 // {
100 // "t": <float> // keyframe time
101 // "s": <T> // keyframe value
102 // "h": <bool> // optional constant/hold keyframe marker
103 // "i": [<float,float>] // optional "in" Bezier control point
104 // "o": [<float,float>] // optional "out" Bezier control point
105 // },
106 // ...
107 // ]
108 //
109 // Legacy keyframe format:
110 //
111 // [ // array of
112 // {
113 // "t": <float> // keyframe time
114 // "s": <T> // keyframe start value
115 // "e": <T> // keyframe end value
116 // "h": <bool> // optional constant/hold keyframe marker (constant mapping)
117 // "i": [<float,float>] // optional "in" Bezier control point (cubic mapping)
118 // "o": [<float,float>] // optional "out" Bezier control point (cubic mapping)
119 // },
120 // ...
121 // {
122 // "t": <float> // last keyframe only specifies a t
123 // // the value is prev. keyframe end value
124 // }
125 // ]
126 //
127 // Note: the legacy format contains duplicates, as normal frames are contiguous:
128 // frame(n).e == frame(n+1).s
129
130 const auto parse_value = [&](const skjson::ObjectValue& jkf, size_t i, Keyframe::Value* v) {
131 auto parsed = this->parseKFValue(abuilder, jkf, jkf["s"], v);
132
133 // A missing value is only OK for the last legacy KF
134 // (where it is pulled from prev KF 'end' value).
135 if (!parsed && i > 0 && i == jkfs.size() - 1) {
136 const skjson::ObjectValue* prev_kf = jkfs[i - 1];
137 SkASSERT(prev_kf);
138 parsed = this->parseKFValue(abuilder, jkf, (*prev_kf)["e"], v);
139 }
140
141 return parsed;
142 };
143
144 bool constant_value = true;
145
146 fKFs.reserve(jkfs.size());
147
148 for (size_t i = 0; i < jkfs.size(); ++i) {
149 const skjson::ObjectValue* jkf = jkfs[i];
150 if (!jkf) {
151 return false;
152 }
153
154 float t;
155 if (!Parse<float>((*jkf)["t"], &t)) {
156 return false;
157 }
158
159 Keyframe::Value v;
160 if (!parse_value(*jkf, i, &v)) {
161 return false;
162 }
163
164 if (i > 0) {
165 auto& prev_kf = fKFs.back();
166
167 // Ts must be strictly monotonic.
168 if (t <= prev_kf.t) {
169 return false;
170 }
171
172 // We can power-reduce the mapping of repeated values (implicitly constant).
173 if (v.equals(prev_kf.v, keyframe_type)) {
174 prev_kf.mapping = Keyframe::kConstantMapping;
175 }
176 }
177
178 fKFs.push_back({t, v, this->parseMapping(*jkf)});
179
180 constant_value = constant_value && (v.equals(fKFs.front().v, keyframe_type));
181 }
182
183 SkASSERT(fKFs.size() == jkfs.size());
184 fCMs.shrink_to_fit();
185
186 if (constant_value) {
187 // When all keyframes hold the same value, we can discard all but one
188 // (interpolation has no effect).
189 fKFs.resize(1);
190 }
191
192#if(DUMP_KF_RECORDS)
193 SkDEBUGF("Animator[%p], values: %lu, KF records: %zu\n",
194 this, fKFs.back().v_idx + 1, fKFs.size());
195 for (const auto& kf : fKFs) {
196 SkDEBUGF(" { t: %1.3f, v_idx: %lu, mapping: %lu }\n", kf.t, kf.v_idx, kf.mapping);
197 }
198#endif
199 return true;
200}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGF(...)
Definition SkDebug.h:24
size_t size() const
Definition SkJSON.h:262
virtual bool parseKFValue(const AnimationBuilder &, const skjson::ObjectValue &, const skjson::Value &, Keyframe::Value *)=0
static constexpr uint32_t kConstantMapping

◆ parseKFValue()

virtual bool skottie::internal::AnimatorBuilder::parseKFValue ( const AnimationBuilder ,
const skjson::ObjectValue ,
const skjson::Value ,
Keyframe::Value  
)
protectedpure virtual

◆ parseValue()

virtual bool skottie::internal::AnimatorBuilder::parseValue ( const AnimationBuilder ,
const skjson::Value  
) const
pure virtual

Member Data Documentation

◆ fCMs

std::vector<SkCubicMap> skottie::internal::AnimatorBuilder::fCMs
protected

Definition at line 141 of file KeyframeAnimator.h.

◆ fKFs

std::vector<Keyframe> skottie::internal::AnimatorBuilder::fKFs
protected

Definition at line 140 of file KeyframeAnimator.h.


The documentation for this class was generated from the following files: