34class InvalidationController;
43class TimeRemapper final :
public AnimatablePropertyContainer {
47 this->bind(*abuilder, jtm, fT);
50 float t()
const {
return fT * fScale; }
53 void onSync()
override {
63class CompTimeMapper final :
public Animator {
67 float time_bias,
float time_scale)
68 : fAnimators(
std::move(layer_animators))
69 , fRemapper(
std::move(remapper))
70 , fTimeBias(time_bias)
71 , fTimeScale(time_scale) {}
73 StateChanged onSeek(
float t)
override {
79 t = (t + fTimeBias) * fTimeScale;
84 for (
const auto& anim : fAnimators) {
85 changed |= anim->seek(t);
94 const float fTimeBias,
102 const LayerInfo& layer_info)
const {
104 if (!fPrecompInterceptor) {
115 auto external_layer = fPrecompInterceptor->onLoadPrecomp(
id->begin(),
118 if (!external_layer) {
128 : fExternal(
std::move(external))
129 , fSize(layer_size) {}
136 void onRender(
SkCanvas* canvas,
const RenderContext* ctx)
const override {
139 const auto local_scope =
140 ScopedRenderContext(canvas, ctx).setIsolation(this->
bounds(),
143 fExternal->render(canvas,
static_cast<double>(fCurrentT));
146 const RenderNode* onNodeAt(
const SkPoint& pt)
const override {
157 class AnimatorAdapter final :
public Animator {
160 : fSGAdapter(
std::move(sg_adapter))
164 StateChanged onSeek(
float t)
override {
165 fSGAdapter->setT(t / fFps);
174 auto sg_adapter = sk_make_sp<SGAdapter>(std::move(external_layer), layer_info.fSize);
176 fCurrentAnimatorScope->push_back(sk_make_sp<AnimatorAdapter>(sg_adapter, fFrameRate));
182 LayerInfo* layer_info)
const {
185 time_remapper = sk_make_sp<TimeRemapper>(*jtm,
this, fFrameRate);
188 const auto start_time = ParseDefault<float>(jlayer[
"st"], 0.0f),
189 stretch_time = ParseDefault<float>(jlayer[
"sr"], 1.0f);
196 return SkSize::Make(ParseDefault<float>(jlayer[
"w"], 0.0f),
197 ParseDefault<float>(jlayer[
"h"], 0.0f));
199 layer_info->fSize = parse_size(jlayer);
202 if (requires_time_mapping) {
203 local_scope.
init(
this);
206 auto precomp_layer = this->attachExternalPrecompLayer(jlayer, *layer_info);
208 if (!precomp_layer) {
209 const ScopedAssetRef precomp_asset(
this, jlayer);
213 if (layer_info->fSize.isEmpty()) {
214 layer_info->fSize = parse_size(*precomp_asset);
223 if (requires_time_mapping) {
224 const auto t_bias = -start_time,
226 auto time_mapper = sk_make_sp<CompTimeMapper>(local_scope->release(),
227 std::move(time_remapper),
231 fCurrentAnimatorScope->push_back(std::move(time_mapper));
234 return precomp_layer;
static constexpr float sk_ieee_float_divide(float numer, float denom)
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
SkMatrix getTotalMatrix() const
T * init(Args &&... args)
friend class CompositionBuilder
Optional< SkRect > bounds
std::vector< sk_sp< Animator > > AnimatorScope
constexpr bool contains(std::string_view str, std::string_view needle)
SINT bool isfinite(const Vec< N, T > &v)
static constexpr SkRect MakeSize(const SkSize &size)
static constexpr SkSize Make(SkScalar w, SkScalar h)