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

Side by Side Diff: cc/test/layer_tree_test.cc

Issue 817603002: cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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/test/layer_tree_test.h" 5 #include "cc/test/layer_tree_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "cc/animation/animation.h" 8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_registrar.h" 9 #include "cc/animation/animation_registrar.h"
10 #include "cc/animation/layer_animation_controller.h" 10 #include "cc/animation/layer_animation_controller.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 tile_task_worker_pool, resource_pool, staging_resource_pool); 54 tile_task_worker_pool, resource_pool, staging_resource_pool);
55 } 55 }
56 56
57 class ExternalBeginFrameSourceForTest 57 class ExternalBeginFrameSourceForTest
58 : public BeginFrameSourceMixIn, 58 : public BeginFrameSourceMixIn,
59 public NON_EXPORTED_BASE(base::NonThreadSafe) { 59 public NON_EXPORTED_BASE(base::NonThreadSafe) {
60 public: 60 public:
61 explicit ExternalBeginFrameSourceForTest(double refresh_rate) 61 explicit ExternalBeginFrameSourceForTest(double refresh_rate)
62 : milliseconds_per_frame_(1000.0 / refresh_rate), 62 : milliseconds_per_frame_(1000.0 / refresh_rate),
63 is_ready_(false), 63 is_ready_(false),
64 needs_begin_frames_(false),
64 weak_ptr_factory_(this) { 65 weak_ptr_factory_(this) {
66 test_on_begin_frame_closure_ = base::Bind(
67 &ExternalBeginFrameSourceForTest::TestOnBeginFrame,
68 weak_ptr_factory_.GetWeakPtr());
65 DetachFromThread(); 69 DetachFromThread();
66 } 70 }
67 71
68 virtual ~ExternalBeginFrameSourceForTest() { 72 virtual ~ExternalBeginFrameSourceForTest() {
69 DCHECK(CalledOnValidThread()); 73 DCHECK(CalledOnValidThread());
70 } 74 }
71 75
72 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { 76 void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
73 DCHECK(CalledOnValidThread()); 77 DCHECK(CalledOnValidThread());
74 if (needs_begin_frames) { 78 if (needs_begin_frames_ == needs_begin_frames)
75 base::MessageLoop::current()->PostDelayedTask( 79 return;
76 FROM_HERE, 80 needs_begin_frames_ = needs_begin_frames;
77 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame, 81 ScheduleBeginFrameIfNeeded();
78 weak_ptr_factory_.GetWeakPtr()),
79 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_));
80 }
81 } 82 }
82 83
83 void SetClientReady() override { 84 void SetClientReady() override {
84 DCHECK(CalledOnValidThread()); 85 DCHECK(CalledOnValidThread());
85 is_ready_ = true; 86 is_ready_ = true;
86 } 87 }
87 88
88 bool is_ready() const { 89 bool is_ready() const {
89 return is_ready_; 90 return is_ready_;
90 } 91 }
91 92
92 void TestOnBeginFrame() { 93 void TestOnBeginFrame() {
93 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
94 CallOnBeginFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 95 CallOnBeginFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
96 ScheduleBeginFrameIfNeeded();
97 }
98
99 void ScheduleBeginFrameIfNeeded() {
100 test_on_begin_frame_task_.Cancel();
101 test_on_begin_frame_task_.Reset(test_on_begin_frame_closure_);
102 if (needs_begin_frames_)
103 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
104 test_on_begin_frame_task_.callback(),
105 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_));
95 } 106 }
96 107
97 private: 108 private:
98 double milliseconds_per_frame_; 109 double milliseconds_per_frame_;
99 bool is_ready_; 110 bool is_ready_;
111 bool needs_begin_frames_;
112 base::Closure test_on_begin_frame_closure_;
113 base::CancelableClosure test_on_begin_frame_task_;
100 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_; 114 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_;
101 }; 115 };
102 116
103 // Adapts ThreadProxy for test. Injects test hooks for testing. 117 // Adapts ThreadProxy for test. Injects test hooks for testing.
104 class ThreadProxyForTest : public ThreadProxy { 118 class ThreadProxyForTest : public ThreadProxy {
105 public: 119 public:
106 static scoped_ptr<Proxy> Create( 120 static scoped_ptr<Proxy> Create(
107 TestHooks* test_hooks, 121 TestHooks* test_hooks,
108 LayerTreeHost* host, 122 LayerTreeHost* host,
109 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 123 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void ScheduledActionBeginOutputSurfaceCreation() override { 165 void ScheduledActionBeginOutputSurfaceCreation() override {
152 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); 166 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
153 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); 167 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
154 } 168 }
155 169
156 void ScheduledActionPrepareTiles() override { 170 void ScheduledActionPrepareTiles() override {
157 ThreadProxy::ScheduledActionPrepareTiles(); 171 ThreadProxy::ScheduledActionPrepareTiles();
158 test_hooks_->ScheduledActionPrepareTiles(); 172 test_hooks_->ScheduledActionPrepareTiles();
159 } 173 }
160 174
175 void ScheduledActionInvalidateOutputSurface() override {
176 ThreadProxy::ScheduledActionInvalidateOutputSurface();
177 test_hooks_->ScheduledActionInvalidateOutputSurface();
178 }
179
161 ThreadProxyForTest( 180 ThreadProxyForTest(
162 TestHooks* test_hooks, 181 TestHooks* test_hooks,
163 LayerTreeHost* host, 182 LayerTreeHost* host,
164 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 183 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
165 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 184 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
166 scoped_ptr<BeginFrameSource> external_begin_frame_source) 185 scoped_ptr<BeginFrameSource> external_begin_frame_source)
167 : ThreadProxy(host, main_task_runner, 186 : ThreadProxy(host, main_task_runner,
168 impl_task_runner, 187 impl_task_runner,
169 external_begin_frame_source.Pass()), 188 external_begin_frame_source.Pass()),
170 test_hooks_(test_hooks) {} 189 test_hooks_(test_hooks) {}
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 return -1; 848 return -1;
830 } 849 }
831 850
832 void LayerTreeTest::DestroyLayerTreeHost() { 851 void LayerTreeTest::DestroyLayerTreeHost() {
833 if (layer_tree_host_ && layer_tree_host_->root_layer()) 852 if (layer_tree_host_ && layer_tree_host_->root_layer())
834 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 853 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
835 layer_tree_host_ = nullptr; 854 layer_tree_host_ = nullptr;
836 } 855 }
837 856
838 } // namespace cc 857 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698