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