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

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_GE(3, num_will_begin_impl_frame_);
2060 EXPECT_EQ(2, num_complete_commits_); 2072 EXPECT_EQ(2, num_send_begin_main_frame_);
2061 } 2073 }
2062 2074
2063 private: 2075 private:
2064 int num_commits_deferred_; 2076 int num_will_begin_impl_frame_;
2065 int num_complete_commits_; 2077 int num_send_begin_main_frame_;
2066 }; 2078 };
2067 2079
2068 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 2080 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
2069 2081
2070 class LayerTreeHostWithProxy : public LayerTreeHost { 2082 class LayerTreeHostWithProxy : public LayerTreeHost {
2071 public: 2083 public:
2072 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, 2084 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client,
2073 const LayerTreeSettings& settings, 2085 const LayerTreeSettings& settings,
2074 scoped_ptr<FakeProxy> proxy) 2086 scoped_ptr<FakeProxy> proxy)
2075 : LayerTreeHost(client, NULL, NULL, settings) { 2087 : LayerTreeHost(client, NULL, NULL, settings) {
(...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after
4791 4803
4792 void AfterTest() override {} 4804 void AfterTest() override {}
4793 4805
4794 private: 4806 private:
4795 scoped_refptr<Layer> layer_; 4807 scoped_refptr<Layer> layer_;
4796 TestSwapPromiseResult swap_promise_result_; 4808 TestSwapPromiseResult swap_promise_result_;
4797 }; 4809 };
4798 4810
4799 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); 4811 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise);
4800 4812
4801 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit 4813 class LayerTreeHostTestBreakSwapPromiseForVisibility
4802 : public LayerTreeHostTest { 4814 : public LayerTreeHostTest {
4803 protected: 4815 protected:
4804 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4816 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4805 4817
4806 void DidCommit() override { 4818 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); 4819 layer_tree_host()->SetVisible(false);
4813 scoped_ptr<SwapPromise> swap_promise( 4820 scoped_ptr<SwapPromise> swap_promise(
4814 new TestSwapPromise(&swap_promise_result_)); 4821 new TestSwapPromise(&swap_promise_result_));
4815 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4822 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4816 layer_tree_host()->SetDeferCommits(false); 4823 }
4824
4825 void ScheduledActionWillSendBeginMainFrame() override {
4826 MainThreadTaskRunner()->PostTask(
4827 FROM_HERE,
4828 base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
4829 ::SetVisibleFalseAndQueueSwapPromise,
4830 base::Unretained(this)));
4817 } 4831 }
4818 4832
4819 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4833 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4820 CommitEarlyOutReason reason) override { 4834 CommitEarlyOutReason reason) override {
4821 EndTest(); 4835 EndTest();
4822 } 4836 }
4823 4837
4824 void AfterTest() override { 4838 void AfterTest() override {
4825 { 4839 {
4826 base::AutoLock lock(swap_promise_result_.lock); 4840 base::AutoLock lock(swap_promise_result_.lock);
4827 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4841 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4828 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4842 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4829 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4843 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4830 EXPECT_TRUE(swap_promise_result_.dtor_called); 4844 EXPECT_TRUE(swap_promise_result_.dtor_called);
4831 } 4845 }
4832 } 4846 }
4833 4847
4834 TestSwapPromiseResult swap_promise_result_; 4848 TestSwapPromiseResult swap_promise_result_;
4835 }; 4849 };
4836 4850
4837 SINGLE_AND_MULTI_THREAD_TEST_F( 4851 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility);
4838 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4839 4852
4840 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit 4853 class LayerTreeHostTestBreakSwapPromiseForContext : public LayerTreeHostTest {
4841 : public LayerTreeHostTest {
4842 protected: 4854 protected:
4855 LayerTreeHostTestBreakSwapPromiseForContext()
4856 : output_surface_lost_triggered_(false) {
4857 }
4858
4843 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 4859 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4844 4860
4845 void DidCommit() override { 4861 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(); 4862 layer_tree_host()->DidLoseOutputSurface();
4854 scoped_ptr<SwapPromise> swap_promise( 4863 scoped_ptr<SwapPromise> swap_promise(
4855 new TestSwapPromise(&swap_promise_result_)); 4864 new TestSwapPromise(&swap_promise_result_));
4856 layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); 4865 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4857 layer_tree_host()->SetDeferCommits(false); 4866 }
4867
4868 void ScheduledActionWillSendBeginMainFrame() override {
4869 if (output_surface_lost_triggered_)
4870 return;
4871 output_surface_lost_triggered_ = true;
4872
4873 MainThreadTaskRunner()->PostTask(
4874 FROM_HERE,
4875 base::Bind(&LayerTreeHostTestBreakSwapPromiseForContext
4876 ::LoseOutputSurfaceAndQueueSwapPromise,
4877 base::Unretained(this)));
4858 } 4878 }
4859 4879
4860 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, 4880 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4861 CommitEarlyOutReason reason) override { 4881 CommitEarlyOutReason reason) override {
4862 // This is needed so that the impl-thread state matches main-thread state. 4882 // This is needed so that the impl-thread state matches main-thread state.
4863 host_impl->DidLoseOutputSurface(); 4883 host_impl->DidLoseOutputSurface();
4864 EndTest(); 4884 EndTest();
4865 } 4885 }
4866 4886
4867 void AfterTest() override { 4887 void AfterTest() override {
4868 { 4888 {
4869 base::AutoLock lock(swap_promise_result_.lock); 4889 base::AutoLock lock(swap_promise_result_.lock);
4870 EXPECT_FALSE(swap_promise_result_.did_swap_called); 4890 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4871 EXPECT_TRUE(swap_promise_result_.did_not_swap_called); 4891 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4872 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason); 4892 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4873 EXPECT_TRUE(swap_promise_result_.dtor_called); 4893 EXPECT_TRUE(swap_promise_result_.dtor_called);
4874 } 4894 }
4875 } 4895 }
4876 4896
4897 bool output_surface_lost_triggered_;
4877 TestSwapPromiseResult swap_promise_result_; 4898 TestSwapPromiseResult swap_promise_result_;
4878 }; 4899 };
4879 4900
4880 SINGLE_AND_MULTI_THREAD_TEST_F( 4901 SINGLE_AND_MULTI_THREAD_TEST_F(
4881 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit); 4902 LayerTreeHostTestBreakSwapPromiseForContext);
4882 4903
4883 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4904 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4884 public: 4905 public:
4885 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4906 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4886 LayerTreeHostImpl* layer_tree_host_impl, 4907 LayerTreeHostImpl* layer_tree_host_impl,
4887 int* set_needs_commit_count, 4908 int* set_needs_commit_count,
4888 int* set_needs_redraw_count) 4909 int* set_needs_redraw_count)
4889 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4910 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4890 set_needs_commit_count_(set_needs_commit_count) {} 4911 set_needs_commit_count_(set_needs_commit_count) {}
4891 4912
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
6174 6195
6175 void AfterTest() override { EXPECT_TRUE(did_commit_); } 6196 void AfterTest() override { EXPECT_TRUE(did_commit_); }
6176 6197
6177 private: 6198 private:
6178 bool did_commit_; 6199 bool did_commit_;
6179 }; 6200 };
6180 6201
6181 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); 6202 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit);
6182 6203
6183 } // namespace cc 6204 } // 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