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

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: Abort commits properly, handle swap promises, test those 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 {
enne (OOO) 2014/08/09 00:04:43 This test is redundant with LayerTreeHostTestBreak
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 2422 matching lines...) Expand 10 before | Expand all | Expand 10 after
4525 } 4504 }
4526 4505
4527 int commit_count_; 4506 int commit_count_;
4528 int commit_complete_count_; 4507 int commit_complete_count_;
4529 TestSwapPromiseResult swap_promise_result_[3]; 4508 TestSwapPromiseResult swap_promise_result_[3];
4530 }; 4509 };
4531 4510
4532 // TODO(miletus): Flaky test: crbug.com/393995 4511 // TODO(miletus): Flaky test: crbug.com/393995
4533 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); 4512 // MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
4534 4513
4535 class LayerTreeHostTestBreakSwapPromiseForAbortedCommit 4514 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit
4536 : public LayerTreeHostTest { 4515 : public LayerTreeHostTest {
4537 protected: 4516 protected:
4538 LayerTreeHostTestBreakSwapPromiseForAbortedCommit() : commit_count_(0) {} 4517 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit()
4518 : commit_count_(0) {}
4539 4519
4540 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 4520 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4541 4521
4542 virtual void WillBeginMainFrame() OVERRIDE { 4522 virtual void WillBeginMainFrame() OVERRIDE {
4543 layer_tree_host()->SetDeferCommits(true); 4523 layer_tree_host()->SetDeferCommits(true);
4544 layer_tree_host()->SetNeedsCommit(); 4524 layer_tree_host()->SetNeedsCommit();
4545 } 4525 }
4546 4526
4547 virtual void DidDeferCommit() OVERRIDE { 4527 virtual void DidDeferCommit() OVERRIDE {
4548 layer_tree_host()->SetVisible(false); 4528 layer_tree_host()->SetVisible(false);
(...skipping 18 matching lines...) Expand all
4567 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4547 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4568 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4548 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4569 EXPECT_TRUE(swap_promise_result_.dtor_called); 4549 EXPECT_TRUE(swap_promise_result_.dtor_called);
4570 } 4550 }
4571 } 4551 }
4572 4552
4573 int commit_count_; 4553 int commit_count_;
4574 TestSwapPromiseResult swap_promise_result_; 4554 TestSwapPromiseResult swap_promise_result_;
4575 }; 4555 };
4576 4556
4577 MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForAbortedCommit); 4557 SINGLE_AND_MULTI_THREAD_TEST_F(
4558 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4559
4560 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit
4561 : public LayerTreeHostTest {
4562 protected:
4563 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit()
4564 : commit_count_(0) {}
4565
4566 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4567
4568 virtual void WillBeginMainFrame() OVERRIDE {
4569 layer_tree_host()->SetDeferCommits(true);
4570 layer_tree_host()->SetNeedsCommit();
4571 }
4572
4573 virtual void DidDeferCommit() OVERRIDE {
4574 layer_tree_host()->DidLoseOutputSurface();
4575 layer_tree_host()->SetDeferCommits(false);
4576
4577 scoped_ptr<SwapPromise> swap_promise(
4578 new TestSwapPromise(&swap_promise_result_));
4579 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4580 }
4581
4582 virtual void DidCommit() OVERRIDE { PostSetNeedsCommitToMainThread(); }
4583
4584 virtual void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4585 bool did_handle) OVERRIDE {
4586 EndTest();
4587 }
4588
4589 virtual void AfterTest() OVERRIDE {
4590 {
4591 base::AutoLock lock(swap_promise_result_.lock);
4592 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4593 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4594 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4595 EXPECT_TRUE(swap_promise_result_.dtor_called);
4596 }
4597 }
4598
4599 int commit_count_;
4600 TestSwapPromiseResult swap_promise_result_;
4601 };
4602
4603 SINGLE_AND_MULTI_THREAD_TEST_F(
4604 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit);
4578 4605
4579 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4606 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4580 public: 4607 public:
4581 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4608 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4582 LayerTreeHostImpl* layer_tree_host_impl, 4609 LayerTreeHostImpl* layer_tree_host_impl,
4583 int* set_needs_commit_count, 4610 int* set_needs_commit_count,
4584 int* set_needs_redraw_count) 4611 int* set_needs_redraw_count)
4585 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4612 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4586 set_needs_commit_count_(set_needs_commit_count), 4613 set_needs_commit_count_(set_needs_commit_count),
4587 set_needs_redraw_count_(set_needs_redraw_count) {} 4614 set_needs_redraw_count_(set_needs_redraw_count) {}
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4647 EXPECT_EQ(3, set_needs_commit_count); 4674 EXPECT_EQ(3, set_needs_commit_count);
4648 EXPECT_EQ(0, set_needs_redraw_count); 4675 EXPECT_EQ(0, set_needs_redraw_count);
4649 } 4676 }
4650 4677
4651 EndTest(); 4678 EndTest();
4652 } 4679 }
4653 4680
4654 virtual void AfterTest() OVERRIDE {} 4681 virtual void AfterTest() OVERRIDE {}
4655 }; 4682 };
4656 4683
4657 MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); 4684 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor);
4658 4685
4659 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources 4686 class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
4660 : public LayerTreeHostTest { 4687 : public LayerTreeHostTest {
4661 protected: 4688 protected:
4662 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 4689 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
4663 settings->impl_side_painting = true; 4690 settings->impl_side_painting = true;
4664 } 4691 }
4665 4692
4666 virtual void SetupTree() OVERRIDE { 4693 virtual void SetupTree() OVERRIDE {
4667 LayerTreeHostTest::SetupTree(); 4694 LayerTreeHostTest::SetupTree();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
4960 const gfx::Size bounds_; 4987 const gfx::Size bounds_;
4961 FakeContentLayerClient client_; 4988 FakeContentLayerClient client_;
4962 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; 4989 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_;
4963 scoped_refptr<FakePictureLayer> picture_layer_; 4990 scoped_refptr<FakePictureLayer> picture_layer_;
4964 Layer* child_layer_; 4991 Layer* child_layer_;
4965 }; 4992 };
4966 4993
4967 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); 4994 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting);
4968 4995
4969 } // namespace cc 4996 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698