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 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 | 1798 |
1799 private: | 1799 private: |
1800 FakeContentLayerClient client_; | 1800 FakeContentLayerClient client_; |
1801 scoped_refptr<EvictionTestLayer> layer_; | 1801 scoped_refptr<EvictionTestLayer> layer_; |
1802 LayerTreeHostImpl* impl_for_evict_textures_; | 1802 LayerTreeHostImpl* impl_for_evict_textures_; |
1803 int num_commits_; | 1803 int num_commits_; |
1804 }; | 1804 }; |
1805 | 1805 |
1806 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestEvictTextures); | 1806 MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestEvictTextures); |
1807 | 1807 |
1808 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { | |
1809 public: | |
1810 LayerTreeHostTestContinuousCommit() | |
1811 : num_commit_complete_(0), num_draw_layers_(0) {} | |
1812 | |
1813 virtual void BeginTest() OVERRIDE { | |
1814 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | |
1815 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | |
1816 | |
1817 PostSetNeedsCommitToMainThread(); | |
1818 } | |
1819 | |
1820 virtual void DidCommit() OVERRIDE { | |
1821 if (num_draw_layers_ == 2) | |
1822 return; | |
1823 layer_tree_host()->SetNeedsCommit(); | |
1824 } | |
1825 | |
1826 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
1827 if (num_draw_layers_ == 1) | |
1828 num_commit_complete_++; | |
1829 } | |
1830 | |
1831 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
1832 num_draw_layers_++; | |
1833 if (num_draw_layers_ == 2) | |
1834 EndTest(); | |
1835 } | |
1836 | |
1837 virtual void AfterTest() OVERRIDE { | |
1838 // Check that we didn't commit twice between first and second draw. | |
1839 EXPECT_EQ(1, num_commit_complete_); | |
1840 } | |
1841 | |
1842 private: | |
1843 int num_commit_complete_; | |
1844 int num_draw_layers_; | |
1845 }; | |
1846 | |
1847 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousCommit); | |
1848 | |
1849 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { | 1808 class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
1850 public: | 1809 public: |
1851 LayerTreeHostTestContinuousInvalidate() | 1810 LayerTreeHostTestContinuousInvalidate() |
1852 : num_commit_complete_(0), num_draw_layers_(0) {} | 1811 : num_commit_complete_(0), num_draw_layers_(0) {} |
1853 | 1812 |
1854 virtual void BeginTest() OVERRIDE { | 1813 virtual void BeginTest() OVERRIDE { |
1855 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); | 1814 layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
1856 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); | 1815 layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
1857 | 1816 |
1858 content_layer_ = ContentLayer::Create(&client_); | 1817 content_layer_ = ContentLayer::Create(&client_); |
(...skipping 2702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4561 int commit_complete_count_; | 4520 int commit_complete_count_; |
4562 TestSwapPromiseResult swap_promise_result_[3]; | 4521 TestSwapPromiseResult swap_promise_result_[3]; |
4563 }; | 4522 }; |
4564 | 4523 |
4565 // TODO(miletus): Flaky test: crbug.com/393995 | 4524 // TODO(miletus): Flaky test: crbug.com/393995 |
4566 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); | 4525 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); |
4567 | 4526 |
4568 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit | 4527 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit |
4569 : public LayerTreeHostTest { | 4528 : public LayerTreeHostTest { |
4570 protected: | 4529 protected: |
4571 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit() | |
4572 : commit_count_(0) {} | |
4573 | |
4574 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4530 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
4575 | 4531 |
4576 virtual void WillBeginMainFrame() OVERRIDE { | 4532 virtual void DidCommit() OVERRIDE { |
4577 layer_tree_host()->SetDeferCommits(true); | 4533 layer_tree_host()->SetDeferCommits(true); |
4578 layer_tree_host()->SetNeedsCommit(); | 4534 layer_tree_host()->SetNeedsCommit(); |
4579 } | 4535 } |
4580 | 4536 |
4581 virtual void DidDeferCommit() OVERRIDE { | 4537 virtual void DidDeferCommit() OVERRIDE { |
4582 layer_tree_host()->SetVisible(false); | 4538 layer_tree_host()->SetVisible(false); |
4583 layer_tree_host()->SetDeferCommits(false); | |
4584 | |
4585 scoped_ptr<SwapPromise> swap_promise( | 4539 scoped_ptr<SwapPromise> swap_promise( |
4586 new TestSwapPromise(&swap_promise_result_)); | 4540 new TestSwapPromise(&swap_promise_result_)); |
4587 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 4541 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 4542 layer_tree_host()->SetDeferCommits(false); |
4588 } | 4543 } |
4589 | 4544 |
4590 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); } | |
4591 | |
4592 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 4545 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
4593 bool did_handle) OVERRIDE { | 4546 bool did_handle) OVERRIDE { |
4594 EndTest(); | 4547 EndTest(); |
4595 } | 4548 } |
4596 | 4549 |
4597 virtual void AfterTest() OVERRIDE { | 4550 virtual void AfterTest() OVERRIDE { |
4598 { | 4551 { |
4599 base::AutoLock lock(swap_promise_result_.lock); | 4552 base::AutoLock lock(swap_promise_result_.lock); |
4600 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4553 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4601 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4554 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
4602 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4555 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
4603 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4556 EXPECT_TRUE(swap_promise_result_.dtor_called); |
4604 } | 4557 } |
4605 } | 4558 } |
4606 | 4559 |
4607 int commit_count_; | |
4608 TestSwapPromiseResult swap_promise_result_; | 4560 TestSwapPromiseResult swap_promise_result_; |
4609 }; | 4561 }; |
4610 | 4562 |
4611 SINGLE_AND_MULTI_THREAD_TEST_F( | 4563 SINGLE_AND_MULTI_THREAD_TEST_F( |
4612 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); | 4564 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); |
4613 | 4565 |
4614 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit | 4566 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit |
4615 : public LayerTreeHostTest { | 4567 : public LayerTreeHostTest { |
4616 protected: | 4568 protected: |
4617 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit() | |
4618 : commit_count_(0) {} | |
4619 | |
4620 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4569 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
4621 | 4570 |
4622 virtual void WillBeginMainFrame() OVERRIDE { | 4571 virtual void DidCommit() OVERRIDE { |
| 4572 if (TestEnded()) |
| 4573 return; |
4623 layer_tree_host()->SetDeferCommits(true); | 4574 layer_tree_host()->SetDeferCommits(true); |
4624 layer_tree_host()->SetNeedsCommit(); | 4575 layer_tree_host()->SetNeedsCommit(); |
4625 } | 4576 } |
4626 | 4577 |
4627 virtual void DidDeferCommit() OVERRIDE { | 4578 virtual void DidDeferCommit() OVERRIDE { |
4628 layer_tree_host()->DidLoseOutputSurface(); | 4579 layer_tree_host()->DidLoseOutputSurface(); |
4629 layer_tree_host()->SetDeferCommits(false); | |
4630 | |
4631 scoped_ptr<SwapPromise> swap_promise( | 4580 scoped_ptr<SwapPromise> swap_promise( |
4632 new TestSwapPromise(&swap_promise_result_)); | 4581 new TestSwapPromise(&swap_promise_result_)); |
4633 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 4582 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 4583 layer_tree_host()->SetDeferCommits(false); |
4634 } | 4584 } |
4635 | 4585 |
4636 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); } | |
4637 | |
4638 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 4586 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
4639 bool did_handle) OVERRIDE { | 4587 bool did_handle) OVERRIDE { |
4640 EndTest(); | 4588 EndTest(); |
| 4589 // This lets the test finally commit and exit. |
| 4590 MainThreadTaskRunner()->PostTask( |
| 4591 FROM_HERE, |
| 4592 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit:: |
| 4593 FindOutputSurface, |
| 4594 base::Unretained(this))); |
| 4595 } |
| 4596 |
| 4597 void FindOutputSurface() { |
| 4598 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true); |
4641 } | 4599 } |
4642 | 4600 |
4643 virtual void AfterTest() OVERRIDE { | 4601 virtual void AfterTest() OVERRIDE { |
4644 { | 4602 { |
4645 base::AutoLock lock(swap_promise_result_.lock); | 4603 base::AutoLock lock(swap_promise_result_.lock); |
4646 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4604 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
4647 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4605 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
4648 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4606 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
4649 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4607 EXPECT_TRUE(swap_promise_result_.dtor_called); |
4650 } | 4608 } |
4651 } | 4609 } |
4652 | 4610 |
4653 int commit_count_; | |
4654 TestSwapPromiseResult swap_promise_result_; | 4611 TestSwapPromiseResult swap_promise_result_; |
4655 }; | 4612 }; |
4656 | 4613 |
4657 SINGLE_AND_MULTI_THREAD_TEST_F( | 4614 SINGLE_AND_MULTI_THREAD_TEST_F( |
4658 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); | 4615 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); |
4659 | 4616 |
4660 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 4617 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
4661 public: | 4618 public: |
4662 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 4619 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
4663 LayerTreeHostImpl* layer_tree_host_impl, | 4620 LayerTreeHostImpl* layer_tree_host_impl, |
(...skipping 16 matching lines...) Expand all Loading... |
4680 private: | 4637 private: |
4681 int* set_needs_commit_count_; | 4638 int* set_needs_commit_count_; |
4682 int* set_needs_redraw_count_; | 4639 int* set_needs_redraw_count_; |
4683 }; | 4640 }; |
4684 | 4641 |
4685 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { | 4642 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { |
4686 public: | 4643 public: |
4687 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4644 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
4688 | 4645 |
4689 virtual void WillBeginMainFrame() OVERRIDE { | 4646 virtual void WillBeginMainFrame() OVERRIDE { |
| 4647 if (TestEnded()) |
| 4648 return; |
| 4649 |
4690 int set_needs_commit_count = 0; | 4650 int set_needs_commit_count = 0; |
4691 int set_needs_redraw_count = 0; | 4651 int set_needs_redraw_count = 0; |
4692 | 4652 |
4693 { | 4653 { |
4694 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 4654 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
4695 new SimpleSwapPromiseMonitor(layer_tree_host(), | 4655 new SimpleSwapPromiseMonitor(layer_tree_host(), |
4696 NULL, | 4656 NULL, |
4697 &set_needs_commit_count, | 4657 &set_needs_commit_count, |
4698 &set_needs_redraw_count)); | 4658 &set_needs_redraw_count)); |
4699 layer_tree_host()->SetNeedsCommit(); | 4659 layer_tree_host()->SetNeedsCommit(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4990 child_layer_->SetBounds(bounds_); | 4950 child_layer_->SetBounds(bounds_); |
4991 child_layer_->SetIsDrawable(true); | 4951 child_layer_->SetIsDrawable(true); |
4992 root_layer->AddChild(child_layer_); | 4952 root_layer->AddChild(child_layer_); |
4993 | 4953 |
4994 layer_tree_host()->SetRootLayer(root_layer); | 4954 layer_tree_host()->SetRootLayer(root_layer); |
4995 layer_tree_host()->SetViewportSize(bounds_); | 4955 layer_tree_host()->SetViewportSize(bounds_); |
4996 LayerTreeHostTest::SetupTree(); | 4956 LayerTreeHostTest::SetupTree(); |
4997 } | 4957 } |
4998 | 4958 |
4999 virtual void BeginTest() OVERRIDE { | 4959 virtual void BeginTest() OVERRIDE { |
5000 // Wait 50x longer than expected. | |
5001 double milliseconds_per_frame = | |
5002 1000 / layer_tree_host()->settings().refresh_rate; | |
5003 EndTestAfterDelay(50 * kExpectedNumCommits * milliseconds_per_frame); | |
5004 MainThreadTaskRunner()->PostTask( | 4960 MainThreadTaskRunner()->PostTask( |
5005 FROM_HERE, | 4961 FROM_HERE, |
5006 base::Bind( | 4962 base::Bind( |
5007 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting, | 4963 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting, |
5008 base::Unretained(this))); | 4964 base::Unretained(this))); |
| 4965 // Wait 50x longer than expected. |
| 4966 double milliseconds_per_frame = |
| 4967 1000.0 / layer_tree_host()->settings().refresh_rate; |
| 4968 MainThreadTaskRunner()->PostDelayedTask( |
| 4969 FROM_HERE, |
| 4970 base::Bind( |
| 4971 &LayerTreeHostTestContinuousPainting::DisableContinuousPainting, |
| 4972 base::Unretained(this)), |
| 4973 base::TimeDelta::FromMilliseconds(50 * kExpectedNumCommits * |
| 4974 milliseconds_per_frame)); |
5009 } | 4975 } |
5010 | 4976 |
5011 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { | 4977 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { |
5012 child_layer_->SetNeedsDisplay(); | 4978 child_layer_->SetNeedsDisplay(); |
5013 } | 4979 } |
5014 | 4980 |
5015 virtual void AfterTest() OVERRIDE { | 4981 virtual void AfterTest() OVERRIDE { |
5016 EXPECT_LE(kExpectedNumCommits, num_commits_); | 4982 EXPECT_LE(kExpectedNumCommits, num_commits_); |
5017 EXPECT_LE(kExpectedNumCommits, num_draws_); | 4983 EXPECT_LE(kExpectedNumCommits, num_draws_); |
5018 int update_count = content_layer_ ? content_layer_->PaintContentsCount() | 4984 int update_count = content_layer_ ? content_layer_->PaintContentsCount() |
(...skipping 10 matching lines...) Expand all Loading... |
5029 ++num_commits_; | 4995 ++num_commits_; |
5030 } | 4996 } |
5031 | 4997 |
5032 private: | 4998 private: |
5033 void EnableContinuousPainting() { | 4999 void EnableContinuousPainting() { |
5034 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); | 5000 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); |
5035 debug_state.continuous_painting = true; | 5001 debug_state.continuous_painting = true; |
5036 layer_tree_host()->SetDebugState(debug_state); | 5002 layer_tree_host()->SetDebugState(debug_state); |
5037 } | 5003 } |
5038 | 5004 |
| 5005 void DisableContinuousPainting() { |
| 5006 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); |
| 5007 debug_state.continuous_painting = false; |
| 5008 layer_tree_host()->SetDebugState(debug_state); |
| 5009 EndTest(); |
| 5010 } |
| 5011 |
5039 int num_commits_; | 5012 int num_commits_; |
5040 int num_draws_; | 5013 int num_draws_; |
5041 const gfx::Size bounds_; | 5014 const gfx::Size bounds_; |
5042 FakeContentLayerClient client_; | 5015 FakeContentLayerClient client_; |
5043 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 5016 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
5044 scoped_refptr<FakePictureLayer> picture_layer_; | 5017 scoped_refptr<FakePictureLayer> picture_layer_; |
5045 Layer* child_layer_; | 5018 Layer* child_layer_; |
5046 }; | 5019 }; |
5047 | 5020 |
5048 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 5021 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
5049 | 5022 |
5050 } // namespace cc | 5023 } // namespace cc |
OLD | NEW |