OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 num_draws_++; | 84 num_draws_++; |
85 if (!impl->active_tree()->source_frame_number()) | 85 if (!impl->active_tree()->source_frame_number()) |
86 EndTest(); | 86 EndTest(); |
87 } | 87 } |
88 | 88 |
89 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 89 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
90 num_commits_++; | 90 num_commits_++; |
91 } | 91 } |
92 | 92 |
93 virtual void AfterTest() OVERRIDE { | 93 virtual void AfterTest() OVERRIDE { |
94 EXPECT_GE(1, num_commits_); | 94 EXPECT_LE(1, num_commits_); |
95 EXPECT_GE(1, num_draws_); | 95 EXPECT_LE(1, num_draws_); |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 int num_commits_; | 99 int num_commits_; |
100 int num_draws_; | 100 int num_draws_; |
101 }; | 101 }; |
102 | 102 |
103 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); | 103 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); |
104 | 104 |
105 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that | 105 // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 | 687 |
688 private: | 688 private: |
689 scoped_refptr<Layer> root_layer_; | 689 scoped_refptr<Layer> root_layer_; |
690 scoped_refptr<Layer> parent_layer_; | 690 scoped_refptr<Layer> parent_layer_; |
691 scoped_refptr<Layer> child_layer_; | 691 scoped_refptr<Layer> child_layer_; |
692 }; | 692 }; |
693 | 693 |
694 SINGLE_AND_MULTI_THREAD_TEST_F( | 694 SINGLE_AND_MULTI_THREAD_TEST_F( |
695 LayerTreeHostTestUndrawnLayersPushContentBoundsLater); | 695 LayerTreeHostTestUndrawnLayersPushContentBoundsLater); |
696 | 696 |
697 class LayerTreeHostTestAbortFrameWhenInvisible : public LayerTreeHostTest { | |
698 public: | |
699 LayerTreeHostTestAbortFrameWhenInvisible() {} | |
700 | |
701 virtual void BeginTest() OVERRIDE { | |
702 // Request a commit (from the main thread), Which will trigger the commit | |
703 // flow from the impl side. | |
704 layer_tree_host()->SetNeedsCommit(); | |
705 // Then mark ourselves as not visible before processing any more messages | |
706 // on the main thread. | |
707 layer_tree_host()->SetVisible(false); | |
708 // If we make it without kicking a frame, we pass! | |
709 EndTestAfterDelay(1); | |
710 } | |
711 | |
712 virtual void Layout() OVERRIDE { | |
713 ASSERT_FALSE(true); | |
714 EndTest(); | |
715 } | |
716 | |
717 virtual void AfterTest() OVERRIDE {} | |
718 }; | |
719 | |
720 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortFrameWhenInvisible); | |
721 | |
722 // This test verifies that properties on the layer tree host are commited | 697 // This test verifies that properties on the layer tree host are commited |
723 // to the impl side. | 698 // to the impl side. |
724 class LayerTreeHostTestCommit : public LayerTreeHostTest { | 699 class LayerTreeHostTestCommit : public LayerTreeHostTest { |
725 public: | 700 public: |
726 LayerTreeHostTestCommit() {} | 701 LayerTreeHostTestCommit() {} |
727 | 702 |
728 virtual void BeginTest() OVERRIDE { | 703 virtual void BeginTest() OVERRIDE { |
729 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); | 704 layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
730 layer_tree_host()->set_background_color(SK_ColorGRAY); | 705 layer_tree_host()->set_background_color(SK_ColorGRAY); |
731 | 706 |
(...skipping 3808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4540 } | 4515 } |
4541 | 4516 |
4542 int commit_count_; | 4517 int commit_count_; |
4543 int commit_complete_count_; | 4518 int commit_complete_count_; |
4544 TestSwapPromiseResult swap_promise_result_[3]; | 4519 TestSwapPromiseResult swap_promise_result_[3]; |
4545 }; | 4520 }; |
4546 | 4521 |
4547 // TODO(miletus): Flaky test: crbug.com/393995 | 4522 // TODO(miletus): Flaky test: crbug.com/393995 |
4548 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); | 4523 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); |
4549 | 4524 |
4550 class LayerTreeHostTestBreakSwapPromiseForAbortedCommit | 4525 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit |
4551 : public LayerTreeHostTest { | 4526 : public LayerTreeHostTest { |
4552 protected: | 4527 protected: |
4553 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4528 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
4554 | 4529 |
4555 virtual void DidCommit() OVERRIDE { | 4530 virtual void DidCommit() OVERRIDE { |
4556 layer_tree_host()->SetDeferCommits(true); | 4531 layer_tree_host()->SetDeferCommits(true); |
4557 layer_tree_host()->SetNeedsCommit(); | 4532 layer_tree_host()->SetNeedsCommit(); |
4558 } | 4533 } |
4559 | 4534 |
4560 virtual void DidDeferCommit() OVERRIDE { | 4535 virtual void DidDeferCommit() OVERRIDE { |
(...skipping 15 matching lines...) Expand all Loading... |
4576 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4551 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4577 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4552 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
4578 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4553 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
4579 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4554 EXPECT_TRUE(swap_promise_result_.dtor_called); |
4580 } | 4555 } |
4581 } | 4556 } |
4582 | 4557 |
4583 TestSwapPromiseResult swap_promise_result_; | 4558 TestSwapPromiseResult swap_promise_result_; |
4584 }; | 4559 }; |
4585 | 4560 |
4586 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForAbortedCommit); | 4561 MULTI_THREAD_TEST_F( |
| 4562 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); |
| 4563 |
| 4564 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit |
| 4565 : public LayerTreeHostTest { |
| 4566 protected: |
| 4567 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 4568 |
| 4569 virtual void DidCommit() OVERRIDE { |
| 4570 if (TestEnded()) |
| 4571 return; |
| 4572 layer_tree_host()->SetDeferCommits(true); |
| 4573 layer_tree_host()->SetNeedsCommit(); |
| 4574 } |
| 4575 |
| 4576 virtual void DidDeferCommit() OVERRIDE { |
| 4577 layer_tree_host()->DidLoseOutputSurface(); |
| 4578 scoped_ptr<SwapPromise> swap_promise( |
| 4579 new TestSwapPromise(&swap_promise_result_)); |
| 4580 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 4581 layer_tree_host()->SetDeferCommits(false); |
| 4582 } |
| 4583 |
| 4584 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| 4585 bool did_handle) OVERRIDE { |
| 4586 EndTest(); |
| 4587 // This lets the test finally commit and exit. |
| 4588 MainThreadTaskRunner()->PostTask( |
| 4589 FROM_HERE, |
| 4590 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit:: |
| 4591 FindOutputSurface, |
| 4592 base::Unretained(this))); |
| 4593 } |
| 4594 |
| 4595 void FindOutputSurface() { |
| 4596 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true); |
| 4597 } |
| 4598 |
| 4599 virtual void AfterTest() OVERRIDE { |
| 4600 { |
| 4601 base::AutoLock lock(swap_promise_result_.lock); |
| 4602 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
| 4603 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
| 4604 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
| 4605 EXPECT_TRUE(swap_promise_result_.dtor_called); |
| 4606 } |
| 4607 } |
| 4608 |
| 4609 TestSwapPromiseResult swap_promise_result_; |
| 4610 }; |
| 4611 |
| 4612 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); |
4587 | 4613 |
4588 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 4614 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
4589 public: | 4615 public: |
4590 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 4616 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
4591 LayerTreeHostImpl* layer_tree_host_impl, | 4617 LayerTreeHostImpl* layer_tree_host_impl, |
4592 int* set_needs_commit_count, | 4618 int* set_needs_commit_count, |
4593 int* set_needs_redraw_count) | 4619 int* set_needs_redraw_count) |
4594 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), | 4620 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), |
4595 set_needs_commit_count_(set_needs_commit_count) {} | 4621 set_needs_commit_count_(set_needs_commit_count) {} |
4596 | 4622 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4987 const gfx::Size bounds_; | 5013 const gfx::Size bounds_; |
4988 FakeContentLayerClient client_; | 5014 FakeContentLayerClient client_; |
4989 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 5015 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
4990 scoped_refptr<FakePictureLayer> picture_layer_; | 5016 scoped_refptr<FakePictureLayer> picture_layer_; |
4991 Layer* child_layer_; | 5017 Layer* child_layer_; |
4992 }; | 5018 }; |
4993 | 5019 |
4994 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 5020 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
4995 | 5021 |
4996 } // namespace cc | 5022 } // namespace cc |
OLD | NEW |