Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 134623005: Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 virtual void AfterTest() OVERRIDE { 1927 virtual void AfterTest() OVERRIDE {
1953 EXPECT_EQ(1, num_commits_deferred_); 1928 EXPECT_EQ(1, num_commits_deferred_);
1954 EXPECT_EQ(2, num_complete_commits_); 1929 EXPECT_EQ(2, num_complete_commits_);
1955 } 1930 }
1956 1931
1957 private: 1932 private:
1958 int num_commits_deferred_; 1933 int num_commits_deferred_;
1959 int num_complete_commits_; 1934 int num_complete_commits_;
1960 }; 1935 };
1961 1936
1962 MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 1937 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
1963 1938
1964 class LayerTreeHostWithProxy : public LayerTreeHost { 1939 class LayerTreeHostWithProxy : public LayerTreeHost {
1965 public: 1940 public:
1966 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, 1941 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client,
1967 const LayerTreeSettings& settings, 1942 const LayerTreeSettings& settings,
1968 scoped_ptr<FakeProxy> proxy) 1943 scoped_ptr<FakeProxy> proxy)
1969 : LayerTreeHost(client, NULL, settings) { 1944 : LayerTreeHost(client, NULL, settings) {
1970 proxy->SetLayerTreeHost(this); 1945 proxy->SetLayerTreeHost(this);
1971 InitializeForTesting(proxy.PassAs<Proxy>()); 1946 InitializeForTesting(proxy.PassAs<Proxy>());
1972 } 1947 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2000
2026 EXPECT_EQ(10u, host.MaxPartialTextureUpdates()); 2001 EXPECT_EQ(10u, host.MaxPartialTextureUpdates());
2027 } 2002 }
2028 } 2003 }
2029 2004
2030 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) { 2005 TEST(LayerTreeHostTest, PartialUpdatesWithGLRenderer) {
2031 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); 2006 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
2032 2007
2033 LayerTreeSettings settings; 2008 LayerTreeSettings settings;
2034 settings.max_partial_texture_updates = 4; 2009 settings.max_partial_texture_updates = 4;
2010 settings.single_thread_proxy_scheduler = false;
2035 2011
2036 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 2012 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
2037 new TestSharedBitmapManager()); 2013 new TestSharedBitmapManager());
2038 scoped_ptr<LayerTreeHost> host = 2014 scoped_ptr<LayerTreeHost> host =
2039 LayerTreeHost::CreateSingleThreaded(&client, 2015 LayerTreeHost::CreateSingleThreaded(&client,
2040 &client, 2016 &client,
2041 shared_bitmap_manager.get(), 2017 shared_bitmap_manager.get(),
2042 settings, 2018 settings,
2043 base::MessageLoopProxy::current()); 2019 base::MessageLoopProxy::current());
2044 host->Composite(base::TimeTicks::Now()); 2020 host->Composite(base::TimeTicks::Now());
2045 2021
2046 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); 2022 EXPECT_EQ(4u, host->settings().max_partial_texture_updates);
2047 } 2023 }
2048 2024
2049 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) { 2025 TEST(LayerTreeHostTest, PartialUpdatesWithSoftwareRenderer) {
2050 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE); 2026 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
2051 2027
2052 LayerTreeSettings settings; 2028 LayerTreeSettings settings;
2053 settings.max_partial_texture_updates = 4; 2029 settings.max_partial_texture_updates = 4;
2030 settings.single_thread_proxy_scheduler = false;
2054 2031
2055 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 2032 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
2056 new TestSharedBitmapManager()); 2033 new TestSharedBitmapManager());
2057 scoped_ptr<LayerTreeHost> host = 2034 scoped_ptr<LayerTreeHost> host =
2058 LayerTreeHost::CreateSingleThreaded(&client, 2035 LayerTreeHost::CreateSingleThreaded(&client,
2059 &client, 2036 &client,
2060 shared_bitmap_manager.get(), 2037 shared_bitmap_manager.get(),
2061 settings, 2038 settings,
2062 base::MessageLoopProxy::current()); 2039 base::MessageLoopProxy::current());
2063 host->Composite(base::TimeTicks::Now()); 2040 host->Composite(base::TimeTicks::Now());
2064 2041
2065 EXPECT_EQ(4u, host->settings().max_partial_texture_updates); 2042 EXPECT_EQ(4u, host->settings().max_partial_texture_updates);
2066 } 2043 }
2067 2044
2068 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) { 2045 TEST(LayerTreeHostTest, PartialUpdatesWithDelegatingRendererAndGLContent) {
2069 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D); 2046 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_3D);
2070 2047
2071 LayerTreeSettings settings; 2048 LayerTreeSettings settings;
2072 settings.max_partial_texture_updates = 4; 2049 settings.max_partial_texture_updates = 4;
2050 settings.single_thread_proxy_scheduler = false;
2073 2051
2074 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 2052 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
2075 new TestSharedBitmapManager()); 2053 new TestSharedBitmapManager());
2076 scoped_ptr<LayerTreeHost> host = 2054 scoped_ptr<LayerTreeHost> host =
2077 LayerTreeHost::CreateSingleThreaded(&client, 2055 LayerTreeHost::CreateSingleThreaded(&client,
2078 &client, 2056 &client,
2079 shared_bitmap_manager.get(), 2057 shared_bitmap_manager.get(),
2080 settings, 2058 settings,
2081 base::MessageLoopProxy::current()); 2059 base::MessageLoopProxy::current());
2082 host->Composite(base::TimeTicks::Now()); 2060 host->Composite(base::TimeTicks::Now());
2083 2061
2084 EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); 2062 EXPECT_EQ(0u, host->MaxPartialTextureUpdates());
2085 } 2063 }
2086 2064
2087 TEST(LayerTreeHostTest, 2065 TEST(LayerTreeHostTest,
2088 PartialUpdatesWithDelegatingRendererAndSoftwareContent) { 2066 PartialUpdatesWithDelegatingRendererAndSoftwareContent) {
2089 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE); 2067 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DELEGATED_SOFTWARE);
2090 2068
2091 LayerTreeSettings settings; 2069 LayerTreeSettings settings;
2092 settings.max_partial_texture_updates = 4; 2070 settings.max_partial_texture_updates = 4;
2071 settings.single_thread_proxy_scheduler = false;
2093 2072
2094 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 2073 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
2095 new TestSharedBitmapManager()); 2074 new TestSharedBitmapManager());
2096 scoped_ptr<LayerTreeHost> host = 2075 scoped_ptr<LayerTreeHost> host =
2097 LayerTreeHost::CreateSingleThreaded(&client, 2076 LayerTreeHost::CreateSingleThreaded(&client,
2098 &client, 2077 &client,
2099 shared_bitmap_manager.get(), 2078 shared_bitmap_manager.get(),
2100 settings, 2079 settings,
2101 base::MessageLoopProxy::current()); 2080 base::MessageLoopProxy::current());
2102 host->Composite(base::TimeTicks::Now()); 2081 host->Composite(base::TimeTicks::Now());
(...skipping 2476 matching lines...) Expand 10 before | Expand all | Expand 10 after
4579 } 4558 }
4580 4559
4581 int commit_count_; 4560 int commit_count_;
4582 int commit_complete_count_; 4561 int commit_complete_count_;
4583 TestSwapPromiseResult swap_promise_result_[3]; 4562 TestSwapPromiseResult swap_promise_result_[3];
4584 }; 4563 };
4585 4564
4586 // TODO(miletus): Flaky test: crbug.com/393995 4565 // TODO(miletus): Flaky test: crbug.com/393995
4587 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); 4566 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
4588 4567
4589 class LayerTreeHostTestBreakSwapPromiseForAbortedCommit 4568 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit
4590 : public LayerTreeHostTest { 4569 : public LayerTreeHostTest {
4591 protected: 4570 protected:
4592 LayerTreeHostTestBreakSwapPromiseForAbortedCommit() : commit_count_(0) {} 4571 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit()
4572 : commit_count_(0) {}
4593 4573
4594 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4574 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4595 4575
4596 virtual void WillBeginMainFrame() OVERRIDE { 4576 virtual void WillBeginMainFrame() OVERRIDE {
4597 layer_tree_host()->SetDeferCommits(true); 4577 layer_tree_host()->SetDeferCommits(true);
4598 layer_tree_host()->SetNeedsCommit(); 4578 layer_tree_host()->SetNeedsCommit();
4599 } 4579 }
4600 4580
4601 virtual void DidDeferCommit() OVERRIDE { 4581 virtual void DidDeferCommit() OVERRIDE {
4602 layer_tree_host()->SetVisible(false); 4582 layer_tree_host()->SetVisible(false);
(...skipping 18 matching lines...) Expand all
4621 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4601 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4622 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4602 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4623 EXPECT_TRUE(swap_promise_result_.dtor_called); 4603 EXPECT_TRUE(swap_promise_result_.dtor_called);
4624 } 4604 }
4625 } 4605 }
4626 4606
4627 int commit_count_; 4607 int commit_count_;
4628 TestSwapPromiseResult swap_promise_result_; 4608 TestSwapPromiseResult swap_promise_result_;
4629 }; 4609 };
4630 4610
4631 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForAbortedCommit); 4611 SINGLE_AND_MULTI_THREAD_TEST_F(
4612 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4613
4614 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit
4615 : public LayerTreeHostTest {
4616 protected:
4617 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit()
4618 : commit_count_(0) {}
4619
4620 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4621
4622 virtual void WillBeginMainFrame() OVERRIDE {
4623 layer_tree_host()->SetDeferCommits(true);
4624 layer_tree_host()->SetNeedsCommit();
4625 }
4626
4627 virtual void DidDeferCommit() OVERRIDE {
4628 layer_tree_host()->DidLoseOutputSurface();
4629 layer_tree_host()->SetDeferCommits(false);
4630
4631 scoped_ptr<SwapPromise> swap_promise(
4632 new TestSwapPromise(&swap_promise_result_));
4633 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4634 }
4635
4636 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4637
4638 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4639 bool did_handle) OVERRIDE {
4640 EndTest();
4641 }
4642
4643 virtual void AfterTest() OVERRIDE {
4644 {
4645 base::AutoLock lock(swap_promise_result_.lock);
4646 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4647 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4648 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4649 EXPECT_TRUE(swap_promise_result_.dtor_called);
4650 }
4651 }
4652
4653 int commit_count_;
4654 TestSwapPromiseResult swap_promise_result_;
4655 };
4656
4657 SINGLE_AND_MULTI_THREAD_TEST_F(
4658 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit);
4632 4659
4633 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4660 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4634 public: 4661 public:
4635 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4662 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4636 LayerTreeHostImpl* layer_tree_host_impl, 4663 LayerTreeHostImpl* layer_tree_host_impl,
4637 int* set_needs_commit_count, 4664 int* set_needs_commit_count,
4638 int* set_needs_redraw_count) 4665 int* set_needs_redraw_count)
4639 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4666 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4640 set_needs_commit_count_(set_needs_commit_count), 4667 set_needs_commit_count_(set_needs_commit_count),
4641 set_needs_redraw_count_(set_needs_redraw_count) {} 4668 set_needs_redraw_count_(set_needs_redraw_count) {}
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4701 EXPECT_EQ(3, set_needs_commit_count); 4728 EXPECT_EQ(3, set_needs_commit_count);
4702 EXPECT_EQ(0, set_needs_redraw_count); 4729 EXPECT_EQ(0, set_needs_redraw_count);
4703 } 4730 }
4704 4731
4705 EndTest(); 4732 EndTest();
4706 } 4733 }
4707 4734
4708 virtual void AfterTest() OVERRIDE {} 4735 virtual void AfterTest() OVERRIDE {}
4709 }; 4736 };
4710 4737
4711 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4738 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4712 4739
4713 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources 4740 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
4714 : public LayerTreeHostTest { 4741 : public LayerTreeHostTest {
4715 protected: 4742 protected:
4716 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 4743 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
4717 settings->impl_side_painting = true; 4744 settings->impl_side_painting = true;
4718 } 4745 }
4719 4746
4720 virtual void SetupTree() OVERRIDE { 4747 virtual void SetupTree() OVERRIDE {
4721 LayerTreeHostTest::SetupTree(); 4748 LayerTreeHostTest::SetupTree();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
5014 const gfx::Size bounds_; 5041 const gfx::Size bounds_;
5015 FakeContentLayerClient client_; 5042 FakeContentLayerClient client_;
5016 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; 5043 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_;
5017 scoped_refptr<FakePictureLayer> picture_layer_; 5044 scoped_refptr<FakePictureLayer> picture_layer_;
5018 Layer* child_layer_; 5045 Layer* child_layer_;
5019 }; 5046 };
5020 5047
5021 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); 5048 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting);
5022 5049
5023 } // namespace cc 5050 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698