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/InvalidatableStyleInterpolation.h" | 6 #include "core/animation/InvalidatableStyleInterpolation.h" |
7 | 7 |
8 #include "core/animation/StringKeyframe.h" | 8 #include "core/animation/StringKeyframe.h" |
9 #include "core/css/resolver/StyleResolverState.h" | 9 #include "core/css/resolver/StyleResolverState.h" |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 || (m_endKeyframe->value() && m_endKeyframe->value()->isInheritedValue()
)) { | 119 || (m_endKeyframe->value() && m_endKeyframe->value()->isInheritedValue()
)) { |
120 state.parentStyle()->setHasExplicitlyInheritedProperties(); | 120 state.parentStyle()->setHasExplicitlyInheritedProperties(); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 double InvalidatableStyleInterpolation::underlyingFraction() const | 124 double InvalidatableStyleInterpolation::underlyingFraction() const |
125 { | 125 { |
126 return m_cachedConversion->interpolateUnderlyingFraction(m_startKeyframe->un
derlyingFraction(), m_endKeyframe->underlyingFraction(), m_currentFraction); | 126 return m_cachedConversion->interpolateUnderlyingFraction(m_startKeyframe->un
derlyingFraction(), m_endKeyframe->underlyingFraction(), m_currentFraction); |
127 } | 127 } |
128 | 128 |
129 // Handles memory management of underlying InterpolationValues in applyStack() | |
130 // Ensures we perform copy on write if we are not the owner of an underlying Int
erpolationValue. | |
131 // This functions similar to a DataRef except on OwnPtr'd objects. | |
132 class UnderlyingValue { | |
133 STACK_ALLOCATED(); | |
134 | |
135 public: | |
136 UnderlyingValue() | |
137 : m_valueOwner(nullptr) | |
138 , m_value(nullptr) | |
139 { } | |
140 | |
141 void set(const InterpolationValue* interpolationValue) | |
142 { | |
143 // By clearing m_valueOwner we will perform a copy before attempting to
mutate m_value, | |
144 // thus upholding the const contract for this instance of interpolationV
alue despite the const_cast. | |
145 m_valueOwner.clear(); | |
146 m_value = const_cast<InterpolationValue*>(interpolationValue); | |
147 } | |
148 void set(PassOwnPtr<InterpolationValue> interpolationValue) | |
149 { | |
150 m_valueOwner = interpolationValue; | |
151 m_value = m_valueOwner.get(); | |
152 } | |
153 InterpolationComponentValue& mutableComponent() | |
154 { | |
155 ASSERT(m_value); | |
156 if (!m_valueOwner) | |
157 set(m_value->clone()); | |
158 return m_value->mutableComponent(); | |
159 } | |
160 const InterpolationValue* get() const { return m_value; } | |
161 operator bool() const { return m_value; } | |
162 const InterpolationValue* operator->() const | |
163 { | |
164 ASSERT(m_value); | |
165 return m_value; | |
166 } | |
167 | |
168 private: | |
169 OwnPtr<InterpolationValue> m_valueOwner; | |
170 InterpolationValue* m_value; | |
171 }; | |
172 | |
173 void InvalidatableStyleInterpolation::applyStack(const ActiveInterpolations& int
erpolations, StyleResolverState& state) | 129 void InvalidatableStyleInterpolation::applyStack(const ActiveInterpolations& int
erpolations, StyleResolverState& state) |
174 { | 130 { |
175 ASSERT(!interpolations.isEmpty()); | 131 ASSERT(!interpolations.isEmpty()); |
176 size_t startingIndex = 0; | 132 size_t startingIndex = 0; |
177 | 133 |
178 // Compute the underlying value to composite onto. | 134 // Compute the underlying value to composite onto. |
179 UnderlyingValue underlyingValue; | 135 UnderlyingValue underlyingValue; |
180 const InvalidatableStyleInterpolation& firstInterpolation = toInvalidatableS
tyleInterpolation(*interpolations.at(startingIndex)); | 136 const InvalidatableStyleInterpolation& firstInterpolation = toInvalidatableS
tyleInterpolation(*interpolations.at(startingIndex)); |
181 if (firstInterpolation.dependsOnUnderlyingValue()) { | 137 if (firstInterpolation.dependsOnUnderlyingValue()) { |
182 underlyingValue.set(firstInterpolation.maybeConvertUnderlyingValue(state
)); | 138 underlyingValue.set(firstInterpolation.maybeConvertUnderlyingValue(state
)); |
(...skipping 18 matching lines...) Expand all Loading... |
201 ASSERT(currentInterpolation.dependsOnUnderlyingValue()); | 157 ASSERT(currentInterpolation.dependsOnUnderlyingValue()); |
202 const InterpolationValue* currentValue = currentInterpolation.ensureVali
dInterpolation(state, underlyingValue.get()); | 158 const InterpolationValue* currentValue = currentInterpolation.ensureVali
dInterpolation(state, underlyingValue.get()); |
203 if (!currentValue) | 159 if (!currentValue) |
204 continue; | 160 continue; |
205 shouldApply = true; | 161 shouldApply = true; |
206 currentInterpolation.setFlagIfInheritUsed(state); | 162 currentInterpolation.setFlagIfInheritUsed(state); |
207 double underlyingFraction = currentInterpolation.underlyingFraction(); | 163 double underlyingFraction = currentInterpolation.underlyingFraction(); |
208 if (underlyingFraction == 0 || !underlyingValue || underlyingValue->type
() != currentValue->type()) | 164 if (underlyingFraction == 0 || !underlyingValue || underlyingValue->type
() != currentValue->type()) |
209 underlyingValue.set(currentValue); | 165 underlyingValue.set(currentValue); |
210 else | 166 else |
211 underlyingValue.mutableComponent().interpolableValue->scaleAndAdd(un
derlyingFraction, currentValue->interpolableValue()); | 167 currentValue->type().composite(underlyingValue, underlyingFraction,
*currentValue); |
212 } | 168 } |
213 | 169 |
214 if (shouldApply && underlyingValue) | 170 if (shouldApply && underlyingValue) |
215 underlyingValue->type().apply(underlyingValue->interpolableValue(), unde
rlyingValue->nonInterpolableValue(), state); | 171 underlyingValue->type().apply(underlyingValue->interpolableValue(), unde
rlyingValue->nonInterpolableValue(), state); |
216 } | 172 } |
217 | 173 |
218 } // namespace blink | 174 } // namespace blink |
OLD | NEW |