Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "platform/RuntimeEnabledFeatures.h" | 40 #include "platform/RuntimeEnabledFeatures.h" |
| 41 #include "platform/TraceEvent.h" | 41 #include "platform/TraceEvent.h" |
| 42 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebCompositorAnimationTimeline.h" | 43 #include "public/platform/WebCompositorAnimationTimeline.h" |
| 44 #include "public/platform/WebCompositorSupport.h" | 44 #include "public/platform/WebCompositorSupport.h" |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 bool compareAnimations(const RefPtrWillBeMember<Animation>& left, const RefPtrWi llBeMember<Animation>& right) | 50 bool compareAnimations(const Member<Animation>& left, const Member<Animation>& r ight) |
| 51 { | 51 { |
| 52 return Animation::hasLowerPriority(left.get(), right.get()); | 52 return Animation::hasLowerPriority(left, right); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } | 55 } |
| 56 | 56 |
| 57 // This value represents 1 frame at 30Hz plus a little bit of wiggle room. | 57 // This value represents 1 frame at 30Hz plus a little bit of wiggle room. |
| 58 // TODO: Plumb a nominal framerate through and derive this value from that. | 58 // TODO: Plumb a nominal framerate through and derive this value from that. |
| 59 const double AnimationTimeline::s_minimumDelay = 0.04; | 59 const double AnimationTimeline::s_minimumDelay = 0.04; |
| 60 | 60 |
| 61 | 61 |
| 62 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) | 62 AnimationTimeline* AnimationTimeline::create(Document* document, PlatformTiming* timing) |
| 63 { | 63 { |
| 64 return adoptRefWillBeNoop(new AnimationTimeline(document, timing)); | 64 return new AnimationTimeline(document, timing); |
| 65 } | 65 } |
| 66 | 66 |
| 67 AnimationTimeline::AnimationTimeline(Document* document, PassOwnPtrWillBeRawPtr< PlatformTiming> timing) | 67 AnimationTimeline::AnimationTimeline(Document* document, PlatformTiming* timing) |
| 68 : m_document(document) | 68 : m_document(document) |
| 69 , m_zeroTime(0) // 0 is used by unit tests which cannot initialize from the loader | 69 , m_zeroTime(0) // 0 is used by unit tests which cannot initialize from the loader |
| 70 , m_zeroTimeInitialized(false) | 70 , m_zeroTimeInitialized(false) |
| 71 , m_playbackRate(1) | 71 , m_playbackRate(1) |
| 72 , m_lastCurrentTimeInternal(0) | 72 , m_lastCurrentTimeInternal(0) |
| 73 { | 73 { |
| 74 if (!timing) | 74 if (!timing) |
| 75 m_timing = adoptPtrWillBeNoop(new AnimationTimelineTiming(this)); | 75 m_timing = new AnimationTimelineTiming(this); |
| 76 else | 76 else |
| 77 m_timing = timing; | 77 m_timing = timing; |
| 78 | 78 |
| 79 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor m::current()->compositorSupport()) | 79 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor m::current()->compositorSupport()) |
| 80 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline()); | 80 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline()); |
| 81 | 81 |
| 82 ASSERT(document); | 82 ASSERT(document); |
| 83 } | 83 } |
| 84 | 84 |
| 85 AnimationTimeline::~AnimationTimeline() | 85 AnimationTimeline::~AnimationTimeline() |
| 86 { | 86 { |
| 87 #if !ENABLE(OILPAN) | 87 #if !ENABLE(OILPAN) |
| 88 for (const auto& animation : m_animations) | 88 for (const auto& animation : m_animations) |
| 89 animation->detachFromTimeline(); | 89 animation->detachFromTimeline(); |
| 90 #endif | 90 #endif |
| 91 } | 91 } |
| 92 | 92 |
| 93 void AnimationTimeline::animationAttached(Animation& animation) | 93 void AnimationTimeline::animationAttached(Animation& animation) |
| 94 { | 94 { |
| 95 ASSERT(animation.timeline() == this); | 95 ASSERT(animation.timeline() == this); |
| 96 ASSERT(!m_animations.contains(&animation)); | 96 ASSERT(!m_animations.contains(&animation)); |
| 97 m_animations.add(&animation); | 97 m_animations.add(&animation); |
| 98 } | 98 } |
| 99 | 99 |
| 100 Animation* AnimationTimeline::play(AnimationEffect* child) | 100 Animation* AnimationTimeline::play(AnimationEffect* child) |
| 101 { | 101 { |
| 102 if (!m_document) | 102 if (!m_document) |
| 103 return nullptr; | 103 return nullptr; |
| 104 | 104 |
| 105 RefPtrWillBeRawPtr<Animation> animation = Animation::create(child, this); | 105 Animation* animation = Animation::create(child, this); |
| 106 ASSERT(m_animations.contains(animation.get())); | 106 ASSERT(m_animations.contains(animation)); |
| 107 | 107 |
| 108 animation->play(); | 108 animation->play(); |
| 109 ASSERT(m_animationsNeedingUpdate.contains(animation)); | 109 ASSERT(m_animationsNeedingUpdate.contains(animation)); |
| 110 | 110 |
| 111 return animation.get(); | 111 return animation; |
| 112 } | 112 } |
| 113 | 113 |
| 114 WillBeHeapVector<RefPtrWillBeMember<Animation>> AnimationTimeline::getAnimations () | 114 HeapVector<Member<Animation>> AnimationTimeline::getAnimations() |
| 115 { | 115 { |
| 116 WillBeHeapVector<RefPtrWillBeMember<Animation>> animations; | 116 HeapVector<Member<Animation>> animations; |
| 117 for (const auto& animation : m_animations) { | 117 for (const auto& animation : m_animations) { |
| 118 if (animation->source() && (animation->source()->isCurrent() || animatio n->source()->isInEffect())) | 118 if (animation->source() && (animation->source()->isCurrent() || animatio n->source()->isInEffect())) |
| 119 animations.append(animation); | 119 animations.append(animation); |
| 120 } | 120 } |
| 121 std::sort(animations.begin(), animations.end(), compareAnimations); | 121 std::sort(animations.begin(), animations.end(), compareAnimations); |
| 122 return animations; | 122 return animations; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void AnimationTimeline::wake() | 125 void AnimationTimeline::wake() |
| 126 { | 126 { |
| 127 m_timing->serviceOnNextFrame(); | 127 m_timing->serviceOnNextFrame(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void AnimationTimeline::serviceAnimations(TimingUpdateReason reason) | 130 void AnimationTimeline::serviceAnimations(TimingUpdateReason reason) |
| 131 { | 131 { |
| 132 TRACE_EVENT0("blink", "AnimationTimeline::serviceAnimations"); | 132 TRACE_EVENT0("blink", "AnimationTimeline::serviceAnimations"); |
| 133 | 133 |
| 134 m_lastCurrentTimeInternal = currentTimeInternal(); | 134 m_lastCurrentTimeInternal = currentTimeInternal(); |
| 135 | 135 |
| 136 m_timing->cancelWake(); | 136 m_timing->cancelWake(); |
| 137 | 137 |
| 138 WillBeHeapVector<RawPtrWillBeMember<Animation>> animations; | 138 HeapVector<Member<Animation>> animations; |
|
sof
2015/05/30 11:34:04
Use copyToVector() instead?
peria
2015/06/01 04:43:02
Done.
| |
| 139 animations.reserveInitialCapacity(m_animationsNeedingUpdate.size()); | 139 animations.reserveInitialCapacity(m_animationsNeedingUpdate.size()); |
| 140 for (RefPtrWillBeMember<Animation> animation : m_animationsNeedingUpdate) | 140 for (Member<Animation> animation : m_animationsNeedingUpdate) |
| 141 animations.append(animation.get()); | 141 animations.append(animation); |
| 142 | 142 |
| 143 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority) ; | 143 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority) ; |
| 144 | 144 |
| 145 for (Animation* animation : animations) { | 145 for (Member<Animation> animation : animations) { |
| 146 if (!animation->update(reason)) | 146 if (!animation->update(reason)) |
| 147 m_animationsNeedingUpdate.remove(animation); | 147 m_animationsNeedingUpdate.remove(animation); |
| 148 } | 148 } |
| 149 | 149 |
| 150 ASSERT(!hasOutdatedAnimation()); | 150 ASSERT(!hasOutdatedAnimation()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void AnimationTimeline::scheduleNextService() | 153 void AnimationTimeline::scheduleNextService() |
| 154 { | 154 { |
| 155 ASSERT(!hasOutdatedAnimation()); | 155 ASSERT(!hasOutdatedAnimation()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 { | 312 { |
| 313 // FIXME: AnimationTimeline should keep Document alive. | 313 // FIXME: AnimationTimeline should keep Document alive. |
| 314 m_document = nullptr; | 314 m_document = nullptr; |
| 315 } | 315 } |
| 316 #endif | 316 #endif |
| 317 | 317 |
| 318 DEFINE_TRACE(AnimationTimeline) | 318 DEFINE_TRACE(AnimationTimeline) |
| 319 { | 319 { |
| 320 #if ENABLE(OILPAN) | 320 #if ENABLE(OILPAN) |
| 321 visitor->trace(m_document); | 321 visitor->trace(m_document); |
| 322 #endif | |
| 322 visitor->trace(m_timing); | 323 visitor->trace(m_timing); |
| 323 visitor->trace(m_animationsNeedingUpdate); | 324 visitor->trace(m_animationsNeedingUpdate); |
| 324 visitor->trace(m_animations); | 325 visitor->trace(m_animations); |
| 325 #endif | |
| 326 } | 326 } |
| 327 | 327 |
| 328 } // namespace | 328 } // namespace |
| OLD | NEW |