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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 return make_scoped_ptr(new ThreadProxyForTest( | 72 return make_scoped_ptr(new ThreadProxyForTest( |
73 test_hooks, | 73 test_hooks, |
74 host, | 74 host, |
75 main_task_runner, | 75 main_task_runner, |
76 impl_task_runner, | 76 impl_task_runner, |
77 external_begin_frame_source.Pass())); | 77 external_begin_frame_source.Pass())); |
78 } | 78 } |
79 | 79 |
80 ~ThreadProxyForTest() override {} | 80 ~ThreadProxyForTest() override {} |
81 | 81 |
82 void test() { | |
83 test_hooks_->Layout(); | |
84 } | |
85 | |
86 private: | 82 private: |
87 TestHooks* test_hooks_; | 83 TestHooks* test_hooks_; |
88 | 84 |
| 85 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 86 ThreadProxy::WillBeginImplFrame(args); |
| 87 test_hooks_->WillBeginImplFrame(args); |
| 88 } |
| 89 |
89 void ScheduledActionSendBeginMainFrame() override { | 90 void ScheduledActionSendBeginMainFrame() override { |
90 test_hooks_->ScheduledActionWillSendBeginMainFrame(); | 91 test_hooks_->ScheduledActionWillSendBeginMainFrame(); |
91 ThreadProxy::ScheduledActionSendBeginMainFrame(); | 92 ThreadProxy::ScheduledActionSendBeginMainFrame(); |
92 test_hooks_->ScheduledActionSendBeginMainFrame(); | 93 test_hooks_->ScheduledActionSendBeginMainFrame(); |
93 } | 94 } |
94 | 95 |
95 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 96 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
96 DrawResult result = ThreadProxy::ScheduledActionDrawAndSwapIfPossible(); | 97 DrawResult result = ThreadProxy::ScheduledActionDrawAndSwapIfPossible(); |
97 test_hooks_->ScheduledActionDrawAndSwapIfPossible(); | 98 test_hooks_->ScheduledActionDrawAndSwapIfPossible(); |
98 return result; | 99 return result; |
(...skipping 24 matching lines...) Expand all Loading... |
123 LayerTreeHost* host, | 124 LayerTreeHost* host, |
124 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 125 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
125 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 126 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
126 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 127 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
127 : ThreadProxy(host, main_task_runner, | 128 : ThreadProxy(host, main_task_runner, |
128 impl_task_runner, | 129 impl_task_runner, |
129 external_begin_frame_source.Pass()), | 130 external_begin_frame_source.Pass()), |
130 test_hooks_(test_hooks) {} | 131 test_hooks_(test_hooks) {} |
131 }; | 132 }; |
132 | 133 |
| 134 // Adapts ThreadProxy for test. Injects test hooks for testing. |
| 135 class SingleThreadProxyForTest : public SingleThreadProxy { |
| 136 public: |
| 137 static scoped_ptr<Proxy> Create( |
| 138 TestHooks* test_hooks, |
| 139 LayerTreeHost* host, |
| 140 LayerTreeHostSingleThreadClient* client, |
| 141 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 142 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 143 return make_scoped_ptr(new SingleThreadProxyForTest( |
| 144 test_hooks, host, client, main_task_runner, |
| 145 external_begin_frame_source.Pass())); |
| 146 } |
| 147 |
| 148 ~SingleThreadProxyForTest() override {} |
| 149 |
| 150 private: |
| 151 TestHooks* test_hooks_; |
| 152 |
| 153 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 154 SingleThreadProxy::WillBeginImplFrame(args); |
| 155 test_hooks_->WillBeginImplFrame(args); |
| 156 } |
| 157 |
| 158 void ScheduledActionSendBeginMainFrame() override { |
| 159 test_hooks_->ScheduledActionWillSendBeginMainFrame(); |
| 160 SingleThreadProxy::ScheduledActionSendBeginMainFrame(); |
| 161 test_hooks_->ScheduledActionSendBeginMainFrame(); |
| 162 } |
| 163 |
| 164 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 165 DrawResult result = |
| 166 SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible(); |
| 167 test_hooks_->ScheduledActionDrawAndSwapIfPossible(); |
| 168 return result; |
| 169 } |
| 170 |
| 171 void ScheduledActionAnimate() override { |
| 172 SingleThreadProxy::ScheduledActionAnimate(); |
| 173 test_hooks_->ScheduledActionAnimate(); |
| 174 } |
| 175 |
| 176 void ScheduledActionCommit() override { |
| 177 SingleThreadProxy::ScheduledActionCommit(); |
| 178 test_hooks_->ScheduledActionCommit(); |
| 179 } |
| 180 |
| 181 void ScheduledActionBeginOutputSurfaceCreation() override { |
| 182 SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
| 183 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
| 184 } |
| 185 |
| 186 void ScheduledActionPrepareTiles() override { |
| 187 SingleThreadProxy::ScheduledActionPrepareTiles(); |
| 188 test_hooks_->ScheduledActionPrepareTiles(); |
| 189 } |
| 190 |
| 191 SingleThreadProxyForTest( |
| 192 TestHooks* test_hooks, |
| 193 LayerTreeHost* host, |
| 194 LayerTreeHostSingleThreadClient* client, |
| 195 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 196 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 197 : SingleThreadProxy(host, client, main_task_runner, |
| 198 external_begin_frame_source.Pass()), |
| 199 test_hooks_(test_hooks) {} |
| 200 }; |
| 201 |
133 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 202 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
134 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 203 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
135 public: | 204 public: |
136 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 205 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
137 TestHooks* test_hooks, | 206 TestHooks* test_hooks, |
138 const LayerTreeSettings& settings, | 207 const LayerTreeSettings& settings, |
139 LayerTreeHostImplClient* host_impl_client, | 208 LayerTreeHostImplClient* host_impl_client, |
140 Proxy* proxy, | 209 Proxy* proxy, |
141 SharedBitmapManager* shared_bitmap_manager, | 210 SharedBitmapManager* shared_bitmap_manager, |
142 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 211 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 464 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
396 new LayerTreeHostForTesting(test_hooks, client, settings)); | 465 new LayerTreeHostForTesting(test_hooks, client, settings)); |
397 if (impl_task_runner.get()) { | 466 if (impl_task_runner.get()) { |
398 layer_tree_host->InitializeForTesting( | 467 layer_tree_host->InitializeForTesting( |
399 ThreadProxyForTest::Create(test_hooks, | 468 ThreadProxyForTest::Create(test_hooks, |
400 layer_tree_host.get(), | 469 layer_tree_host.get(), |
401 main_task_runner, | 470 main_task_runner, |
402 impl_task_runner, | 471 impl_task_runner, |
403 external_begin_frame_source.Pass())); | 472 external_begin_frame_source.Pass())); |
404 } else { | 473 } else { |
405 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 474 layer_tree_host->InitializeForTesting( |
406 layer_tree_host.get(), | 475 SingleThreadProxyForTest::Create( |
407 client, | 476 test_hooks, |
408 main_task_runner, | 477 layer_tree_host.get(), |
409 external_begin_frame_source.Pass())); | 478 client, |
| 479 main_task_runner, |
| 480 external_begin_frame_source.Pass())); |
410 } | 481 } |
411 return layer_tree_host.Pass(); | 482 return layer_tree_host.Pass(); |
412 } | 483 } |
413 | 484 |
414 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 485 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
415 LayerTreeHostImplClient* host_impl_client) override { | 486 LayerTreeHostImplClient* host_impl_client) override { |
416 return LayerTreeHostImplForTesting::Create( | 487 return LayerTreeHostImplForTesting::Create( |
417 test_hooks_, | 488 test_hooks_, |
418 settings(), | 489 settings(), |
419 host_impl_client, | 490 host_impl_client, |
420 proxy(), | 491 proxy(), |
421 shared_bitmap_manager_.get(), | 492 shared_bitmap_manager_.get(), |
422 gpu_memory_buffer_manager_.get(), | 493 gpu_memory_buffer_manager_.get(), |
423 rendering_stats_instrumentation()); | 494 rendering_stats_instrumentation()); |
424 } | 495 } |
425 | 496 |
426 void SetNeedsCommit() override { | 497 void SetNeedsCommit() override { |
427 if (!test_started_) | 498 if (!test_started_) |
428 return; | 499 return; |
429 LayerTreeHost::SetNeedsCommit(); | 500 LayerTreeHost::SetNeedsCommit(); |
430 } | 501 } |
431 | 502 |
432 void set_test_started(bool started) { test_started_ = started; } | 503 void set_test_started(bool started) { test_started_ = started; } |
433 | 504 |
434 void DidDeferCommit() override { test_hooks_->DidDeferCommit(); } | |
435 | |
436 private: | 505 private: |
437 LayerTreeHostForTesting(TestHooks* test_hooks, | 506 LayerTreeHostForTesting(TestHooks* test_hooks, |
438 LayerTreeHostClient* client, | 507 LayerTreeHostClient* client, |
439 const LayerTreeSettings& settings) | 508 const LayerTreeSettings& settings) |
440 : LayerTreeHost(client, NULL, NULL, settings), | 509 : LayerTreeHost(client, NULL, NULL, settings), |
441 shared_bitmap_manager_(new TestSharedBitmapManager), | 510 shared_bitmap_manager_(new TestSharedBitmapManager), |
442 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), | 511 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), |
443 test_hooks_(test_hooks), | 512 test_hooks_(test_hooks), |
444 test_started_(false) {} | 513 test_started_(false) {} |
445 | 514 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 void LayerTreeTest::PostAddLongAnimationToMainThread( | 586 void LayerTreeTest::PostAddLongAnimationToMainThread( |
518 Layer* layer_to_receive_animation) { | 587 Layer* layer_to_receive_animation) { |
519 main_task_runner_->PostTask( | 588 main_task_runner_->PostTask( |
520 FROM_HERE, | 589 FROM_HERE, |
521 base::Bind(&LayerTreeTest::DispatchAddAnimation, | 590 base::Bind(&LayerTreeTest::DispatchAddAnimation, |
522 main_thread_weak_ptr_, | 591 main_thread_weak_ptr_, |
523 base::Unretained(layer_to_receive_animation), | 592 base::Unretained(layer_to_receive_animation), |
524 1.0)); | 593 1.0)); |
525 } | 594 } |
526 | 595 |
| 596 void LayerTreeTest::PostSetDeferCommitsToMainThread(bool defer_commits) { |
| 597 main_task_runner_->PostTask( |
| 598 FROM_HERE, |
| 599 base::Bind(&LayerTreeTest::DispatchSetDeferCommits, |
| 600 main_thread_weak_ptr_, defer_commits)); |
| 601 } |
| 602 |
527 void LayerTreeTest::PostSetNeedsCommitToMainThread() { | 603 void LayerTreeTest::PostSetNeedsCommitToMainThread() { |
528 main_task_runner_->PostTask(FROM_HERE, | 604 main_task_runner_->PostTask(FROM_HERE, |
529 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit, | 605 base::Bind(&LayerTreeTest::DispatchSetNeedsCommit, |
530 main_thread_weak_ptr_)); | 606 main_thread_weak_ptr_)); |
531 } | 607 } |
532 | 608 |
533 void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() { | 609 void LayerTreeTest::PostSetNeedsUpdateLayersToMainThread() { |
534 main_task_runner_->PostTask( | 610 main_task_runner_->PostTask( |
535 FROM_HERE, | 611 FROM_HERE, |
536 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers, | 612 base::Bind(&LayerTreeTest::DispatchSetNeedsUpdateLayers, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation, | 724 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation, |
649 double animation_duration) { | 725 double animation_duration) { |
650 DCHECK(!proxy() || proxy()->IsMainThread()); | 726 DCHECK(!proxy() || proxy()->IsMainThread()); |
651 | 727 |
652 if (layer_to_receive_animation) { | 728 if (layer_to_receive_animation) { |
653 AddOpacityTransitionToLayer( | 729 AddOpacityTransitionToLayer( |
654 layer_to_receive_animation, animation_duration, 0, 0.5, true); | 730 layer_to_receive_animation, animation_duration, 0, 0.5, true); |
655 } | 731 } |
656 } | 732 } |
657 | 733 |
| 734 void LayerTreeTest::DispatchSetDeferCommits(bool defer_commits) { |
| 735 DCHECK(!proxy() || proxy()->IsMainThread()); |
| 736 |
| 737 if (layer_tree_host_) |
| 738 layer_tree_host_->SetDeferCommits(defer_commits); |
| 739 } |
| 740 |
658 void LayerTreeTest::DispatchSetNeedsCommit() { | 741 void LayerTreeTest::DispatchSetNeedsCommit() { |
659 DCHECK(!proxy() || proxy()->IsMainThread()); | 742 DCHECK(!proxy() || proxy()->IsMainThread()); |
660 | 743 |
661 if (layer_tree_host_) | 744 if (layer_tree_host_) |
662 layer_tree_host_->SetNeedsCommit(); | 745 layer_tree_host_->SetNeedsCommit(); |
663 } | 746 } |
664 | 747 |
665 void LayerTreeTest::DispatchSetNeedsUpdateLayers() { | 748 void LayerTreeTest::DispatchSetNeedsUpdateLayers() { |
666 DCHECK(!proxy() || proxy()->IsMainThread()); | 749 DCHECK(!proxy() || proxy()->IsMainThread()); |
667 | 750 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 return -1; | 874 return -1; |
792 } | 875 } |
793 | 876 |
794 void LayerTreeTest::DestroyLayerTreeHost() { | 877 void LayerTreeTest::DestroyLayerTreeHost() { |
795 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 878 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
796 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 879 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
797 layer_tree_host_ = nullptr; | 880 layer_tree_host_ = nullptr; |
798 } | 881 } |
799 | 882 |
800 } // namespace cc | 883 } // namespace cc |
OLD | NEW |