OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef Interpolation_h | 5 #ifndef Interpolation_h |
6 #define Interpolation_h | 6 #define Interpolation_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/animation/InterpolableValue.h" | 9 #include "core/animation/InterpolableValue.h" |
10 #include "wtf/Forward.h" | 10 #include "wtf/Forward.h" |
11 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class PropertyHandle; | 16 class PropertyHandle; |
17 | 17 |
18 // Represents an animation's effect between an adjacent pair of PropertySpecific
Keyframes. | 18 // Represents an animation's effect between two values. |
19 class CORE_EXPORT Interpolation : public RefCounted<Interpolation> { | 19 class CORE_EXPORT Interpolation : public RefCounted<Interpolation> { |
20 WTF_MAKE_NONCOPYABLE(Interpolation); | 20 WTF_MAKE_NONCOPYABLE(Interpolation); |
21 public: | 21 public: |
22 virtual ~Interpolation(); | 22 // TODO(alancutter): Remove StyleInterpolation and LegacyStyleInterpolation
and upstream StackableInterpolation as Interpolation. |
| 23 virtual bool isStyleInterpolation() const { return false; } |
| 24 virtual bool isLegacyStyleInterpolation() const { return false; } |
23 | 25 |
24 virtual void interpolate(int iteration, double fraction); | 26 virtual bool isStackableInterpolation() const { return false; } |
| 27 virtual bool isKeyframeInterpolation() const { return false; } |
| 28 virtual bool isPairwiseInterpolation() const { return false; } |
25 | 29 |
26 virtual bool isStyleInterpolation() const { return false; } | 30 void interpolate(int iteration, double fraction) |
27 virtual bool isInvalidatableInterpolation() const { return false; } | 31 { |
28 virtual bool isLegacyStyleInterpolation() const { return false; } | 32 if (iteration == m_currentIteration && fraction == m_currentFraction) |
| 33 return; |
| 34 m_currentIteration = iteration; |
| 35 m_currentFraction = fraction; |
| 36 interpolateImpl(); |
| 37 } |
29 | 38 |
30 virtual PropertyHandle getProperty() const = 0; | 39 virtual PropertyHandle getProperty() const = 0; |
31 virtual bool dependsOnUnderlyingValue() const { return false; } | 40 virtual bool dependsOnUnderlyingValue() const { return false; } |
32 | 41 |
| 42 virtual ~Interpolation() {} |
| 43 |
33 protected: | 44 protected: |
34 const std::unique_ptr<InterpolableValue> m_start; | 45 Interpolation() |
35 const std::unique_ptr<InterpolableValue> m_end; | 46 : m_currentIteration(std::numeric_limits<double>::quiet_NaN()) |
| 47 , m_currentFraction(std::numeric_limits<double>::quiet_NaN()) |
| 48 { } |
36 | 49 |
37 mutable double m_cachedFraction; | 50 virtual void interpolateImpl() = 0; |
38 mutable int m_cachedIteration; | |
39 mutable std::unique_ptr<InterpolableValue> m_cachedValue; | |
40 | 51 |
41 Interpolation(std::unique_ptr<InterpolableValue> start, std::unique_ptr<Inte
rpolableValue> end); | 52 double m_currentIteration; |
42 | 53 double m_currentFraction; |
43 private: | |
44 InterpolableValue* getCachedValueForTesting() const { return m_cachedValue.g
et(); } | |
45 | |
46 friend class AnimationInterpolableValueTest; | |
47 friend class AnimationInterpolationEffectTest; | |
48 friend class AnimationDoubleStyleInterpolationTest; | |
49 friend class AnimationVisibilityStyleInterpolationTest; | |
50 }; | 54 }; |
51 | 55 |
52 using ActiveInterpolations = Vector<RefPtr<Interpolation>, 1>; | 56 using ActiveInterpolations = Vector<RefPtr<Interpolation>, 1>; |
53 | 57 |
54 } // namespace blink | 58 } // namespace blink |
55 | 59 |
56 #endif // Interpolation_h | 60 #endif // Interpolation_h |
OLD | NEW |