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

Side by Side Diff: third_party/WebKit/Source/core/animation/InvalidatableInterpolation.cpp

Issue 1412313005: Rename InvalidatableStyleInterpolation to InvalidatableInterpolation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_renameCSSInterpolationTypes
Patch Set: Created 5 years, 1 month 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
OLDNEW
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/InvalidatableStyleInterpolation.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 InvalidatableStyleInterpolation::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> InvalidatableStyleInterpolation::mayb eConvertPairwise(const InterpolationEnvironment* environment, const UnderlyingVa lue& 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> InvalidatableStyleInterpolation::convertSingleKey frame(const PropertySpecificKeyframe& keyframe, const InterpolationEnvironment& environment, 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> InvalidatableStyleInterpolation::maybeConvertUnde rlyingValue(const InterpolationEnvironment& environment) const 60 PassOwnPtr<InterpolationValue> InvalidatableInterpolation::maybeConvertUnderlyin gValue(const InterpolationEnvironment& environment) const
61 { 61 {
62 for (const auto& interpolationType : m_interpolationTypes) { 62 for (const auto& interpolationType : m_interpolationTypes) {
63 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertUnder lyingValue(environment); 63 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertUnder lyingValue(environment);
64 if (result) 64 if (result)
65 return result.release(); 65 return result.release();
66 } 66 }
67 return nullptr; 67 return nullptr;
68 } 68 }
69 69
70 bool InvalidatableStyleInterpolation::dependsOnUnderlyingValue() const 70 bool InvalidatableInterpolation::dependsOnUnderlyingValue() const
71 { 71 {
72 return (m_startKeyframe->underlyingFraction() != 0 && m_currentFraction != 1 ) || (m_endKeyframe->underlyingFraction() != 0 && m_currentFraction != 0); 72 return (m_startKeyframe->underlyingFraction() != 0 && m_currentFraction != 1 ) || (m_endKeyframe->underlyingFraction() != 0 && m_currentFraction != 0);
73 } 73 }
74 74
75 bool InvalidatableStyleInterpolation::isNeutralKeyframeActive() const 75 bool InvalidatableInterpolation::isNeutralKeyframeActive() const
76 { 76 {
77 return (m_startKeyframe->isNeutral() && m_currentFraction != 1) || (m_endKey frame->isNeutral() && m_currentFraction != 0); 77 return (m_startKeyframe->isNeutral() && m_currentFraction != 1) || (m_endKey frame->isNeutral() && m_currentFraction != 0);
78 } 78 }
79 79
80 void InvalidatableStyleInterpolation::clearCache() const 80 void InvalidatableInterpolation::clearCache() const
81 { 81 {
82 m_isCached = false; 82 m_isCached = false;
83 m_cachedPairConversion.clear(); 83 m_cachedPairConversion.clear();
84 m_conversionCheckers.clear(); 84 m_conversionCheckers.clear();
85 m_cachedValue.clear(); 85 m_cachedValue.clear();
86 } 86 }
87 87
88 bool InvalidatableStyleInterpolation::isCacheValid(const InterpolationEnvironmen t& environment, const UnderlyingValue& underlyingValue) const 88 bool InvalidatableInterpolation::isCacheValid(const InterpolationEnvironment& en vironment, const UnderlyingValue& underlyingValue) const
89 { 89 {
90 if (!m_isCached) 90 if (!m_isCached)
91 return false; 91 return false;
92 if (isNeutralKeyframeActive()) { 92 if (isNeutralKeyframeActive()) {
93 if (m_cachedPairConversion && m_cachedPairConversion->isFlip()) 93 if (m_cachedPairConversion && m_cachedPairConversion->isFlip())
94 return false; 94 return false;
95 // Pairwise interpolation can never happen between different Interpolati onTypes, neutral values always represent the underlying value. 95 // Pairwise interpolation can never happen between different Interpolati onTypes, neutral values always represent the underlying value.
96 if (!underlyingValue || !m_cachedValue || m_cachedValue->type() != under lyingValue->type()) 96 if (!underlyingValue || !m_cachedValue || m_cachedValue->type() != under lyingValue->type())
97 return false; 97 return false;
98 } 98 }
99 for (const auto& checker : m_conversionCheckers) { 99 for (const auto& checker : m_conversionCheckers) {
100 if (!checker->isValid(environment, underlyingValue)) 100 if (!checker->isValid(environment, underlyingValue))
101 return false; 101 return false;
102 } 102 }
103 return true; 103 return true;
104 } 104 }
105 105
106 const InterpolationValue* InvalidatableStyleInterpolation::ensureValidInterpolat ion(const InterpolationEnvironment& environment, const UnderlyingValue& underlyi ngValue) const 106 const InterpolationValue* InvalidatableInterpolation::ensureValidInterpolation(c onst InterpolationEnvironment& environment, const UnderlyingValue& underlyingVal ue) const
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 }
128 m_isCached = true; 128 m_isCached = true;
129 return m_cachedValue.get(); 129 return m_cachedValue.get();
130 } 130 }
131 131
132 void InvalidatableStyleInterpolation::setFlagIfInheritUsed(InterpolationEnvironm ent& environment) const 132 void InvalidatableInterpolation::setFlagIfInheritUsed(InterpolationEnvironment& environment) const
133 { 133 {
134 if (!property().isCSSProperty()) 134 if (!property().isCSSProperty())
135 return; 135 return;
136 if (!environment.state().parentStyle()) 136 if (!environment.state().parentStyle())
137 return; 137 return;
138 const CSSValue* startValue = toCSSPropertySpecificKeyframe(m_startKeyframe)- >value(); 138 const CSSValue* startValue = toCSSPropertySpecificKeyframe(m_startKeyframe)- >value();
139 const CSSValue* endValue = toCSSPropertySpecificKeyframe(m_endKeyframe)->val ue(); 139 const CSSValue* endValue = toCSSPropertySpecificKeyframe(m_endKeyframe)->val ue();
140 if ((startValue && startValue->isInheritedValue()) 140 if ((startValue && startValue->isInheritedValue())
141 || (endValue && endValue->isInheritedValue())) { 141 || (endValue && endValue->isInheritedValue())) {
142 environment.state().parentStyle()->setHasExplicitlyInheritedProperties() ; 142 environment.state().parentStyle()->setHasExplicitlyInheritedProperties() ;
143 } 143 }
144 } 144 }
145 145
146 double InvalidatableStyleInterpolation::underlyingFraction() const 146 double InvalidatableInterpolation::underlyingFraction() const
147 { 147 {
148 if (m_currentFraction == 0) 148 if (m_currentFraction == 0)
149 return m_startKeyframe->underlyingFraction(); 149 return m_startKeyframe->underlyingFraction();
150 if (m_currentFraction == 1) 150 if (m_currentFraction == 1)
151 return m_endKeyframe->underlyingFraction(); 151 return m_endKeyframe->underlyingFraction();
152 return m_cachedPairConversion->interpolateUnderlyingFraction(m_startKeyframe ->underlyingFraction(), m_endKeyframe->underlyingFraction(), m_currentFraction); 152 return m_cachedPairConversion->interpolateUnderlyingFraction(m_startKeyframe ->underlyingFraction(), m_endKeyframe->underlyingFraction(), m_currentFraction);
153 } 153 }
154 154
155 void InvalidatableStyleInterpolation::applyStack(const ActiveInterpolations& int erpolations, InterpolationEnvironment& environment) 155 void InvalidatableInterpolation::applyStack(const ActiveInterpolations& interpol ations, InterpolationEnvironment& environment)
156 { 156 {
157 ASSERT(!interpolations.isEmpty()); 157 ASSERT(!interpolations.isEmpty());
158 size_t startingIndex = 0; 158 size_t startingIndex = 0;
159 159
160 // Compute the underlying value to composite onto. 160 // Compute the underlying value to composite onto.
161 UnderlyingValue underlyingValue; 161 UnderlyingValue underlyingValue;
162 const InvalidatableStyleInterpolation& firstInterpolation = toInvalidatableS tyleInterpolation(*interpolations.at(startingIndex)); 162 const InvalidatableInterpolation& firstInterpolation = toInvalidatableInterp olation(*interpolations.at(startingIndex));
163 if (firstInterpolation.dependsOnUnderlyingValue()) { 163 if (firstInterpolation.dependsOnUnderlyingValue()) {
164 underlyingValue.set(firstInterpolation.maybeConvertUnderlyingValue(envir onment)); 164 underlyingValue.set(firstInterpolation.maybeConvertUnderlyingValue(envir onment));
165 } else { 165 } else {
166 const InterpolationValue* firstValue = firstInterpolation.ensureValidInt erpolation(environment, UnderlyingValue()); 166 const InterpolationValue* firstValue = firstInterpolation.ensureValidInt erpolation(environment, UnderlyingValue());
167 // Fast path for replace interpolations that are the only one to apply. 167 // Fast path for replace interpolations that are the only one to apply.
168 if (interpolations.size() == 1) { 168 if (interpolations.size() == 1) {
169 if (firstValue) { 169 if (firstValue) {
170 firstInterpolation.setFlagIfInheritUsed(environment); 170 firstInterpolation.setFlagIfInheritUsed(environment);
171 firstValue->type().apply(firstValue->interpolableValue(), firstV alue->nonInterpolableValue(), environment); 171 firstValue->type().apply(firstValue->interpolableValue(), firstV alue->nonInterpolableValue(), environment);
172 } 172 }
173 return; 173 return;
174 } 174 }
175 underlyingValue.set(firstValue); 175 underlyingValue.set(firstValue);
176 startingIndex++; 176 startingIndex++;
177 } 177 }
178 178
179 // Composite interpolations onto the underlying value. 179 // Composite interpolations onto the underlying value.
180 bool shouldApply = false; 180 bool shouldApply = false;
181 for (size_t i = startingIndex; i < interpolations.size(); i++) { 181 for (size_t i = startingIndex; i < interpolations.size(); i++) {
182 const InvalidatableStyleInterpolation& currentInterpolation = toInvalida tableStyleInterpolation(*interpolations.at(i)); 182 const InvalidatableInterpolation& currentInterpolation = toInvalidatable Interpolation(*interpolations.at(i));
183 ASSERT(currentInterpolation.dependsOnUnderlyingValue()); 183 ASSERT(currentInterpolation.dependsOnUnderlyingValue());
184 const InterpolationValue* currentValue = currentInterpolation.ensureVali dInterpolation(environment, underlyingValue); 184 const InterpolationValue* currentValue = currentInterpolation.ensureVali dInterpolation(environment, underlyingValue);
185 if (!currentValue) 185 if (!currentValue)
186 continue; 186 continue;
187 shouldApply = true; 187 shouldApply = true;
188 currentInterpolation.setFlagIfInheritUsed(environment); 188 currentInterpolation.setFlagIfInheritUsed(environment);
189 double underlyingFraction = currentInterpolation.underlyingFraction(); 189 double underlyingFraction = currentInterpolation.underlyingFraction();
190 if (underlyingFraction == 0 || !underlyingValue || underlyingValue->type () != currentValue->type()) 190 if (underlyingFraction == 0 || !underlyingValue || underlyingValue->type () != currentValue->type())
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698