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