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 "platform/scroll/ProgrammaticScrollAnimator.h" | 6 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
7 | 7 |
8 #include "platform/RuntimeEnabledFeatures.h" | |
8 #include "platform/geometry/IntPoint.h" | 9 #include "platform/geometry/IntPoint.h" |
9 #include "platform/graphics/GraphicsLayer.h" | 10 #include "platform/graphics/GraphicsLayer.h" |
10 #include "platform/scroll/ScrollableArea.h" | 11 #include "platform/scroll/ScrollableArea.h" |
11 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
12 #include "public/platform/WebCompositorAnimation.h" | 13 #include "public/platform/WebCompositorAnimation.h" |
14 #include "public/platform/WebCompositorAnimationPlayer.h" | |
15 #include "public/platform/WebCompositorAnimationTimeline.h" | |
13 #include "public/platform/WebCompositorSupport.h" | 16 #include "public/platform/WebCompositorSupport.h" |
14 #include "public/platform/WebScrollOffsetAnimationCurve.h" | 17 #include "public/platform/WebScrollOffsetAnimationCurve.h" |
15 | 18 |
16 namespace blink { | 19 namespace blink { |
17 | 20 |
18 PassOwnPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::create(Scroll ableArea* scrollableArea) | 21 PassOwnPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::create(Scroll ableArea* scrollableArea) |
19 { | 22 { |
20 return adoptPtr(new ProgrammaticScrollAnimator(scrollableArea)); | 23 return adoptPtr(new ProgrammaticScrollAnimator(scrollableArea)); |
21 } | 24 } |
22 | 25 |
23 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl eArea) | 26 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl eArea) |
24 : m_scrollableArea(scrollableArea) | 27 : m_scrollableArea(scrollableArea) |
25 , m_startTime(0.0) | 28 , m_startTime(0.0) |
26 , m_runState(RunState::Idle) | 29 , m_runState(RunState::Idle) |
27 , m_compositorAnimationId(0) | 30 , m_compositorAnimationId(0) |
28 , m_compositorAnimationGroupId(0) | 31 , m_compositorAnimationGroupId(0) |
29 { | 32 { |
33 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor m::current()->compositorSupport()) { | |
34 m_compositorPlayer = adoptPtr(Platform::current()->compositorSupport()-> createAnimationPlayer()); | |
35 ASSERT(m_compositorPlayer); | |
36 m_compositorPlayer->setAnimationDelegate(this); | |
37 } | |
30 } | 38 } |
31 | 39 |
32 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() | 40 ProgrammaticScrollAnimator::~ProgrammaticScrollAnimator() |
33 { | 41 { |
42 if (m_compositorPlayer) { | |
43 m_compositorPlayer->setAnimationDelegate(nullptr); | |
44 m_compositorPlayer.clear(); | |
45 } | |
34 } | 46 } |
35 | 47 |
36 void ProgrammaticScrollAnimator::resetAnimationState() | 48 void ProgrammaticScrollAnimator::resetAnimationState() |
37 { | 49 { |
38 m_animationCurve.clear(); | 50 m_animationCurve.clear(); |
39 m_startTime = 0.0; | 51 m_startTime = 0.0; |
40 m_runState = RunState::Idle; | 52 m_runState = RunState::Idle; |
41 m_compositorAnimationId = 0; | 53 m_compositorAnimationId = 0; |
42 m_compositorAnimationGroupId = 0; | 54 m_compositorAnimationGroupId = 0; |
43 } | 55 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 } | 141 } |
130 | 142 |
131 void ProgrammaticScrollAnimator::updateCompositorAnimations() | 143 void ProgrammaticScrollAnimator::updateCompositorAnimations() |
132 { | 144 { |
133 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor) { | 145 if (m_compositorAnimationId && m_runState != RunState::RunningOnCompositor) { |
134 // If the current run state is WaitingToSendToCompositor but we have a | 146 // If the current run state is WaitingToSendToCompositor but we have a |
135 // non-zero compositor animation id, there's a currently running | 147 // non-zero compositor animation id, there's a currently running |
136 // compositor animation that needs to be removed here before the new | 148 // compositor animation that needs to be removed here before the new |
137 // animation is added below. | 149 // animation is added below. |
138 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor || m_runState == RunState::WaitingToSendToCompositor); | 150 ASSERT(m_runState == RunState::WaitingToCancelOnCompositor || m_runState == RunState::WaitingToSendToCompositor); |
139 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) | 151 |
140 layer->removeAnimation(m_compositorAnimationId); | 152 if (m_compositorPlayer) { |
153 if (m_compositorPlayer->isLayerAttached()) | |
154 m_compositorPlayer->removeAnimation(m_compositorAnimationId); | |
155 } else { | |
156 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) | |
157 layer->removeAnimation(m_compositorAnimationId); | |
158 } | |
159 | |
141 m_compositorAnimationId = 0; | 160 m_compositorAnimationId = 0; |
142 m_compositorAnimationGroupId = 0; | 161 m_compositorAnimationGroupId = 0; |
143 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 162 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
144 resetAnimationState(); | 163 resetAnimationState(); |
145 return; | 164 return; |
146 } | 165 } |
147 } | 166 } |
148 | 167 |
149 if (m_runState == RunState::WaitingToSendToCompositor) { | 168 if (m_runState == RunState::WaitingToSendToCompositor) { |
150 bool sentToCompositor = false; | 169 bool sentToCompositor = false; |
151 | 170 |
152 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) { | 171 if (GraphicsLayer* layer = m_scrollableArea->layerForScrolling()) { |
153 if (!layer->platformLayer()->shouldScrollOnMainThread()) { | 172 if (!layer->platformLayer()->shouldScrollOnMainThread()) { |
154 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::cu rrent()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAn imation::TargetPropertyScrollOffset)); | 173 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::cu rrent()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAn imation::TargetPropertyScrollOffset)); |
155 | 174 |
156 int animationId = animation->id(); | 175 int animationId = animation->id(); |
157 int animationGroupId = animation->group(); | 176 int animationGroupId = animation->group(); |
158 if (m_scrollableArea->layerForScrolling()->addAnimation(animatio n.release())) { | 177 |
178 bool animatonAdded = false; | |
Ian Vollick
2015/07/10 03:06:45
nit: animation.
loyso (OOO)
2015/07/22 05:24:23
Done.
| |
179 if (m_compositorPlayer && m_compositorPlayer->isLayerAttached()) { | |
Ian Vollick
2015/07/10 03:06:45
If we have a compositor player, should we expect t
loyso (OOO)
2015/07/22 05:24:23
If it's not attached, it runs on main thread (!sen
| |
180 m_compositorPlayer->addAnimation(animation.leakPtr()); | |
181 animatonAdded = true; | |
182 } else { | |
183 animatonAdded = m_scrollableArea->layerForScrolling()->addAn imation(animation.release()); | |
184 } | |
185 | |
186 if (animatonAdded) { | |
159 sentToCompositor = true; | 187 sentToCompositor = true; |
160 m_runState = RunState::RunningOnCompositor; | 188 m_runState = RunState::RunningOnCompositor; |
161 m_compositorAnimationId = animationId; | 189 m_compositorAnimationId = animationId; |
162 m_compositorAnimationGroupId = animationGroupId; | 190 m_compositorAnimationGroupId = animationGroupId; |
163 } | 191 } |
164 } | 192 } |
165 } | 193 } |
166 | 194 |
167 if (!sentToCompositor) { | 195 if (!sentToCompositor) { |
168 m_runState = RunState::RunningOnMainThread; | 196 m_runState = RunState::RunningOnMainThread; |
169 if (!m_scrollableArea->scheduleAnimation()) { | 197 if (!m_scrollableArea->scheduleAnimation()) { |
170 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse t.y())); | 198 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse t.y())); |
171 resetAnimationState(); | 199 resetAnimationState(); |
172 } | 200 } |
173 } | 201 } |
174 } | 202 } |
175 } | 203 } |
176 | 204 |
177 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange() | 205 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(WebComposi torAnimationTimeline* timeline) |
178 { | 206 { |
207 if (m_compositorPlayer && timeline) { | |
208 if (m_compositorPlayer->isLayerAttached()) | |
209 m_compositorPlayer->detachLayer(); | |
210 timeline->playerDestroyed(*this); | |
211 } | |
212 | |
179 // If the composited scrolling layer is lost during a composited animation, | 213 // If the composited scrolling layer is lost during a composited animation, |
180 // continue the animation on the main thread. | 214 // continue the animation on the main thread. |
181 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF orScrolling()) { | 215 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF orScrolling()) { |
182 m_runState = RunState::RunningOnMainThread; | 216 m_runState = RunState::RunningOnMainThread; |
183 m_compositorAnimationId = 0; | 217 m_compositorAnimationId = 0; |
184 m_compositorAnimationGroupId = 0; | 218 m_compositorAnimationGroupId = 0; |
185 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos ition())); | 219 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos ition())); |
186 m_scrollableArea->registerForAnimation(); | 220 m_scrollableArea->registerForAnimation(); |
187 if (!m_scrollableArea->scheduleAnimation()) { | 221 if (!m_scrollableArea->scheduleAnimation()) { |
188 resetAnimationState(); | 222 resetAnimationState(); |
189 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffset.y( ))); | 223 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffset.y( ))); |
190 } | 224 } |
191 } | 225 } |
226 | |
227 if (m_compositorPlayer && timeline && m_scrollableArea->layerForScrolling()) { | |
228 timeline->playerAttached(*this); | |
229 m_compositorPlayer->attachLayer(m_scrollableArea->layerForScrolling()->p latformLayer()); | |
230 } | |
192 } | 231 } |
193 | 232 |
194 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 233 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
195 { | 234 { |
196 if (m_compositorAnimationGroupId != groupId) | 235 if (m_compositorAnimationGroupId != groupId) |
197 return; | 236 return; |
198 | 237 |
199 m_compositorAnimationId = 0; | 238 m_compositorAnimationId = 0; |
200 m_compositorAnimationGroupId = 0; | 239 m_compositorAnimationGroupId = 0; |
201 | 240 |
202 switch (m_runState) { | 241 switch (m_runState) { |
203 case RunState::Idle: | 242 case RunState::Idle: |
204 case RunState::RunningOnMainThread: | 243 case RunState::RunningOnMainThread: |
205 ASSERT_NOT_REACHED(); | 244 ASSERT_NOT_REACHED(); |
206 break; | 245 break; |
207 case RunState::WaitingToSendToCompositor: | 246 case RunState::WaitingToSendToCompositor: |
208 break; | 247 break; |
209 case RunState::RunningOnCompositor: | 248 case RunState::RunningOnCompositor: |
210 case RunState::WaitingToCancelOnCompositor: | 249 case RunState::WaitingToCancelOnCompositor: |
211 resetAnimationState(); | 250 resetAnimationState(); |
212 } | 251 } |
213 } | 252 } |
214 | 253 |
254 void ProgrammaticScrollAnimator::notifyAnimationStarted(double monotonicTime, in t group) | |
255 { | |
256 } | |
257 | |
258 void ProgrammaticScrollAnimator::notifyAnimationFinished(double monotonicTime, i nt group) | |
259 { | |
260 notifyCompositorAnimationFinished(group); | |
261 } | |
262 | |
263 WebCompositorAnimationPlayer* ProgrammaticScrollAnimator::compositorPlayer() con st | |
264 { | |
265 return m_compositorPlayer.get(); | |
266 } | |
267 | |
215 } // namespace blink | 268 } // namespace blink |
OLD | NEW |