Coverage Report

Created: 2021-08-22 09:07

/src/skia/modules/skottie/src/animator/Animator.h
Line
Count
Source
1
/*
2
 * Copyright 2020 Google Inc.
3
 *
4
 * Use of this source code is governed by a BSD-style license that can be
5
 * found in the LICENSE file.
6
 */
7
8
#ifndef SkottieAnimator_DEFINED
9
#define SkottieAnimator_DEFINED
10
11
#include "include/core/SkRefCnt.h"
12
13
#include <vector>
14
15
struct SkV2;
16
17
namespace skjson {
18
19
class ObjectValue;
20
21
} // namespace skjson
22
23
namespace skottie {
24
namespace internal {
25
26
class AnimationBuilder;
27
class AnimatorBuilder;
28
29
class Animator : public SkRefCnt {
30
public:
31
    using StateChanged = bool;
32
1.89M
    StateChanged seek(float t) { return this->onSeek(t); }
33
34
protected:
35
2.24M
    Animator() = default;
36
37
    virtual StateChanged onSeek(float t) = 0;
38
39
private:
40
    Animator(const Animator&) = delete;
41
    Animator& operator=(const Animator&) = delete;
42
};
43
44
class AnimatablePropertyContainer : public Animator {
45
public:
46
    // This is the workhorse for property binding: depending on whether the property is animated,
47
    // it will either apply immediately or instantiate and attach a keyframe animator, scoped to
48
    // this container.
49
    template <typename T>
50
    bool bind(const AnimationBuilder&, const skjson::ObjectValue*, T*);
51
52
    template <typename T>
53
2.21M
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
2.21M
        return this->bind<T>(abuilder, jobject, &v);
55
2.21M
    }
bool skottie::internal::AnimatablePropertyContainer::bind<float>(skottie::internal::AnimationBuilder const&, skjson::ObjectValue const*, float&)
Line
Count
Source
53
1.30M
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
1.30M
        return this->bind<T>(abuilder, jobject, &v);
55
1.30M
    }
bool skottie::internal::AnimatablePropertyContainer::bind<skottie::TextPropertyValue>(skottie::internal::AnimationBuilder const&, skjson::ObjectValue const*, skottie::TextPropertyValue&)
Line
Count
Source
53
1.53k
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
1.53k
        return this->bind<T>(abuilder, jobject, &v);
55
1.53k
    }
bool skottie::internal::AnimatablePropertyContainer::bind<SkV2>(skottie::internal::AnimationBuilder const&, skjson::ObjectValue const*, SkV2&)
Line
Count
Source
53
596k
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
596k
        return this->bind<T>(abuilder, jobject, &v);
55
596k
    }
bool skottie::internal::AnimatablePropertyContainer::bind<skottie::VectorValue>(skottie::internal::AnimationBuilder const&, skjson::ObjectValue const*, skottie::VectorValue&)
Line
Count
Source
53
230k
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
230k
        return this->bind<T>(abuilder, jobject, &v);
55
230k
    }
bool skottie::internal::AnimatablePropertyContainer::bind<skottie::ShapeValue>(skottie::internal::AnimationBuilder const&, skjson::ObjectValue const*, skottie::ShapeValue&)
Line
Count
Source
53
80.1k
    bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54
80.1k
        return this->bind<T>(abuilder, jobject, &v);
55
80.1k
    }
56
57
    // A flavor of bind<Vec2Value> which drives an additional/optional orientation target
58
    // (rotation in degrees), when bound to a motion path property.
59
    bool bindAutoOrientable(const AnimationBuilder& abuilder,
60
                            const skjson::ObjectValue* jobject,
61
                            SkV2* v, float* orientation);
62
63
1.87M
    bool isStatic() const { return fAnimators.empty(); }
64
65
protected:
66
    virtual void onSync() = 0;
67
68
    void shrink_to_fit();
69
70
    void attachDiscardableAdapter(sk_sp<AnimatablePropertyContainer>);
71
72
private:
73
    StateChanged onSeek(float) final;
74
75
    bool bindImpl(const AnimationBuilder&, const skjson::ObjectValue*, AnimatorBuilder&);
76
77
    std::vector<sk_sp<Animator>> fAnimators;
78
    bool                         fHasSynced = false;
79
};
80
81
} // namespace internal
82
} // namespace skottie
83
84
#endif // SkottieAnimator_DEFINED