| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/InvalidatableInterpolation.h" | 6 #include "core/animation/InvalidatableInterpolation.h" |
| 7 | 7 |
| 8 #include "core/animation/InterpolationEnvironment.h" | 8 #include "core/animation/InterpolationEnvironment.h" |
| 9 #include "core/animation/StringKeyframe.h" | 9 #include "core/animation/StringKeyframe.h" |
| 10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void InvalidatableInterpolation::interpolate(int, double fraction) | 14 void InvalidatableInterpolation::interpolate(int, double fraction) |
| 15 { | 15 { |
| 16 if (fraction == m_currentFraction) | 16 if (fraction == m_currentFraction) |
| 17 return; | 17 return; |
| 18 | 18 |
| 19 if (m_currentFraction == 0 || m_currentFraction == 1 || fraction == 0 || fra
ction == 1) | 19 if (m_currentFraction == 0 || m_currentFraction == 1 || fraction == 0 || fra
ction == 1) |
| 20 clearCache(); | 20 clearCache(); |
| 21 | 21 |
| 22 m_currentFraction = fraction; | 22 m_currentFraction = fraction; |
| 23 if (m_isCached && m_cachedPairConversion) | 23 if (m_isCached && m_cachedPairConversion) |
| 24 m_cachedPairConversion->interpolateValue(fraction, m_cachedValue); | 24 m_cachedPairConversion->interpolateValue(fraction, m_cachedValue); |
| 25 // We defer the interpolation to ensureValidInterpolation() if m_cachedPairC
onversion is null. | 25 // We defer the interpolation to ensureValidInterpolation() if m_cachedPairC
onversion is null. |
| 26 } | 26 } |
| 27 | 27 |
| 28 PassOwnPtr<PairwisePrimitiveInterpolation> InvalidatableInterpolation::maybeConv
ertPairwise(const InterpolationEnvironment* environment, const UnderlyingValue&
underlyingValue) const | 28 PassOwnPtr<PairwisePrimitiveInterpolation> InvalidatableInterpolation::maybeConv
ertPairwise(const InterpolationEnvironment& environment, const UnderlyingValue&
underlyingValue) const |
| 29 { | 29 { |
| 30 ASSERT(m_currentFraction != 0 && m_currentFraction != 1); | 30 ASSERT(m_currentFraction != 0 && m_currentFraction != 1); |
| 31 for (const auto& interpolationType : m_interpolationTypes) { | 31 for (const auto& interpolationType : m_interpolationTypes) { |
| 32 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValue || underlyingValue->type() != *interpolationType)) | 32 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValue || underlyingValue->type() != *interpolationType)) |
| 33 continue; | 33 continue; |
| 34 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = interpolatio
nType->maybeConvertPairwise(*m_startKeyframe, *m_endKeyframe, environment, under
lyingValue, m_conversionCheckers); | 34 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = interpolatio
nType->maybeConvertPairwise(*m_startKeyframe, *m_endKeyframe, environment, under
lyingValue, m_conversionCheckers); |
| 35 if (pairwiseConversion) { | 35 if (pairwiseConversion) { |
| 36 ASSERT(pairwiseConversion->type() == *interpolationType); | 36 ASSERT(pairwiseConversion->type() == *interpolationType); |
| 37 return pairwiseConversion.release(); | 37 return pairwiseConversion.release(); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 return nullptr; | 40 return nullptr; |
| 41 } | 41 } |
| 42 | 42 |
| 43 PassOwnPtr<InterpolationValue> InvalidatableInterpolation::convertSingleKeyframe
(const PropertySpecificKeyframe& keyframe, const InterpolationEnvironment& envir
onment, const UnderlyingValue& underlyingValue) const | 43 PassOwnPtr<InterpolationValue> InvalidatableInterpolation::convertSingleKeyframe
(const PropertySpecificKeyframe& keyframe, const InterpolationEnvironment& envir
onment, const UnderlyingValue& underlyingValue) const |
| 44 { | 44 { |
| 45 if (keyframe.isNeutral() && !underlyingValue) | 45 if (keyframe.isNeutral() && !underlyingValue) |
| 46 return nullptr; | 46 return nullptr; |
| 47 for (const auto& interpolationType : m_interpolationTypes) { | 47 for (const auto& interpolationType : m_interpolationTypes) { |
| 48 if (keyframe.isNeutral() && underlyingValue->type() != *interpolationTyp
e) | 48 if (keyframe.isNeutral() && underlyingValue->type() != *interpolationTyp
e) |
| 49 continue; | 49 continue; |
| 50 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertSingl
e(keyframe, &environment, underlyingValue, m_conversionCheckers); | 50 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertSingl
e(keyframe, environment, underlyingValue, m_conversionCheckers); |
| 51 if (result) { | 51 if (result) { |
| 52 ASSERT(result->type() == *interpolationType); | 52 ASSERT(result->type() == *interpolationType); |
| 53 return result.release(); | 53 return result.release(); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 ASSERT(keyframe.isNeutral()); | 56 ASSERT(keyframe.isNeutral()); |
| 57 return nullptr; | 57 return nullptr; |
| 58 } | 58 } |
| 59 | 59 |
| 60 PassOwnPtr<InterpolationValue> InvalidatableInterpolation::maybeConvertUnderlyin
gValue(const InterpolationEnvironment& environment) const | 60 PassOwnPtr<InterpolationValue> InvalidatableInterpolation::maybeConvertUnderlyin
gValue(const InterpolationEnvironment& environment) const |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 { | 107 { |
| 108 ASSERT(!std::isnan(m_currentFraction)); | 108 ASSERT(!std::isnan(m_currentFraction)); |
| 109 if (isCacheValid(environment, underlyingValue)) | 109 if (isCacheValid(environment, underlyingValue)) |
| 110 return m_cachedValue.get(); | 110 return m_cachedValue.get(); |
| 111 clearCache(); | 111 clearCache(); |
| 112 if (m_currentFraction == 0) { | 112 if (m_currentFraction == 0) { |
| 113 m_cachedValue = convertSingleKeyframe(*m_startKeyframe, environment, und
erlyingValue); | 113 m_cachedValue = convertSingleKeyframe(*m_startKeyframe, environment, und
erlyingValue); |
| 114 } else if (m_currentFraction == 1) { | 114 } else if (m_currentFraction == 1) { |
| 115 m_cachedValue = convertSingleKeyframe(*m_endKeyframe, environment, under
lyingValue); | 115 m_cachedValue = convertSingleKeyframe(*m_endKeyframe, environment, under
lyingValue); |
| 116 } else { | 116 } else { |
| 117 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = maybeConvert
Pairwise(&environment, underlyingValue); | 117 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = maybeConvert
Pairwise(environment, underlyingValue); |
| 118 if (pairwiseConversion) { | 118 if (pairwiseConversion) { |
| 119 m_cachedValue = pairwiseConversion->initialValue(); | 119 m_cachedValue = pairwiseConversion->initialValue(); |
| 120 m_cachedPairConversion = pairwiseConversion.release(); | 120 m_cachedPairConversion = pairwiseConversion.release(); |
| 121 } else { | 121 } else { |
| 122 m_cachedPairConversion = FlipPrimitiveInterpolation::create( | 122 m_cachedPairConversion = FlipPrimitiveInterpolation::create( |
| 123 convertSingleKeyframe(*m_startKeyframe, environment, underlyingV
alue), | 123 convertSingleKeyframe(*m_startKeyframe, environment, underlyingV
alue), |
| 124 convertSingleKeyframe(*m_endKeyframe, environment, underlyingVal
ue)); | 124 convertSingleKeyframe(*m_endKeyframe, environment, underlyingVal
ue)); |
| 125 } | 125 } |
| 126 m_cachedPairConversion->interpolateValue(m_currentFraction, m_cachedValu
e); | 126 m_cachedPairConversion->interpolateValue(m_currentFraction, m_cachedValu
e); |
| 127 } | 127 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 underlyingValue.set(currentValue); | 191 underlyingValue.set(currentValue); |
| 192 else | 192 else |
| 193 currentValue->type().composite(underlyingValue, underlyingFraction,
*currentValue); | 193 currentValue->type().composite(underlyingValue, underlyingFraction,
*currentValue); |
| 194 } | 194 } |
| 195 | 195 |
| 196 if (shouldApply && underlyingValue) | 196 if (shouldApply && underlyingValue) |
| 197 underlyingValue->type().apply(underlyingValue->interpolableValue(), unde
rlyingValue->nonInterpolableValue(), environment); | 197 underlyingValue->type().apply(underlyingValue->interpolableValue(), unde
rlyingValue->nonInterpolableValue(), environment); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |