OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
8 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
9 #include "cc/animation/scroll_offset_animation_curve.h" | 9 #include "cc/animation/scroll_offset_animation_curve.h" |
10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
12 #include "cc/layers/layer_impl.h" | 12 #include "cc/layers/layer_impl.h" |
13 #include "cc/test/animation_test_common.h" | 13 #include "cc/test/animation_test_common.h" |
14 #include "cc/test/fake_content_layer.h" | 14 #include "cc/test/fake_content_layer.h" |
15 #include "cc/test/fake_content_layer_client.h" | 15 #include "cc/test/fake_content_layer_client.h" |
16 #include "cc/test/layer_tree_test.h" | 16 #include "cc/test/layer_tree_test.h" |
17 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class LayerTreeHostAnimationTest : public LayerTreeTest { | 22 class LayerTreeHostAnimationTest : public LayerTreeTest { |
23 public: | 23 public: |
24 virtual void SetupTree() OVERRIDE { | 24 virtual void SetupTree() override { |
25 LayerTreeTest::SetupTree(); | 25 LayerTreeTest::SetupTree(); |
26 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); | 26 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); |
27 } | 27 } |
28 }; | 28 }; |
29 | 29 |
30 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to | 30 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
31 // be set. | 31 // be set. |
32 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | 32 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
33 : public LayerTreeHostAnimationTest { | 33 : public LayerTreeHostAnimationTest { |
34 public: | 34 public: |
35 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() | 35 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() |
36 : num_commits_(0) {} | 36 : num_commits_(0) {} |
37 | 37 |
38 virtual void BeginTest() OVERRIDE { | 38 virtual void BeginTest() override { |
39 PostSetNeedsCommitToMainThread(); | 39 PostSetNeedsCommitToMainThread(); |
40 } | 40 } |
41 | 41 |
42 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 42 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
43 // We skip the first commit because its the commit that populates the | 43 // We skip the first commit because its the commit that populates the |
44 // impl thread with a tree. After the second commit, the test is done. | 44 // impl thread with a tree. After the second commit, the test is done. |
45 if (num_commits_ != 1) | 45 if (num_commits_ != 1) |
46 return; | 46 return; |
47 | 47 |
48 layer_tree_host()->SetNeedsAnimate(); | 48 layer_tree_host()->SetNeedsAnimate(); |
49 // Right now, CommitRequested is going to be true, because during | 49 // Right now, CommitRequested is going to be true, because during |
50 // BeginFrame, we force CommitRequested to true to prevent requests from | 50 // BeginFrame, we force CommitRequested to true to prevent requests from |
51 // hitting the impl thread. But, when the next DidCommit happens, we should | 51 // hitting the impl thread. But, when the next DidCommit happens, we should |
52 // verify that CommitRequested has gone back to false. | 52 // verify that CommitRequested has gone back to false. |
53 } | 53 } |
54 | 54 |
55 virtual void DidCommit() OVERRIDE { | 55 virtual void DidCommit() override { |
56 if (!num_commits_) { | 56 if (!num_commits_) { |
57 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 57 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
58 layer_tree_host()->SetNeedsAnimate(); | 58 layer_tree_host()->SetNeedsAnimate(); |
59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 59 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
60 } | 60 } |
61 | 61 |
62 // Verifies that the SetNeedsAnimate we made in ::Animate did not | 62 // Verifies that the SetNeedsAnimate we made in ::Animate did not |
63 // trigger CommitRequested. | 63 // trigger CommitRequested. |
64 EXPECT_FALSE(layer_tree_host()->CommitRequested()); | 64 EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
65 EndTest(); | 65 EndTest(); |
66 num_commits_++; | 66 num_commits_++; |
67 } | 67 } |
68 | 68 |
69 virtual void AfterTest() OVERRIDE {} | 69 virtual void AfterTest() override {} |
70 | 70 |
71 private: | 71 private: |
72 int num_commits_; | 72 int num_commits_; |
73 }; | 73 }; |
74 | 74 |
75 MULTI_THREAD_TEST_F( | 75 MULTI_THREAD_TEST_F( |
76 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); | 76 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); |
77 | 77 |
78 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate | 78 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate |
79 // callback, request another frame using SetNeedsAnimate. End the test when | 79 // callback, request another frame using SetNeedsAnimate. End the test when |
80 // animate gets called yet-again, indicating that the proxy is correctly | 80 // animate gets called yet-again, indicating that the proxy is correctly |
81 // handling the case where SetNeedsAnimate() is called inside the BeginFrame | 81 // handling the case where SetNeedsAnimate() is called inside the BeginFrame |
82 // flow. | 82 // flow. |
83 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback | 83 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback |
84 : public LayerTreeHostAnimationTest { | 84 : public LayerTreeHostAnimationTest { |
85 public: | 85 public: |
86 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() | 86 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() |
87 : num_begin_frames_(0) {} | 87 : num_begin_frames_(0) {} |
88 | 88 |
89 virtual void BeginTest() OVERRIDE { | 89 virtual void BeginTest() override { |
90 PostSetNeedsCommitToMainThread(); | 90 PostSetNeedsCommitToMainThread(); |
91 } | 91 } |
92 | 92 |
93 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 93 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
94 if (!num_begin_frames_) { | 94 if (!num_begin_frames_) { |
95 layer_tree_host()->SetNeedsAnimate(); | 95 layer_tree_host()->SetNeedsAnimate(); |
96 num_begin_frames_++; | 96 num_begin_frames_++; |
97 return; | 97 return; |
98 } | 98 } |
99 EndTest(); | 99 EndTest(); |
100 } | 100 } |
101 | 101 |
102 virtual void AfterTest() OVERRIDE {} | 102 virtual void AfterTest() override {} |
103 | 103 |
104 private: | 104 private: |
105 int num_begin_frames_; | 105 int num_begin_frames_; |
106 }; | 106 }; |
107 | 107 |
108 MULTI_THREAD_TEST_F( | 108 MULTI_THREAD_TEST_F( |
109 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); | 109 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); |
110 | 110 |
111 // Add a layer animation and confirm that | 111 // Add a layer animation and confirm that |
112 // LayerTreeHostImpl::updateAnimationState does get called and continues to | 112 // LayerTreeHostImpl::updateAnimationState does get called and continues to |
113 // get called. | 113 // get called. |
114 class LayerTreeHostAnimationTestAddAnimation | 114 class LayerTreeHostAnimationTestAddAnimation |
115 : public LayerTreeHostAnimationTest { | 115 : public LayerTreeHostAnimationTest { |
116 public: | 116 public: |
117 LayerTreeHostAnimationTestAddAnimation() | 117 LayerTreeHostAnimationTestAddAnimation() |
118 : num_begin_frames_(0), received_animation_started_notification_(false) {} | 118 : num_begin_frames_(0), received_animation_started_notification_(false) {} |
119 | 119 |
120 virtual void BeginTest() OVERRIDE { | 120 virtual void BeginTest() override { |
121 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 121 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
122 } | 122 } |
123 | 123 |
124 virtual void UpdateAnimationState( | 124 virtual void UpdateAnimationState( |
125 LayerTreeHostImpl* host_impl, | 125 LayerTreeHostImpl* host_impl, |
126 bool has_unfinished_animation) OVERRIDE { | 126 bool has_unfinished_animation) override { |
127 if (!num_begin_frames_) { | 127 if (!num_begin_frames_) { |
128 // The animation had zero duration so LayerTreeHostImpl should no | 128 // The animation had zero duration so LayerTreeHostImpl should no |
129 // longer need to animate its layers. | 129 // longer need to animate its layers. |
130 EXPECT_FALSE(has_unfinished_animation); | 130 EXPECT_FALSE(has_unfinished_animation); |
131 num_begin_frames_++; | 131 num_begin_frames_++; |
132 return; | 132 return; |
133 } | 133 } |
134 | 134 |
135 if (received_animation_started_notification_) { | 135 if (received_animation_started_notification_) { |
136 EXPECT_LT(base::TimeTicks(), start_time_); | 136 EXPECT_LT(base::TimeTicks(), start_time_); |
137 | 137 |
138 LayerAnimationController* controller_impl = | 138 LayerAnimationController* controller_impl = |
139 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 139 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
140 Animation* animation_impl = | 140 Animation* animation_impl = |
141 controller_impl->GetAnimation(Animation::Opacity); | 141 controller_impl->GetAnimation(Animation::Opacity); |
142 if (animation_impl) | 142 if (animation_impl) |
143 controller_impl->RemoveAnimation(animation_impl->id()); | 143 controller_impl->RemoveAnimation(animation_impl->id()); |
144 | 144 |
145 EndTest(); | 145 EndTest(); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 virtual void NotifyAnimationStarted( | 149 virtual void NotifyAnimationStarted( |
150 base::TimeTicks monotonic_time, | 150 base::TimeTicks monotonic_time, |
151 Animation::TargetProperty target_property) OVERRIDE { | 151 Animation::TargetProperty target_property) override { |
152 received_animation_started_notification_ = true; | 152 received_animation_started_notification_ = true; |
153 start_time_ = monotonic_time; | 153 start_time_ = monotonic_time; |
154 if (num_begin_frames_) { | 154 if (num_begin_frames_) { |
155 EXPECT_LT(base::TimeTicks(), start_time_); | 155 EXPECT_LT(base::TimeTicks(), start_time_); |
156 | 156 |
157 LayerAnimationController* controller = | 157 LayerAnimationController* controller = |
158 layer_tree_host()->root_layer()->layer_animation_controller(); | 158 layer_tree_host()->root_layer()->layer_animation_controller(); |
159 Animation* animation = | 159 Animation* animation = |
160 controller->GetAnimation(Animation::Opacity); | 160 controller->GetAnimation(Animation::Opacity); |
161 if (animation) | 161 if (animation) |
162 controller->RemoveAnimation(animation->id()); | 162 controller->RemoveAnimation(animation->id()); |
163 | 163 |
164 EndTest(); | 164 EndTest(); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 virtual void AfterTest() OVERRIDE {} | 168 virtual void AfterTest() override {} |
169 | 169 |
170 private: | 170 private: |
171 int num_begin_frames_; | 171 int num_begin_frames_; |
172 bool received_animation_started_notification_; | 172 bool received_animation_started_notification_; |
173 base::TimeTicks start_time_; | 173 base::TimeTicks start_time_; |
174 }; | 174 }; |
175 | 175 |
176 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); | 176 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); |
177 | 177 |
178 // Add a layer animation to a layer, but continually fail to draw. Confirm that | 178 // Add a layer animation to a layer, but continually fail to draw. Confirm that |
179 // after a while, we do eventually force a draw. | 179 // after a while, we do eventually force a draw. |
180 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws | 180 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
181 : public LayerTreeHostAnimationTest { | 181 : public LayerTreeHostAnimationTest { |
182 public: | 182 public: |
183 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 183 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
184 : started_animating_(false) {} | 184 : started_animating_(false) {} |
185 | 185 |
186 virtual void BeginTest() OVERRIDE { | 186 virtual void BeginTest() override { |
187 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 187 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
188 } | 188 } |
189 | 189 |
190 virtual void AnimateLayers( | 190 virtual void AnimateLayers( |
191 LayerTreeHostImpl* host_impl, | 191 LayerTreeHostImpl* host_impl, |
192 base::TimeTicks monotonic_time) OVERRIDE { | 192 base::TimeTicks monotonic_time) override { |
193 started_animating_ = true; | 193 started_animating_ = true; |
194 } | 194 } |
195 | 195 |
196 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 196 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
197 if (started_animating_) | 197 if (started_animating_) |
198 EndTest(); | 198 EndTest(); |
199 } | 199 } |
200 | 200 |
201 virtual DrawResult PrepareToDrawOnThread( | 201 virtual DrawResult PrepareToDrawOnThread( |
202 LayerTreeHostImpl* host_impl, | 202 LayerTreeHostImpl* host_impl, |
203 LayerTreeHostImpl::FrameData* frame, | 203 LayerTreeHostImpl::FrameData* frame, |
204 DrawResult draw_result) OVERRIDE { | 204 DrawResult draw_result) override { |
205 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 205 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
206 } | 206 } |
207 | 207 |
208 virtual void AfterTest() OVERRIDE { } | 208 virtual void AfterTest() override { } |
209 | 209 |
210 private: | 210 private: |
211 bool started_animating_; | 211 bool started_animating_; |
212 }; | 212 }; |
213 | 213 |
214 // Starvation can only be an issue with the MT compositor. | 214 // Starvation can only be an issue with the MT compositor. |
215 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); | 215 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); |
216 | 216 |
217 // Ensures that animations eventually get deleted. | 217 // Ensures that animations eventually get deleted. |
218 class LayerTreeHostAnimationTestAnimationsGetDeleted | 218 class LayerTreeHostAnimationTestAnimationsGetDeleted |
219 : public LayerTreeHostAnimationTest { | 219 : public LayerTreeHostAnimationTest { |
220 public: | 220 public: |
221 LayerTreeHostAnimationTestAnimationsGetDeleted() | 221 LayerTreeHostAnimationTestAnimationsGetDeleted() |
222 : started_animating_(false) {} | 222 : started_animating_(false) {} |
223 | 223 |
224 virtual void BeginTest() OVERRIDE { | 224 virtual void BeginTest() override { |
225 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 225 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
226 } | 226 } |
227 | 227 |
228 virtual void AnimateLayers( | 228 virtual void AnimateLayers( |
229 LayerTreeHostImpl* host_impl, | 229 LayerTreeHostImpl* host_impl, |
230 base::TimeTicks monotonic_time) OVERRIDE { | 230 base::TimeTicks monotonic_time) override { |
231 bool have_animations = !host_impl->animation_registrar()-> | 231 bool have_animations = !host_impl->animation_registrar()-> |
232 active_animation_controllers().empty(); | 232 active_animation_controllers().empty(); |
233 if (!started_animating_ && have_animations) { | 233 if (!started_animating_ && have_animations) { |
234 started_animating_ = true; | 234 started_animating_ = true; |
235 return; | 235 return; |
236 } | 236 } |
237 | 237 |
238 if (started_animating_ && !have_animations) | 238 if (started_animating_ && !have_animations) |
239 EndTest(); | 239 EndTest(); |
240 } | 240 } |
241 | 241 |
242 virtual void NotifyAnimationFinished( | 242 virtual void NotifyAnimationFinished( |
243 base::TimeTicks monotonic_time, | 243 base::TimeTicks monotonic_time, |
244 Animation::TargetProperty target_property) OVERRIDE { | 244 Animation::TargetProperty target_property) override { |
245 // Animations on the impl-side controller only get deleted during a commit, | 245 // Animations on the impl-side controller only get deleted during a commit, |
246 // so we need to schedule a commit. | 246 // so we need to schedule a commit. |
247 layer_tree_host()->SetNeedsCommit(); | 247 layer_tree_host()->SetNeedsCommit(); |
248 } | 248 } |
249 | 249 |
250 virtual void AfterTest() OVERRIDE {} | 250 virtual void AfterTest() override {} |
251 | 251 |
252 private: | 252 private: |
253 bool started_animating_; | 253 bool started_animating_; |
254 }; | 254 }; |
255 | 255 |
256 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); | 256 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); |
257 | 257 |
258 // Ensures that animations continue to be ticked when we are backgrounded. | 258 // Ensures that animations continue to be ticked when we are backgrounded. |
259 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded | 259 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded |
260 : public LayerTreeHostAnimationTest { | 260 : public LayerTreeHostAnimationTest { |
261 public: | 261 public: |
262 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded() | 262 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded() |
263 : num_begin_frames_(0) {} | 263 : num_begin_frames_(0) {} |
264 | 264 |
265 virtual void BeginTest() OVERRIDE { | 265 virtual void BeginTest() override { |
266 PostAddLongAnimationToMainThread(layer_tree_host()->root_layer()); | 266 PostAddLongAnimationToMainThread(layer_tree_host()->root_layer()); |
267 } | 267 } |
268 | 268 |
269 // Use WillAnimateLayers to set visible false before the animation runs and | 269 // Use WillAnimateLayers to set visible false before the animation runs and |
270 // causes a commit, so we block the second visible animate in single-thread | 270 // causes a commit, so we block the second visible animate in single-thread |
271 // mode. | 271 // mode. |
272 virtual void WillAnimateLayers( | 272 virtual void WillAnimateLayers( |
273 LayerTreeHostImpl* host_impl, | 273 LayerTreeHostImpl* host_impl, |
274 base::TimeTicks monotonic_time) OVERRIDE { | 274 base::TimeTicks monotonic_time) override { |
275 // Verify that the host can draw, it's just not visible. | 275 // Verify that the host can draw, it's just not visible. |
276 EXPECT_TRUE(host_impl->CanDraw()); | 276 EXPECT_TRUE(host_impl->CanDraw()); |
277 if (num_begin_frames_ < 2) { | 277 if (num_begin_frames_ < 2) { |
278 if (!num_begin_frames_) { | 278 if (!num_begin_frames_) { |
279 // We have a long animation running. It should continue to tick even | 279 // We have a long animation running. It should continue to tick even |
280 // if we are not visible. | 280 // if we are not visible. |
281 PostSetVisibleToMainThread(false); | 281 PostSetVisibleToMainThread(false); |
282 } | 282 } |
283 num_begin_frames_++; | 283 num_begin_frames_++; |
284 return; | 284 return; |
285 } | 285 } |
286 EndTest(); | 286 EndTest(); |
287 } | 287 } |
288 | 288 |
289 virtual void AfterTest() OVERRIDE {} | 289 virtual void AfterTest() override {} |
290 | 290 |
291 private: | 291 private: |
292 int num_begin_frames_; | 292 int num_begin_frames_; |
293 }; | 293 }; |
294 | 294 |
295 SINGLE_AND_MULTI_THREAD_TEST_F( | 295 SINGLE_AND_MULTI_THREAD_TEST_F( |
296 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); | 296 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); |
297 | 297 |
298 // Ensures that animation time remains monotonic when we switch from foreground | 298 // Ensures that animation time remains monotonic when we switch from foreground |
299 // to background ticking and back, even if we're skipping draws due to | 299 // to background ticking and back, even if we're skipping draws due to |
300 // checkerboarding when in the foreground. | 300 // checkerboarding when in the foreground. |
301 class LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic | 301 class LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic |
302 : public LayerTreeHostAnimationTest { | 302 : public LayerTreeHostAnimationTest { |
303 public: | 303 public: |
304 LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic() | 304 LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic() |
305 : has_background_ticked_(false), num_foreground_animates_(0) {} | 305 : has_background_ticked_(false), num_foreground_animates_(0) {} |
306 | 306 |
307 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 307 virtual void InitializeSettings(LayerTreeSettings* settings) override { |
308 // Make sure that drawing many times doesn't cause a checkerboarded | 308 // Make sure that drawing many times doesn't cause a checkerboarded |
309 // animation to start so we avoid flake in this test. | 309 // animation to start so we avoid flake in this test. |
310 settings->timeout_and_draw_when_animation_checkerboards = false; | 310 settings->timeout_and_draw_when_animation_checkerboards = false; |
311 } | 311 } |
312 | 312 |
313 virtual void BeginTest() OVERRIDE { | 313 virtual void BeginTest() override { |
314 PostAddLongAnimationToMainThread(layer_tree_host()->root_layer()); | 314 PostAddLongAnimationToMainThread(layer_tree_host()->root_layer()); |
315 } | 315 } |
316 | 316 |
317 virtual void AnimateLayers(LayerTreeHostImpl* host_impl, | 317 virtual void AnimateLayers(LayerTreeHostImpl* host_impl, |
318 base::TimeTicks monotonic_time) OVERRIDE { | 318 base::TimeTicks monotonic_time) override { |
319 EXPECT_GE(monotonic_time, last_tick_time_); | 319 EXPECT_GE(monotonic_time, last_tick_time_); |
320 last_tick_time_ = monotonic_time; | 320 last_tick_time_ = monotonic_time; |
321 if (host_impl->visible()) { | 321 if (host_impl->visible()) { |
322 num_foreground_animates_++; | 322 num_foreground_animates_++; |
323 if (num_foreground_animates_ > 1 && !has_background_ticked_) | 323 if (num_foreground_animates_ > 1 && !has_background_ticked_) |
324 PostSetVisibleToMainThread(false); | 324 PostSetVisibleToMainThread(false); |
325 else if (has_background_ticked_) | 325 else if (has_background_ticked_) |
326 EndTest(); | 326 EndTest(); |
327 } else { | 327 } else { |
328 has_background_ticked_ = true; | 328 has_background_ticked_ = true; |
329 PostSetVisibleToMainThread(true); | 329 PostSetVisibleToMainThread(true); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 virtual DrawResult PrepareToDrawOnThread( | 333 virtual DrawResult PrepareToDrawOnThread( |
334 LayerTreeHostImpl* host_impl, | 334 LayerTreeHostImpl* host_impl, |
335 LayerTreeHostImpl::FrameData* frame, | 335 LayerTreeHostImpl::FrameData* frame, |
336 DrawResult draw_result) OVERRIDE { | 336 DrawResult draw_result) override { |
337 if (TestEnded()) | 337 if (TestEnded()) |
338 return draw_result; | 338 return draw_result; |
339 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 339 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
340 } | 340 } |
341 | 341 |
342 virtual void AfterTest() OVERRIDE {} | 342 virtual void AfterTest() override {} |
343 | 343 |
344 private: | 344 private: |
345 bool has_background_ticked_; | 345 bool has_background_ticked_; |
346 int num_foreground_animates_; | 346 int num_foreground_animates_; |
347 base::TimeTicks last_tick_time_; | 347 base::TimeTicks last_tick_time_; |
348 }; | 348 }; |
349 | 349 |
350 SINGLE_AND_MULTI_THREAD_TEST_F( | 350 SINGLE_AND_MULTI_THREAD_TEST_F( |
351 LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic); | 351 LayerTreeHostAnimationTestAnimationTickTimeIsMonotonic); |
352 | 352 |
353 // Ensures that animations do not tick when we are backgrounded and | 353 // Ensures that animations do not tick when we are backgrounded and |
354 // and we have an empty active tree. | 354 // and we have an empty active tree. |
355 class LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree | 355 class LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree |
356 : public LayerTreeHostAnimationTest { | 356 : public LayerTreeHostAnimationTest { |
357 protected: | 357 protected: |
358 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree() | 358 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree() |
359 : active_tree_was_animated_(false) {} | 359 : active_tree_was_animated_(false) {} |
360 | 360 |
361 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE { | 361 virtual base::TimeDelta LowFrequencyAnimationInterval() const override { |
362 return base::TimeDelta::FromMilliseconds(4); | 362 return base::TimeDelta::FromMilliseconds(4); |
363 } | 363 } |
364 | 364 |
365 virtual void BeginTest() OVERRIDE { | 365 virtual void BeginTest() override { |
366 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 366 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
367 } | 367 } |
368 | 368 |
369 virtual void NotifyAnimationFinished( | 369 virtual void NotifyAnimationFinished( |
370 base::TimeTicks monotonic_time, | 370 base::TimeTicks monotonic_time, |
371 Animation::TargetProperty target_property) OVERRIDE { | 371 Animation::TargetProperty target_property) override { |
372 // Replace animated commits with an empty tree. | 372 // Replace animated commits with an empty tree. |
373 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL)); | 373 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL)); |
374 } | 374 } |
375 | 375 |
376 virtual void DidCommit() OVERRIDE { | 376 virtual void DidCommit() override { |
377 // This alternates setting an empty tree and a non-empty tree with an | 377 // This alternates setting an empty tree and a non-empty tree with an |
378 // animation. | 378 // animation. |
379 switch (layer_tree_host()->source_frame_number()) { | 379 switch (layer_tree_host()->source_frame_number()) { |
380 case 1: | 380 case 1: |
381 // Wait for NotifyAnimationFinished to commit an empty tree. | 381 // Wait for NotifyAnimationFinished to commit an empty tree. |
382 break; | 382 break; |
383 case 2: | 383 case 2: |
384 SetupTree(); | 384 SetupTree(); |
385 AddOpacityTransitionToLayer( | 385 AddOpacityTransitionToLayer( |
386 layer_tree_host()->root_layer(), 0.000001, 0, 0.5, true); | 386 layer_tree_host()->root_layer(), 0.000001, 0, 0.5, true); |
387 break; | 387 break; |
388 case 3: | 388 case 3: |
389 // Wait for NotifyAnimationFinished to commit an empty tree. | 389 // Wait for NotifyAnimationFinished to commit an empty tree. |
390 break; | 390 break; |
391 case 4: | 391 case 4: |
392 EndTest(); | 392 EndTest(); |
393 break; | 393 break; |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 397 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
398 // At the start of every commit, block activations and make sure | 398 // At the start of every commit, block activations and make sure |
399 // we are backgrounded. | 399 // we are backgrounded. |
400 host_impl->BlockNotifyReadyToActivateForTesting(true); | 400 host_impl->BlockNotifyReadyToActivateForTesting(true); |
401 PostSetVisibleToMainThread(false); | 401 PostSetVisibleToMainThread(false); |
402 } | 402 } |
403 | 403 |
404 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 404 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
405 if (!host_impl->settings().impl_side_painting) { | 405 if (!host_impl->settings().impl_side_painting) { |
406 // There are no activations to block if we're not impl-side-painting, | 406 // There are no activations to block if we're not impl-side-painting, |
407 // so just advance the test immediately. | 407 // so just advance the test immediately. |
408 if (host_impl->active_tree()->source_frame_number() < 3) | 408 if (host_impl->active_tree()->source_frame_number() < 3) |
409 UnblockActivations(host_impl); | 409 UnblockActivations(host_impl); |
410 return; | 410 return; |
411 } | 411 } |
412 | 412 |
413 // We block activation for several ticks to make sure that, even though | 413 // We block activation for several ticks to make sure that, even though |
414 // there is a pending tree with animations, we still do not background | 414 // there is a pending tree with animations, we still do not background |
415 // tick if the active tree is empty. | 415 // tick if the active tree is empty. |
416 if (host_impl->pending_tree()->source_frame_number() < 3) { | 416 if (host_impl->pending_tree()->source_frame_number() < 3) { |
417 base::MessageLoopProxy::current()->PostDelayedTask( | 417 base::MessageLoopProxy::current()->PostDelayedTask( |
418 FROM_HERE, | 418 FROM_HERE, |
419 base::Bind( | 419 base::Bind( |
420 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | 420 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: |
421 UnblockActivations, | 421 UnblockActivations, |
422 base::Unretained(this), | 422 base::Unretained(this), |
423 host_impl), | 423 host_impl), |
424 4 * LowFrequencyAnimationInterval()); | 424 4 * LowFrequencyAnimationInterval()); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) { | 428 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) { |
429 host_impl->BlockNotifyReadyToActivateForTesting(false); | 429 host_impl->BlockNotifyReadyToActivateForTesting(false); |
430 } | 430 } |
431 | 431 |
432 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 432 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
433 active_tree_was_animated_ = false; | 433 active_tree_was_animated_ = false; |
434 | 434 |
435 // Verify that commits are actually alternating with empty / non-empty | 435 // Verify that commits are actually alternating with empty / non-empty |
436 // trees. | 436 // trees. |
437 int frame_number = host_impl->active_tree()->source_frame_number(); | 437 int frame_number = host_impl->active_tree()->source_frame_number(); |
438 switch (frame_number) { | 438 switch (frame_number) { |
439 case 0: | 439 case 0: |
440 case 2: | 440 case 2: |
441 EXPECT_TRUE(host_impl->active_tree()->root_layer()) | 441 EXPECT_TRUE(host_impl->active_tree()->root_layer()) |
442 << "frame: " << frame_number; | 442 << "frame: " << frame_number; |
(...skipping 13 matching lines...) Expand all Loading... |
456 base::Bind( | 456 base::Bind( |
457 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | 457 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: |
458 InitiateNextCommit, | 458 InitiateNextCommit, |
459 base::Unretained(this), | 459 base::Unretained(this), |
460 host_impl), | 460 host_impl), |
461 4 * LowFrequencyAnimationInterval()); | 461 4 * LowFrequencyAnimationInterval()); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl, | 465 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl, |
466 base::TimeTicks monotonic_time) OVERRIDE { | 466 base::TimeTicks monotonic_time) override { |
467 EXPECT_TRUE(host_impl->active_tree()->root_layer()); | 467 EXPECT_TRUE(host_impl->active_tree()->root_layer()); |
468 active_tree_was_animated_ = true; | 468 active_tree_was_animated_ = true; |
469 } | 469 } |
470 | 470 |
471 void InitiateNextCommit(LayerTreeHostImpl* host_impl) { | 471 void InitiateNextCommit(LayerTreeHostImpl* host_impl) { |
472 // Verify that we actually animated when we should have. | 472 // Verify that we actually animated when we should have. |
473 bool has_active_tree = host_impl->active_tree()->root_layer(); | 473 bool has_active_tree = host_impl->active_tree()->root_layer(); |
474 EXPECT_EQ(has_active_tree, active_tree_was_animated_); | 474 EXPECT_EQ(has_active_tree, active_tree_was_animated_); |
475 | 475 |
476 // The next commit is blocked until we become visible again. | 476 // The next commit is blocked until we become visible again. |
477 PostSetVisibleToMainThread(true); | 477 PostSetVisibleToMainThread(true); |
478 } | 478 } |
479 | 479 |
480 virtual void AfterTest() OVERRIDE {} | 480 virtual void AfterTest() override {} |
481 | 481 |
482 bool active_tree_was_animated_; | 482 bool active_tree_was_animated_; |
483 }; | 483 }; |
484 | 484 |
485 SINGLE_AND_MULTI_THREAD_TEST_F( | 485 SINGLE_AND_MULTI_THREAD_TEST_F( |
486 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree); | 486 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree); |
487 | 487 |
488 // Ensure that an animation's timing function is respected. | 488 // Ensure that an animation's timing function is respected. |
489 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 489 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
490 : public LayerTreeHostAnimationTest { | 490 : public LayerTreeHostAnimationTest { |
491 public: | 491 public: |
492 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} | 492 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} |
493 | 493 |
494 virtual void SetupTree() OVERRIDE { | 494 virtual void SetupTree() override { |
495 LayerTreeHostAnimationTest::SetupTree(); | 495 LayerTreeHostAnimationTest::SetupTree(); |
496 content_ = FakeContentLayer::Create(&client_); | 496 content_ = FakeContentLayer::Create(&client_); |
497 content_->SetBounds(gfx::Size(4, 4)); | 497 content_->SetBounds(gfx::Size(4, 4)); |
498 layer_tree_host()->root_layer()->AddChild(content_); | 498 layer_tree_host()->root_layer()->AddChild(content_); |
499 } | 499 } |
500 | 500 |
501 virtual void BeginTest() OVERRIDE { | 501 virtual void BeginTest() override { |
502 PostAddAnimationToMainThread(content_.get()); | 502 PostAddAnimationToMainThread(content_.get()); |
503 } | 503 } |
504 | 504 |
505 virtual void AnimateLayers( | 505 virtual void AnimateLayers( |
506 LayerTreeHostImpl* host_impl, | 506 LayerTreeHostImpl* host_impl, |
507 base::TimeTicks monotonic_time) OVERRIDE { | 507 base::TimeTicks monotonic_time) override { |
508 LayerAnimationController* controller_impl = | 508 LayerAnimationController* controller_impl = |
509 host_impl->active_tree()->root_layer()->children()[0]-> | 509 host_impl->active_tree()->root_layer()->children()[0]-> |
510 layer_animation_controller(); | 510 layer_animation_controller(); |
511 Animation* animation = | 511 Animation* animation = |
512 controller_impl->GetAnimation(Animation::Opacity); | 512 controller_impl->GetAnimation(Animation::Opacity); |
513 if (!animation) | 513 if (!animation) |
514 return; | 514 return; |
515 | 515 |
516 const FloatAnimationCurve* curve = | 516 const FloatAnimationCurve* curve = |
517 animation->curve()->ToFloatAnimationCurve(); | 517 animation->curve()->ToFloatAnimationCurve(); |
518 float start_opacity = curve->GetValue(0.0); | 518 float start_opacity = curve->GetValue(0.0); |
519 float end_opacity = curve->GetValue(curve->Duration()); | 519 float end_opacity = curve->GetValue(curve->Duration()); |
520 float linearly_interpolated_opacity = | 520 float linearly_interpolated_opacity = |
521 0.25f * end_opacity + 0.75f * start_opacity; | 521 0.25f * end_opacity + 0.75f * start_opacity; |
522 double time = curve->Duration() * 0.25; | 522 double time = curve->Duration() * 0.25; |
523 // If the linear timing function associated with this animation was not | 523 // If the linear timing function associated with this animation was not |
524 // picked up, then the linearly interpolated opacity would be different | 524 // picked up, then the linearly interpolated opacity would be different |
525 // because of the default ease timing function. | 525 // because of the default ease timing function. |
526 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); | 526 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); |
527 | 527 |
528 EndTest(); | 528 EndTest(); |
529 } | 529 } |
530 | 530 |
531 virtual void AfterTest() OVERRIDE {} | 531 virtual void AfterTest() override {} |
532 | 532 |
533 FakeContentLayerClient client_; | 533 FakeContentLayerClient client_; |
534 scoped_refptr<FakeContentLayer> content_; | 534 scoped_refptr<FakeContentLayer> content_; |
535 }; | 535 }; |
536 | 536 |
537 SINGLE_AND_MULTI_THREAD_TEST_F( | 537 SINGLE_AND_MULTI_THREAD_TEST_F( |
538 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); | 538 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); |
539 | 539 |
540 // Ensures that main thread animations have their start times synchronized with | 540 // Ensures that main thread animations have their start times synchronized with |
541 // impl thread animations. | 541 // impl thread animations. |
542 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 542 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
543 : public LayerTreeHostAnimationTest { | 543 : public LayerTreeHostAnimationTest { |
544 public: | 544 public: |
545 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() | 545 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() |
546 : main_start_time_(-1.0), | 546 : main_start_time_(-1.0), |
547 impl_start_time_(-1.0) {} | 547 impl_start_time_(-1.0) {} |
548 | 548 |
549 virtual void SetupTree() OVERRIDE { | 549 virtual void SetupTree() override { |
550 LayerTreeHostAnimationTest::SetupTree(); | 550 LayerTreeHostAnimationTest::SetupTree(); |
551 content_ = FakeContentLayer::Create(&client_); | 551 content_ = FakeContentLayer::Create(&client_); |
552 content_->SetBounds(gfx::Size(4, 4)); | 552 content_->SetBounds(gfx::Size(4, 4)); |
553 content_->set_layer_animation_delegate(this); | 553 content_->set_layer_animation_delegate(this); |
554 layer_tree_host()->root_layer()->AddChild(content_); | 554 layer_tree_host()->root_layer()->AddChild(content_); |
555 } | 555 } |
556 | 556 |
557 virtual void BeginTest() OVERRIDE { | 557 virtual void BeginTest() override { |
558 PostAddAnimationToMainThread(content_.get()); | 558 PostAddAnimationToMainThread(content_.get()); |
559 } | 559 } |
560 | 560 |
561 virtual void NotifyAnimationStarted( | 561 virtual void NotifyAnimationStarted( |
562 base::TimeTicks monotonic_time, | 562 base::TimeTicks monotonic_time, |
563 Animation::TargetProperty target_property) OVERRIDE { | 563 Animation::TargetProperty target_property) override { |
564 LayerAnimationController* controller = | 564 LayerAnimationController* controller = |
565 layer_tree_host()->root_layer()->children()[0]-> | 565 layer_tree_host()->root_layer()->children()[0]-> |
566 layer_animation_controller(); | 566 layer_animation_controller(); |
567 Animation* animation = | 567 Animation* animation = |
568 controller->GetAnimation(Animation::Opacity); | 568 controller->GetAnimation(Animation::Opacity); |
569 main_start_time_ = | 569 main_start_time_ = |
570 (animation->start_time() - base::TimeTicks()).InSecondsF(); | 570 (animation->start_time() - base::TimeTicks()).InSecondsF(); |
571 controller->RemoveAnimation(animation->id()); | 571 controller->RemoveAnimation(animation->id()); |
572 | 572 |
573 if (impl_start_time_ > 0.0) | 573 if (impl_start_time_ > 0.0) |
574 EndTest(); | 574 EndTest(); |
575 } | 575 } |
576 | 576 |
577 virtual void UpdateAnimationState( | 577 virtual void UpdateAnimationState( |
578 LayerTreeHostImpl* impl_host, | 578 LayerTreeHostImpl* impl_host, |
579 bool has_unfinished_animation) OVERRIDE { | 579 bool has_unfinished_animation) override { |
580 LayerAnimationController* controller = | 580 LayerAnimationController* controller = |
581 impl_host->active_tree()->root_layer()->children()[0]-> | 581 impl_host->active_tree()->root_layer()->children()[0]-> |
582 layer_animation_controller(); | 582 layer_animation_controller(); |
583 Animation* animation = | 583 Animation* animation = |
584 controller->GetAnimation(Animation::Opacity); | 584 controller->GetAnimation(Animation::Opacity); |
585 if (!animation) | 585 if (!animation) |
586 return; | 586 return; |
587 | 587 |
588 impl_start_time_ = | 588 impl_start_time_ = |
589 (animation->start_time() - base::TimeTicks()).InSecondsF(); | 589 (animation->start_time() - base::TimeTicks()).InSecondsF(); |
590 controller->RemoveAnimation(animation->id()); | 590 controller->RemoveAnimation(animation->id()); |
591 | 591 |
592 if (main_start_time_ > 0.0) | 592 if (main_start_time_ > 0.0) |
593 EndTest(); | 593 EndTest(); |
594 } | 594 } |
595 | 595 |
596 virtual void AfterTest() OVERRIDE { | 596 virtual void AfterTest() override { |
597 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); | 597 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); |
598 } | 598 } |
599 | 599 |
600 private: | 600 private: |
601 double main_start_time_; | 601 double main_start_time_; |
602 double impl_start_time_; | 602 double impl_start_time_; |
603 FakeContentLayerClient client_; | 603 FakeContentLayerClient client_; |
604 scoped_refptr<FakeContentLayer> content_; | 604 scoped_refptr<FakeContentLayer> content_; |
605 }; | 605 }; |
606 | 606 |
607 SINGLE_AND_MULTI_THREAD_TEST_F( | 607 SINGLE_AND_MULTI_THREAD_TEST_F( |
608 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 608 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
609 | 609 |
610 // Ensures that notify animation finished is called. | 610 // Ensures that notify animation finished is called. |
611 class LayerTreeHostAnimationTestAnimationFinishedEvents | 611 class LayerTreeHostAnimationTestAnimationFinishedEvents |
612 : public LayerTreeHostAnimationTest { | 612 : public LayerTreeHostAnimationTest { |
613 public: | 613 public: |
614 LayerTreeHostAnimationTestAnimationFinishedEvents() {} | 614 LayerTreeHostAnimationTestAnimationFinishedEvents() {} |
615 | 615 |
616 virtual void BeginTest() OVERRIDE { | 616 virtual void BeginTest() override { |
617 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 617 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
618 } | 618 } |
619 | 619 |
620 virtual void NotifyAnimationFinished( | 620 virtual void NotifyAnimationFinished( |
621 base::TimeTicks monotonic_time, | 621 base::TimeTicks monotonic_time, |
622 Animation::TargetProperty target_property) OVERRIDE { | 622 Animation::TargetProperty target_property) override { |
623 LayerAnimationController* controller = | 623 LayerAnimationController* controller = |
624 layer_tree_host()->root_layer()->layer_animation_controller(); | 624 layer_tree_host()->root_layer()->layer_animation_controller(); |
625 Animation* animation = | 625 Animation* animation = |
626 controller->GetAnimation(Animation::Opacity); | 626 controller->GetAnimation(Animation::Opacity); |
627 if (animation) | 627 if (animation) |
628 controller->RemoveAnimation(animation->id()); | 628 controller->RemoveAnimation(animation->id()); |
629 EndTest(); | 629 EndTest(); |
630 } | 630 } |
631 | 631 |
632 virtual void AfterTest() OVERRIDE {} | 632 virtual void AfterTest() override {} |
633 }; | 633 }; |
634 | 634 |
635 SINGLE_AND_MULTI_THREAD_TEST_F( | 635 SINGLE_AND_MULTI_THREAD_TEST_F( |
636 LayerTreeHostAnimationTestAnimationFinishedEvents); | 636 LayerTreeHostAnimationTestAnimationFinishedEvents); |
637 | 637 |
638 // Ensures that when opacity is being animated, this value does not cause the | 638 // Ensures that when opacity is being animated, this value does not cause the |
639 // subtree to be skipped. | 639 // subtree to be skipped. |
640 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity | 640 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity |
641 : public LayerTreeHostAnimationTest { | 641 : public LayerTreeHostAnimationTest { |
642 public: | 642 public: |
643 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() | 643 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() |
644 : update_check_layer_(FakeContentLayer::Create(&client_)) { | 644 : update_check_layer_(FakeContentLayer::Create(&client_)) { |
645 } | 645 } |
646 | 646 |
647 virtual void SetupTree() OVERRIDE { | 647 virtual void SetupTree() override { |
648 update_check_layer_->SetOpacity(0.f); | 648 update_check_layer_->SetOpacity(0.f); |
649 layer_tree_host()->SetRootLayer(update_check_layer_); | 649 layer_tree_host()->SetRootLayer(update_check_layer_); |
650 LayerTreeHostAnimationTest::SetupTree(); | 650 LayerTreeHostAnimationTest::SetupTree(); |
651 } | 651 } |
652 | 652 |
653 virtual void BeginTest() OVERRIDE { | 653 virtual void BeginTest() override { |
654 PostAddAnimationToMainThread(update_check_layer_.get()); | 654 PostAddAnimationToMainThread(update_check_layer_.get()); |
655 } | 655 } |
656 | 656 |
657 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 657 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
658 LayerAnimationController* controller_impl = | 658 LayerAnimationController* controller_impl = |
659 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 659 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
660 Animation* animation_impl = | 660 Animation* animation_impl = |
661 controller_impl->GetAnimation(Animation::Opacity); | 661 controller_impl->GetAnimation(Animation::Opacity); |
662 controller_impl->RemoveAnimation(animation_impl->id()); | 662 controller_impl->RemoveAnimation(animation_impl->id()); |
663 EndTest(); | 663 EndTest(); |
664 } | 664 } |
665 | 665 |
666 virtual void AfterTest() OVERRIDE { | 666 virtual void AfterTest() override { |
667 // Update() should have been called once, proving that the layer was not | 667 // Update() should have been called once, proving that the layer was not |
668 // skipped. | 668 // skipped. |
669 EXPECT_EQ(1u, update_check_layer_->update_count()); | 669 EXPECT_EQ(1u, update_check_layer_->update_count()); |
670 | 670 |
671 // clear update_check_layer_ so LayerTreeHost dies. | 671 // clear update_check_layer_ so LayerTreeHost dies. |
672 update_check_layer_ = NULL; | 672 update_check_layer_ = NULL; |
673 } | 673 } |
674 | 674 |
675 private: | 675 private: |
676 FakeContentLayerClient client_; | 676 FakeContentLayerClient client_; |
677 scoped_refptr<FakeContentLayer> update_check_layer_; | 677 scoped_refptr<FakeContentLayer> update_check_layer_; |
678 }; | 678 }; |
679 | 679 |
680 SINGLE_AND_MULTI_THREAD_TEST_F( | 680 SINGLE_AND_MULTI_THREAD_TEST_F( |
681 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); | 681 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); |
682 | 682 |
683 // Layers added to tree with existing active animations should have the | 683 // Layers added to tree with existing active animations should have the |
684 // animation correctly recognized. | 684 // animation correctly recognized. |
685 class LayerTreeHostAnimationTestLayerAddedWithAnimation | 685 class LayerTreeHostAnimationTestLayerAddedWithAnimation |
686 : public LayerTreeHostAnimationTest { | 686 : public LayerTreeHostAnimationTest { |
687 public: | 687 public: |
688 LayerTreeHostAnimationTestLayerAddedWithAnimation() {} | 688 LayerTreeHostAnimationTestLayerAddedWithAnimation() {} |
689 | 689 |
690 virtual void BeginTest() OVERRIDE { | 690 virtual void BeginTest() override { |
691 PostSetNeedsCommitToMainThread(); | 691 PostSetNeedsCommitToMainThread(); |
692 } | 692 } |
693 | 693 |
694 virtual void DidCommit() OVERRIDE { | 694 virtual void DidCommit() override { |
695 if (layer_tree_host()->source_frame_number() == 1) { | 695 if (layer_tree_host()->source_frame_number() == 1) { |
696 scoped_refptr<Layer> layer = Layer::Create(); | 696 scoped_refptr<Layer> layer = Layer::Create(); |
697 layer->set_layer_animation_delegate(this); | 697 layer->set_layer_animation_delegate(this); |
698 | 698 |
699 // Any valid AnimationCurve will do here. | 699 // Any valid AnimationCurve will do here. |
700 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); | 700 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); |
701 scoped_ptr<Animation> animation( | 701 scoped_ptr<Animation> animation( |
702 Animation::Create(curve.Pass(), 1, 1, | 702 Animation::Create(curve.Pass(), 1, 1, |
703 Animation::Opacity)); | 703 Animation::Opacity)); |
704 layer->layer_animation_controller()->AddAnimation(animation.Pass()); | 704 layer->layer_animation_controller()->AddAnimation(animation.Pass()); |
705 | 705 |
706 // We add the animation *before* attaching the layer to the tree. | 706 // We add the animation *before* attaching the layer to the tree. |
707 layer_tree_host()->root_layer()->AddChild(layer); | 707 layer_tree_host()->root_layer()->AddChild(layer); |
708 } | 708 } |
709 } | 709 } |
710 | 710 |
711 virtual void AnimateLayers( | 711 virtual void AnimateLayers( |
712 LayerTreeHostImpl* impl_host, | 712 LayerTreeHostImpl* impl_host, |
713 base::TimeTicks monotonic_time) OVERRIDE { | 713 base::TimeTicks monotonic_time) override { |
714 EndTest(); | 714 EndTest(); |
715 } | 715 } |
716 | 716 |
717 virtual void AfterTest() OVERRIDE {} | 717 virtual void AfterTest() override {} |
718 }; | 718 }; |
719 | 719 |
720 SINGLE_AND_MULTI_THREAD_TEST_F( | 720 SINGLE_AND_MULTI_THREAD_TEST_F( |
721 LayerTreeHostAnimationTestLayerAddedWithAnimation); | 721 LayerTreeHostAnimationTestLayerAddedWithAnimation); |
722 | 722 |
723 class LayerTreeHostAnimationTestCancelAnimateCommit | 723 class LayerTreeHostAnimationTestCancelAnimateCommit |
724 : public LayerTreeHostAnimationTest { | 724 : public LayerTreeHostAnimationTest { |
725 public: | 725 public: |
726 LayerTreeHostAnimationTestCancelAnimateCommit() | 726 LayerTreeHostAnimationTestCancelAnimateCommit() |
727 : num_begin_frames_(0), num_commit_calls_(0), num_draw_calls_(0) {} | 727 : num_begin_frames_(0), num_commit_calls_(0), num_draw_calls_(0) {} |
728 | 728 |
729 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 729 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
730 | 730 |
731 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 731 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
732 num_begin_frames_++; | 732 num_begin_frames_++; |
733 // No-op animate will cancel the commit. | 733 // No-op animate will cancel the commit. |
734 if (layer_tree_host()->source_frame_number() == 1) { | 734 if (layer_tree_host()->source_frame_number() == 1) { |
735 EndTest(); | 735 EndTest(); |
736 return; | 736 return; |
737 } | 737 } |
738 layer_tree_host()->SetNeedsAnimate(); | 738 layer_tree_host()->SetNeedsAnimate(); |
739 } | 739 } |
740 | 740 |
741 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 741 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
742 num_commit_calls_++; | 742 num_commit_calls_++; |
743 if (impl->active_tree()->source_frame_number() > 1) | 743 if (impl->active_tree()->source_frame_number() > 1) |
744 FAIL() << "Commit should have been canceled."; | 744 FAIL() << "Commit should have been canceled."; |
745 } | 745 } |
746 | 746 |
747 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 747 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
748 num_draw_calls_++; | 748 num_draw_calls_++; |
749 if (impl->active_tree()->source_frame_number() > 1) | 749 if (impl->active_tree()->source_frame_number() > 1) |
750 FAIL() << "Draw should have been canceled."; | 750 FAIL() << "Draw should have been canceled."; |
751 } | 751 } |
752 | 752 |
753 virtual void AfterTest() OVERRIDE { | 753 virtual void AfterTest() override { |
754 EXPECT_EQ(2, num_begin_frames_); | 754 EXPECT_EQ(2, num_begin_frames_); |
755 EXPECT_EQ(1, num_commit_calls_); | 755 EXPECT_EQ(1, num_commit_calls_); |
756 EXPECT_EQ(1, num_draw_calls_); | 756 EXPECT_EQ(1, num_draw_calls_); |
757 } | 757 } |
758 | 758 |
759 private: | 759 private: |
760 int num_begin_frames_; | 760 int num_begin_frames_; |
761 int num_commit_calls_; | 761 int num_commit_calls_; |
762 int num_draw_calls_; | 762 int num_draw_calls_; |
763 FakeContentLayerClient client_; | 763 FakeContentLayerClient client_; |
764 scoped_refptr<FakeContentLayer> content_; | 764 scoped_refptr<FakeContentLayer> content_; |
765 }; | 765 }; |
766 | 766 |
767 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); | 767 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); |
768 | 768 |
769 class LayerTreeHostAnimationTestForceRedraw | 769 class LayerTreeHostAnimationTestForceRedraw |
770 : public LayerTreeHostAnimationTest { | 770 : public LayerTreeHostAnimationTest { |
771 public: | 771 public: |
772 LayerTreeHostAnimationTestForceRedraw() | 772 LayerTreeHostAnimationTestForceRedraw() |
773 : num_animate_(0), num_draw_layers_(0) {} | 773 : num_animate_(0), num_draw_layers_(0) {} |
774 | 774 |
775 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 775 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
776 | 776 |
777 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 777 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
778 if (++num_animate_ < 2) | 778 if (++num_animate_ < 2) |
779 layer_tree_host()->SetNeedsAnimate(); | 779 layer_tree_host()->SetNeedsAnimate(); |
780 } | 780 } |
781 | 781 |
782 virtual void Layout() OVERRIDE { | 782 virtual void Layout() override { |
783 layer_tree_host()->SetNextCommitForcesRedraw(); | 783 layer_tree_host()->SetNextCommitForcesRedraw(); |
784 } | 784 } |
785 | 785 |
786 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 786 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
787 if (++num_draw_layers_ == 2) | 787 if (++num_draw_layers_ == 2) |
788 EndTest(); | 788 EndTest(); |
789 } | 789 } |
790 | 790 |
791 virtual void AfterTest() OVERRIDE { | 791 virtual void AfterTest() override { |
792 // The first commit will always draw; make sure the second draw triggered | 792 // The first commit will always draw; make sure the second draw triggered |
793 // by the animation was not cancelled. | 793 // by the animation was not cancelled. |
794 EXPECT_EQ(2, num_draw_layers_); | 794 EXPECT_EQ(2, num_draw_layers_); |
795 EXPECT_EQ(2, num_animate_); | 795 EXPECT_EQ(2, num_animate_); |
796 } | 796 } |
797 | 797 |
798 private: | 798 private: |
799 int num_animate_; | 799 int num_animate_; |
800 int num_draw_layers_; | 800 int num_draw_layers_; |
801 }; | 801 }; |
802 | 802 |
803 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw); | 803 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw); |
804 | 804 |
805 class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit | 805 class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit |
806 : public LayerTreeHostAnimationTest { | 806 : public LayerTreeHostAnimationTest { |
807 public: | 807 public: |
808 LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit() | 808 LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit() |
809 : num_animate_(0), num_draw_layers_(0) {} | 809 : num_animate_(0), num_draw_layers_(0) {} |
810 | 810 |
811 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 811 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
812 | 812 |
813 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 813 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
814 if (++num_animate_ <= 2) { | 814 if (++num_animate_ <= 2) { |
815 layer_tree_host()->SetNeedsCommit(); | 815 layer_tree_host()->SetNeedsCommit(); |
816 layer_tree_host()->SetNeedsAnimate(); | 816 layer_tree_host()->SetNeedsAnimate(); |
817 } | 817 } |
818 } | 818 } |
819 | 819 |
820 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 820 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
821 if (++num_draw_layers_ == 2) | 821 if (++num_draw_layers_ == 2) |
822 EndTest(); | 822 EndTest(); |
823 } | 823 } |
824 | 824 |
825 virtual void AfterTest() OVERRIDE { | 825 virtual void AfterTest() override { |
826 // The first commit will always draw; make sure the second draw triggered | 826 // The first commit will always draw; make sure the second draw triggered |
827 // by the SetNeedsCommit was not cancelled. | 827 // by the SetNeedsCommit was not cancelled. |
828 EXPECT_EQ(2, num_draw_layers_); | 828 EXPECT_EQ(2, num_draw_layers_); |
829 EXPECT_GE(num_animate_, 2); | 829 EXPECT_GE(num_animate_, 2); |
830 } | 830 } |
831 | 831 |
832 private: | 832 private: |
833 int num_animate_; | 833 int num_animate_; |
834 int num_draw_layers_; | 834 int num_draw_layers_; |
835 }; | 835 }; |
836 | 836 |
837 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit); | 837 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit); |
838 | 838 |
839 // Make sure the main thread can still execute animations when CanDraw() is not | 839 // Make sure the main thread can still execute animations when CanDraw() is not |
840 // true. | 840 // true. |
841 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw | 841 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
842 : public LayerTreeHostAnimationTest { | 842 : public LayerTreeHostAnimationTest { |
843 public: | 843 public: |
844 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} | 844 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
845 | 845 |
846 virtual void SetupTree() OVERRIDE { | 846 virtual void SetupTree() override { |
847 LayerTreeHostAnimationTest::SetupTree(); | 847 LayerTreeHostAnimationTest::SetupTree(); |
848 content_ = FakeContentLayer::Create(&client_); | 848 content_ = FakeContentLayer::Create(&client_); |
849 content_->SetBounds(gfx::Size(4, 4)); | 849 content_->SetBounds(gfx::Size(4, 4)); |
850 content_->set_layer_animation_delegate(this); | 850 content_->set_layer_animation_delegate(this); |
851 layer_tree_host()->root_layer()->AddChild(content_); | 851 layer_tree_host()->root_layer()->AddChild(content_); |
852 } | 852 } |
853 | 853 |
854 virtual void BeginTest() OVERRIDE { | 854 virtual void BeginTest() override { |
855 layer_tree_host()->SetViewportSize(gfx::Size()); | 855 layer_tree_host()->SetViewportSize(gfx::Size()); |
856 PostAddAnimationToMainThread(content_.get()); | 856 PostAddAnimationToMainThread(content_.get()); |
857 } | 857 } |
858 | 858 |
859 virtual void NotifyAnimationStarted( | 859 virtual void NotifyAnimationStarted( |
860 base::TimeTicks monotonic_time, | 860 base::TimeTicks monotonic_time, |
861 Animation::TargetProperty target_property) OVERRIDE { | 861 Animation::TargetProperty target_property) override { |
862 started_times_++; | 862 started_times_++; |
863 } | 863 } |
864 | 864 |
865 virtual void NotifyAnimationFinished( | 865 virtual void NotifyAnimationFinished( |
866 base::TimeTicks monotonic_time, | 866 base::TimeTicks monotonic_time, |
867 Animation::TargetProperty target_property) OVERRIDE { | 867 Animation::TargetProperty target_property) override { |
868 EndTest(); | 868 EndTest(); |
869 } | 869 } |
870 | 870 |
871 virtual void AfterTest() OVERRIDE { | 871 virtual void AfterTest() override { |
872 EXPECT_EQ(1, started_times_); | 872 EXPECT_EQ(1, started_times_); |
873 } | 873 } |
874 | 874 |
875 private: | 875 private: |
876 int started_times_; | 876 int started_times_; |
877 FakeContentLayerClient client_; | 877 FakeContentLayerClient client_; |
878 scoped_refptr<FakeContentLayer> content_; | 878 scoped_refptr<FakeContentLayer> content_; |
879 }; | 879 }; |
880 | 880 |
881 SINGLE_AND_MULTI_THREAD_TEST_F( | 881 SINGLE_AND_MULTI_THREAD_TEST_F( |
882 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw); | 882 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw); |
883 | 883 |
884 // Make sure the main thread can still execute animations when the renderer is | 884 // Make sure the main thread can still execute animations when the renderer is |
885 // backgrounded. | 885 // backgrounded. |
886 class LayerTreeHostAnimationTestRunAnimationWhenNotVisible | 886 class LayerTreeHostAnimationTestRunAnimationWhenNotVisible |
887 : public LayerTreeHostAnimationTest { | 887 : public LayerTreeHostAnimationTest { |
888 public: | 888 public: |
889 LayerTreeHostAnimationTestRunAnimationWhenNotVisible() : started_times_(0) {} | 889 LayerTreeHostAnimationTestRunAnimationWhenNotVisible() : started_times_(0) {} |
890 | 890 |
891 virtual void SetupTree() OVERRIDE { | 891 virtual void SetupTree() override { |
892 LayerTreeHostAnimationTest::SetupTree(); | 892 LayerTreeHostAnimationTest::SetupTree(); |
893 content_ = FakeContentLayer::Create(&client_); | 893 content_ = FakeContentLayer::Create(&client_); |
894 content_->SetBounds(gfx::Size(4, 4)); | 894 content_->SetBounds(gfx::Size(4, 4)); |
895 content_->set_layer_animation_delegate(this); | 895 content_->set_layer_animation_delegate(this); |
896 layer_tree_host()->root_layer()->AddChild(content_); | 896 layer_tree_host()->root_layer()->AddChild(content_); |
897 } | 897 } |
898 | 898 |
899 virtual void BeginTest() OVERRIDE { | 899 virtual void BeginTest() override { |
900 visible_ = true; | 900 visible_ = true; |
901 PostAddAnimationToMainThread(content_.get()); | 901 PostAddAnimationToMainThread(content_.get()); |
902 } | 902 } |
903 | 903 |
904 virtual void DidCommit() OVERRIDE { | 904 virtual void DidCommit() override { |
905 visible_ = false; | 905 visible_ = false; |
906 layer_tree_host()->SetVisible(false); | 906 layer_tree_host()->SetVisible(false); |
907 } | 907 } |
908 | 908 |
909 virtual void NotifyAnimationStarted( | 909 virtual void NotifyAnimationStarted( |
910 base::TimeTicks monotonic_time, | 910 base::TimeTicks monotonic_time, |
911 Animation::TargetProperty target_property) OVERRIDE { | 911 Animation::TargetProperty target_property) override { |
912 EXPECT_FALSE(visible_); | 912 EXPECT_FALSE(visible_); |
913 started_times_++; | 913 started_times_++; |
914 } | 914 } |
915 | 915 |
916 virtual void NotifyAnimationFinished( | 916 virtual void NotifyAnimationFinished( |
917 base::TimeTicks monotonic_time, | 917 base::TimeTicks monotonic_time, |
918 Animation::TargetProperty target_property) OVERRIDE { | 918 Animation::TargetProperty target_property) override { |
919 EXPECT_FALSE(visible_); | 919 EXPECT_FALSE(visible_); |
920 EXPECT_EQ(1, started_times_); | 920 EXPECT_EQ(1, started_times_); |
921 EndTest(); | 921 EndTest(); |
922 } | 922 } |
923 | 923 |
924 virtual void AfterTest() OVERRIDE {} | 924 virtual void AfterTest() override {} |
925 | 925 |
926 private: | 926 private: |
927 bool visible_; | 927 bool visible_; |
928 int started_times_; | 928 int started_times_; |
929 FakeContentLayerClient client_; | 929 FakeContentLayerClient client_; |
930 scoped_refptr<FakeContentLayer> content_; | 930 scoped_refptr<FakeContentLayer> content_; |
931 }; | 931 }; |
932 | 932 |
933 SINGLE_AND_MULTI_THREAD_TEST_F( | 933 SINGLE_AND_MULTI_THREAD_TEST_F( |
934 LayerTreeHostAnimationTestRunAnimationWhenNotVisible); | 934 LayerTreeHostAnimationTestRunAnimationWhenNotVisible); |
935 | 935 |
936 // Animations should not be started when frames are being skipped due to | 936 // Animations should not be started when frames are being skipped due to |
937 // checkerboard. | 937 // checkerboard. |
938 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations | 938 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
939 : public LayerTreeHostAnimationTest { | 939 : public LayerTreeHostAnimationTest { |
940 virtual void SetupTree() OVERRIDE { | 940 virtual void SetupTree() override { |
941 LayerTreeHostAnimationTest::SetupTree(); | 941 LayerTreeHostAnimationTest::SetupTree(); |
942 content_ = FakeContentLayer::Create(&client_); | 942 content_ = FakeContentLayer::Create(&client_); |
943 content_->SetBounds(gfx::Size(4, 4)); | 943 content_->SetBounds(gfx::Size(4, 4)); |
944 content_->set_layer_animation_delegate(this); | 944 content_->set_layer_animation_delegate(this); |
945 layer_tree_host()->root_layer()->AddChild(content_); | 945 layer_tree_host()->root_layer()->AddChild(content_); |
946 } | 946 } |
947 | 947 |
948 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 948 virtual void InitializeSettings(LayerTreeSettings* settings) override { |
949 // Make sure that drawing many times doesn't cause a checkerboarded | 949 // Make sure that drawing many times doesn't cause a checkerboarded |
950 // animation to start so we avoid flake in this test. | 950 // animation to start so we avoid flake in this test. |
951 settings->timeout_and_draw_when_animation_checkerboards = false; | 951 settings->timeout_and_draw_when_animation_checkerboards = false; |
952 } | 952 } |
953 | 953 |
954 virtual void BeginTest() OVERRIDE { | 954 virtual void BeginTest() override { |
955 prevented_draw_ = 0; | 955 prevented_draw_ = 0; |
956 added_animations_ = 0; | 956 added_animations_ = 0; |
957 started_times_ = 0; | 957 started_times_ = 0; |
958 | 958 |
959 PostSetNeedsCommitToMainThread(); | 959 PostSetNeedsCommitToMainThread(); |
960 } | 960 } |
961 | 961 |
962 virtual DrawResult PrepareToDrawOnThread( | 962 virtual DrawResult PrepareToDrawOnThread( |
963 LayerTreeHostImpl* host_impl, | 963 LayerTreeHostImpl* host_impl, |
964 LayerTreeHostImpl::FrameData* frame_data, | 964 LayerTreeHostImpl::FrameData* frame_data, |
965 DrawResult draw_result) OVERRIDE { | 965 DrawResult draw_result) override { |
966 if (added_animations_ < 2) | 966 if (added_animations_ < 2) |
967 return draw_result; | 967 return draw_result; |
968 if (TestEnded()) | 968 if (TestEnded()) |
969 return draw_result; | 969 return draw_result; |
970 // Act like there is checkerboard when the second animation wants to draw. | 970 // Act like there is checkerboard when the second animation wants to draw. |
971 ++prevented_draw_; | 971 ++prevented_draw_; |
972 if (prevented_draw_ > 2) | 972 if (prevented_draw_ > 2) |
973 EndTest(); | 973 EndTest(); |
974 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 974 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
975 } | 975 } |
976 | 976 |
977 virtual void DidCommitAndDrawFrame() OVERRIDE { | 977 virtual void DidCommitAndDrawFrame() override { |
978 switch (layer_tree_host()->source_frame_number()) { | 978 switch (layer_tree_host()->source_frame_number()) { |
979 case 1: | 979 case 1: |
980 // The animation is longer than 1 BeginFrame interval. | 980 // The animation is longer than 1 BeginFrame interval. |
981 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); | 981 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); |
982 added_animations_++; | 982 added_animations_++; |
983 break; | 983 break; |
984 case 2: | 984 case 2: |
985 // This second animation will not be drawn so it should not start. | 985 // This second animation will not be drawn so it should not start. |
986 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); | 986 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); |
987 added_animations_++; | 987 added_animations_++; |
988 break; | 988 break; |
989 } | 989 } |
990 } | 990 } |
991 | 991 |
992 virtual void NotifyAnimationStarted( | 992 virtual void NotifyAnimationStarted( |
993 base::TimeTicks monotonic_time, | 993 base::TimeTicks monotonic_time, |
994 Animation::TargetProperty target_property) OVERRIDE { | 994 Animation::TargetProperty target_property) override { |
995 if (TestEnded()) | 995 if (TestEnded()) |
996 return; | 996 return; |
997 started_times_++; | 997 started_times_++; |
998 } | 998 } |
999 | 999 |
1000 virtual void AfterTest() OVERRIDE { | 1000 virtual void AfterTest() override { |
1001 // Make sure we tried to draw the second animation but failed. | 1001 // Make sure we tried to draw the second animation but failed. |
1002 EXPECT_LT(0, prevented_draw_); | 1002 EXPECT_LT(0, prevented_draw_); |
1003 // The first animation should be started, but the second should not because | 1003 // The first animation should be started, but the second should not because |
1004 // of checkerboard. | 1004 // of checkerboard. |
1005 EXPECT_EQ(1, started_times_); | 1005 EXPECT_EQ(1, started_times_); |
1006 } | 1006 } |
1007 | 1007 |
1008 int prevented_draw_; | 1008 int prevented_draw_; |
1009 int added_animations_; | 1009 int added_animations_; |
1010 int started_times_; | 1010 int started_times_; |
1011 FakeContentLayerClient client_; | 1011 FakeContentLayerClient client_; |
1012 scoped_refptr<FakeContentLayer> content_; | 1012 scoped_refptr<FakeContentLayer> content_; |
1013 }; | 1013 }; |
1014 | 1014 |
1015 MULTI_THREAD_TEST_F( | 1015 MULTI_THREAD_TEST_F( |
1016 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 1016 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
1017 | 1017 |
1018 // Verifies that scroll offset animations are only accepted when impl-scrolling | 1018 // Verifies that scroll offset animations are only accepted when impl-scrolling |
1019 // is supported, and that when scroll offset animations are accepted, | 1019 // is supported, and that when scroll offset animations are accepted, |
1020 // scroll offset updates are sent back to the main thread. | 1020 // scroll offset updates are sent back to the main thread. |
1021 class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated | 1021 class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
1022 : public LayerTreeHostAnimationTest { | 1022 : public LayerTreeHostAnimationTest { |
1023 public: | 1023 public: |
1024 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated() {} | 1024 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated() {} |
1025 | 1025 |
1026 virtual void SetupTree() OVERRIDE { | 1026 virtual void SetupTree() override { |
1027 LayerTreeHostAnimationTest::SetupTree(); | 1027 LayerTreeHostAnimationTest::SetupTree(); |
1028 | 1028 |
1029 scroll_layer_ = FakeContentLayer::Create(&client_); | 1029 scroll_layer_ = FakeContentLayer::Create(&client_); |
1030 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 1030 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
1031 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); | 1031 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
1032 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 1032 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
1033 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 1033 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
1034 } | 1034 } |
1035 | 1035 |
1036 virtual void BeginTest() OVERRIDE { | 1036 virtual void BeginTest() override { |
1037 PostSetNeedsCommitToMainThread(); | 1037 PostSetNeedsCommitToMainThread(); |
1038 } | 1038 } |
1039 | 1039 |
1040 virtual void DidCommit() OVERRIDE { | 1040 virtual void DidCommit() override { |
1041 switch (layer_tree_host()->source_frame_number()) { | 1041 switch (layer_tree_host()->source_frame_number()) { |
1042 case 1: { | 1042 case 1: { |
1043 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 1043 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
1044 ScrollOffsetAnimationCurve::Create( | 1044 ScrollOffsetAnimationCurve::Create( |
1045 gfx::ScrollOffset(500.f, 550.f), | 1045 gfx::ScrollOffset(500.f, 550.f), |
1046 EaseInOutTimingFunction::Create())); | 1046 EaseInOutTimingFunction::Create())); |
1047 scoped_ptr<Animation> animation( | 1047 scoped_ptr<Animation> animation( |
1048 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); | 1048 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset)); |
1049 animation->set_needs_synchronized_start_time(true); | 1049 animation->set_needs_synchronized_start_time(true); |
1050 bool animation_added = scroll_layer_->AddAnimation(animation.Pass()); | 1050 bool animation_added = scroll_layer_->AddAnimation(animation.Pass()); |
1051 bool impl_scrolling_supported = | 1051 bool impl_scrolling_supported = |
1052 layer_tree_host()->proxy()->SupportsImplScrolling(); | 1052 layer_tree_host()->proxy()->SupportsImplScrolling(); |
1053 EXPECT_EQ(impl_scrolling_supported, animation_added); | 1053 EXPECT_EQ(impl_scrolling_supported, animation_added); |
1054 if (!impl_scrolling_supported) | 1054 if (!impl_scrolling_supported) |
1055 EndTest(); | 1055 EndTest(); |
1056 break; | 1056 break; |
1057 } | 1057 } |
1058 default: | 1058 default: |
1059 if (scroll_layer_->scroll_offset().x() > 10 && | 1059 if (scroll_layer_->scroll_offset().x() > 10 && |
1060 scroll_layer_->scroll_offset().y() > 20) | 1060 scroll_layer_->scroll_offset().y() > 20) |
1061 EndTest(); | 1061 EndTest(); |
1062 } | 1062 } |
1063 } | 1063 } |
1064 | 1064 |
1065 virtual void AfterTest() OVERRIDE {} | 1065 virtual void AfterTest() override {} |
1066 | 1066 |
1067 private: | 1067 private: |
1068 FakeContentLayerClient client_; | 1068 FakeContentLayerClient client_; |
1069 scoped_refptr<FakeContentLayer> scroll_layer_; | 1069 scoped_refptr<FakeContentLayer> scroll_layer_; |
1070 }; | 1070 }; |
1071 | 1071 |
1072 SINGLE_AND_MULTI_THREAD_TEST_F( | 1072 SINGLE_AND_MULTI_THREAD_TEST_F( |
1073 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); | 1073 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
1074 | 1074 |
1075 // Ensure that animation time is correctly updated when animations are frozen | 1075 // Ensure that animation time is correctly updated when animations are frozen |
1076 // because of checkerboarding. | 1076 // because of checkerboarding. |
1077 class LayerTreeHostAnimationTestFrozenAnimationTickTime | 1077 class LayerTreeHostAnimationTestFrozenAnimationTickTime |
1078 : public LayerTreeHostAnimationTest { | 1078 : public LayerTreeHostAnimationTest { |
1079 public: | 1079 public: |
1080 LayerTreeHostAnimationTestFrozenAnimationTickTime() | 1080 LayerTreeHostAnimationTestFrozenAnimationTickTime() |
1081 : started_animating_(false), num_commits_(0), num_draw_attempts_(2) {} | 1081 : started_animating_(false), num_commits_(0), num_draw_attempts_(2) {} |
1082 | 1082 |
1083 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 1083 virtual void InitializeSettings(LayerTreeSettings* settings) override { |
1084 // Make sure that drawing many times doesn't cause a checkerboarded | 1084 // Make sure that drawing many times doesn't cause a checkerboarded |
1085 // animation to start so we avoid flake in this test. | 1085 // animation to start so we avoid flake in this test. |
1086 settings->timeout_and_draw_when_animation_checkerboards = false; | 1086 settings->timeout_and_draw_when_animation_checkerboards = false; |
1087 } | 1087 } |
1088 | 1088 |
1089 virtual void BeginTest() OVERRIDE { | 1089 virtual void BeginTest() override { |
1090 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 1090 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
1091 } | 1091 } |
1092 | 1092 |
1093 virtual void BeginMainFrame(const BeginFrameArgs& args) OVERRIDE { | 1093 virtual void BeginMainFrame(const BeginFrameArgs& args) override { |
1094 last_main_thread_tick_time_ = args.frame_time; | 1094 last_main_thread_tick_time_ = args.frame_time; |
1095 } | 1095 } |
1096 | 1096 |
1097 virtual void AnimateLayers(LayerTreeHostImpl* host_impl, | 1097 virtual void AnimateLayers(LayerTreeHostImpl* host_impl, |
1098 base::TimeTicks monotonic_time) OVERRIDE { | 1098 base::TimeTicks monotonic_time) override { |
1099 if (TestEnded()) | 1099 if (TestEnded()) |
1100 return; | 1100 return; |
1101 if (!started_animating_) { | 1101 if (!started_animating_) { |
1102 started_animating_ = true; | 1102 started_animating_ = true; |
1103 expected_impl_tick_time_ = monotonic_time; | 1103 expected_impl_tick_time_ = monotonic_time; |
1104 } else { | 1104 } else { |
1105 EXPECT_EQ(expected_impl_tick_time_, monotonic_time); | 1105 EXPECT_EQ(expected_impl_tick_time_, monotonic_time); |
1106 if (num_commits_ > 2) | 1106 if (num_commits_ > 2) |
1107 EndTest(); | 1107 EndTest(); |
1108 } | 1108 } |
1109 } | 1109 } |
1110 | 1110 |
1111 virtual DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1111 virtual DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
1112 LayerTreeHostImpl::FrameData* frame, | 1112 LayerTreeHostImpl::FrameData* frame, |
1113 DrawResult draw_result) OVERRIDE { | 1113 DrawResult draw_result) override { |
1114 if (TestEnded()) | 1114 if (TestEnded()) |
1115 return draw_result; | 1115 return draw_result; |
1116 num_draw_attempts_++; | 1116 num_draw_attempts_++; |
1117 if (num_draw_attempts_ > 2) { | 1117 if (num_draw_attempts_ > 2) { |
1118 num_draw_attempts_ = 0; | 1118 num_draw_attempts_ = 0; |
1119 PostSetNeedsCommitToMainThread(); | 1119 PostSetNeedsCommitToMainThread(); |
1120 } | 1120 } |
1121 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 1121 return DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
1122 } | 1122 } |
1123 | 1123 |
1124 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1124 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
1125 if (!started_animating_) | 1125 if (!started_animating_) |
1126 return; | 1126 return; |
1127 expected_impl_tick_time_ = | 1127 expected_impl_tick_time_ = |
1128 std::max(expected_impl_tick_time_, last_main_thread_tick_time_); | 1128 std::max(expected_impl_tick_time_, last_main_thread_tick_time_); |
1129 num_commits_++; | 1129 num_commits_++; |
1130 } | 1130 } |
1131 | 1131 |
1132 virtual void AfterTest() OVERRIDE {} | 1132 virtual void AfterTest() override {} |
1133 | 1133 |
1134 private: | 1134 private: |
1135 bool started_animating_; | 1135 bool started_animating_; |
1136 int num_commits_; | 1136 int num_commits_; |
1137 int num_draw_attempts_; | 1137 int num_draw_attempts_; |
1138 base::TimeTicks last_main_thread_tick_time_; | 1138 base::TimeTicks last_main_thread_tick_time_; |
1139 base::TimeTicks expected_impl_tick_time_; | 1139 base::TimeTicks expected_impl_tick_time_; |
1140 }; | 1140 }; |
1141 | 1141 |
1142 // Only the non-impl-paint multi-threaded compositor freezes animations. | 1142 // Only the non-impl-paint multi-threaded compositor freezes animations. |
1143 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostAnimationTestFrozenAnimationTickTime); | 1143 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostAnimationTestFrozenAnimationTickTime); |
1144 | 1144 |
1145 // When animations are simultaneously added to an existing layer and to a new | 1145 // When animations are simultaneously added to an existing layer and to a new |
1146 // layer, they should start at the same time, even when there's already a | 1146 // layer, they should start at the same time, even when there's already a |
1147 // running animation on the existing layer. | 1147 // running animation on the existing layer. |
1148 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers | 1148 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
1149 : public LayerTreeHostAnimationTest { | 1149 : public LayerTreeHostAnimationTest { |
1150 public: | 1150 public: |
1151 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() | 1151 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() |
1152 : frame_count_with_pending_tree_(0) {} | 1152 : frame_count_with_pending_tree_(0) {} |
1153 | 1153 |
1154 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1154 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1155 | 1155 |
1156 virtual void DidCommit() OVERRIDE { | 1156 virtual void DidCommit() override { |
1157 if (layer_tree_host()->source_frame_number() == 1) { | 1157 if (layer_tree_host()->source_frame_number() == 1) { |
1158 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 4, 1, 1); | 1158 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 4, 1, 1); |
1159 } else if (layer_tree_host()->source_frame_number() == 2) { | 1159 } else if (layer_tree_host()->source_frame_number() == 2) { |
1160 AddOpacityTransitionToLayer( | 1160 AddOpacityTransitionToLayer( |
1161 layer_tree_host()->root_layer(), 1, 0.f, 0.5f, true); | 1161 layer_tree_host()->root_layer(), 1, 0.f, 0.5f, true); |
1162 | 1162 |
1163 scoped_refptr<Layer> layer = Layer::Create(); | 1163 scoped_refptr<Layer> layer = Layer::Create(); |
1164 layer_tree_host()->root_layer()->AddChild(layer); | 1164 layer_tree_host()->root_layer()->AddChild(layer); |
1165 layer->set_layer_animation_delegate(this); | 1165 layer->set_layer_animation_delegate(this); |
1166 layer->SetBounds(gfx::Size(4, 4)); | 1166 layer->SetBounds(gfx::Size(4, 4)); |
1167 AddOpacityTransitionToLayer(layer.get(), 1, 0.f, 0.5f, true); | 1167 AddOpacityTransitionToLayer(layer.get(), 1, 0.f, 0.5f, true); |
1168 } | 1168 } |
1169 } | 1169 } |
1170 | 1170 |
1171 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1171 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
1172 host_impl->BlockNotifyReadyToActivateForTesting(true); | 1172 host_impl->BlockNotifyReadyToActivateForTesting(true); |
1173 } | 1173 } |
1174 | 1174 |
1175 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 1175 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1176 // For the commit that added animations to new and existing layers, keep | 1176 // For the commit that added animations to new and existing layers, keep |
1177 // blocking activation. We want to verify that even with activation blocked, | 1177 // blocking activation. We want to verify that even with activation blocked, |
1178 // the animation on the layer that's already in the active tree won't get a | 1178 // the animation on the layer that's already in the active tree won't get a |
1179 // head start. | 1179 // head start. |
1180 if (!host_impl->settings().impl_side_painting || | 1180 if (!host_impl->settings().impl_side_painting || |
1181 host_impl->pending_tree()->source_frame_number() != 2) | 1181 host_impl->pending_tree()->source_frame_number() != 2) |
1182 host_impl->BlockNotifyReadyToActivateForTesting(false); | 1182 host_impl->BlockNotifyReadyToActivateForTesting(false); |
1183 } | 1183 } |
1184 | 1184 |
1185 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 1185 virtual void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
1186 const BeginFrameArgs& args) OVERRIDE { | 1186 const BeginFrameArgs& args) override { |
1187 if (!host_impl->pending_tree() || | 1187 if (!host_impl->pending_tree() || |
1188 host_impl->pending_tree()->source_frame_number() != 2) | 1188 host_impl->pending_tree()->source_frame_number() != 2) |
1189 return; | 1189 return; |
1190 | 1190 |
1191 frame_count_with_pending_tree_++; | 1191 frame_count_with_pending_tree_++; |
1192 if (frame_count_with_pending_tree_ == 2) | 1192 if (frame_count_with_pending_tree_ == 2) |
1193 host_impl->BlockNotifyReadyToActivateForTesting(false); | 1193 host_impl->BlockNotifyReadyToActivateForTesting(false); |
1194 } | 1194 } |
1195 | 1195 |
1196 virtual void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 1196 virtual void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
1197 bool has_unfinished_animation) OVERRIDE { | 1197 bool has_unfinished_animation) override { |
1198 LayerAnimationController* root_controller_impl = | 1198 LayerAnimationController* root_controller_impl = |
1199 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 1199 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
1200 Animation* root_animation = | 1200 Animation* root_animation = |
1201 root_controller_impl->GetAnimation(Animation::Opacity); | 1201 root_controller_impl->GetAnimation(Animation::Opacity); |
1202 if (!root_animation || root_animation->run_state() != Animation::Running) | 1202 if (!root_animation || root_animation->run_state() != Animation::Running) |
1203 return; | 1203 return; |
1204 | 1204 |
1205 LayerAnimationController* child_controller_impl = | 1205 LayerAnimationController* child_controller_impl = |
1206 host_impl->active_tree()->root_layer()->children() | 1206 host_impl->active_tree()->root_layer()->children() |
1207 [0]->layer_animation_controller(); | 1207 [0]->layer_animation_controller(); |
1208 Animation* child_animation = | 1208 Animation* child_animation = |
1209 child_controller_impl->GetAnimation(Animation::Opacity); | 1209 child_controller_impl->GetAnimation(Animation::Opacity); |
1210 EXPECT_EQ(Animation::Running, child_animation->run_state()); | 1210 EXPECT_EQ(Animation::Running, child_animation->run_state()); |
1211 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); | 1211 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); |
1212 root_controller_impl->AbortAnimations(Animation::Opacity); | 1212 root_controller_impl->AbortAnimations(Animation::Opacity); |
1213 root_controller_impl->AbortAnimations(Animation::Transform); | 1213 root_controller_impl->AbortAnimations(Animation::Transform); |
1214 child_controller_impl->AbortAnimations(Animation::Opacity); | 1214 child_controller_impl->AbortAnimations(Animation::Opacity); |
1215 EndTest(); | 1215 EndTest(); |
1216 } | 1216 } |
1217 | 1217 |
1218 virtual void AfterTest() OVERRIDE {} | 1218 virtual void AfterTest() override {} |
1219 | 1219 |
1220 private: | 1220 private: |
1221 int frame_count_with_pending_tree_; | 1221 int frame_count_with_pending_tree_; |
1222 }; | 1222 }; |
1223 | 1223 |
1224 SINGLE_AND_MULTI_THREAD_TEST_F( | 1224 SINGLE_AND_MULTI_THREAD_TEST_F( |
1225 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); | 1225 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); |
1226 | 1226 |
1227 class LayerTreeHostAnimationTestAddAnimationAfterAnimating | 1227 class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
1228 : public LayerTreeHostAnimationTest { | 1228 : public LayerTreeHostAnimationTest { |
1229 public: | 1229 public: |
1230 LayerTreeHostAnimationTestAddAnimationAfterAnimating() | 1230 LayerTreeHostAnimationTestAddAnimationAfterAnimating() |
1231 : num_swap_buffers_(0) {} | 1231 : num_swap_buffers_(0) {} |
1232 | 1232 |
1233 virtual void SetupTree() OVERRIDE { | 1233 virtual void SetupTree() override { |
1234 LayerTreeHostAnimationTest::SetupTree(); | 1234 LayerTreeHostAnimationTest::SetupTree(); |
1235 content_ = Layer::Create(); | 1235 content_ = Layer::Create(); |
1236 content_->SetBounds(gfx::Size(4, 4)); | 1236 content_->SetBounds(gfx::Size(4, 4)); |
1237 layer_tree_host()->root_layer()->AddChild(content_); | 1237 layer_tree_host()->root_layer()->AddChild(content_); |
1238 } | 1238 } |
1239 | 1239 |
1240 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1240 virtual void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1241 | 1241 |
1242 virtual void DidCommit() OVERRIDE { | 1242 virtual void DidCommit() override { |
1243 switch (layer_tree_host()->source_frame_number()) { | 1243 switch (layer_tree_host()->source_frame_number()) { |
1244 case 1: | 1244 case 1: |
1245 // First frame: add an animation to the root layer. | 1245 // First frame: add an animation to the root layer. |
1246 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 0.1, 5, 5); | 1246 AddAnimatedTransformToLayer(layer_tree_host()->root_layer(), 0.1, 5, 5); |
1247 break; | 1247 break; |
1248 case 2: | 1248 case 2: |
1249 // Second frame: add an animation to the content layer. The root layer | 1249 // Second frame: add an animation to the content layer. The root layer |
1250 // animation has caused us to animate already during this frame. | 1250 // animation has caused us to animate already during this frame. |
1251 AddOpacityTransitionToLayer(content_.get(), 0.1, 5, 5, false); | 1251 AddOpacityTransitionToLayer(content_.get(), 0.1, 5, 5, false); |
1252 break; | 1252 break; |
1253 } | 1253 } |
1254 } | 1254 } |
1255 | 1255 |
1256 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, | 1256 virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
1257 bool result) OVERRIDE { | 1257 bool result) override { |
1258 // After both animations have started, verify that they have valid | 1258 // After both animations have started, verify that they have valid |
1259 // start times. | 1259 // start times. |
1260 num_swap_buffers_++; | 1260 num_swap_buffers_++; |
1261 AnimationRegistrar::AnimationControllerMap copy = | 1261 AnimationRegistrar::AnimationControllerMap copy = |
1262 host_impl->animation_registrar()->active_animation_controllers(); | 1262 host_impl->animation_registrar()->active_animation_controllers(); |
1263 if (copy.size() == 2u) { | 1263 if (copy.size() == 2u) { |
1264 EndTest(); | 1264 EndTest(); |
1265 EXPECT_GE(num_swap_buffers_, 3); | 1265 EXPECT_GE(num_swap_buffers_, 3); |
1266 for (AnimationRegistrar::AnimationControllerMap::iterator iter = | 1266 for (AnimationRegistrar::AnimationControllerMap::iterator iter = |
1267 copy.begin(); | 1267 copy.begin(); |
1268 iter != copy.end(); | 1268 iter != copy.end(); |
1269 ++iter) { | 1269 ++iter) { |
1270 int id = ((*iter).second->id()); | 1270 int id = ((*iter).second->id()); |
1271 if (id == host_impl->RootLayer()->id()) { | 1271 if (id == host_impl->RootLayer()->id()) { |
1272 Animation* anim = (*iter).second->GetAnimation(Animation::Transform); | 1272 Animation* anim = (*iter).second->GetAnimation(Animation::Transform); |
1273 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1273 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1274 } else if (id == host_impl->RootLayer()->children()[0]->id()) { | 1274 } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
1275 Animation* anim = (*iter).second->GetAnimation(Animation::Opacity); | 1275 Animation* anim = (*iter).second->GetAnimation(Animation::Opacity); |
1276 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1276 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1277 } | 1277 } |
1278 } | 1278 } |
1279 } | 1279 } |
1280 } | 1280 } |
1281 | 1281 |
1282 virtual void AfterTest() OVERRIDE {} | 1282 virtual void AfterTest() override {} |
1283 | 1283 |
1284 private: | 1284 private: |
1285 scoped_refptr<Layer> content_; | 1285 scoped_refptr<Layer> content_; |
1286 int num_swap_buffers_; | 1286 int num_swap_buffers_; |
1287 }; | 1287 }; |
1288 | 1288 |
1289 SINGLE_AND_MULTI_THREAD_TEST_F( | 1289 SINGLE_AND_MULTI_THREAD_TEST_F( |
1290 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1290 LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
1291 | 1291 |
1292 } // namespace | 1292 } // namespace |
1293 } // namespace cc | 1293 } // namespace cc |
OLD | NEW |