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

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, 11 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 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 scoped_refptr<Layer> layer_; 2026 scoped_refptr<Layer> layer_;
2027 int num_commit_complete_; 2027 int num_commit_complete_;
2028 int num_draw_layers_; 2028 int num_draw_layers_;
2029 }; 2029 };
2030 2030
2031 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); 2031 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
2032 2032
2033 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { 2033 class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
2034 public: 2034 public:
2035 LayerTreeHostTestDeferCommits() 2035 LayerTreeHostTestDeferCommits()
2036 : num_commits_deferred_(0), num_complete_commits_(0) {} 2036 : num_complete_commits_(0),
2037 num_will_begin_main_frame_(0) {}
2037 2038
2038 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2039 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2039 2040
2040 void DidDeferCommit() override { 2041 void WillBeginMainFrame() override {
2041 num_commits_deferred_++; 2042 num_will_begin_main_frame_++;
2043 }
2044
2045 void TestWillBeginMainFrameCallCount(
2046 int expected_will_begin_main_frame_call_count) {
2047 EXPECT_EQ(expected_will_begin_main_frame_call_count,
2048 num_will_begin_main_frame_);
2042 layer_tree_host()->SetDeferCommits(false); 2049 layer_tree_host()->SetDeferCommits(false);
2043 } 2050 }
2044 2051
2045 void DidCommit() override { 2052 void DidCommit() override {
2046 num_complete_commits_++; 2053 num_complete_commits_++;
2047 switch (num_complete_commits_) { 2054 switch (num_complete_commits_) {
2048 case 1: 2055 case 1:
2049 EXPECT_EQ(0, num_commits_deferred_); 2056 EXPECT_EQ(1, num_will_begin_main_frame_);
2050 layer_tree_host()->SetDeferCommits(true); 2057 layer_tree_host()->SetDeferCommits(true);
2051 PostSetNeedsCommitToMainThread(); 2058 PostSetNeedsCommitToMainThread();
2059 // PostDelayedTask to check whether WillBeginMainFrame is called.
enne (OOO) 2015/01/23 01:35:21 This time delay is a little weird. Could you just
simonhong 2015/01/28 19:44:24 Done.
2060 MainThreadTaskRunner()->PostDelayedTask(
2061 FROM_HERE,
2062 base::Bind(
2063 &LayerTreeHostTestDeferCommits::TestWillBeginMainFrameCallCount,
2064 base::Unretained(this), 1),
2065 base::TimeDelta::FromMilliseconds(100));
2052 break; 2066 break;
2053 case 2: 2067 case 2:
2054 EndTest(); 2068 EndTest();
2055 break; 2069 break;
2056 default: 2070 default:
2057 NOTREACHED(); 2071 NOTREACHED();
2058 break; 2072 break;
2059 } 2073 }
2060 } 2074 }
2061 2075
2062 void AfterTest() override { 2076 void AfterTest() override {
2063 EXPECT_EQ(1, num_commits_deferred_);
2064 EXPECT_EQ(2, num_complete_commits_); 2077 EXPECT_EQ(2, num_complete_commits_);
2078 EXPECT_EQ(2, num_will_begin_main_frame_);
2065 } 2079 }
2066 2080
2067 private: 2081 private:
2068 int num_commits_deferred_;
2069 int num_complete_commits_; 2082 int num_complete_commits_;
2083 int num_will_begin_main_frame_;
2070 }; 2084 };
2071 2085
2072 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); 2086 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits);
2073 2087
2074 class LayerTreeHostWithProxy : public LayerTreeHost { 2088 class LayerTreeHostWithProxy : public LayerTreeHost {
2075 public: 2089 public:
2076 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client, 2090 LayerTreeHostWithProxy(FakeLayerTreeHostClient* client,
2077 const LayerTreeSettings& settings, 2091 const LayerTreeSettings& settings,
2078 scoped_ptr<FakeProxy> proxy) 2092 scoped_ptr<FakeProxy> proxy)
2079 : LayerTreeHost(client, NULL, NULL, settings) { 2093 : LayerTreeHost(client, NULL, NULL, settings) {
(...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after
4795 4809
4796 void AfterTest() override {} 4810 void AfterTest() override {}
4797 4811
4798 private: 4812 private:
4799 scoped_refptr<Layer> layer_; 4813 scoped_refptr<Layer> layer_;
4800 TestSwapPromiseResult swap_promise_result_; 4814 TestSwapPromiseResult swap_promise_result_;
4801 }; 4815 };
4802 4816
4803 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); 4817 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise);
4804 4818
4805 class LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit
4806 : public LayerTreeHostTest {
4807 protected:
4808 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4809
4810 void DidCommit() override {
4811 layer_tree_host()->SetDeferCommits(true);
4812 layer_tree_host()->SetNeedsCommit();
4813 }
4814
4815 void DidDeferCommit() override {
4816 layer_tree_host()->SetVisible(false);
4817 scoped_ptr<SwapPromise> swap_promise(
4818 new TestSwapPromise(&swap_promise_result_));
4819 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4820 layer_tree_host()->SetDeferCommits(false);
4821 }
4822
4823 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4824 CommitEarlyOutReason reason) override {
4825 EndTest();
4826 }
4827
4828 void AfterTest() override {
4829 {
4830 base::AutoLock lock(swap_promise_result_.lock);
4831 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4832 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4833 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4834 EXPECT_TRUE(swap_promise_result_.dtor_called);
4835 }
4836 }
4837
4838 TestSwapPromiseResult swap_promise_result_;
4839 };
4840
4841 SINGLE_AND_MULTI_THREAD_TEST_F(
4842 LayerTreeHostTestBreakSwapPromiseForVisibilityAbortedCommit);
4843
4844 class LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit
4845 : public LayerTreeHostTest {
4846 protected:
4847 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
4848
4849 void DidCommit() override {
4850 if (TestEnded())
4851 return;
4852 layer_tree_host()->SetDeferCommits(true);
4853 layer_tree_host()->SetNeedsCommit();
4854 }
4855
4856 void DidDeferCommit() override {
4857 layer_tree_host()->DidLoseOutputSurface();
4858 scoped_ptr<SwapPromise> swap_promise(
4859 new TestSwapPromise(&swap_promise_result_));
4860 layer_tree_host()->QueueSwapPromise(swap_promise.Pass());
4861 layer_tree_host()->SetDeferCommits(false);
4862 }
4863
4864 void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl,
4865 CommitEarlyOutReason reason) override {
4866 // This is needed so that the impl-thread state matches main-thread state.
4867 host_impl->DidLoseOutputSurface();
4868 EndTest();
4869 }
4870
4871 void AfterTest() override {
4872 {
4873 base::AutoLock lock(swap_promise_result_.lock);
4874 EXPECT_FALSE(swap_promise_result_.did_swap_called);
4875 EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
4876 EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
4877 EXPECT_TRUE(swap_promise_result_.dtor_called);
4878 }
4879 }
4880
4881 TestSwapPromiseResult swap_promise_result_;
4882 };
4883
4884 SINGLE_AND_MULTI_THREAD_TEST_F(
4885 LayerTreeHostTestBreakSwapPromiseForContextAbortedCommit);
4886
4887 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { 4819 class SimpleSwapPromiseMonitor : public SwapPromiseMonitor {
4888 public: 4820 public:
4889 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host, 4821 SimpleSwapPromiseMonitor(LayerTreeHost* layer_tree_host,
4890 LayerTreeHostImpl* layer_tree_host_impl, 4822 LayerTreeHostImpl* layer_tree_host_impl,
4891 int* set_needs_commit_count, 4823 int* set_needs_commit_count,
4892 int* set_needs_redraw_count) 4824 int* set_needs_redraw_count)
4893 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl), 4825 : SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
4894 set_needs_commit_count_(set_needs_commit_count) {} 4826 set_needs_commit_count_(set_needs_commit_count) {}
4895 4827
4896 ~SimpleSwapPromiseMonitor() override {} 4828 ~SimpleSwapPromiseMonitor() override {}
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
6111 6043
6112 void AfterTest() override { EXPECT_TRUE(did_commit_); } 6044 void AfterTest() override { EXPECT_TRUE(did_commit_); }
6113 6045
6114 private: 6046 private:
6115 bool did_commit_; 6047 bool did_commit_;
6116 }; 6048 };
6117 6049
6118 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); 6050 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit);
6119 6051
6120 } // namespace cc 6052 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698