| 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/base/thread_impl.h" | 13 #include "cc/base/thread_impl.h" |
| 14 #include "cc/input/input_handler.h" | 14 #include "cc/input/input_handler.h" |
| 15 #include "cc/layers/content_layer.h" | 15 #include "cc/layers/content_layer.h" |
| 16 #include "cc/layers/layer.h" | 16 #include "cc/layers/layer.h" |
| 17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
| 18 #include "cc/test/animation_test_common.h" | 18 #include "cc/test/animation_test_common.h" |
| 19 #include "cc/test/fake_context_provider.h" |
| 19 #include "cc/test/fake_layer_tree_host_client.h" | 20 #include "cc/test/fake_layer_tree_host_client.h" |
| 20 #include "cc/test/fake_output_surface.h" | 21 #include "cc/test/fake_output_surface.h" |
| 21 #include "cc/test/occlusion_tracker_test_common.h" | 22 #include "cc/test/occlusion_tracker_test_common.h" |
| 22 #include "cc/test/tiled_layer_test_common.h" | 23 #include "cc/test/tiled_layer_test_common.h" |
| 23 #include "cc/trees/layer_tree_host_impl.h" | 24 #include "cc/trees/layer_tree_host_impl.h" |
| 24 #include "cc/trees/single_thread_proxy.h" | 25 #include "cc/trees/single_thread_proxy.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "ui/gfx/size_conversions.h" | 27 #include "ui/gfx/size_conversions.h" |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 | 30 |
| 30 TestHooks::TestHooks() | 31 TestHooks::TestHooks() {} |
| 31 : fake_client_( | |
| 32 new FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} | |
| 33 | 32 |
| 34 TestHooks::~TestHooks() {} | 33 TestHooks::~TestHooks() {} |
| 35 | 34 |
| 36 bool TestHooks::PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 35 bool TestHooks::PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 37 LayerTreeHostImpl::FrameData* frame_data, | 36 LayerTreeHostImpl::FrameData* frame_data, |
| 38 bool result) { | 37 bool result) { |
| 39 return true; | 38 return true; |
| 40 } | 39 } |
| 41 | 40 |
| 42 bool TestHooks::CanActivatePendingTree() { | 41 bool TestHooks::CanActivatePendingTree() { |
| 43 return true; | 42 return true; |
| 44 } | 43 } |
| 45 | 44 |
| 46 scoped_ptr<OutputSurface> TestHooks::CreateOutputSurface() { | |
| 47 return CreateFakeOutputSurface(); | |
| 48 } | |
| 49 | |
| 50 scoped_refptr<cc::ContextProvider> TestHooks:: | |
| 51 OffscreenContextProviderForMainThread() { | |
| 52 return fake_client_->OffscreenContextProviderForMainThread(); | |
| 53 } | |
| 54 | |
| 55 scoped_refptr<cc::ContextProvider> TestHooks:: | |
| 56 OffscreenContextProviderForCompositorThread() { | |
| 57 return fake_client_->OffscreenContextProviderForCompositorThread(); | |
| 58 } | |
| 59 | |
| 60 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 45 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
| 61 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 46 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
| 62 public: | 47 public: |
| 63 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 48 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
| 64 TestHooks* test_hooks, | 49 TestHooks* test_hooks, |
| 65 const LayerTreeSettings& settings, | 50 const LayerTreeSettings& settings, |
| 66 LayerTreeHostImplClient* host_impl_client, | 51 LayerTreeHostImplClient* host_impl_client, |
| 67 Proxy* proxy, | 52 Proxy* proxy, |
| 68 RenderingStatsInstrumentation* stats_instrumentation) { | 53 RenderingStatsInstrumentation* stats_instrumentation) { |
| 69 return make_scoped_ptr( | 54 return make_scoped_ptr( |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 schedule_when_set_visible_true_ = true; | 529 schedule_when_set_visible_true_ = true; |
| 545 return; | 530 return; |
| 546 } | 531 } |
| 547 | 532 |
| 548 schedule_when_set_visible_true_ = false; | 533 schedule_when_set_visible_true_ = false; |
| 549 base::TimeTicks now = base::TimeTicks::Now(); | 534 base::TimeTicks now = base::TimeTicks::Now(); |
| 550 layer_tree_host_->UpdateAnimations(now); | 535 layer_tree_host_->UpdateAnimations(now); |
| 551 layer_tree_host_->Composite(now); | 536 layer_tree_host_->Composite(now); |
| 552 } | 537 } |
| 553 | 538 |
| 554 void LayerTreeTest::RunTest(bool threaded) { | 539 void LayerTreeTest::RunTest(bool threaded, bool delegating_renderer) { |
| 555 if (threaded) { | 540 if (threaded) { |
| 556 impl_thread_.reset(new base::Thread("Compositor")); | 541 impl_thread_.reset(new base::Thread("Compositor")); |
| 557 ASSERT_TRUE(impl_thread_->Start()); | 542 ASSERT_TRUE(impl_thread_->Start()); |
| 558 } | 543 } |
| 559 | 544 |
| 560 main_ccthread_ = cc::ThreadImpl::CreateForCurrentThread(); | 545 main_ccthread_ = cc::ThreadImpl::CreateForCurrentThread(); |
| 561 | 546 |
| 547 delegating_renderer_ = delegating_renderer; |
| 548 |
| 562 // Spend less time waiting for vsync because the output is mocked out. | 549 // Spend less time waiting for vsync because the output is mocked out. |
| 563 settings_.refresh_rate = 200.0; | 550 settings_.refresh_rate = 200.0; |
| 564 InitializeSettings(&settings_); | 551 InitializeSettings(&settings_); |
| 565 | 552 |
| 566 main_ccthread_->PostTask( | 553 main_ccthread_->PostTask( |
| 567 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); | 554 base::Bind(&LayerTreeTest::DoBeginTest, base::Unretained(this))); |
| 568 | 555 |
| 569 if (timeout_seconds_) { | 556 if (timeout_seconds_) { |
| 570 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); | 557 timeout_.Reset(base::Bind(&LayerTreeTest::Timeout, base::Unretained(this))); |
| 571 main_ccthread_->PostDelayedTask( | 558 main_ccthread_->PostDelayedTask( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 582 | 569 |
| 583 ASSERT_FALSE(layer_tree_host_.get()); | 570 ASSERT_FALSE(layer_tree_host_.get()); |
| 584 client_.reset(); | 571 client_.reset(); |
| 585 if (timed_out_) { | 572 if (timed_out_) { |
| 586 FAIL() << "Test timed out"; | 573 FAIL() << "Test timed out"; |
| 587 return; | 574 return; |
| 588 } | 575 } |
| 589 AfterTest(); | 576 AfterTest(); |
| 590 } | 577 } |
| 591 | 578 |
| 579 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface() { |
| 580 if (delegating_renderer_) |
| 581 return FakeOutputSurface::CreateDelegating3d().PassAs<OutputSurface>(); |
| 582 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); |
| 583 } |
| 584 |
| 585 scoped_refptr<cc::ContextProvider> LayerTreeTest:: |
| 586 OffscreenContextProviderForMainThread() { |
| 587 if (!main_thread_contexts_ || |
| 588 main_thread_contexts_->DestroyedOnMainThread()) { |
| 589 main_thread_contexts_ = FakeContextProvider::Create(); |
| 590 if (!main_thread_contexts_->BindToCurrentThread()) |
| 591 main_thread_contexts_ = NULL; |
| 592 } |
| 593 return main_thread_contexts_; |
| 594 } |
| 595 |
| 596 scoped_refptr<cc::ContextProvider> LayerTreeTest:: |
| 597 OffscreenContextProviderForCompositorThread() { |
| 598 if (!compositor_thread_contexts_ || |
| 599 compositor_thread_contexts_->DestroyedOnMainThread()) |
| 600 compositor_thread_contexts_ = FakeContextProvider::Create(); |
| 601 return compositor_thread_contexts_; |
| 602 } |
| 603 |
| 592 } // namespace cc | 604 } // namespace cc |
| OLD | NEW |