| OLD | NEW |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return base::TimeDelta::FromMilliseconds(16); | 47 return base::TimeDelta::FromMilliseconds(16); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Adapts ThreadProxy for test. Injects test hooks for testing. | 50 // Adapts ThreadProxy for test. Injects test hooks for testing. |
| 51 class ThreadProxyForTest : public ThreadProxy { | 51 class ThreadProxyForTest : public ThreadProxy { |
| 52 public: | 52 public: |
| 53 static scoped_ptr<Proxy> Create( | 53 static scoped_ptr<Proxy> Create( |
| 54 TestHooks* test_hooks, | 54 TestHooks* test_hooks, |
| 55 LayerTreeHost* host, | 55 LayerTreeHost* host, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 57 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 58 scoped_ptr<ExternalBeginFrameSource> external_begin_frame_source) { |
| 58 return make_scoped_ptr(new ThreadProxyForTest( | 59 return make_scoped_ptr(new ThreadProxyForTest( |
| 59 test_hooks, host, main_task_runner, impl_task_runner)); | 60 test_hooks, |
| 61 host, |
| 62 main_task_runner, |
| 63 impl_task_runner, |
| 64 external_begin_frame_source.Pass())); |
| 60 } | 65 } |
| 61 | 66 |
| 62 virtual ~ThreadProxyForTest() {} | 67 virtual ~ThreadProxyForTest() {} |
| 63 | 68 |
| 64 void test() { | 69 void test() { |
| 65 test_hooks_->Layout(); | 70 test_hooks_->Layout(); |
| 66 } | 71 } |
| 67 | 72 |
| 68 private: | 73 private: |
| 69 TestHooks* test_hooks_; | 74 TestHooks* test_hooks_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 | 97 |
| 93 virtual void ScheduledActionBeginOutputSurfaceCreation() override { | 98 virtual void ScheduledActionBeginOutputSurfaceCreation() override { |
| 94 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); | 99 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
| 95 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); | 100 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
| 96 } | 101 } |
| 97 | 102 |
| 98 ThreadProxyForTest( | 103 ThreadProxyForTest( |
| 99 TestHooks* test_hooks, | 104 TestHooks* test_hooks, |
| 100 LayerTreeHost* host, | 105 LayerTreeHost* host, |
| 101 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 106 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 102 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 107 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 103 : ThreadProxy(host, main_task_runner, impl_task_runner), | 108 scoped_ptr<ExternalBeginFrameSource> external_begin_frame_source) |
| 109 : ThreadProxy(host, main_task_runner, |
| 110 impl_task_runner, |
| 111 external_begin_frame_source.Pass()), |
| 104 test_hooks_(test_hooks) {} | 112 test_hooks_(test_hooks) {} |
| 105 }; | 113 }; |
| 106 | 114 |
| 107 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 115 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
| 108 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 116 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| 109 public: | 117 public: |
| 110 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 118 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
| 111 TestHooks* test_hooks, | 119 TestHooks* test_hooks, |
| 112 const LayerTreeSettings& settings, | 120 const LayerTreeSettings& settings, |
| 113 LayerTreeHostImplClient* host_impl_client, | 121 LayerTreeHostImplClient* host_impl_client, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 }; | 343 }; |
| 336 | 344 |
| 337 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 345 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
| 338 class LayerTreeHostForTesting : public LayerTreeHost { | 346 class LayerTreeHostForTesting : public LayerTreeHost { |
| 339 public: | 347 public: |
| 340 static scoped_ptr<LayerTreeHostForTesting> Create( | 348 static scoped_ptr<LayerTreeHostForTesting> Create( |
| 341 TestHooks* test_hooks, | 349 TestHooks* test_hooks, |
| 342 LayerTreeHostClientForTesting* client, | 350 LayerTreeHostClientForTesting* client, |
| 343 const LayerTreeSettings& settings, | 351 const LayerTreeSettings& settings, |
| 344 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 352 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 345 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 353 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 354 scoped_ptr<ExternalBeginFrameSource> external_begin_frame_source) { |
| 346 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 355 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
| 347 new LayerTreeHostForTesting(test_hooks, client, settings)); | 356 new LayerTreeHostForTesting(test_hooks, client, settings)); |
| 348 if (impl_task_runner.get()) { | 357 if (impl_task_runner.get()) { |
| 349 layer_tree_host->InitializeForTesting( | 358 layer_tree_host->InitializeForTesting( |
| 350 ThreadProxyForTest::Create(test_hooks, | 359 ThreadProxyForTest::Create(test_hooks, |
| 351 layer_tree_host.get(), | 360 layer_tree_host.get(), |
| 352 main_task_runner, | 361 main_task_runner, |
| 353 impl_task_runner)); | 362 impl_task_runner, |
| 363 external_begin_frame_source.Pass())); |
| 354 } else { | 364 } else { |
| 355 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 365 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( |
| 356 layer_tree_host.get(), client, main_task_runner)); | 366 layer_tree_host.get(), |
| 367 client, |
| 368 main_task_runner, |
| 369 external_begin_frame_source.Pass())); |
| 357 } | 370 } |
| 358 return layer_tree_host.Pass(); | 371 return layer_tree_host.Pass(); |
| 359 } | 372 } |
| 360 | 373 |
| 361 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 374 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
| 362 LayerTreeHostImplClient* host_impl_client) override { | 375 LayerTreeHostImplClient* host_impl_client) override { |
| 363 return LayerTreeHostImplForTesting::Create( | 376 return LayerTreeHostImplForTesting::Create( |
| 364 test_hooks_, | 377 test_hooks_, |
| 365 settings(), | 378 settings(), |
| 366 host_impl_client, | 379 host_impl_client, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 528 |
| 516 void LayerTreeTest::DoBeginTest() { | 529 void LayerTreeTest::DoBeginTest() { |
| 517 client_ = LayerTreeHostClientForTesting::Create(this); | 530 client_ = LayerTreeHostClientForTesting::Create(this); |
| 518 | 531 |
| 519 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); | 532 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); |
| 520 layer_tree_host_ = LayerTreeHostForTesting::Create( | 533 layer_tree_host_ = LayerTreeHostForTesting::Create( |
| 521 this, | 534 this, |
| 522 client_.get(), | 535 client_.get(), |
| 523 settings_, | 536 settings_, |
| 524 base::MessageLoopProxy::current(), | 537 base::MessageLoopProxy::current(), |
| 525 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); | 538 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL, |
| 539 scoped_ptr<ExternalBeginFrameSource>()); |
| 526 ASSERT_TRUE(layer_tree_host_); | 540 ASSERT_TRUE(layer_tree_host_); |
| 527 | 541 |
| 528 started_ = true; | 542 started_ = true; |
| 529 beginning_ = true; | 543 beginning_ = true; |
| 530 SetupTree(); | 544 SetupTree(); |
| 531 WillBeginTest(); | 545 WillBeginTest(); |
| 532 BeginTest(); | 546 BeginTest(); |
| 533 beginning_ = false; | 547 beginning_ = false; |
| 534 if (end_when_begin_returns_) | 548 if (end_when_begin_returns_) |
| 535 RealEndTest(); | 549 RealEndTest(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 return -1; | 724 return -1; |
| 711 } | 725 } |
| 712 | 726 |
| 713 void LayerTreeTest::DestroyLayerTreeHost() { | 727 void LayerTreeTest::DestroyLayerTreeHost() { |
| 714 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 728 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
| 715 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 729 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
| 716 layer_tree_host_ = nullptr; | 730 layer_tree_host_ = nullptr; |
| 717 } | 731 } |
| 718 | 732 |
| 719 } // namespace cc | 733 } // namespace cc |
| OLD | NEW |