| 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" |
| 11 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
| 12 #include "cc/base/switches.h" | 12 #include "cc/base/switches.h" |
| 13 #include "cc/input/input_handler.h" | 13 #include "cc/input/input_handler.h" |
| 14 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
| 15 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
| 17 #include "cc/test/animation_test_common.h" | 17 #include "cc/test/animation_test_common.h" |
| 18 #include "cc/test/begin_frame_args_test.h" |
| 18 #include "cc/test/fake_layer_tree_host_client.h" | 19 #include "cc/test/fake_layer_tree_host_client.h" |
| 19 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
| 20 #include "cc/test/test_context_provider.h" | 21 #include "cc/test/test_context_provider.h" |
| 21 #include "cc/test/test_gpu_memory_buffer_manager.h" | 22 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 22 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
| 23 #include "cc/test/tiled_layer_test_common.h" | 24 #include "cc/test/tiled_layer_test_common.h" |
| 24 #include "cc/trees/layer_tree_host_client.h" | 25 #include "cc/trees/layer_tree_host_client.h" |
| 25 #include "cc/trees/layer_tree_host_impl.h" | 26 #include "cc/trees/layer_tree_host_impl.h" |
| 26 #include "cc/trees/layer_tree_host_single_thread_client.h" | 27 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 27 #include "cc/trees/layer_tree_impl.h" | 28 #include "cc/trees/layer_tree_impl.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 LayerTreeHostImpl* host_impl, | 42 LayerTreeHostImpl* host_impl, |
| 42 LayerTreeHostImpl::FrameData* frame_data, | 43 LayerTreeHostImpl::FrameData* frame_data, |
| 43 DrawResult draw_result) { | 44 DrawResult draw_result) { |
| 44 return draw_result; | 45 return draw_result; |
| 45 } | 46 } |
| 46 | 47 |
| 47 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { | 48 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { |
| 48 return base::TimeDelta::FromMilliseconds(16); | 49 return base::TimeDelta::FromMilliseconds(16); |
| 49 } | 50 } |
| 50 | 51 |
| 52 class ExternalBeginFrameSourceForTest |
| 53 : public BeginFrameSourceMixIn, |
| 54 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 55 public: |
| 56 explicit ExternalBeginFrameSourceForTest(double refresh_rate) |
| 57 : milliseconds_per_frame_(1000.0 / refresh_rate), |
| 58 weak_ptr_factory_(this) { |
| 59 DetachFromThread(); |
| 60 } |
| 61 |
| 62 virtual ~ExternalBeginFrameSourceForTest() { |
| 63 DCHECK(CalledOnValidThread()); |
| 64 } |
| 65 |
| 66 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 67 DCHECK(CalledOnValidThread()); |
| 68 if (needs_begin_frames) { |
| 69 base::MessageLoop::current()->PostDelayedTask( |
| 70 FROM_HERE, |
| 71 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame, |
| 72 weak_ptr_factory_.GetWeakPtr()), |
| 73 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_)); |
| 74 } |
| 75 } |
| 76 |
| 77 void TestOnBeginFrame() { |
| 78 DCHECK(CalledOnValidThread()); |
| 79 CallOnBeginFrame(CreateBeginFrameArgsForTesting()); |
| 80 } |
| 81 |
| 82 private: |
| 83 double milliseconds_per_frame_; |
| 84 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_; |
| 85 }; |
| 86 |
| 51 // Adapts ThreadProxy for test. Injects test hooks for testing. | 87 // Adapts ThreadProxy for test. Injects test hooks for testing. |
| 52 class ThreadProxyForTest : public ThreadProxy { | 88 class ThreadProxyForTest : public ThreadProxy { |
| 53 public: | 89 public: |
| 54 static scoped_ptr<Proxy> Create( | 90 static scoped_ptr<Proxy> Create( |
| 55 TestHooks* test_hooks, | 91 TestHooks* test_hooks, |
| 56 LayerTreeHost* host, | 92 LayerTreeHost* host, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 93 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 58 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 94 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 95 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 59 return make_scoped_ptr(new ThreadProxyForTest( | 96 return make_scoped_ptr(new ThreadProxyForTest( |
| 60 test_hooks, host, main_task_runner, impl_task_runner)); | 97 test_hooks, |
| 98 host, |
| 99 main_task_runner, |
| 100 impl_task_runner, |
| 101 external_begin_frame_source.Pass())); |
| 61 } | 102 } |
| 62 | 103 |
| 63 ~ThreadProxyForTest() override {} | 104 ~ThreadProxyForTest() override {} |
| 64 | 105 |
| 65 void test() { | 106 void test() { |
| 66 test_hooks_->Layout(); | 107 test_hooks_->Layout(); |
| 67 } | 108 } |
| 68 | 109 |
| 69 private: | 110 private: |
| 70 TestHooks* test_hooks_; | 111 TestHooks* test_hooks_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 | 134 |
| 94 void ScheduledActionBeginOutputSurfaceCreation() override { | 135 void ScheduledActionBeginOutputSurfaceCreation() override { |
| 95 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); | 136 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
| 96 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); | 137 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
| 97 } | 138 } |
| 98 | 139 |
| 99 ThreadProxyForTest( | 140 ThreadProxyForTest( |
| 100 TestHooks* test_hooks, | 141 TestHooks* test_hooks, |
| 101 LayerTreeHost* host, | 142 LayerTreeHost* host, |
| 102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 143 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 103 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 144 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 104 : ThreadProxy(host, main_task_runner, impl_task_runner), | 145 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 146 : ThreadProxy(host, main_task_runner, |
| 147 impl_task_runner, |
| 148 external_begin_frame_source.Pass()), |
| 105 test_hooks_(test_hooks) {} | 149 test_hooks_(test_hooks) {} |
| 106 }; | 150 }; |
| 107 | 151 |
| 108 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 152 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
| 109 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 153 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| 110 public: | 154 public: |
| 111 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 155 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
| 112 TestHooks* test_hooks, | 156 TestHooks* test_hooks, |
| 113 const LayerTreeSettings& settings, | 157 const LayerTreeSettings& settings, |
| 114 LayerTreeHostImplClient* host_impl_client, | 158 LayerTreeHostImplClient* host_impl_client, |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 }; | 381 }; |
| 338 | 382 |
| 339 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 383 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
| 340 class LayerTreeHostForTesting : public LayerTreeHost { | 384 class LayerTreeHostForTesting : public LayerTreeHost { |
| 341 public: | 385 public: |
| 342 static scoped_ptr<LayerTreeHostForTesting> Create( | 386 static scoped_ptr<LayerTreeHostForTesting> Create( |
| 343 TestHooks* test_hooks, | 387 TestHooks* test_hooks, |
| 344 LayerTreeHostClientForTesting* client, | 388 LayerTreeHostClientForTesting* client, |
| 345 const LayerTreeSettings& settings, | 389 const LayerTreeSettings& settings, |
| 346 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 390 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 347 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 391 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 392 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 348 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 393 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
| 349 new LayerTreeHostForTesting(test_hooks, client, settings)); | 394 new LayerTreeHostForTesting(test_hooks, client, settings)); |
| 350 if (impl_task_runner.get()) { | 395 if (impl_task_runner.get()) { |
| 351 layer_tree_host->InitializeForTesting( | 396 layer_tree_host->InitializeForTesting( |
| 352 ThreadProxyForTest::Create(test_hooks, | 397 ThreadProxyForTest::Create(test_hooks, |
| 353 layer_tree_host.get(), | 398 layer_tree_host.get(), |
| 354 main_task_runner, | 399 main_task_runner, |
| 355 impl_task_runner)); | 400 impl_task_runner, |
| 401 external_begin_frame_source.Pass())); |
| 356 } else { | 402 } else { |
| 357 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 403 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( |
| 358 layer_tree_host.get(), client, main_task_runner)); | 404 layer_tree_host.get(), |
| 405 client, |
| 406 main_task_runner, |
| 407 external_begin_frame_source.Pass())); |
| 359 } | 408 } |
| 360 return layer_tree_host.Pass(); | 409 return layer_tree_host.Pass(); |
| 361 } | 410 } |
| 362 | 411 |
| 363 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 412 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
| 364 LayerTreeHostImplClient* host_impl_client) override { | 413 LayerTreeHostImplClient* host_impl_client) override { |
| 365 return LayerTreeHostImplForTesting::Create( | 414 return LayerTreeHostImplForTesting::Create( |
| 366 test_hooks_, | 415 test_hooks_, |
| 367 settings(), | 416 settings(), |
| 368 host_impl_client, | 417 host_impl_client, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 main_thread_weak_ptr_)); | 563 main_thread_weak_ptr_)); |
| 515 } | 564 } |
| 516 | 565 |
| 517 void LayerTreeTest::WillBeginTest() { | 566 void LayerTreeTest::WillBeginTest() { |
| 518 layer_tree_host_->SetLayerTreeHostClientReady(); | 567 layer_tree_host_->SetLayerTreeHostClientReady(); |
| 519 } | 568 } |
| 520 | 569 |
| 521 void LayerTreeTest::DoBeginTest() { | 570 void LayerTreeTest::DoBeginTest() { |
| 522 client_ = LayerTreeHostClientForTesting::Create(this); | 571 client_ = LayerTreeHostClientForTesting::Create(this); |
| 523 | 572 |
| 573 scoped_ptr<BeginFrameSource> external_begin_frame_source; |
| 574 if (settings_.begin_frame_scheduling_enabled && |
| 575 settings_.throttle_frame_production) |
| 576 external_begin_frame_source.reset( |
| 577 new ExternalBeginFrameSourceForTest(settings_.refresh_rate)); |
| 578 |
| 524 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); | 579 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); |
| 525 layer_tree_host_ = LayerTreeHostForTesting::Create( | 580 layer_tree_host_ = LayerTreeHostForTesting::Create( |
| 526 this, | 581 this, |
| 527 client_.get(), | 582 client_.get(), |
| 528 settings_, | 583 settings_, |
| 529 base::MessageLoopProxy::current(), | 584 base::MessageLoopProxy::current(), |
| 530 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); | 585 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL, |
| 586 external_begin_frame_source.Pass()); |
| 531 ASSERT_TRUE(layer_tree_host_); | 587 ASSERT_TRUE(layer_tree_host_); |
| 532 | 588 |
| 533 started_ = true; | 589 started_ = true; |
| 534 beginning_ = true; | 590 beginning_ = true; |
| 535 SetupTree(); | 591 SetupTree(); |
| 536 WillBeginTest(); | 592 WillBeginTest(); |
| 537 BeginTest(); | 593 BeginTest(); |
| 538 beginning_ = false; | 594 beginning_ = false; |
| 539 if (end_when_begin_returns_) | 595 if (end_when_begin_returns_) |
| 540 RealEndTest(); | 596 RealEndTest(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return -1; | 771 return -1; |
| 716 } | 772 } |
| 717 | 773 |
| 718 void LayerTreeTest::DestroyLayerTreeHost() { | 774 void LayerTreeTest::DestroyLayerTreeHost() { |
| 719 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 775 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
| 720 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 776 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
| 721 layer_tree_host_ = nullptr; | 777 layer_tree_host_ = nullptr; |
| 722 } | 778 } |
| 723 | 779 |
| 724 } // namespace cc | 780 } // namespace cc |
| OLD | NEW |