Chromium Code Reviews| Index: Source/core/animation/InvalidatableStyleInterpolation.cpp |
| diff --git a/Source/core/animation/InvalidatableStyleInterpolation.cpp b/Source/core/animation/InvalidatableStyleInterpolation.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c610e59f5c8e963d10d905952f296dc1b7dfce85 |
| --- /dev/null |
| +++ b/Source/core/animation/InvalidatableStyleInterpolation.cpp |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/animation/InvalidatableStyleInterpolation.h" |
| + |
| +#include "core/animation/StringKeyframe.h" |
| + |
| +namespace blink { |
| + |
| +InvalidatableStyleInterpolation::InvalidatableStyleInterpolation( |
| + const Vector<const AnimationType*>& animationTypes, |
| + const CSSPropertySpecificKeyframe& startKeyframe, |
| + const CSSPropertySpecificKeyframe& endKeyframe) |
| + : StyleInterpolation(nullptr, nullptr, animationTypes.first()->property()) |
| + , m_animationTypes(animationTypes) |
| + , m_startKeyframe(startKeyframe) |
| + , m_endKeyframe(endKeyframe) |
| +{ |
| + maybeCachePairwiseConversion(nullptr); |
| + interpolate(0, 0); |
| +} |
| + |
| +bool InvalidatableStyleInterpolation::maybeCachePairwiseConversion(const StyleResolverState* state) const |
| +{ |
| + for (const auto& animationType : m_animationTypes) { |
| + OwnPtrWillBeRawPtr<PairwiseInterpolationPrimitive> pairwiseConversion = animationType->maybeConvertPairwise(m_startKeyframe, m_endKeyframe, state, m_conversionInvalidators); |
| + if (pairwiseConversion) { |
| + m_cachedValue.type = animationType; |
| + pairwiseConversion->initialiseAnimationValue(m_cachedValue); |
| + m_cachedConversion = pairwiseConversion.release(); |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +void InvalidatableStyleInterpolation::interpolate(int, double fraction) |
| +{ |
| + m_currentFraction = fraction; |
| + if (m_cachedConversion) |
| + m_cachedConversion->interpolate(fraction, m_cachedValue); |
|
shans
2015/06/22 11:43:21
comment inline that interpolation is deferred to v
alancutter (OOO until 2018)
2015/06/23 05:05:33
Done.
|
| +} |
| + |
| +PassOwnPtrWillBeRawPtr<FlipInterpolationPrimitive::Side> InvalidatableStyleInterpolation::convertSingleKeyframe(const CSSPropertySpecificKeyframe& keyframe, const StyleResolverState& state) const |
| +{ |
| + for (const auto& animationType : m_animationTypes) { |
| + OwnPtrWillBeRawPtr<FlipInterpolationPrimitive::Side> result = animationType->maybeConvertSingle(keyframe, &state, m_conversionInvalidators); |
| + if (result) |
| + return result.release(); |
| + } |
| + ASSERT_NOT_REACHED(); |
| + return nullptr; |
| +} |
| + |
| +bool InvalidatableStyleInterpolation::isCacheValid(const StyleResolverState& state) const |
| +{ |
| + for (const auto& invalidator : m_conversionInvalidators) { |
| + if (invalidator->isInvalid(state)) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +void InvalidatableStyleInterpolation::ensureValidCache(const StyleResolverState& state) const |
| +{ |
| + if (m_cachedConversion && isCacheValid(state)) |
| + return; |
| + m_conversionInvalidators.clear(); |
| + if (!maybeCachePairwiseConversion(&state)) { |
| + m_cachedConversion = FlipInterpolationPrimitive::create( |
| + convertSingleKeyframe(m_startKeyframe, state), |
| + convertSingleKeyframe(m_endKeyframe, state)); |
| + } |
| + m_cachedConversion->interpolate(m_currentFraction, m_cachedValue); |
|
shans
2015/06/22 11:43:21
It's slightly weird to see interpolate called insi
alancutter (OOO until 2018)
2015/06/23 05:05:33
We may have already interpolated, this also checks
|
| +} |
|
shans
2015/06/22 11:43:22
Is this method going to blow out as we have more P
alancutter (OOO until 2018)
2015/06/23 05:05:33
We will not be adding more PrimitiveInterpolation
|
| + |
| +void InvalidatableStyleInterpolation::apply(StyleResolverState& state) const |
| +{ |
| + ensureValidCache(state); |
| + m_cachedValue.type->apply(*m_cachedValue.interpolableValue, m_cachedValue.nonInterpolableValue.get(), state); |
| +} |
| + |
| +} // namespace blink |