Chromium Code Reviews| 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); | 4539 layer_tree_host()->SetDeferCommits(false); |
| 4584 | 4540 |
| 4585 scoped_ptr<SwapPromise> swap_promise( | 4541 scoped_ptr<SwapPromise> swap_promise( |
| 4586 new TestSwapPromise(&swap_promise_result_)); | 4542 new TestSwapPromise(&swap_promise_result_)); |
| 4587 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 4543 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 4588 } | 4544 } |
| 4589 | 4545 |
| 4590 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); } | |
| 4591 | |
| 4592 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 4546 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| 4593 bool did_handle) OVERRIDE { | 4547 bool did_handle) OVERRIDE { |
| 4594 EndTest(); | 4548 EndTest(); |
| 4595 } | 4549 } |
| 4596 | 4550 |
| 4597 virtual void AfterTest() OVERRIDE { | 4551 virtual void AfterTest() OVERRIDE { |
| 4598 { | 4552 { |
| 4599 base::AutoLock lock(swap_promise_result_.lock); | 4553 base::AutoLock lock(swap_promise_result_.lock); |
| 4600 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4554 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
| 4601 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4555 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
| 4602 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4556 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
| 4603 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4557 EXPECT_TRUE(swap_promise_result_.dtor_called); |
| 4604 } | 4558 } |
| 4605 } | 4559 } |
| 4606 | 4560 |
| 4607 int commit_count_; | |
| 4608 TestSwapPromiseResult swap_promise_result_; | 4561 TestSwapPromiseResult swap_promise_result_; |
| 4609 }; | 4562 }; |
| 4610 | 4563 |
| 4611 SINGLE_AND_MULTI_THREAD_TEST_F( | 4564 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 4612 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); | 4565 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit); |
| 4613 | 4566 |
| 4614 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit | 4567 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit |
| 4615 : public LayerTreeHostTest { | 4568 : public LayerTreeHostTest { |
| 4616 protected: | 4569 protected: |
| 4617 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit() | |
| 4618 : commit_count_(0) {} | |
| 4619 | |
| 4620 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4570 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 4621 | 4571 |
| 4622 virtual void WillBeginMainFrame() OVERRIDE { | 4572 virtual void DidCommit() OVERRIDE { |
| 4573 if (TestEnded()) | |
| 4574 return; | |
| 4623 layer_tree_host()->SetDeferCommits(true); | 4575 layer_tree_host()->SetDeferCommits(true); |
| 4624 layer_tree_host()->SetNeedsCommit(); | 4576 layer_tree_host()->SetNeedsCommit(); |
| 4625 } | 4577 } |
| 4626 | 4578 |
| 4627 virtual void DidDeferCommit() OVERRIDE { | 4579 virtual void DidDeferCommit() OVERRIDE { |
| 4628 layer_tree_host()->DidLoseOutputSurface(); | 4580 layer_tree_host()->DidLoseOutputSurface(); |
| 4629 layer_tree_host()->SetDeferCommits(false); | 4581 layer_tree_host()->SetDeferCommits(false); |
| 4630 | 4582 |
| 4631 scoped_ptr<SwapPromise> swap_promise( | 4583 scoped_ptr<SwapPromise> swap_promise( |
|
enne (OOO)
2014/08/12 17:49:56
Can you put this swap promise before the SetDeferC
danakj
2014/08/12 18:05:43
Sure, tho I don' think it can flake because the Fi
| |
| 4632 new TestSwapPromise(&swap_promise_result_)); | 4584 new TestSwapPromise(&swap_promise_result_)); |
| 4633 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 4585 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 4634 } | 4586 } |
| 4635 | 4587 |
| 4636 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); } | |
| 4637 | |
| 4638 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, | 4588 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| 4639 bool did_handle) OVERRIDE { | 4589 bool did_handle) OVERRIDE { |
| 4640 EndTest(); | 4590 EndTest(); |
| 4591 // This lets the test finally commit and exit. | |
| 4592 MainThreadTaskRunner()->PostTask( | |
| 4593 FROM_HERE, | |
| 4594 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit:: | |
| 4595 FindOutputSurface, | |
| 4596 base::Unretained(this))); | |
| 4597 } | |
| 4598 | |
| 4599 void FindOutputSurface() { | |
| 4600 layer_tree_host()->OnCreateAndInitializeOutputSurfaceAttempted(true); | |
| 4641 } | 4601 } |
| 4642 | 4602 |
| 4643 virtual void AfterTest() OVERRIDE { | 4603 virtual void AfterTest() OVERRIDE { |
| 4644 { | 4604 { |
| 4645 base::AutoLock lock(swap_promise_result_.lock); | 4605 base::AutoLock lock(swap_promise_result_.lock); |
| 4646 EXPECT_FALSE(swap_promise_result_.did_swap_called); | 4606 EXPECT_FALSE(swap_promise_result_.did_swap_called); |
| 4647 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); | 4607 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); |
| 4648 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); | 4608 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); |
| 4649 EXPECT_TRUE(swap_promise_result_.dtor_called); | 4609 EXPECT_TRUE(swap_promise_result_.dtor_called); |
| 4650 } | 4610 } |
| 4651 } | 4611 } |
| 4652 | 4612 |
| 4653 int commit_count_; | |
| 4654 TestSwapPromiseResult swap_promise_result_; | 4613 TestSwapPromiseResult swap_promise_result_; |
| 4655 }; | 4614 }; |
| 4656 | 4615 |
| 4657 SINGLE_AND_MULTI_THREAD_TEST_F( | 4616 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 4658 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); | 4617 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); |
| 4659 | 4618 |
| 4660 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { | 4619 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { |
| 4661 public: | 4620 public: |
| 4662 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, | 4621 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, |
| 4663 LayerTreeHostImpl* layer_tree_host_impl, | 4622 LayerTreeHostImpl* layer_tree_host_impl, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4680 private: | 4639 private: |
| 4681 int* set_needs_commit_count_; | 4640 int* set_needs_commit_count_; |
| 4682 int* set_needs_redraw_count_; | 4641 int* set_needs_redraw_count_; |
| 4683 }; | 4642 }; |
| 4684 | 4643 |
| 4685 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { | 4644 class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { |
| 4686 public: | 4645 public: |
| 4687 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 4646 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 4688 | 4647 |
| 4689 virtual void WillBeginMainFrame() OVERRIDE { | 4648 virtual void WillBeginMainFrame() OVERRIDE { |
| 4649 if (TestEnded()) | |
| 4650 return; | |
| 4651 | |
| 4690 int set_needs_commit_count = 0; | 4652 int set_needs_commit_count = 0; |
| 4691 int set_needs_redraw_count = 0; | 4653 int set_needs_redraw_count = 0; |
| 4692 | 4654 |
| 4693 { | 4655 { |
| 4694 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( | 4656 scoped_ptr<SimpleSwapPromiseMonitor> swap_promise_monitor( |
| 4695 new SimpleSwapPromiseMonitor(layer_tree_host(), | 4657 new SimpleSwapPromiseMonitor(layer_tree_host(), |
| 4696 NULL, | 4658 NULL, |
| 4697 &set_needs_commit_count, | 4659 &set_needs_commit_count, |
| 4698 &set_needs_redraw_count)); | 4660 &set_needs_redraw_count)); |
| 4699 layer_tree_host()->SetNeedsCommit(); | 4661 layer_tree_host()->SetNeedsCommit(); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4990 child_layer_->SetBounds(bounds_); | 4952 child_layer_->SetBounds(bounds_); |
| 4991 child_layer_->SetIsDrawable(true); | 4953 child_layer_->SetIsDrawable(true); |
| 4992 root_layer->AddChild(child_layer_); | 4954 root_layer->AddChild(child_layer_); |
| 4993 | 4955 |
| 4994 layer_tree_host()->SetRootLayer(root_layer); | 4956 layer_tree_host()->SetRootLayer(root_layer); |
| 4995 layer_tree_host()->SetViewportSize(bounds_); | 4957 layer_tree_host()->SetViewportSize(bounds_); |
| 4996 LayerTreeHostTest::SetupTree(); | 4958 LayerTreeHostTest::SetupTree(); |
| 4997 } | 4959 } |
| 4998 | 4960 |
| 4999 virtual void BeginTest() OVERRIDE { | 4961 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( | 4962 MainThreadTaskRunner()->PostTask( |
| 5005 FROM_HERE, | 4963 FROM_HERE, |
| 5006 base::Bind( | 4964 base::Bind( |
| 5007 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting, | 4965 &LayerTreeHostTestContinuousPainting::EnableContinuousPainting, |
| 5008 base::Unretained(this))); | 4966 base::Unretained(this))); |
| 4967 // Wait 50x longer than expected. | |
| 4968 double milliseconds_per_frame = | |
| 4969 1000.0 / layer_tree_host()->settings().refresh_rate; | |
| 4970 MainThreadTaskRunner()->PostDelayedTask( | |
| 4971 FROM_HERE, | |
| 4972 base::Bind( | |
| 4973 &LayerTreeHostTestContinuousPainting::DisableContinuousPainting, | |
| 4974 base::Unretained(this)), | |
| 4975 base::TimeDelta::FromMilliseconds(50 * kExpectedNumCommits * | |
| 4976 milliseconds_per_frame)); | |
| 5009 } | 4977 } |
| 5010 | 4978 |
| 5011 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { | 4979 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { |
| 5012 child_layer_->SetNeedsDisplay(); | 4980 child_layer_->SetNeedsDisplay(); |
| 5013 } | 4981 } |
| 5014 | 4982 |
| 5015 virtual void AfterTest() OVERRIDE { | 4983 virtual void AfterTest() OVERRIDE { |
| 5016 EXPECT_LE(kExpectedNumCommits, num_commits_); | 4984 EXPECT_LE(kExpectedNumCommits, num_commits_); |
| 5017 EXPECT_LE(kExpectedNumCommits, num_draws_); | 4985 EXPECT_LE(kExpectedNumCommits, num_draws_); |
| 5018 int update_count = content_layer_ ? content_layer_->PaintContentsCount() | 4986 int update_count = content_layer_ ? content_layer_->PaintContentsCount() |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5029 ++num_commits_; | 4997 ++num_commits_; |
| 5030 } | 4998 } |
| 5031 | 4999 |
| 5032 private: | 5000 private: |
| 5033 void EnableContinuousPainting() { | 5001 void EnableContinuousPainting() { |
| 5034 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); | 5002 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); |
| 5035 debug_state.continuous_painting = true; | 5003 debug_state.continuous_painting = true; |
| 5036 layer_tree_host()->SetDebugState(debug_state); | 5004 layer_tree_host()->SetDebugState(debug_state); |
| 5037 } | 5005 } |
| 5038 | 5006 |
| 5007 void DisableContinuousPainting() { | |
| 5008 LayerTreeDebugState debug_state = layer_tree_host()->debug_state(); | |
| 5009 debug_state.continuous_painting = false; | |
| 5010 layer_tree_host()->SetDebugState(debug_state); | |
| 5011 EndTest(); | |
| 5012 } | |
| 5013 | |
| 5039 int num_commits_; | 5014 int num_commits_; |
| 5040 int num_draws_; | 5015 int num_draws_; |
| 5041 const gfx::Size bounds_; | 5016 const gfx::Size bounds_; |
| 5042 FakeContentLayerClient client_; | 5017 FakeContentLayerClient client_; |
| 5043 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 5018 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
| 5044 scoped_refptr<FakePictureLayer> picture_layer_; | 5019 scoped_refptr<FakePictureLayer> picture_layer_; |
| 5045 Layer* child_layer_; | 5020 Layer* child_layer_; |
| 5046 }; | 5021 }; |
| 5047 | 5022 |
| 5048 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 5023 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
| 5049 | 5024 |
| 5050 } // namespace cc | 5025 } // namespace cc |
| OLD | NEW |