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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 return make_scoped_ptr(new ThreadProxyForTest( | 58 return make_scoped_ptr( |
59 test_hooks, host, main_task_runner, impl_task_runner)); | 59 new ThreadProxyForTest( |
| 60 test_hooks, host, main_task_runner, impl_task_runner)) |
| 61 .PassAs<Proxy>(); |
60 } | 62 } |
61 | 63 |
62 virtual ~ThreadProxyForTest() {} | 64 virtual ~ThreadProxyForTest() {} |
63 | 65 |
64 void test() { | 66 void test() { |
65 test_hooks_->Layout(); | 67 test_hooks_->Layout(); |
66 } | 68 } |
67 | 69 |
68 private: | 70 private: |
69 TestHooks* test_hooks_; | 71 TestHooks* test_hooks_; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } else { | 344 } else { |
343 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 345 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( |
344 layer_tree_host.get(), client, main_task_runner)); | 346 layer_tree_host.get(), client, main_task_runner)); |
345 } | 347 } |
346 return layer_tree_host.Pass(); | 348 return layer_tree_host.Pass(); |
347 } | 349 } |
348 | 350 |
349 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 351 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
350 LayerTreeHostImplClient* host_impl_client) OVERRIDE { | 352 LayerTreeHostImplClient* host_impl_client) OVERRIDE { |
351 return LayerTreeHostImplForTesting::Create( | 353 return LayerTreeHostImplForTesting::Create( |
352 test_hooks_, | 354 test_hooks_, |
353 settings(), | 355 settings(), |
354 host_impl_client, | 356 host_impl_client, |
355 proxy(), | 357 proxy(), |
356 shared_bitmap_manager_.get(), | 358 shared_bitmap_manager_.get(), |
357 rendering_stats_instrumentation()); | 359 rendering_stats_instrumentation()).PassAs<LayerTreeHostImpl>(); |
358 } | 360 } |
359 | 361 |
360 virtual void SetNeedsCommit() OVERRIDE { | 362 virtual void SetNeedsCommit() OVERRIDE { |
361 if (!test_started_) | 363 if (!test_started_) |
362 return; | 364 return; |
363 LayerTreeHost::SetNeedsCommit(); | 365 LayerTreeHost::SetNeedsCommit(); |
364 } | 366 } |
365 | 367 |
366 void set_test_started(bool started) { test_started_ = started; } | 368 void set_test_started(bool started) { test_started_ = started; } |
367 | 369 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 timeout_.callback(), | 647 timeout_.callback(), |
646 base::TimeDelta::FromSeconds(timeout_seconds_)); | 648 base::TimeDelta::FromSeconds(timeout_seconds_)); |
647 } | 649 } |
648 | 650 |
649 base::MessageLoop::current()->Run(); | 651 base::MessageLoop::current()->Run(); |
650 DestroyLayerTreeHost(); | 652 DestroyLayerTreeHost(); |
651 | 653 |
652 timeout_.Cancel(); | 654 timeout_.Cancel(); |
653 | 655 |
654 ASSERT_FALSE(layer_tree_host_.get()); | 656 ASSERT_FALSE(layer_tree_host_.get()); |
655 client_ = nullptr; | 657 client_.reset(); |
656 if (timed_out_) { | 658 if (timed_out_) { |
657 FAIL() << "Test timed out"; | 659 FAIL() << "Test timed out"; |
658 return; | 660 return; |
659 } | 661 } |
660 AfterTest(); | 662 AfterTest(); |
661 } | 663 } |
662 | 664 |
663 void LayerTreeTest::RunTestWithImplSidePainting() { | 665 void LayerTreeTest::RunTestWithImplSidePainting() { |
664 RunTest(true, false, true); | 666 RunTest(true, false, true); |
665 } | 667 } |
666 | 668 |
667 void LayerTreeTest::RequestNewOutputSurface(bool fallback) { | 669 void LayerTreeTest::RequestNewOutputSurface(bool fallback) { |
668 layer_tree_host_->SetOutputSurface(CreateOutputSurface(fallback)); | 670 layer_tree_host_->SetOutputSurface(CreateOutputSurface(fallback)); |
669 } | 671 } |
670 | 672 |
671 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { | 673 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
672 scoped_ptr<FakeOutputSurface> output_surface = | 674 scoped_ptr<FakeOutputSurface> output_surface = |
673 CreateFakeOutputSurface(fallback); | 675 CreateFakeOutputSurface(fallback); |
674 if (output_surface) { | 676 if (output_surface) { |
675 DCHECK_EQ(delegating_renderer_, | 677 DCHECK_EQ(delegating_renderer_, |
676 output_surface->capabilities().delegated_rendering); | 678 output_surface->capabilities().delegated_rendering); |
677 } | 679 } |
678 output_surface_ = output_surface.get(); | 680 output_surface_ = output_surface.get(); |
679 return output_surface.Pass(); | 681 return output_surface.PassAs<OutputSurface>(); |
680 } | 682 } |
681 | 683 |
682 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( | 684 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( |
683 bool fallback) { | 685 bool fallback) { |
684 if (delegating_renderer_) | 686 if (delegating_renderer_) |
685 return FakeOutputSurface::CreateDelegating3d(); | 687 return FakeOutputSurface::CreateDelegating3d(); |
686 else | 688 else |
687 return FakeOutputSurface::Create3d(); | 689 return FakeOutputSurface::Create3d(); |
688 } | 690 } |
689 | 691 |
690 TestWebGraphicsContext3D* LayerTreeTest::TestContext() { | 692 TestWebGraphicsContext3D* LayerTreeTest::TestContext() { |
691 return static_cast<TestContextProvider*>(output_surface_->context_provider()) | 693 return static_cast<TestContextProvider*>(output_surface_->context_provider()) |
692 ->TestContext3d(); | 694 ->TestContext3d(); |
693 } | 695 } |
694 | 696 |
695 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) | 697 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) |
696 const { | 698 const { |
697 if (impl->pending_tree()) | 699 if (impl->pending_tree()) |
698 return impl->pending_tree()->source_frame_number(); | 700 return impl->pending_tree()->source_frame_number(); |
699 if (impl->active_tree()) | 701 if (impl->active_tree()) |
700 return impl->active_tree()->source_frame_number(); | 702 return impl->active_tree()->source_frame_number(); |
701 // Source frames start at 0, so this is invalid. | 703 // Source frames start at 0, so this is invalid. |
702 return -1; | 704 return -1; |
703 } | 705 } |
704 | 706 |
705 void LayerTreeTest::DestroyLayerTreeHost() { | 707 void LayerTreeTest::DestroyLayerTreeHost() { |
706 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 708 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
707 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 709 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
708 layer_tree_host_ = nullptr; | 710 layer_tree_host_.reset(); |
709 } | 711 } |
710 | 712 |
711 } // namespace cc | 713 } // namespace cc |
OLD | NEW |