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

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

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