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

Side by Side 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: Review changes Created 5 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/animation/InvalidatableStyleInterpolation.h"
7
8 #include "core/animation/StringKeyframe.h"
9
10 namespace blink {
11
12 InvalidatableStyleInterpolation::InvalidatableStyleInterpolation(
13 const Vector<const AnimationType*>& animationTypes,
14 const CSSPropertySpecificKeyframe& startKeyframe,
15 const CSSPropertySpecificKeyframe& endKeyframe)
16 : StyleInterpolation(nullptr, nullptr, animationTypes.first()->property())
17 , m_animationTypes(animationTypes)
18 , m_startKeyframe(startKeyframe)
19 , m_endKeyframe(endKeyframe)
20 {
21 maybeCachePairwiseConversion(nullptr);
22 interpolate(0, 0);
23 }
24
25 bool InvalidatableStyleInterpolation::maybeCachePairwiseConversion(const StyleRe solverState* state) const
26 {
27 for (const auto& animationType : m_animationTypes) {
28 OwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> pairwiseConversion = animationType->maybeConvertPairwise(m_startKeyframe, m_endKeyframe, state, m_con versionCheckers);
29 if (pairwiseConversion) {
30 m_cachedValue.type = animationType;
31 pairwiseConversion->initializeAnimationValue(m_cachedValue);
32 m_cachedConversion = pairwiseConversion.release();
33 return true;
34 }
35 }
36 return false;
37 }
38
39 void InvalidatableStyleInterpolation::interpolate(int, double fraction)
40 {
41 m_currentFraction = fraction;
42 if (m_cachedConversion)
43 m_cachedConversion->interpolate(fraction, m_cachedValue);
44 // We defer the interpolation to ensureValidInterpolation() if m_cachedConve rsion is null.
45 }
46
47 PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation::Side> InvalidatableStyleInter polation::convertSingleKeyframe(const CSSPropertySpecificKeyframe& keyframe, con st StyleResolverState& state) const
48 {
49 for (const auto& animationType : m_animationTypes) {
50 OwnPtrWillBeRawPtr<FlipPrimitiveInterpolation::Side> result = animationT ype->maybeConvertSingle(keyframe, &state, m_conversionCheckers);
51 if (result)
52 return result.release();
53 }
54 ASSERT_NOT_REACHED();
55 return nullptr;
56 }
57
58 bool InvalidatableStyleInterpolation::isCacheValid(const StyleResolverState& sta te) const
59 {
60 for (const auto& checker : m_conversionCheckers) {
61 if (!checker->isValid(state))
62 return false;
63 }
64 return true;
65 }
66
67 void InvalidatableStyleInterpolation::ensureValidInterpolation(const StyleResolv erState& state) const
68 {
69 if (m_cachedConversion && isCacheValid(state))
70 return;
71 m_conversionCheckers.clear();
72 if (!maybeCachePairwiseConversion(&state)) {
73 m_cachedConversion = FlipPrimitiveInterpolation::create(
74 convertSingleKeyframe(m_startKeyframe, state),
75 convertSingleKeyframe(m_endKeyframe, state));
76 }
77 m_cachedConversion->interpolate(m_currentFraction, m_cachedValue);
78 }
79
80 void InvalidatableStyleInterpolation::apply(StyleResolverState& state) const
81 {
82 ensureValidInterpolation(state);
83 m_cachedValue.type->apply(*m_cachedValue.interpolableValue, m_cachedValue.no nInterpolableValue.get(), state);
84 }
85
86 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/animation/InvalidatableStyleInterpolation.h ('k') | Source/core/animation/NonInterpolableValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698