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

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

Issue 337693005: cc: Control defer_commits logic by Scheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 5 years, 10 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
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | cc/trees/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 scoped_refptr<Layer> layer_; 2022 scoped_refptr<Layer> layer_;
2023 int num_commit_complete_; 2023 int num_commit_complete_;
2024 int num_draw_layers_; 2024 int num_draw_layers_;
2025 }; 2025 };
2026 2026
2027 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); 2027 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
2028 2028
2029 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { 2029 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
2030 public: 2030 public:
2031 LayerTreeHostTestDeferCommits() 2031 LayerTreeHostTestDeferCommits()
2032 : num_commits_deferred_(0), num_complete_commits_(0) {} 2032 : num_will_begin_impl_frame_(0),
2033 num_send_begin_main_frame_(0) {}
2033 2034
2034 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2035 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2035 2036
2036 void DidDeferCommit() override { 2037 void WillBeginImplFrame(const BeginFrameArgs& args) override {
2037 num_commits_deferred_++; 2038 num_will_begin_impl_frame_++;
2038 layer_tree_host()->SetDeferCommits(false); 2039 switch (num_will_begin_impl_frame_) {
2040 case 1:
2041 break;
2042 case 2:
2043 PostSetNeedsCommitToMainThread();
2044 break;
2045 case 3:
2046 PostSetDeferCommitsToMainThread(false);
2047 break;
2048 default:
2049 // Sometimes |num_will_begin_impl_frame_| will be greater than 3 if the
2050 // main thread is slow to respond.
2051 break;
2052 }
2039 } 2053 }
2040 2054
2041 void DidCommit() override { 2055 void ScheduledActionSendBeginMainFrame() override {
2042 num_complete_commits_++; 2056 num_send_begin_main_frame_++;
2043 switch (num_complete_commits_) { 2057 switch (num_send_begin_main_frame_) {
2044 case 1: 2058 case 1:
2045 EXPECT_EQ(0, num_commits_deferred_); 2059 PostSetDeferCommitsToMainThread(true);
2046 layer_tree_host()->SetDeferCommits(true);
2047 PostSetNeedsCommitToMainThread();
2048 break; 2060 break;
2049 case 2: 2061 case 2:
2050 EndTest(); 2062 EndTest();
2051 break; 2063 break;
2052 default: 2064 default:
2053 NOTREACHED(); 2065 NOTREACHED();
2054 break; 2066 break;
2055 } 2067 }
2056 } 2068 }
2057 2069
2058 void AfterTest() override { 2070 void AfterTest() override {
2059 EXPECT_EQ(1, num_commits_deferred_); 2071 EXPECT_GT(num_will_begin_impl_frame_, num_send_begin_main_frame_);
brianderson 2015/01/31 01:45:24 I don't think it should be possible for there to b
simonhong 2015/01/31 02:03:53 Done.
2060 EXPECT_EQ(2, num_complete_commits_);
2061 } 2072 }
2062 2073
2063 private: 2074 private:
2064 int num_commits_deferred_; 2075 int num_will_begin_impl_frame_;
2065 int num_complete_commits_; 2076 int num_send_begin_main_frame_;
2066 }; 2077 };
2067 2078
2068 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 2079 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
2069 2080
2070 class LayerTreeHostWithProxy : public LayerTreeHost { 2081 class LayerTreeHostWithProxy : public LayerTreeHost {
2071 public: 2082 public:
2072 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, 2083 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client,
2073 const LayerTreeSettings& settings, 2084 const LayerTreeSettings& settings,
2074 scoped_ptr<FakeProxy> proxy) 2085 scoped_ptr<FakeProxy> proxy)
2075 : LayerTreeHost(client, NULL, NULL, settings) { 2086 : LayerTreeHost(client, NULL, NULL, settings) {
(...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after
4791 4802
4792 void AfterTest() override {} 4803 void AfterTest() override {}
4793 4804
4794 private: 4805 private:
4795 scoped_refptr<Layer> layer_; 4806 scoped_refptr<Layer> layer_;
4796 TestSwapPromiseResult swap_promise_result_; 4807 TestSwapPromiseResult swap_promise_result_;
4797 }; 4808 };
4798 4809
4799 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); 4810 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise);
4800 4811
4801 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit 4812 class LayerTreeHostTestBreakSwapPromiseForVisibility
4802 : public LayerTreeHostTest { 4813 : public LayerTreeHostTest {
4803 protected: 4814 protected:
4804 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4815 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4805 4816
4806 void DidCommit() override { 4817 void SetVisibleFalseAndQueueSwapPromise() {
4807 layer_tree_host()->SetDeferCommits(true);
4808 layer_tree_host()->SetNeedsCommit();
4809 }
4810
4811 void DidDeferCommit() override {
4812 layer_tree_host()->SetVisible(false); 4818 layer_tree_host()->SetVisible(false);
4813 scoped_ptr<SwapPromise> swap_promise( 4819 scoped_ptr<SwapPromise> swap_promise(
4814 new TestSwapPromise(&swap_promise_result_)); 4820 new TestSwapPromise(&swap_promise_result_));
4815 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4821 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4816 layer_tree_host()->SetDeferCommits(false); 4822 }
4823
4824 void ScheduledActionWillSendBeginMainFrame() override {
4825 MainThreadTaskRunner()->PostTask(
4826 FROM_HERE,
4827 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
4828 ::SetVisibleFalseAndQueueSwapPromise,
4829 base::Unretained(this)));
4817 } 4830 }
4818 4831
4819 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4832 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4820 CommitEarlyOutReason reason) override { 4833 CommitEarlyOutReason reason) override {
4821 EndTest(); 4834 EndTest();
4822 } 4835 }
4823 4836
4824 void AfterTest() override { 4837 void AfterTest() override {
4825 { 4838 {
4826 base::AutoLock lock(swap_promise_result_.lock); 4839 base::AutoLock lock(swap_promise_result_.lock);
4827 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4840 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4828 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4841 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4829 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4842 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4830 EXPECT_TRUE(swap_promise_result_.dtor_called); 4843 EXPECT_TRUE(swap_promise_result_.dtor_called);
4831 } 4844 }
4832 } 4845 }
4833 4846
4834 TestSwapPromiseResult swap_promise_result_; 4847 TestSwapPromiseResult swap_promise_result_;
4835 }; 4848 };
4836 4849
4837 SINGLE_AND_MULTI_THREAD_TEST_F( 4850 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility);
4838 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4839 4851
4840 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit 4852 class LayerTreeHostTestBreakSwapPromiseForContext : public LayerTreeHostTest {
4841 : public LayerTreeHostTest {
4842 protected: 4853 protected:
4854 LayerTreeHostTestBreakSwapPromiseForContext()
4855 : output_surface_lost_triggered_(false) {
4856 }
4857
4843 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4858 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4844 4859
4845 void DidCommit() override { 4860 void LoseOutputSurfaceAndQueueSwapPromise() {
4846 if (TestEnded())
4847 return;
4848 layer_tree_host()->SetDeferCommits(true);
4849 layer_tree_host()->SetNeedsCommit();
4850 }
4851
4852 void DidDeferCommit() override {
4853 layer_tree_host()->DidLoseOutputSurface(); 4861 layer_tree_host()->DidLoseOutputSurface();
4854 scoped_ptr<SwapPromise> swap_promise( 4862 scoped_ptr<SwapPromise> swap_promise(
4855 new TestSwapPromise(&swap_promise_result_)); 4863 new TestSwapPromise(&swap_promise_result_));
4856 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4864 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4857 layer_tree_host()->SetDeferCommits(false); 4865 }
4866
4867 void ScheduledActionWillSendBeginMainFrame() override {
4868 if (output_surface_lost_triggered_)
4869 return;
4870 output_surface_lost_triggered_ = true;
4871
4872 MainThreadTaskRunner()->PostTask(
4873 FROM_HERE,
4874 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4875 ::LoseOutputSurfaceAndQueueSwapPromise,
4876 base::Unretained(this)));
4858 } 4877 }
4859 4878
4860 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4879 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4861 CommitEarlyOutReason reason) override { 4880 CommitEarlyOutReason reason) override {
4862 // This is needed so that the impl-thread state matches main-thread state. 4881 // This is needed so that the impl-thread state matches main-thread state.
4863 host_impl->DidLoseOutputSurface(); 4882 host_impl->DidLoseOutputSurface();
4864 EndTest(); 4883 EndTest();
4865 } 4884 }
4866 4885
4867 void AfterTest() override { 4886 void AfterTest() override {
4868 { 4887 {
4869 base::AutoLock lock(swap_promise_result_.lock); 4888 base::AutoLock lock(swap_promise_result_.lock);
4870 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4889 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4871 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4890 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4872 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4891 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4873 EXPECT_TRUE(swap_promise_result_.dtor_called); 4892 EXPECT_TRUE(swap_promise_result_.dtor_called);
4874 } 4893 }
4875 } 4894 }
4876 4895
4896 bool output_surface_lost_triggered_;
4877 TestSwapPromiseResult swap_promise_result_; 4897 TestSwapPromiseResult swap_promise_result_;
4878 }; 4898 };
4879 4899
4880 SINGLE_AND_MULTI_THREAD_TEST_F( 4900 SINGLE_AND_MULTI_THREAD_TEST_F(
4881 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); 4901 LayerTreeHostTestBreakSwapPromiseForContext);
4882 4902
4883 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4903 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4884 public: 4904 public:
4885 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4905 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4886 LayerTreeHostImpl* layer_tree_host_impl, 4906 LayerTreeHostImpl* layer_tree_host_impl,
4887 int* set_needs_commit_count, 4907 int* set_needs_commit_count,
4888 int* set_needs_redraw_count) 4908 int* set_needs_redraw_count)
4889 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4909 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4890 set_needs_commit_count_(set_needs_commit_count) {} 4910 set_needs_commit_count_(set_needs_commit_count) {}
4891 4911
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
6174 6194
6175 void AfterTest() override { EXPECT_TRUE(did_commit_); } 6195 void AfterTest() override { EXPECT_TRUE(did_commit_); }
6176 6196
6177 private: 6197 private:
6178 bool did_commit_; 6198 bool did_commit_;
6179 }; 6199 };
6180 6200
6181 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); 6201 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit);
6182 6202
6183 } // namespace cc 6203 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | cc/trees/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698