OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "core/animation/StackableInterpolation.h" |
| 6 |
| 7 #include "core/animation/InterpolationType.h" |
| 8 #include "core/animation/TypedInterpolationValue.h" |
| 9 #include "core/animation/UnderlyingValueOwner.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 void StackableInterpolation::applyStack(const ActiveInterpolations& interpolatio
ns, InterpolationEnvironment& environment) |
| 14 { |
| 15 DCHECK(!interpolations.isEmpty()); |
| 16 size_t startingIndex = 0; |
| 17 |
| 18 // Compute the underlying value to composite onto. |
| 19 UnderlyingValueOwner underlyingValueOwner; |
| 20 const StackableInterpolation& firstInterpolation = toStackableInterpolation(
*interpolations.at(startingIndex)); |
| 21 if (firstInterpolation.dependsOnUnderlyingValue()) { |
| 22 underlyingValueOwner.set(firstInterpolation.maybeConvertUnderlyingValue(
environment)); |
| 23 } else { |
| 24 const TypedInterpolationValue* firstValue = firstInterpolation.ensureVal
idInterpolation(environment, underlyingValueOwner); |
| 25 // Fast path for replace interpolations that are the only one to apply. |
| 26 if (interpolations.size() == 1) { |
| 27 if (firstValue) { |
| 28 firstInterpolation.setFlagIfInheritUsed(environment); |
| 29 firstValue->type().apply(firstValue->interpolableValue(), firstV
alue->getNonInterpolableValue(), environment); |
| 30 } |
| 31 return; |
| 32 } |
| 33 underlyingValueOwner.set(firstValue); |
| 34 startingIndex++; |
| 35 } |
| 36 |
| 37 // Composite interpolations onto the underlying value. |
| 38 bool shouldApply = false; |
| 39 for (size_t i = startingIndex; i < interpolations.size(); i++) { |
| 40 const StackableInterpolation& currentInterpolation = toStackableInterpol
ation(*interpolations.at(i)); |
| 41 DCHECK(currentInterpolation.dependsOnUnderlyingValue()); |
| 42 const TypedInterpolationValue* currentValue = currentInterpolation.ensur
eValidInterpolation(environment, underlyingValueOwner); |
| 43 if (!currentValue) |
| 44 continue; |
| 45 shouldApply = true; |
| 46 currentInterpolation.setFlagIfInheritUsed(environment); |
| 47 double underlyingFraction = currentInterpolation.underlyingFraction(); |
| 48 if (underlyingFraction == 0 || !underlyingValueOwner || underlyingValueO
wner.type() != currentValue->type()) |
| 49 underlyingValueOwner.set(currentValue); |
| 50 else |
| 51 currentValue->type().composite(underlyingValueOwner, underlyingFract
ion, currentValue->value(), currentInterpolation.m_currentFraction); |
| 52 } |
| 53 |
| 54 if (shouldApply && underlyingValueOwner) |
| 55 underlyingValueOwner.type().apply(*underlyingValueOwner.value().interpol
ableValue, underlyingValueOwner.value().nonInterpolableValue.get(), environment)
; |
| 56 } |
| 57 |
| 58 } // namespace blink |
OLD | NEW |