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

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

Issue 2717553005: cc: Glue LTHI and Scheduler changes for checker-imaging. (Closed)
Patch Set: .. Created 3 years, 9 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
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 "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. 87 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
88 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { 88 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
89 public: 89 public:
90 static std::unique_ptr<LayerTreeHostImplForTesting> Create( 90 static std::unique_ptr<LayerTreeHostImplForTesting> Create(
91 TestHooks* test_hooks, 91 TestHooks* test_hooks,
92 const LayerTreeSettings& settings, 92 const LayerTreeSettings& settings,
93 LayerTreeHostImplClient* host_impl_client, 93 LayerTreeHostImplClient* host_impl_client,
94 TaskRunnerProvider* task_runner_provider, 94 TaskRunnerProvider* task_runner_provider,
95 TaskGraphRunner* task_graph_runner, 95 TaskGraphRunner* task_graph_runner,
96 RenderingStatsInstrumentation* stats_instrumentation) { 96 RenderingStatsInstrumentation* stats_instrumentation,
97 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner) {
97 return base::WrapUnique(new LayerTreeHostImplForTesting( 98 return base::WrapUnique(new LayerTreeHostImplForTesting(
98 test_hooks, settings, host_impl_client, task_runner_provider, 99 test_hooks, settings, host_impl_client, task_runner_provider,
99 task_graph_runner, stats_instrumentation)); 100 task_graph_runner, stats_instrumentation,
101 std::move(image_worker_task_runner)));
100 } 102 }
101 103
102 protected: 104 protected:
103 LayerTreeHostImplForTesting( 105 LayerTreeHostImplForTesting(
104 TestHooks* test_hooks, 106 TestHooks* test_hooks,
105 const LayerTreeSettings& settings, 107 const LayerTreeSettings& settings,
106 LayerTreeHostImplClient* host_impl_client, 108 LayerTreeHostImplClient* host_impl_client,
107 TaskRunnerProvider* task_runner_provider, 109 TaskRunnerProvider* task_runner_provider,
108 TaskGraphRunner* task_graph_runner, 110 TaskGraphRunner* task_graph_runner,
109 RenderingStatsInstrumentation* stats_instrumentation) 111 RenderingStatsInstrumentation* stats_instrumentation,
112 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner)
110 : LayerTreeHostImpl(settings, 113 : LayerTreeHostImpl(settings,
111 host_impl_client, 114 host_impl_client,
112 task_runner_provider, 115 task_runner_provider,
113 stats_instrumentation, 116 stats_instrumentation,
114 task_graph_runner, 117 task_graph_runner,
115 AnimationHost::CreateForTesting(ThreadInstance::IMPL), 118 AnimationHost::CreateForTesting(ThreadInstance::IMPL),
116 0, 119 0,
117 nullptr), 120 std::move(image_worker_task_runner)),
118 test_hooks_(test_hooks), 121 test_hooks_(test_hooks),
119 block_notify_ready_to_activate_for_testing_(false), 122 block_notify_ready_to_activate_for_testing_(false),
120 notify_ready_to_activate_was_blocked_(false) {} 123 notify_ready_to_activate_was_blocked_(false) {}
121 124
122 void CreateResourceAndRasterBufferProvider( 125 void CreateResourceAndRasterBufferProvider(
123 std::unique_ptr<RasterBufferProvider>* raster_buffer_provider, 126 std::unique_ptr<RasterBufferProvider>* raster_buffer_provider,
124 std::unique_ptr<ResourcePool>* resource_pool) override { 127 std::unique_ptr<ResourcePool>* resource_pool) override {
125 test_hooks_->CreateResourceAndRasterBufferProvider( 128 test_hooks_->CreateResourceAndRasterBufferProvider(
126 this, raster_buffer_provider, resource_pool); 129 this, raster_buffer_provider, resource_pool);
127 } 130 }
128 131
129 void WillBeginImplFrame(const BeginFrameArgs& args) override { 132 void WillBeginImplFrame(const BeginFrameArgs& args) override {
130 LayerTreeHostImpl::WillBeginImplFrame(args); 133 LayerTreeHostImpl::WillBeginImplFrame(args);
131 test_hooks_->WillBeginImplFrameOnThread(this, args); 134 test_hooks_->WillBeginImplFrameOnThread(this, args);
132 } 135 }
133 136
134 void DidFinishImplFrame() override { 137 void DidFinishImplFrame() override {
135 LayerTreeHostImpl::DidFinishImplFrame(); 138 LayerTreeHostImpl::DidFinishImplFrame();
136 test_hooks_->DidFinishImplFrameOnThread(this); 139 test_hooks_->DidFinishImplFrameOnThread(this);
137 } 140 }
138 141
142 void DidSendBeginMainFrameForTesting() override {
143 LayerTreeHostImpl::DidSendBeginMainFrameForTesting();
144 test_hooks_->DidSendBeginMainFrameOnThread(this);
145 }
146
139 void BeginMainFrameAborted( 147 void BeginMainFrameAborted(
140 CommitEarlyOutReason reason, 148 CommitEarlyOutReason reason,
141 std::vector<std::unique_ptr<SwapPromise>> swap_promises) override { 149 std::vector<std::unique_ptr<SwapPromise>> swap_promises) override {
142 LayerTreeHostImpl::BeginMainFrameAborted(reason, std::move(swap_promises)); 150 LayerTreeHostImpl::BeginMainFrameAborted(reason, std::move(swap_promises));
143 test_hooks_->BeginMainFrameAbortedOnThread(this, reason); 151 test_hooks_->BeginMainFrameAbortedOnThread(this, reason);
144 } 152 }
145 153
146 void ReadyToCommit() override { 154 void ReadyToCommit() override {
147 LayerTreeHostImpl::ReadyToCommit(); 155 LayerTreeHostImpl::ReadyToCommit();
148 test_hooks_->ReadyToCommitOnThread(this); 156 test_hooks_->ReadyToCommitOnThread(this);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 block_notify_ready_to_activate_for_testing_ = block; 209 block_notify_ready_to_activate_for_testing_ = block;
202 if (!block && notify_ready_to_activate_was_blocked_) { 210 if (!block && notify_ready_to_activate_was_blocked_) {
203 task_runner_provider_->ImplThreadTaskRunner()->PostTask( 211 task_runner_provider_->ImplThreadTaskRunner()->PostTask(
204 FROM_HERE, 212 FROM_HERE,
205 base::Bind(&LayerTreeHostImplForTesting::NotifyReadyToActivate, 213 base::Bind(&LayerTreeHostImplForTesting::NotifyReadyToActivate,
206 base::Unretained(this))); 214 base::Unretained(this)));
207 notify_ready_to_activate_was_blocked_ = false; 215 notify_ready_to_activate_was_blocked_ = false;
208 } 216 }
209 } 217 }
210 218
219 void BlockImplSideInvalidationRequestsForTesting(bool block) override {
220 block_impl_side_invalidation_ = block;
221 if (!block_impl_side_invalidation_ && impl_side_invalidation_was_blocked_) {
222 RequestImplSideInvalidation();
223 }
224 }
225
211 void ActivateSyncTree() override { 226 void ActivateSyncTree() override {
212 test_hooks_->WillActivateTreeOnThread(this); 227 test_hooks_->WillActivateTreeOnThread(this);
213 LayerTreeHostImpl::ActivateSyncTree(); 228 LayerTreeHostImpl::ActivateSyncTree();
214 DCHECK(!pending_tree()); 229 DCHECK(!pending_tree());
215 test_hooks_->DidActivateTreeOnThread(this); 230 test_hooks_->DidActivateTreeOnThread(this);
216 } 231 }
217 232
218 bool InitializeRenderer(CompositorFrameSink* compositor_frame_sink) override { 233 bool InitializeRenderer(CompositorFrameSink* compositor_frame_sink) override {
219 bool success = LayerTreeHostImpl::InitializeRenderer(compositor_frame_sink); 234 bool success = LayerTreeHostImpl::InitializeRenderer(compositor_frame_sink);
220 test_hooks_->InitializedRendererOnThread(this, success); 235 test_hooks_->InitializedRendererOnThread(this, success);
(...skipping 22 matching lines...) Expand all
243 } 258 }
244 } 259 }
245 test_hooks_->UpdateAnimationState(this, has_unfinished_animation); 260 test_hooks_->UpdateAnimationState(this, has_unfinished_animation);
246 } 261 }
247 262
248 void NotifyTileStateChanged(const Tile* tile) override { 263 void NotifyTileStateChanged(const Tile* tile) override {
249 LayerTreeHostImpl::NotifyTileStateChanged(tile); 264 LayerTreeHostImpl::NotifyTileStateChanged(tile);
250 test_hooks_->NotifyTileStateChangedOnThread(this, tile); 265 test_hooks_->NotifyTileStateChangedOnThread(this, tile);
251 } 266 }
252 267
268 void InvalidateContentOnImplSide() override {
269 LayerTreeHostImpl::InvalidateContentOnImplSide();
270 test_hooks_->DidInvalidateContentOnImplSide(this);
271 }
272
273 void RequestImplSideInvalidation() override {
274 if (block_impl_side_invalidation_) {
275 impl_side_invalidation_was_blocked_ = true;
276 return;
277 }
278
279 impl_side_invalidation_was_blocked_ = false;
280 LayerTreeHostImpl::RequestImplSideInvalidation();
281 test_hooks_->DidRequestImplSideInvalidation(this);
282 }
283
253 AnimationHost* animation_host() const { 284 AnimationHost* animation_host() const {
254 return static_cast<AnimationHost*>(mutator_host()); 285 return static_cast<AnimationHost*>(mutator_host());
255 } 286 }
256 287
257 private: 288 private:
258 TestHooks* test_hooks_; 289 TestHooks* test_hooks_;
259 bool block_notify_ready_to_activate_for_testing_; 290 bool block_notify_ready_to_activate_for_testing_;
vmpstr 2017/02/27 21:16:57 while here, can you also initialize the rest of th
Khushal 2017/02/28 00:39:49 Done.
260 bool notify_ready_to_activate_was_blocked_; 291 bool notify_ready_to_activate_was_blocked_;
292
293 bool block_impl_side_invalidation_ = false;
294 bool impl_side_invalidation_was_blocked_ = false;
261 }; 295 };
262 296
263 // Implementation of LayerTreeHost callback interface. 297 // Implementation of LayerTreeHost callback interface.
264 class LayerTreeHostClientForTesting : public LayerTreeHostClient, 298 class LayerTreeHostClientForTesting : public LayerTreeHostClient,
265 public LayerTreeHostSingleThreadClient { 299 public LayerTreeHostSingleThreadClient {
266 public: 300 public:
267 static std::unique_ptr<LayerTreeHostClientForTesting> Create( 301 static std::unique_ptr<LayerTreeHostClientForTesting> Create(
268 TestHooks* test_hooks) { 302 TestHooks* test_hooks) {
269 return base::WrapUnique(new LayerTreeHostClientForTesting(test_hooks)); 303 return base::WrapUnique(new LayerTreeHostClientForTesting(test_hooks));
270 } 304 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 public: 369 public:
336 static std::unique_ptr<LayerTreeHostForTesting> Create( 370 static std::unique_ptr<LayerTreeHostForTesting> Create(
337 TestHooks* test_hooks, 371 TestHooks* test_hooks,
338 CompositorMode mode, 372 CompositorMode mode,
339 LayerTreeHostClient* client, 373 LayerTreeHostClient* client,
340 LayerTreeHostSingleThreadClient* single_thread_client, 374 LayerTreeHostSingleThreadClient* single_thread_client,
341 TaskGraphRunner* task_graph_runner, 375 TaskGraphRunner* task_graph_runner,
342 const LayerTreeSettings& settings, 376 const LayerTreeSettings& settings,
343 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 377 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
344 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 378 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
379 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner,
345 MutatorHost* mutator_host) { 380 MutatorHost* mutator_host) {
346 LayerTreeHost::InitParams params; 381 LayerTreeHost::InitParams params;
347 params.client = client; 382 params.client = client;
348 params.task_graph_runner = task_graph_runner; 383 params.task_graph_runner = task_graph_runner;
349 params.settings = &settings; 384 params.settings = &settings;
350 params.mutator_host = mutator_host; 385 params.mutator_host = mutator_host;
386 params.image_worker_task_runner = std::move(image_worker_task_runner);
351 387
352 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host( 388 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host(
353 new LayerTreeHostForTesting(test_hooks, &params, mode)); 389 new LayerTreeHostForTesting(test_hooks, &params, mode));
354 std::unique_ptr<TaskRunnerProvider> task_runner_provider = 390 std::unique_ptr<TaskRunnerProvider> task_runner_provider =
355 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 391 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
356 std::unique_ptr<Proxy> proxy; 392 std::unique_ptr<Proxy> proxy;
357 switch (mode) { 393 switch (mode) {
358 case CompositorMode::SINGLE_THREADED: 394 case CompositorMode::SINGLE_THREADED:
359 proxy = SingleThreadProxy::Create(layer_tree_host.get(), 395 proxy = SingleThreadProxy::Create(layer_tree_host.get(),
360 single_thread_client, 396 single_thread_client,
361 task_runner_provider.get()); 397 task_runner_provider.get());
362 break; 398 break;
363 case CompositorMode::THREADED: 399 case CompositorMode::THREADED:
364 DCHECK(impl_task_runner.get()); 400 DCHECK(impl_task_runner.get());
365 proxy = base::MakeUnique<ProxyMain>(layer_tree_host.get(), 401 proxy = base::MakeUnique<ProxyMain>(layer_tree_host.get(),
366 task_runner_provider.get()); 402 task_runner_provider.get());
367 break; 403 break;
368 } 404 }
369 layer_tree_host->InitializeForTesting(std::move(task_runner_provider), 405 layer_tree_host->InitializeForTesting(std::move(task_runner_provider),
370 std::move(proxy)); 406 std::move(proxy));
371 return layer_tree_host; 407 return layer_tree_host;
372 } 408 }
373 409
374 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( 410 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
375 LayerTreeHostImplClient* host_impl_client) override { 411 LayerTreeHostImplClient* host_impl_client) override {
376 std::unique_ptr<LayerTreeHostImpl> host_impl = 412 std::unique_ptr<LayerTreeHostImpl> host_impl =
377 LayerTreeHostImplForTesting::Create( 413 LayerTreeHostImplForTesting::Create(
378 test_hooks_, GetSettings(), host_impl_client, 414 test_hooks_, GetSettings(), host_impl_client,
379 GetTaskRunnerProvider(), task_graph_runner(), 415 GetTaskRunnerProvider(), task_graph_runner(),
380 rendering_stats_instrumentation()); 416 rendering_stats_instrumentation(), image_worker_task_runner_);
381 input_handler_weak_ptr_ = host_impl->AsWeakPtr(); 417 input_handler_weak_ptr_ = host_impl->AsWeakPtr();
382 return host_impl; 418 return host_impl;
383 } 419 }
384 420
385 void SetNeedsCommit() override { 421 void SetNeedsCommit() override {
386 if (!test_started_) 422 if (!test_started_)
387 return; 423 return;
388 LayerTreeHost::SetNeedsCommit(); 424 LayerTreeHost::SetNeedsCommit();
389 } 425 }
390 426
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 624
589 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = 625 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner =
590 base::ThreadTaskRunnerHandle::Get(); 626 base::ThreadTaskRunnerHandle::Get();
591 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner = 627 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner =
592 impl_thread_ ? impl_thread_->task_runner() : nullptr; 628 impl_thread_ ? impl_thread_->task_runner() : nullptr;
593 629
594 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 630 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
595 631
596 layer_tree_host_ = LayerTreeHostForTesting::Create( 632 layer_tree_host_ = LayerTreeHostForTesting::Create(
597 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(), 633 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(),
598 settings_, main_task_runner, impl_task_runner, animation_host_.get()); 634 settings_, main_task_runner, impl_task_runner,
635 image_worker_->task_runner(), animation_host_.get());
599 ASSERT_TRUE(layer_tree_host_); 636 ASSERT_TRUE(layer_tree_host_);
600 637
601 main_task_runner_ = 638 main_task_runner_ =
602 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner(); 639 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner();
603 impl_task_runner_ = 640 impl_task_runner_ =
604 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner(); 641 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner();
605 if (!impl_task_runner_) { 642 if (!impl_task_runner_) {
606 // For tests, if there's no impl thread, make things easier by just giving 643 // For tests, if there's no impl thread, make things easier by just giving
607 // the main thread task runner. 644 // the main thread task runner.
608 impl_task_runner_ = main_task_runner_; 645 impl_task_runner_ = main_task_runner_;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 layer_tree_host_->SetNextCommitWaitsForActivation(); 771 layer_tree_host_->SetNextCommitWaitsForActivation();
735 } 772 }
736 773
737 void LayerTreeTest::RunTest(CompositorMode mode) { 774 void LayerTreeTest::RunTest(CompositorMode mode) {
738 mode_ = mode; 775 mode_ = mode;
739 if (mode_ == CompositorMode::THREADED) { 776 if (mode_ == CompositorMode::THREADED) {
740 impl_thread_.reset(new base::Thread("Compositor")); 777 impl_thread_.reset(new base::Thread("Compositor"));
741 ASSERT_TRUE(impl_thread_->Start()); 778 ASSERT_TRUE(impl_thread_->Start());
742 } 779 }
743 780
781 image_worker_ = base::MakeUnique<base::Thread>("ImageWorker");
782 ASSERT_TRUE(image_worker_->Start());
783
744 shared_bitmap_manager_.reset(new TestSharedBitmapManager); 784 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
745 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); 785 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager);
746 task_graph_runner_.reset(new TestTaskGraphRunner); 786 task_graph_runner_.reset(new TestTaskGraphRunner);
747 787
748 // Spend less time waiting for BeginFrame because the output is 788 // Spend less time waiting for BeginFrame because the output is
749 // mocked out. 789 // mocked out.
750 settings_.renderer_settings.refresh_rate = 200.0; 790 settings_.renderer_settings.refresh_rate = 200.0;
751 settings_.background_animation_rate = 200.0; 791 settings_.background_animation_rate = 200.0;
752 // Disable latency recovery to make the scheduler more predictable in its 792 // Disable latency recovery to make the scheduler more predictable in its
753 // actions and less dependent on timings to make decisions. 793 // actions and less dependent on timings to make decisions.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 DCHECK(task_runner_provider()->IsMainThread() || 871 DCHECK(task_runner_provider()->IsMainThread() ||
832 task_runner_provider()->IsMainThreadBlocked()); 872 task_runner_provider()->IsMainThreadBlocked());
833 return layer_tree_host_.get(); 873 return layer_tree_host_.get();
834 } 874 }
835 875
836 Proxy* LayerTreeTest::proxy() { 876 Proxy* LayerTreeTest::proxy() {
837 return layer_tree_host() ? layer_tree_host()->proxy() : NULL; 877 return layer_tree_host() ? layer_tree_host()->proxy() : NULL;
838 } 878 }
839 879
840 } // namespace cc 880 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | cc/test/test_hooks.h » ('j') | cc/trees/proxy_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698