| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "sky/engine/core/animation/AnimationStack.h" | |
| 32 | |
| 33 #include <algorithm> | |
| 34 #include "sky/engine/core/animation/StyleInterpolation.h" | |
| 35 #include "sky/engine/core/animation/css/CSSAnimations.h" | |
| 36 #include "sky/engine/wtf/BitArray.h" | |
| 37 #include "sky/engine/wtf/NonCopyingSort.h" | |
| 38 | |
| 39 namespace blink { | |
| 40 | |
| 41 namespace { | |
| 42 | |
| 43 void copyToActiveInterpolationMap(const Vector<RefPtr<blink::Interpolation> >& s
ource, HashMap<CSSPropertyID, RefPtr<blink::Interpolation> >& target) | |
| 44 { | |
| 45 for (size_t i = 0; i < source.size(); ++i) { | |
| 46 Interpolation* interpolation = source[i].get(); | |
| 47 target.set(toStyleInterpolation(interpolation)->id(), interpolation); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 bool compareEffects(const OwnPtr<SampledEffect>& effect1, const OwnPtr<SampledEf
fect>& effect2) | |
| 52 { | |
| 53 ASSERT(effect1 && effect2); | |
| 54 return effect1->sequenceNumber() < effect2->sequenceNumber(); | |
| 55 } | |
| 56 | |
| 57 void copyNewAnimationsToActiveInterpolationMap(const Vector<RawPtr<InertAnimatio
n> >& newAnimations, HashMap<CSSPropertyID, RefPtr<Interpolation> >& result) | |
| 58 { | |
| 59 for (size_t i = 0; i < newAnimations.size(); ++i) { | |
| 60 OwnPtr<Vector<RefPtr<Interpolation> > > sample = newAnimations[i]->sampl
e(0); | |
| 61 if (sample) { | |
| 62 copyToActiveInterpolationMap(*sample, result); | |
| 63 } | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 AnimationStack::AnimationStack() | |
| 70 { | |
| 71 } | |
| 72 | |
| 73 HashMap<CSSPropertyID, RefPtr<Interpolation> > AnimationStack::activeInterpolati
ons(AnimationStack* animationStack, const Vector<RawPtr<InertAnimation> >* newAn
imations, const HashSet<RawPtr<const AnimationPlayer> >* cancelledAnimationPlaye
rs, Animation::Priority priority, double timelineCurrentTime) | |
| 74 { | |
| 75 // We don't exactly know when new animations will start, but timelineCurrent
Time is a good estimate. | |
| 76 | |
| 77 HashMap<CSSPropertyID, RefPtr<Interpolation> > result; | |
| 78 | |
| 79 if (animationStack) { | |
| 80 Vector<OwnPtr<SampledEffect> >& effects = animationStack->m_effects; | |
| 81 // std::sort doesn't work with OwnPtrs | |
| 82 nonCopyingSort(effects.begin(), effects.end(), compareEffects); | |
| 83 animationStack->simplifyEffects(); | |
| 84 for (size_t i = 0; i < effects.size(); ++i) { | |
| 85 const SampledEffect& effect = *effects[i]; | |
| 86 if (effect.priority() != priority || (cancelledAnimationPlayers && e
ffect.animation() && cancelledAnimationPlayers->contains(effect.animation()->pla
yer()))) | |
| 87 continue; | |
| 88 copyToActiveInterpolationMap(effect.interpolations(), result); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 if (newAnimations) | |
| 93 copyNewAnimationsToActiveInterpolationMap(*newAnimations, result); | |
| 94 | |
| 95 return result; | |
| 96 } | |
| 97 | |
| 98 void AnimationStack::simplifyEffects() | |
| 99 { | |
| 100 // FIXME: This will need to be updated when we have 'add' keyframes. | |
| 101 | |
| 102 BitArray<numCSSProperties> replacedProperties; | |
| 103 for (size_t i = m_effects.size(); i--; ) { | |
| 104 SampledEffect& effect = *m_effects[i]; | |
| 105 effect.removeReplacedInterpolationsIfNeeded(replacedProperties); | |
| 106 if (!effect.canChange()) { | |
| 107 for (size_t i = 0; i < effect.interpolations().size(); ++i) | |
| 108 replacedProperties.set(toStyleInterpolation(effect.interpolation
s()[i].get())->id()); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 size_t dest = 0; | |
| 113 for (size_t i = 0; i < m_effects.size(); ++i) { | |
| 114 if (!m_effects[i]->interpolations().isEmpty()) { | |
| 115 m_effects[dest++].swap(m_effects[i]); | |
| 116 continue; | |
| 117 } | |
| 118 if (m_effects[i]->animation()) | |
| 119 m_effects[i]->animation()->notifySampledEffectRemovedFromAnimationSt
ack(); | |
| 120 } | |
| 121 m_effects.shrink(dest); | |
| 122 } | |
| 123 | |
| 124 } // namespace blink | |
| OLD | NEW |