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