Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Unified Diff: Source/core/animation/InvalidatableStyleInterpolation.cpp

Issue 1153943003: Add foundation for removing AnimatableValues from StyleInterpolation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: PassOwnPtr Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bfcd657621f7f26aca894f480b3d0537310864fe
--- /dev/null
+++ b/Source/core/animation/InvalidatableStyleInterpolation.cpp
@@ -0,0 +1,78 @@
+// 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,
+ PassRefPtrWillBeRawPtr<CSSPropertySpecificKeyframe> startKeyframe,
+ PassRefPtrWillBeRawPtr<CSSPropertySpecificKeyframe> endKeyframe)
+ : StyleInterpolation(nullptr, nullptr, animationTypes.first()->property())
+ , m_animationTypes(animationTypes)
+ , m_startKeyframe(startKeyframe)
+ , m_endKeyframe(endKeyframe)
+ , m_cachedConversion(nullptr)
+{
+ maybeCachePairwiseConversion(nullptr);
shans 2015/06/04 00:15:15 should be doing the convertSingleKeyframe fallback
alancutter (OOO until 2018) 2015/06/11 04:15:13 If pairwise conversion fails here we hold off unti
+ interpolate(0, 0);
+}
+
+bool InvalidatableStyleInterpolation::maybeCachePairwiseConversion(const StyleResolverState* state) const
+{
+ for (const auto& animationType : m_animationTypes) {
+ OwnPtrWillBeRawPtr<PairwiseAnimationConversion> pairwiseConversion = animationType->maybeConvertPairwise(*m_startKeyframe, *m_endKeyframe, state);
+ 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);
+ else
+ m_cachedValue.clear();
shans 2015/06/04 00:15:15 Is this right? I thought we always needed a way to
alancutter (OOO until 2018) 2015/06/11 04:15:13 interpolate() may be called prior to apply(). Some
+}
+
+static PassOwnPtrWillBeRawPtr<AnimationConversionHalf> convertSingleKeyframe(const Vector<const AnimationType*>& animationTypes, const CSSPropertySpecificKeyframe& keyframe, const StyleResolverState& state)
+{
+ for (const auto& animationType : animationTypes) {
+ OwnPtrWillBeRawPtr<AnimationConversionHalf> result = animationType->maybeConvertSingle(keyframe, &state);
+ if (result) {
+ result->type = animationType;
shans 2015/06/04 00:15:15 This isn't the right way to do this! result was *j
alancutter (OOO until 2018) 2015/06/11 04:15:13 Done.
+ return result.release();
+ }
+ }
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+void InvalidatableStyleInterpolation::validateCache(const StyleResolverState& state) const
+{
+ if (m_cachedConversion && !m_cachedConversion->isInvalid(state))
+ return;
+ if (!maybeCachePairwiseConversion(&state))
+ m_cachedConversion = DefaultAnimationConversion::create(convertSingleKeyframe(m_animationTypes, *m_startKeyframe, state), convertSingleKeyframe(m_animationTypes, *m_endKeyframe, state));
+ m_cachedConversion->interpolate(m_currentFraction, m_cachedValue);
+}
+
+void InvalidatableStyleInterpolation::apply(StyleResolverState& state) const
+{
+ validateCache(state);
+ if (m_cachedValue)
+ m_cachedValue.type->apply(*m_cachedValue.interpolableValue, m_cachedValue.nonInterpolableValue.get(), state);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698