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

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

Issue 2158973002: cc: Clean up LayerTreeTest and TestHooks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: proxy-impls: android-build Created 4 years, 5 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"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "cc/animation/animation.h" 13 #include "cc/animation/animation.h"
14 #include "cc/animation/animation_host.h" 14 #include "cc/animation/animation_host.h"
15 #include "cc/animation/element_animations.h" 15 #include "cc/animation/element_animations.h"
16 #include "cc/animation/timing_function.h" 16 #include "cc/animation/timing_function.h"
17 #include "cc/base/switches.h" 17 #include "cc/base/switches.h"
18 #include "cc/blimp/image_serialization_processor.h" 18 #include "cc/blimp/image_serialization_processor.h"
19 #include "cc/input/input_handler.h" 19 #include "cc/input/input_handler.h"
20 #include "cc/layers/layer.h" 20 #include "cc/layers/layer.h"
21 #include "cc/layers/layer_impl.h" 21 #include "cc/layers/layer_impl.h"
22 #include "cc/proto/compositor_message_to_impl.pb.h" 22 #include "cc/proto/compositor_message_to_impl.pb.h"
23 #include "cc/test/animation_test_common.h" 23 #include "cc/test/animation_test_common.h"
24 #include "cc/test/begin_frame_args_test.h" 24 #include "cc/test/begin_frame_args_test.h"
25 #include "cc/test/fake_external_begin_frame_source.h" 25 #include "cc/test/fake_external_begin_frame_source.h"
26 #include "cc/test/fake_image_serialization_processor.h" 26 #include "cc/test/fake_image_serialization_processor.h"
27 #include "cc/test/fake_layer_tree_host_client.h" 27 #include "cc/test/fake_layer_tree_host_client.h"
28 #include "cc/test/fake_output_surface.h" 28 #include "cc/test/fake_output_surface.h"
29 #include "cc/test/remote_channel_impl_for_test.h"
30 #include "cc/test/test_context_provider.h" 29 #include "cc/test/test_context_provider.h"
31 #include "cc/test/test_gpu_memory_buffer_manager.h" 30 #include "cc/test/test_gpu_memory_buffer_manager.h"
32 #include "cc/test/test_shared_bitmap_manager.h" 31 #include "cc/test/test_shared_bitmap_manager.h"
33 #include "cc/test/test_task_graph_runner.h" 32 #include "cc/test/test_task_graph_runner.h"
34 #include "cc/test/threaded_channel_for_test.h"
35 #include "cc/trees/layer_tree_host_client.h" 33 #include "cc/trees/layer_tree_host_client.h"
36 #include "cc/trees/layer_tree_host_impl.h" 34 #include "cc/trees/layer_tree_host_impl.h"
37 #include "cc/trees/layer_tree_host_single_thread_client.h" 35 #include "cc/trees/layer_tree_host_single_thread_client.h"
38 #include "cc/trees/layer_tree_impl.h" 36 #include "cc/trees/layer_tree_impl.h"
39 #include "cc/trees/proxy_impl.h" 37 #include "cc/trees/proxy_impl.h"
40 #include "cc/trees/proxy_main.h" 38 #include "cc/trees/proxy_main.h"
39 #include "cc/trees/remote_channel_impl.h"
41 #include "cc/trees/single_thread_proxy.h" 40 #include "cc/trees/single_thread_proxy.h"
42 #include "cc/trees/threaded_channel.h" 41 #include "cc/trees/threaded_channel.h"
43 #include "testing/gmock/include/gmock/gmock.h" 42 #include "testing/gmock/include/gmock/gmock.h"
44 #include "ui/gfx/geometry/size_conversions.h" 43 #include "ui/gfx/geometry/size_conversions.h"
45 44
46 namespace cc { 45 namespace cc {
47 46
48 void CreateVirtualViewportLayers(Layer* root_layer, 47 void CreateVirtualViewportLayers(Layer* root_layer,
49 scoped_refptr<Layer> outer_scroll_layer, 48 scoped_refptr<Layer> outer_scroll_layer,
50 const gfx::Size& inner_bounds, 49 const gfx::Size& inner_bounds,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const gfx::Size& scroll_bounds, 81 const gfx::Size& scroll_bounds,
83 LayerTreeHost* host) { 82 LayerTreeHost* host) {
84 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); 83 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
85 84
86 outer_viewport_scroll_layer->SetBounds(scroll_bounds); 85 outer_viewport_scroll_layer->SetBounds(scroll_bounds);
87 outer_viewport_scroll_layer->SetIsDrawable(true); 86 outer_viewport_scroll_layer->SetIsDrawable(true);
88 CreateVirtualViewportLayers(root_layer, outer_viewport_scroll_layer, 87 CreateVirtualViewportLayers(root_layer, outer_viewport_scroll_layer,
89 inner_bounds, outer_bounds, host); 88 inner_bounds, outer_bounds, host);
90 } 89 }
91 90
92 // Creates a SingleThreadProxy that notifies the supplied |test_hooks| of
93 // various actions.
94 class SingleThreadProxyForTest : public SingleThreadProxy {
95 public:
96 static std::unique_ptr<Proxy> Create(
97 TestHooks* test_hooks,
98 LayerTreeHost* host,
99 LayerTreeHostSingleThreadClient* client,
100 TaskRunnerProvider* task_runner_provider) {
101 return base::WrapUnique(new SingleThreadProxyForTest(
102 test_hooks, host, client, task_runner_provider));
103 }
104
105 ~SingleThreadProxyForTest() override {}
106
107 private:
108 SingleThreadProxyForTest(TestHooks* test_hooks,
109 LayerTreeHost* host,
110 LayerTreeHostSingleThreadClient* client,
111 TaskRunnerProvider* task_runner_provider)
112 : SingleThreadProxy(host, client, task_runner_provider),
113 test_hooks_(test_hooks) {}
114
115 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override {
116 test_hooks_->ScheduledActionWillSendBeginMainFrame();
117 SingleThreadProxy::ScheduledActionSendBeginMainFrame(args);
118 test_hooks_->ScheduledActionSendBeginMainFrame();
119 }
120
121 DrawResult ScheduledActionDrawAndSwapIfPossible() override {
122 DrawResult result =
123 SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible();
124 test_hooks_->ScheduledActionDrawAndSwapIfPossible();
125 return result;
126 }
127
128 void ScheduledActionCommit() override {
129 SingleThreadProxy::ScheduledActionCommit();
130 test_hooks_->ScheduledActionCommit();
131 }
132
133 void ScheduledActionBeginOutputSurfaceCreation() override {
134 SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation();
135 test_hooks_->ScheduledActionBeginOutputSurfaceCreation();
136 }
137
138 void ScheduledActionPrepareTiles() override {
139 SingleThreadProxy::ScheduledActionPrepareTiles();
140 test_hooks_->ScheduledActionPrepareTiles();
141 }
142
143 void ScheduledActionInvalidateOutputSurface() override {
144 SingleThreadProxy::ScheduledActionInvalidateOutputSurface();
145 test_hooks_->ScheduledActionInvalidateOutputSurface();
146 }
147
148 void SendBeginMainFrameNotExpectedSoon() override {
149 SingleThreadProxy::SendBeginMainFrameNotExpectedSoon();
150 test_hooks_->SendBeginMainFrameNotExpectedSoon();
151 }
152
153 TestHooks* test_hooks_;
154 };
155
156 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. 91 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks.
157 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { 92 class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
158 public: 93 public:
159 static std::unique_ptr<LayerTreeHostImplForTesting> Create( 94 static std::unique_ptr<LayerTreeHostImplForTesting> Create(
160 TestHooks* test_hooks, 95 TestHooks* test_hooks,
161 const LayerTreeSettings& settings, 96 const LayerTreeSettings& settings,
162 LayerTreeHostImplClient* host_impl_client, 97 LayerTreeHostImplClient* host_impl_client,
163 TaskRunnerProvider* task_runner_provider, 98 TaskRunnerProvider* task_runner_provider,
164 SharedBitmapManager* shared_bitmap_manager, 99 SharedBitmapManager* shared_bitmap_manager,
165 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 100 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void DidFinishImplFrame() override { 144 void DidFinishImplFrame() override {
210 LayerTreeHostImpl::DidFinishImplFrame(); 145 LayerTreeHostImpl::DidFinishImplFrame();
211 test_hooks_->DidFinishImplFrameOnThread(this); 146 test_hooks_->DidFinishImplFrameOnThread(this);
212 } 147 }
213 148
214 void BeginMainFrameAborted(CommitEarlyOutReason reason) override { 149 void BeginMainFrameAborted(CommitEarlyOutReason reason) override {
215 LayerTreeHostImpl::BeginMainFrameAborted(reason); 150 LayerTreeHostImpl::BeginMainFrameAborted(reason);
216 test_hooks_->BeginMainFrameAbortedOnThread(this, reason); 151 test_hooks_->BeginMainFrameAbortedOnThread(this, reason);
217 } 152 }
218 153
154 void BeginMainFrameCompleted() override {
155 LayerTreeHostImpl::BeginMainFrameCompleted();
156 test_hooks_->BeginMainFrameCompletedOnThread(this);
157 }
158
219 void BeginCommit() override { 159 void BeginCommit() override {
220 LayerTreeHostImpl::BeginCommit(); 160 LayerTreeHostImpl::BeginCommit();
221 test_hooks_->BeginCommitOnThread(this); 161 test_hooks_->BeginCommitOnThread(this);
222 } 162 }
223 163
224 void CommitComplete() override { 164 void CommitComplete() override {
225 test_hooks_->WillCommitCompleteOnThread(this); 165 test_hooks_->WillCommitCompleteOnThread(this);
226 LayerTreeHostImpl::CommitComplete(); 166 LayerTreeHostImpl::CommitComplete();
227 test_hooks_->CommitCompleteOnThread(this); 167 test_hooks_->CommitCompleteOnThread(this);
228 } 168 }
229 169
230 bool PrepareTiles() override { 170 bool PrepareTiles() override {
231 test_hooks_->WillPrepareTiles(this); 171 test_hooks_->WillPrepareTilesOnThread(this);
232 return LayerTreeHostImpl::PrepareTiles(); 172 return LayerTreeHostImpl::PrepareTiles();
233 } 173 }
234 174
235 DrawResult PrepareToDraw(FrameData* frame) override { 175 DrawResult PrepareToDraw(FrameData* frame) override {
236 DrawResult draw_result = LayerTreeHostImpl::PrepareToDraw(frame); 176 DrawResult draw_result = LayerTreeHostImpl::PrepareToDraw(frame);
237 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result); 177 return test_hooks_->PrepareToDrawOnThread(this, frame, draw_result);
238 } 178 }
239 179
240 void DrawLayers(FrameData* frame) override { 180 void DrawLayers(FrameData* frame) override {
241 LayerTreeHostImpl::DrawLayers(frame); 181 LayerTreeHostImpl::DrawLayers(frame);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 323 }
384 324
385 void DidCompleteSwapBuffers() override { 325 void DidCompleteSwapBuffers() override {
386 test_hooks_->DidCompleteSwapBuffers(); 326 test_hooks_->DidCompleteSwapBuffers();
387 } 327 }
388 328
389 void DidPostSwapBuffers() override {} 329 void DidPostSwapBuffers() override {}
390 void DidAbortSwapBuffers() override {} 330 void DidAbortSwapBuffers() override {}
391 void RequestScheduleComposite() override { test_hooks_->ScheduleComposite(); } 331 void RequestScheduleComposite() override { test_hooks_->ScheduleComposite(); }
392 void DidCompletePageScaleAnimation() override {} 332 void DidCompletePageScaleAnimation() override {}
393 void BeginMainFrameNotExpectedSoon() override {} 333 void BeginMainFrameNotExpectedSoon() override {
334 test_hooks_->BeginMainFrameNotExpectedSoon();
335 }
394 336
395 private: 337 private:
396 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) 338 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
397 : test_hooks_(test_hooks) {} 339 : test_hooks_(test_hooks) {}
398 340
399 TestHooks* test_hooks_; 341 TestHooks* test_hooks_;
400 }; 342 };
401 343
402 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 344 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
403 class LayerTreeHostForTesting : public LayerTreeHost { 345 class LayerTreeHostForTesting : public LayerTreeHost {
(...skipping 21 matching lines...) Expand all
425 367
426 params.animation_host = 368 params.animation_host =
427 AnimationHost::CreateForTesting(ThreadInstance::MAIN); 369 AnimationHost::CreateForTesting(ThreadInstance::MAIN);
428 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host( 370 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host(
429 new LayerTreeHostForTesting(test_hooks, &params, mode)); 371 new LayerTreeHostForTesting(test_hooks, &params, mode));
430 std::unique_ptr<TaskRunnerProvider> task_runner_provider = 372 std::unique_ptr<TaskRunnerProvider> task_runner_provider =
431 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 373 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
432 std::unique_ptr<Proxy> proxy; 374 std::unique_ptr<Proxy> proxy;
433 switch (mode) { 375 switch (mode) {
434 case CompositorMode::SINGLE_THREADED: 376 case CompositorMode::SINGLE_THREADED:
435 proxy = SingleThreadProxyForTest::Create(test_hooks, 377 proxy = SingleThreadProxy::Create(layer_tree_host.get(), client,
436 layer_tree_host.get(), client, 378 task_runner_provider.get());
437 task_runner_provider.get());
438 break; 379 break;
439 case CompositorMode::THREADED: 380 case CompositorMode::THREADED:
440 DCHECK(impl_task_runner.get()); 381 DCHECK(impl_task_runner.get());
441 proxy = ProxyMainForTest::CreateThreaded( 382 proxy = ProxyMain::CreateThreaded(layer_tree_host.get(),
442 test_hooks, layer_tree_host.get(), task_runner_provider.get()); 383 task_runner_provider.get());
443 break; 384 break;
444 case CompositorMode::REMOTE: 385 case CompositorMode::REMOTE:
445 DCHECK(!external_begin_frame_source); 386 DCHECK(!external_begin_frame_source);
446 // The Remote LayerTreeHost on the client has the impl task runner. 387 // The Remote LayerTreeHost on the client has the impl task runner.
447 if (task_runner_provider->HasImplThread()) { 388 if (task_runner_provider->HasImplThread()) {
448 proxy = RemoteChannelImplForTest::Create( 389 proxy = base::MakeUnique<RemoteChannelImpl>(
449 test_hooks, layer_tree_host.get(), remote_proto_channel, 390 layer_tree_host.get(), remote_proto_channel,
450 task_runner_provider.get()); 391 task_runner_provider.get());
451 } else { 392 } else {
452 proxy = ProxyMainForTest::CreateRemote( 393 proxy = ProxyMain::CreateRemote(remote_proto_channel,
453 test_hooks, remote_proto_channel, layer_tree_host.get(), 394 layer_tree_host.get(),
454 task_runner_provider.get()); 395 task_runner_provider.get());
455 396
456 // The LayerTreeHost on the server will never have an output surface. 397 // The LayerTreeHost on the server will never have an output surface.
457 // Set output_surface_lost_ to false by default. 398 // Set output_surface_lost_ to false by default.
458 layer_tree_host->SetOutputSurfaceLostForTesting(false); 399 layer_tree_host->SetOutputSurfaceLostForTesting(false);
459 } 400 }
460 break; 401 break;
461 } 402 }
462 layer_tree_host->InitializeForTesting( 403 layer_tree_host->InitializeForTesting(
463 std::move(task_runner_provider), std::move(proxy), 404 std::move(task_runner_provider), std::move(proxy),
464 std::move(external_begin_frame_source)); 405 std::move(external_begin_frame_source));
465 return layer_tree_host; 406 return layer_tree_host;
466 } 407 }
467 408
468 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( 409 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
469 LayerTreeHostImplClient* host_impl_client) override { 410 LayerTreeHostImplClient* host_impl_client) override {
470 return LayerTreeHostImplForTesting::Create( 411 return LayerTreeHostImplForTesting::Create(
471 test_hooks_, settings(), host_impl_client, task_runner_provider(), 412 test_hooks_, settings(), host_impl_client, task_runner_provider(),
472 shared_bitmap_manager(), gpu_memory_buffer_manager(), 413 shared_bitmap_manager(), gpu_memory_buffer_manager(),
473 task_graph_runner(), rendering_stats_instrumentation()); 414 task_graph_runner(), rendering_stats_instrumentation());
474 } 415 }
475 416
476 void SetNeedsCommit() override { 417 void SetNeedsCommit() override {
477 if (!test_started_) 418 if (!test_started_)
478 return; 419 return;
420 test_hooks_->DidSetNeedsCommit();
enne (OOO) 2016/07/18 21:48:02 What is this used for?
danakj 2016/07/18 23:20:10 I just added this cuz I added it below. <_<
danakj 2016/07/19 00:56:24 Removed
479 LayerTreeHost::SetNeedsCommit(); 421 LayerTreeHost::SetNeedsCommit();
480 } 422 }
481 423
482 void SetNeedsUpdateLayers() override { 424 void SetNeedsUpdateLayers() override {
483 if (!test_started_) 425 if (!test_started_)
484 return; 426 return;
427 test_hooks_->DidSetNeedsUpdateLayers();
enne (OOO) 2016/07/18 21:48:02 This looks like it's used by only one test. Is it
danakj 2016/07/18 23:20:10 That test is checking that layer_tree_host()->Appl
danakj 2016/07/18 23:24:11 It could also maybe not be a LayerTreeTest and jus
danakj 2016/07/19 00:56:24 Removed along with the test since it is covered by
485 LayerTreeHost::SetNeedsUpdateLayers(); 428 LayerTreeHost::SetNeedsUpdateLayers();
486 } 429 }
487 430
488 void set_test_started(bool started) { test_started_ = started; } 431 void set_test_started(bool started) { test_started_ = started; }
489 432
490 private: 433 private:
491 LayerTreeHostForTesting(TestHooks* test_hooks, 434 LayerTreeHostForTesting(TestHooks* test_hooks,
492 LayerTreeHost::InitParams* params, 435 LayerTreeHost::InitParams* params,
493 CompositorMode mode) 436 CompositorMode mode)
494 : LayerTreeHost(params, mode), 437 : LayerTreeHost(params, mode),
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return layer_tree_host_.get(); 929 return layer_tree_host_.get();
987 } 930 }
988 931
989 LayerTreeHost* LayerTreeTest::remote_client_layer_tree_host() { 932 LayerTreeHost* LayerTreeTest::remote_client_layer_tree_host() {
990 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() || 933 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() ||
991 task_runner_provider()->IsMainThreadBlocked()); 934 task_runner_provider()->IsMainThreadBlocked());
992 DCHECK(IsRemoteTest()); 935 DCHECK(IsRemoteTest());
993 return remote_client_layer_tree_host_.get(); 936 return remote_client_layer_tree_host_.get();
994 } 937 }
995 938
996 ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const {
997 DCHECK(HasImplThread());
998 return static_cast<ProxyMainForTest*>(proxy());
999 }
1000
1001 ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const {
1002 DCHECK(HasImplThread());
1003
1004 if (IsRemoteTest()) {
1005 return GetRemoteChannelImplForTest()->proxy_impl_for_test();
1006 }
1007
1008 ProxyImplForTest* proxy_impl_for_test =
1009 GetThreadedChannelForTest()->proxy_impl_for_test();
1010
1011 // We check for null ProxyImpl since ProxyImpl exists in the ThreadedChannel
1012 // only after it is initialized.
1013 DCHECK(proxy_impl_for_test);
1014 return proxy_impl_for_test;
1015 }
1016
1017 ThreadedChannelForTest* LayerTreeTest::GetThreadedChannelForTest() const {
1018 DCHECK(mode_ == CompositorMode::THREADED);
1019
1020 return GetProxyMainForTest()->threaded_channel_for_test();
1021 }
1022
1023 RemoteChannelImplForTest* LayerTreeTest::GetRemoteChannelImplForTest() const {
1024 DCHECK(IsRemoteTest());
1025 DCHECK(remote_client_layer_tree_host_);
1026
1027 return static_cast<RemoteChannelImplForTest*>(
1028 remote_client_layer_tree_host_->proxy());
1029 }
1030
1031 } // namespace cc 939 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698