| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/InterpolationEffect.h" | 6 #include "core/animation/InterpolationEffect.h" |
| 7 | 7 |
| 8 namespace blink { | 8 namespace blink { |
| 9 | 9 |
| 10 void InterpolationEffect::getActiveInterpolations(double fraction, double iterat
ionDuration, OwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolatio
n>>>& result) const | 10 void InterpolationEffect::getActiveInterpolations(double fraction, double iterat
ionDuration, HeapVector<Member<Interpolation>>*& result) const |
| 11 { | 11 { |
| 12 if (!result) | 12 if (!result) |
| 13 result = adoptPtrWillBeNoop(new WillBeHeapVector<RefPtrWillBeMember<Inte
rpolation>>()); | 13 result = new HeapVector<Member<Interpolation>>(); |
| 14 | 14 |
| 15 size_t existingSize = result->size(); | 15 size_t existingSize = result->size(); |
| 16 size_t resultIndex = 0; | 16 size_t resultIndex = 0; |
| 17 | 17 |
| 18 for (const auto& record : m_interpolations) { | 18 for (const auto& record : m_interpolations) { |
| 19 if (fraction >= record->m_applyFrom && fraction < record->m_applyTo) { | 19 if (fraction >= record->m_applyFrom && fraction < record->m_applyTo) { |
| 20 RefPtrWillBeRawPtr<Interpolation> interpolation = record->m_interpol
ation; | 20 Interpolation* interpolation = record->m_interpolation; |
| 21 double localFraction = (fraction - record->m_start) / (record->m_end
- record->m_start); | 21 double localFraction = (fraction - record->m_start) / (record->m_end
- record->m_start); |
| 22 if (record->m_easing) | 22 if (record->m_easing) |
| 23 localFraction = record->m_easing->evaluate(localFraction, accura
cyForDuration(iterationDuration)); | 23 localFraction = record->m_easing->evaluate(localFraction, accura
cyForDuration(iterationDuration)); |
| 24 interpolation->interpolate(0, localFraction); | 24 interpolation->interpolate(0, localFraction); |
| 25 if (resultIndex < existingSize) | 25 if (resultIndex < existingSize) |
| 26 (*result)[resultIndex++] = interpolation; | 26 (*result)[resultIndex++] = interpolation; |
| 27 else | 27 else |
| 28 result->append(interpolation); | 28 result->append(interpolation); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 if (resultIndex < existingSize) | 31 if (resultIndex < existingSize) |
| 32 result->shrink(resultIndex); | 32 result->shrink(resultIndex); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void InterpolationEffect::addInterpolationsFromKeyframes(PropertyHandle property
, Element* element, const ComputedStyle* baseStyle, Keyframe::PropertySpecificKe
yframe& keyframeA, Keyframe::PropertySpecificKeyframe& keyframeB, double applyFr
om, double applyTo) | 35 void InterpolationEffect::addInterpolationsFromKeyframes(PropertyHandle property
, Element* element, const ComputedStyle* baseStyle, Keyframe::PropertySpecificKe
yframe& keyframeA, Keyframe::PropertySpecificKeyframe& keyframeB, double applyFr
om, double applyTo) |
| 36 { | 36 { |
| 37 RefPtrWillBeRawPtr<Interpolation> interpolation = keyframeA.maybeCreateInter
polation(property, keyframeB, element, baseStyle); | 37 Interpolation* interpolation = keyframeA.maybeCreateInterpolation(property,
keyframeB, element, baseStyle); |
| 38 | 38 |
| 39 if (interpolation) { | 39 if (interpolation) { |
| 40 addInterpolation(interpolation, &keyframeA.easing(), keyframeA.offset(),
keyframeB.offset(), applyFrom, applyTo); | 40 addInterpolation(interpolation, &keyframeA.easing(), keyframeA.offset(),
keyframeB.offset(), applyFrom, applyTo); |
| 41 } else { | 41 } else { |
| 42 RefPtrWillBeRawPtr<Interpolation> interpolationA = keyframeA.maybeCreate
Interpolation(property, keyframeA, element, baseStyle); | 42 Interpolation* interpolationA = keyframeA.maybeCreateInterpolation(prope
rty, keyframeA, element, baseStyle); |
| 43 RefPtrWillBeRawPtr<Interpolation> interpolationB = keyframeB.maybeCreate
Interpolation(property, keyframeB, element, baseStyle); | 43 Interpolation* interpolationB = keyframeB.maybeCreateInterpolation(prope
rty, keyframeB, element, baseStyle); |
| 44 | 44 |
| 45 Vector<TimingFunction::PartitionRegion> regions = Vector<TimingFunction:
:PartitionRegion>(); | 45 Vector<TimingFunction::PartitionRegion> regions = Vector<TimingFunction:
:PartitionRegion>(); |
| 46 keyframeA.easing().partition(regions); | 46 keyframeA.easing().partition(regions); |
| 47 | 47 |
| 48 size_t regionIndex = 0; | 48 size_t regionIndex = 0; |
| 49 for (const auto& region : regions) { | 49 for (const auto& region : regions) { |
| 50 double regionStart = blend(keyframeA.offset(), keyframeB.offset(), r
egion.start); | 50 double regionStart = blend(keyframeA.offset(), keyframeB.offset(), r
egion.start); |
| 51 double regionEnd = blend(keyframeA.offset(), keyframeB.offset(), reg
ion.end); | 51 double regionEnd = blend(keyframeA.offset(), keyframeB.offset(), reg
ion.end); |
| 52 | 52 |
| 53 double regionApplyFrom = regionIndex == 0 ? applyFrom : regionStart; | 53 double regionApplyFrom = regionIndex == 0 ? applyFrom : regionStart; |
| 54 double regionApplyTo = regionIndex == regions.size() - 1 ? applyTo :
regionEnd; | 54 double regionApplyTo = regionIndex == regions.size() - 1 ? applyTo :
regionEnd; |
| 55 | 55 |
| 56 if (region.half == TimingFunction::RangeHalf::Lower) { | 56 if (region.half == TimingFunction::RangeHalf::Lower) { |
| 57 interpolation = interpolationA; | 57 interpolation = interpolationA; |
| 58 } else if (region.half == TimingFunction::RangeHalf::Upper) { | 58 } else if (region.half == TimingFunction::RangeHalf::Upper) { |
| 59 interpolation = interpolationB; | 59 interpolation = interpolationB; |
| 60 } else { | 60 } else { |
| 61 ASSERT_NOT_REACHED(); | 61 ASSERT_NOT_REACHED(); |
| 62 continue; | 62 continue; |
| 63 } | 63 } |
| 64 | 64 |
| 65 if (interpolation) { | 65 if (interpolation) { |
| 66 addInterpolation(interpolation.release(), | 66 addInterpolation(interpolation, &keyframeA.easing(), regionStart
, regionEnd, regionApplyFrom, regionApplyTo); |
| 67 &keyframeA.easing(), regionStart, regionEnd, regionApplyFrom
, regionApplyTo); | |
| 68 } | 67 } |
| 69 | 68 |
| 70 regionIndex++; | 69 regionIndex++; |
| 71 } | 70 } |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 | 73 |
| 75 DEFINE_TRACE(InterpolationEffect::InterpolationRecord) | 74 DEFINE_TRACE(InterpolationEffect::InterpolationRecord) |
| 76 { | 75 { |
| 77 visitor->trace(m_interpolation); | 76 visitor->trace(m_interpolation); |
| 78 } | 77 } |
| 79 | 78 |
| 80 DEFINE_TRACE(InterpolationEffect) | 79 DEFINE_TRACE(InterpolationEffect) |
| 81 { | 80 { |
| 82 visitor->trace(m_interpolations); | 81 visitor->trace(m_interpolations); |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace blink | 84 } // namespace blink |
| OLD | NEW |