OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "core/animation/InvalidatableInterpolation.h" | 5 #include "core/animation/InvalidatableInterpolation.h" |
6 | 6 |
7 #include "core/animation/InterpolationEnvironment.h" | 7 #include "core/animation/InterpolationEnvironment.h" |
8 #include "core/animation/StringKeyframe.h" | 8 #include "core/animation/StringKeyframe.h" |
9 #include "core/css/resolver/StyleResolverState.h" | 9 #include "core/css/resolver/StyleResolverState.h" |
10 #include <memory> | |
11 | 10 |
12 namespace blink { | 11 namespace blink { |
13 | 12 |
14 void InvalidatableInterpolation::interpolate(int, double fraction) | 13 void InvalidatableInterpolation::interpolate(int, double fraction) |
15 { | 14 { |
16 if (fraction == m_currentFraction) | 15 if (fraction == m_currentFraction) |
17 return; | 16 return; |
18 | 17 |
19 if (m_currentFraction == 0 || m_currentFraction == 1 || fraction == 0 || fra
ction == 1) | 18 if (m_currentFraction == 0 || m_currentFraction == 1 || fraction == 0 || fra
ction == 1) |
20 clearCache(); | 19 clearCache(); |
21 | 20 |
22 m_currentFraction = fraction; | 21 m_currentFraction = fraction; |
23 if (m_isCached && m_cachedPairConversion) | 22 if (m_isCached && m_cachedPairConversion) |
24 m_cachedPairConversion->interpolateValue(fraction, m_cachedValue); | 23 m_cachedPairConversion->interpolateValue(fraction, m_cachedValue); |
25 // We defer the interpolation to ensureValidInterpolation() if m_cachedPairC
onversion is null. | 24 // We defer the interpolation to ensureValidInterpolation() if m_cachedPairC
onversion is null. |
26 } | 25 } |
27 | 26 |
28 std::unique_ptr<PairwisePrimitiveInterpolation> InvalidatableInterpolation::mayb
eConvertPairwise(const InterpolationEnvironment& environment, const UnderlyingVa
lueOwner& underlyingValueOwner) const | 27 PassOwnPtr<PairwisePrimitiveInterpolation> InvalidatableInterpolation::maybeConv
ertPairwise(const InterpolationEnvironment& environment, const UnderlyingValueOw
ner& underlyingValueOwner) const |
29 { | 28 { |
30 ASSERT(m_currentFraction != 0 && m_currentFraction != 1); | 29 ASSERT(m_currentFraction != 0 && m_currentFraction != 1); |
31 for (const auto& interpolationType : m_interpolationTypes) { | 30 for (const auto& interpolationType : m_interpolationTypes) { |
32 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValueOwner || underlyingValueOwner.type() != *interpolationType)) | 31 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValueOwner || underlyingValueOwner.type() != *interpolationType)) |
33 continue; | 32 continue; |
34 ConversionCheckers conversionCheckers; | 33 ConversionCheckers conversionCheckers; |
35 PairwiseInterpolationValue result = interpolationType->maybeConvertPairw
ise(*m_startKeyframe, *m_endKeyframe, environment, underlyingValueOwner.value(),
conversionCheckers); | 34 PairwiseInterpolationValue result = interpolationType->maybeConvertPairw
ise(*m_startKeyframe, *m_endKeyframe, environment, underlyingValueOwner.value(),
conversionCheckers); |
36 addConversionCheckers(*interpolationType, conversionCheckers); | 35 addConversionCheckers(*interpolationType, conversionCheckers); |
37 if (result) { | 36 if (result) { |
38 return PairwisePrimitiveInterpolation::create(*interpolationType, | 37 return PairwisePrimitiveInterpolation::create(*interpolationType, |
39 std::move(result.startInterpolableValue), | 38 std::move(result.startInterpolableValue), |
40 std::move(result.endInterpolableValue), | 39 std::move(result.endInterpolableValue), |
41 result.nonInterpolableValue.release()); | 40 result.nonInterpolableValue.release()); |
42 } | 41 } |
43 } | 42 } |
44 return nullptr; | 43 return nullptr; |
45 } | 44 } |
46 | 45 |
47 std::unique_ptr<TypedInterpolationValue> InvalidatableInterpolation::convertSing
leKeyframe(const PropertySpecificKeyframe& keyframe, const InterpolationEnvironm
ent& environment, const UnderlyingValueOwner& underlyingValueOwner) const | 46 PassOwnPtr<TypedInterpolationValue> InvalidatableInterpolation::convertSingleKey
frame(const PropertySpecificKeyframe& keyframe, const InterpolationEnvironment&
environment, const UnderlyingValueOwner& underlyingValueOwner) const |
48 { | 47 { |
49 if (keyframe.isNeutral() && !underlyingValueOwner) | 48 if (keyframe.isNeutral() && !underlyingValueOwner) |
50 return nullptr; | 49 return nullptr; |
51 for (const auto& interpolationType : m_interpolationTypes) { | 50 for (const auto& interpolationType : m_interpolationTypes) { |
52 if (keyframe.isNeutral() && underlyingValueOwner.type() != *interpolatio
nType) | 51 if (keyframe.isNeutral() && underlyingValueOwner.type() != *interpolatio
nType) |
53 continue; | 52 continue; |
54 ConversionCheckers conversionCheckers; | 53 ConversionCheckers conversionCheckers; |
55 InterpolationValue result = interpolationType->maybeConvertSingle(keyfra
me, environment, underlyingValueOwner.value(), conversionCheckers); | 54 InterpolationValue result = interpolationType->maybeConvertSingle(keyfra
me, environment, underlyingValueOwner.value(), conversionCheckers); |
56 addConversionCheckers(*interpolationType, conversionCheckers); | 55 addConversionCheckers(*interpolationType, conversionCheckers); |
57 if (result) | 56 if (result) |
58 return TypedInterpolationValue::create(*interpolationType, std::move
(result.interpolableValue), result.nonInterpolableValue.release()); | 57 return TypedInterpolationValue::create(*interpolationType, std::move
(result.interpolableValue), result.nonInterpolableValue.release()); |
59 } | 58 } |
60 ASSERT(keyframe.isNeutral()); | 59 ASSERT(keyframe.isNeutral()); |
61 return nullptr; | 60 return nullptr; |
62 } | 61 } |
63 | 62 |
64 void InvalidatableInterpolation::addConversionCheckers(const InterpolationType&
type, ConversionCheckers& conversionCheckers) const | 63 void InvalidatableInterpolation::addConversionCheckers(const InterpolationType&
type, ConversionCheckers& conversionCheckers) const |
65 { | 64 { |
66 for (size_t i = 0; i < conversionCheckers.size(); i++) { | 65 for (size_t i = 0; i < conversionCheckers.size(); i++) { |
67 conversionCheckers[i]->setType(type); | 66 conversionCheckers[i]->setType(type); |
68 m_conversionCheckers.append(std::move(conversionCheckers[i])); | 67 m_conversionCheckers.append(std::move(conversionCheckers[i])); |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 std::unique_ptr<TypedInterpolationValue> InvalidatableInterpolation::maybeConver
tUnderlyingValue(const InterpolationEnvironment& environment) const | 71 PassOwnPtr<TypedInterpolationValue> InvalidatableInterpolation::maybeConvertUnde
rlyingValue(const InterpolationEnvironment& environment) const |
73 { | 72 { |
74 for (const auto& interpolationType : m_interpolationTypes) { | 73 for (const auto& interpolationType : m_interpolationTypes) { |
75 InterpolationValue result = interpolationType->maybeConvertUnderlyingVal
ue(environment); | 74 InterpolationValue result = interpolationType->maybeConvertUnderlyingVal
ue(environment); |
76 if (result) | 75 if (result) |
77 return TypedInterpolationValue::create(*interpolationType, std::move
(result.interpolableValue), result.nonInterpolableValue.release()); | 76 return TypedInterpolationValue::create(*interpolationType, std::move
(result.interpolableValue), result.nonInterpolableValue.release()); |
78 } | 77 } |
79 return nullptr; | 78 return nullptr; |
80 } | 79 } |
81 | 80 |
82 bool InvalidatableInterpolation::dependsOnUnderlyingValue() const | 81 bool InvalidatableInterpolation::dependsOnUnderlyingValue() const |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 { | 118 { |
120 ASSERT(!std::isnan(m_currentFraction)); | 119 ASSERT(!std::isnan(m_currentFraction)); |
121 if (isCacheValid(environment, underlyingValueOwner)) | 120 if (isCacheValid(environment, underlyingValueOwner)) |
122 return m_cachedValue.get(); | 121 return m_cachedValue.get(); |
123 clearCache(); | 122 clearCache(); |
124 if (m_currentFraction == 0) { | 123 if (m_currentFraction == 0) { |
125 m_cachedValue = convertSingleKeyframe(*m_startKeyframe, environment, und
erlyingValueOwner); | 124 m_cachedValue = convertSingleKeyframe(*m_startKeyframe, environment, und
erlyingValueOwner); |
126 } else if (m_currentFraction == 1) { | 125 } else if (m_currentFraction == 1) { |
127 m_cachedValue = convertSingleKeyframe(*m_endKeyframe, environment, under
lyingValueOwner); | 126 m_cachedValue = convertSingleKeyframe(*m_endKeyframe, environment, under
lyingValueOwner); |
128 } else { | 127 } else { |
129 std::unique_ptr<PairwisePrimitiveInterpolation> pairwiseConversion = may
beConvertPairwise(environment, underlyingValueOwner); | 128 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = maybeConvert
Pairwise(environment, underlyingValueOwner); |
130 if (pairwiseConversion) { | 129 if (pairwiseConversion) { |
131 m_cachedValue = pairwiseConversion->initialValue(); | 130 m_cachedValue = pairwiseConversion->initialValue(); |
132 m_cachedPairConversion = std::move(pairwiseConversion); | 131 m_cachedPairConversion = std::move(pairwiseConversion); |
133 } else { | 132 } else { |
134 m_cachedPairConversion = FlipPrimitiveInterpolation::create( | 133 m_cachedPairConversion = FlipPrimitiveInterpolation::create( |
135 convertSingleKeyframe(*m_startKeyframe, environment, underlyingV
alueOwner), | 134 convertSingleKeyframe(*m_startKeyframe, environment, underlyingV
alueOwner), |
136 convertSingleKeyframe(*m_endKeyframe, environment, underlyingVal
ueOwner)); | 135 convertSingleKeyframe(*m_endKeyframe, environment, underlyingVal
ueOwner)); |
137 } | 136 } |
138 m_cachedPairConversion->interpolateValue(m_currentFraction, m_cachedValu
e); | 137 m_cachedPairConversion->interpolateValue(m_currentFraction, m_cachedValu
e); |
139 } | 138 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 underlyingValueOwner.set(currentValue); | 202 underlyingValueOwner.set(currentValue); |
204 else | 203 else |
205 currentValue->type().composite(underlyingValueOwner, underlyingFract
ion, currentValue->value(), currentInterpolation.m_currentFraction); | 204 currentValue->type().composite(underlyingValueOwner, underlyingFract
ion, currentValue->value(), currentInterpolation.m_currentFraction); |
206 } | 205 } |
207 | 206 |
208 if (shouldApply && underlyingValueOwner) | 207 if (shouldApply && underlyingValueOwner) |
209 underlyingValueOwner.type().apply(*underlyingValueOwner.value().interpol
ableValue, underlyingValueOwner.value().nonInterpolableValue.get(), environment)
; | 208 underlyingValueOwner.type().apply(*underlyingValueOwner.value().interpol
ableValue, underlyingValueOwner.value().nonInterpolableValue.get(), environment)
; |
210 } | 209 } |
211 | 210 |
212 } // namespace blink | 211 } // namespace blink |
OLD | NEW |