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/timing_function.h" | 9 #include "cc/animation/timing_function.h" |
10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 } | 97 } |
98 EndTest(); | 98 EndTest(); |
99 } | 99 } |
100 | 100 |
101 virtual void AfterTest() OVERRIDE {} | 101 virtual void AfterTest() OVERRIDE {} |
102 | 102 |
103 private: | 103 private: |
104 int num_animates_; | 104 int num_animates_; |
105 }; | 105 }; |
106 | 106 |
107 // Temporarily suppressed per crbug.com/280706. | 107 MULTI_THREAD_TEST_F( |
108 //MULTI_THREAD_TEST_F( | 108 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); |
109 // LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); | |
110 | 109 |
111 // Add a layer animation and confirm that | 110 // Add a layer animation and confirm that |
112 // LayerTreeHostImpl::updateAnimationState does get called and continues to | 111 // LayerTreeHostImpl::updateAnimationState does get called and continues to |
113 // get called. | 112 // get called. |
114 class LayerTreeHostAnimationTestAddAnimation | 113 class LayerTreeHostAnimationTestAddAnimation |
115 : public LayerTreeHostAnimationTest { | 114 : public LayerTreeHostAnimationTest { |
116 public: | 115 public: |
117 LayerTreeHostAnimationTestAddAnimation() | 116 LayerTreeHostAnimationTestAddAnimation() |
118 : num_animates_(0), | 117 : num_animates_(0), |
119 received_animation_started_notification_(false), | 118 received_animation_started_notification_(false), |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 286 |
288 virtual void AfterTest() OVERRIDE {} | 287 virtual void AfterTest() OVERRIDE {} |
289 | 288 |
290 private: | 289 private: |
291 int num_animates_; | 290 int num_animates_; |
292 }; | 291 }; |
293 | 292 |
294 SINGLE_AND_MULTI_THREAD_TEST_F( | 293 SINGLE_AND_MULTI_THREAD_TEST_F( |
295 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); | 294 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); |
296 | 295 |
296 // Ensures that animations do not tick when we are backgrounded and | |
297 // and we have an empty active tree. | |
298 class LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree | |
299 : public LayerTreeHostAnimationTest { | |
300 public: | |
danakj
2013/08/29 19:58:20
nit: protected:
| |
301 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree() | |
302 : active_tree_was_animated_(false) {} | |
303 | |
304 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE { | |
305 return base::TimeDelta::FromMilliseconds(4); | |
306 } | |
307 | |
308 virtual void BeginTest() OVERRIDE { | |
309 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | |
310 } | |
311 | |
312 virtual void NotifyAnimationFinished(double time) OVERRIDE { | |
313 // Replace animated commits with an empty tree. | |
314 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL)); | |
315 } | |
316 | |
317 virtual void DidCommit() OVERRIDE { | |
318 // This alternates setting an empty tree and a non-empty tree with an | |
319 // animation. | |
320 switch (layer_tree_host()->source_frame_number()) { | |
321 case 1: | |
322 // Wait for NotifyAnimationFinished to commit an empty tree. | |
323 break; | |
324 case 2: | |
325 SetupTree(); | |
326 AddOpacityTransitionToLayer( | |
327 layer_tree_host()->root_layer(), 0.000001, 0, 0.5, true); | |
328 break; | |
329 case 3: | |
330 // Wait for NotifyAnimationFinished to commit an empty tree. | |
331 break; | |
332 case 4: | |
333 EndTest(); | |
334 break; | |
335 } | |
336 } | |
337 | |
338 virtual void BeginCommitOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
339 // At the start of every commit, block activations and make sure | |
340 // we are backgrounded. | |
341 host_impl->BlockNotifyReadyToActivateForTesting(true); | |
342 PostSetVisibleToMainThread(false); | |
343 } | |
344 | |
345 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
346 if (!host_impl->settings().impl_side_painting) { | |
347 // There are no activations to block if we're not impl-side-painting, | |
348 // so just addvance the test imeediately. | |
danakj
2013/08/29 19:58:20
nit: addvance...imeediately
| |
349 if (host_impl->active_tree()->source_frame_number() < 3) | |
350 UnblockActivations(host_impl); | |
351 return; | |
352 } | |
353 | |
354 // We block activation for several ticks to make sure that, even though | |
355 // there is a pending tree with animations, we still do not background | |
356 // tick if the active tree is empty. | |
357 if (host_impl->pending_tree()->source_frame_number() < 3) { | |
358 base::MessageLoopProxy::current()->PostDelayedTask( | |
359 FROM_HERE, | |
360 base::Bind( | |
361 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | |
362 UnblockActivations, | |
363 base::Unretained(this), | |
364 host_impl), | |
365 4 * LowFrequencyAnimationInterval()); | |
366 } | |
367 } | |
368 | |
369 virtual void UnblockActivations(LayerTreeHostImpl* host_impl) { | |
370 host_impl->BlockNotifyReadyToActivateForTesting(false); | |
371 } | |
372 | |
373 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | |
374 active_tree_was_animated_ = false; | |
375 | |
376 // Verify that commits are actually alternating with empty / non-empty | |
377 // trees. | |
378 switch (host_impl->active_tree()->source_frame_number()) { | |
379 case 0: | |
380 case 2: | |
381 EXPECT_TRUE(host_impl->active_tree()->root_layer()); | |
382 break; | |
383 case 1: | |
384 case 3: | |
385 EXPECT_FALSE(host_impl->active_tree()->root_layer()); | |
386 break; | |
387 } | |
388 | |
389 if (host_impl->active_tree()->source_frame_number() < 3) { | |
390 // Initiate the next commit after a delay to give us a chance to | |
391 // background tick if the active tree isn't empty. | |
392 base::MessageLoopProxy::current()->PostDelayedTask( | |
393 FROM_HERE, | |
394 base::Bind( | |
395 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | |
396 InitiateNextCommit, | |
397 base::Unretained(this), | |
398 host_impl), | |
399 4 * LowFrequencyAnimationInterval()); | |
400 } | |
401 } | |
402 | |
403 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl, | |
404 base::TimeTicks monotonic_time) OVERRIDE { | |
405 EXPECT_TRUE(host_impl->active_tree()->root_layer()); | |
406 active_tree_was_animated_ = true; | |
407 } | |
408 | |
409 void InitiateNextCommit(LayerTreeHostImpl* host_impl) { | |
410 // Verify that we actually animated when we should have. | |
411 bool has_active_tree = host_impl->active_tree()->root_layer(); | |
412 EXPECT_EQ(has_active_tree, active_tree_was_animated_); | |
danakj
2013/08/29 19:58:20
Thanks for this, i love tests that test themselves
| |
413 | |
414 // The next commit is blocked until we become visible again. | |
415 PostSetVisibleToMainThread(true); | |
416 } | |
417 | |
418 virtual void AfterTest() OVERRIDE {} | |
419 | |
420 bool active_tree_was_animated_; | |
421 }; | |
422 | |
423 SINGLE_AND_MULTI_THREAD_TEST_F( | |
424 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree); | |
425 | |
297 // Ensure that an animation's timing function is respected. | 426 // Ensure that an animation's timing function is respected. |
298 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 427 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
299 : public LayerTreeHostAnimationTest { | 428 : public LayerTreeHostAnimationTest { |
300 public: | 429 public: |
301 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} | 430 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} |
302 | 431 |
303 virtual void SetupTree() OVERRIDE { | 432 virtual void SetupTree() OVERRIDE { |
304 LayerTreeHostAnimationTest::SetupTree(); | 433 LayerTreeHostAnimationTest::SetupTree(); |
305 content_ = FakeContentLayer::Create(&client_); | 434 content_ = FakeContentLayer::Create(&client_); |
306 content_->SetBounds(gfx::Size(4, 4)); | 435 content_->SetBounds(gfx::Size(4, 4)); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 int finished_times_; | 927 int finished_times_; |
799 FakeContentLayerClient client_; | 928 FakeContentLayerClient client_; |
800 scoped_refptr<FakeContentLayer> content_; | 929 scoped_refptr<FakeContentLayer> content_; |
801 }; | 930 }; |
802 | 931 |
803 MULTI_THREAD_TEST_F( | 932 MULTI_THREAD_TEST_F( |
804 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 933 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
805 | 934 |
806 } // namespace | 935 } // namespace |
807 } // namespace cc | 936 } // namespace cc |
OLD | NEW |