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/input/input_handler.h" | 13 #include "cc/input/input_handler.h" |
14 #include "cc/layers/content_layer.h" | 14 #include "cc/layers/content_layer.h" |
15 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
17 #include "cc/test/animation_test_common.h" | 17 #include "cc/test/animation_test_common.h" |
| 18 #include "cc/test/begin_frame_args_test.h" |
18 #include "cc/test/fake_layer_tree_host_client.h" | 19 #include "cc/test/fake_layer_tree_host_client.h" |
19 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
20 #include "cc/test/test_context_provider.h" | 21 #include "cc/test/test_context_provider.h" |
21 #include "cc/test/test_gpu_memory_buffer_manager.h" | 22 #include "cc/test/test_gpu_memory_buffer_manager.h" |
22 #include "cc/test/test_shared_bitmap_manager.h" | 23 #include "cc/test/test_shared_bitmap_manager.h" |
23 #include "cc/test/tiled_layer_test_common.h" | 24 #include "cc/test/tiled_layer_test_common.h" |
24 #include "cc/trees/layer_tree_host_client.h" | 25 #include "cc/trees/layer_tree_host_client.h" |
25 #include "cc/trees/layer_tree_host_impl.h" | 26 #include "cc/trees/layer_tree_host_impl.h" |
26 #include "cc/trees/layer_tree_host_single_thread_client.h" | 27 #include "cc/trees/layer_tree_host_single_thread_client.h" |
27 #include "cc/trees/layer_tree_impl.h" | 28 #include "cc/trees/layer_tree_impl.h" |
(...skipping 22 matching lines...) Expand all Loading... |
50 scoped_ptr<ResourcePool>* resource_pool, | 51 scoped_ptr<ResourcePool>* resource_pool, |
51 scoped_ptr<ResourcePool>* staging_resource_pool) { | 52 scoped_ptr<ResourcePool>* staging_resource_pool) { |
52 host_impl->LayerTreeHostImpl::CreateResourceAndRasterWorkerPool( | 53 host_impl->LayerTreeHostImpl::CreateResourceAndRasterWorkerPool( |
53 raster_worker_pool, resource_pool, staging_resource_pool); | 54 raster_worker_pool, resource_pool, staging_resource_pool); |
54 } | 55 } |
55 | 56 |
56 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { | 57 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { |
57 return base::TimeDelta::FromMilliseconds(16); | 58 return base::TimeDelta::FromMilliseconds(16); |
58 } | 59 } |
59 | 60 |
| 61 class ExternalBeginFrameSourceForTest |
| 62 : public BeginFrameSourceMixIn, |
| 63 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 64 public: |
| 65 explicit ExternalBeginFrameSourceForTest(double refresh_rate) |
| 66 : milliseconds_per_frame_(1000.0 / refresh_rate), |
| 67 is_ready_(false), |
| 68 weak_ptr_factory_(this) { |
| 69 DetachFromThread(); |
| 70 } |
| 71 |
| 72 virtual ~ExternalBeginFrameSourceForTest() { |
| 73 DCHECK(CalledOnValidThread()); |
| 74 } |
| 75 |
| 76 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 77 DCHECK(CalledOnValidThread()); |
| 78 if (needs_begin_frames) { |
| 79 base::MessageLoop::current()->PostDelayedTask( |
| 80 FROM_HERE, |
| 81 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame, |
| 82 weak_ptr_factory_.GetWeakPtr()), |
| 83 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_)); |
| 84 } |
| 85 } |
| 86 |
| 87 virtual void SetClientReady() override { |
| 88 DCHECK(CalledOnValidThread()); |
| 89 is_ready_ = true; |
| 90 } |
| 91 |
| 92 bool is_ready() const { |
| 93 return is_ready_; |
| 94 } |
| 95 |
| 96 void TestOnBeginFrame() { |
| 97 DCHECK(CalledOnValidThread()); |
| 98 CallOnBeginFrame(CreateBeginFrameArgsForTesting()); |
| 99 } |
| 100 |
| 101 private: |
| 102 double milliseconds_per_frame_; |
| 103 bool is_ready_; |
| 104 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_; |
| 105 }; |
| 106 |
60 // Adapts ThreadProxy for test. Injects test hooks for testing. | 107 // Adapts ThreadProxy for test. Injects test hooks for testing. |
61 class ThreadProxyForTest : public ThreadProxy { | 108 class ThreadProxyForTest : public ThreadProxy { |
62 public: | 109 public: |
63 static scoped_ptr<Proxy> Create( | 110 static scoped_ptr<Proxy> Create( |
64 TestHooks* test_hooks, | 111 TestHooks* test_hooks, |
65 LayerTreeHost* host, | 112 LayerTreeHost* host, |
66 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
67 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 114 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 115 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
68 return make_scoped_ptr(new ThreadProxyForTest( | 116 return make_scoped_ptr(new ThreadProxyForTest( |
69 test_hooks, host, main_task_runner, impl_task_runner)); | 117 test_hooks, |
| 118 host, |
| 119 main_task_runner, |
| 120 impl_task_runner, |
| 121 external_begin_frame_source.Pass())); |
70 } | 122 } |
71 | 123 |
72 ~ThreadProxyForTest() override {} | 124 ~ThreadProxyForTest() override {} |
73 | 125 |
74 void test() { | 126 void test() { |
75 test_hooks_->Layout(); | 127 test_hooks_->Layout(); |
76 } | 128 } |
77 | 129 |
78 private: | 130 private: |
79 TestHooks* test_hooks_; | 131 TestHooks* test_hooks_; |
(...skipping 22 matching lines...) Expand all Loading... |
102 | 154 |
103 void ScheduledActionBeginOutputSurfaceCreation() override { | 155 void ScheduledActionBeginOutputSurfaceCreation() override { |
104 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); | 156 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
105 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); | 157 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
106 } | 158 } |
107 | 159 |
108 ThreadProxyForTest( | 160 ThreadProxyForTest( |
109 TestHooks* test_hooks, | 161 TestHooks* test_hooks, |
110 LayerTreeHost* host, | 162 LayerTreeHost* host, |
111 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 163 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
112 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 164 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
113 : ThreadProxy(host, main_task_runner, impl_task_runner), | 165 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 166 : ThreadProxy(host, main_task_runner, |
| 167 impl_task_runner, |
| 168 external_begin_frame_source.Pass()), |
114 test_hooks_(test_hooks) {} | 169 test_hooks_(test_hooks) {} |
115 }; | 170 }; |
116 | 171 |
117 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 172 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
118 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 173 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
119 public: | 174 public: |
120 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 175 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
121 TestHooks* test_hooks, | 176 TestHooks* test_hooks, |
122 const LayerTreeSettings& settings, | 177 const LayerTreeSettings& settings, |
123 LayerTreeHostImplClient* host_impl_client, | 178 LayerTreeHostImplClient* host_impl_client, |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 }; | 409 }; |
355 | 410 |
356 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 411 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
357 class LayerTreeHostForTesting : public LayerTreeHost { | 412 class LayerTreeHostForTesting : public LayerTreeHost { |
358 public: | 413 public: |
359 static scoped_ptr<LayerTreeHostForTesting> Create( | 414 static scoped_ptr<LayerTreeHostForTesting> Create( |
360 TestHooks* test_hooks, | 415 TestHooks* test_hooks, |
361 LayerTreeHostClientForTesting* client, | 416 LayerTreeHostClientForTesting* client, |
362 const LayerTreeSettings& settings, | 417 const LayerTreeSettings& settings, |
363 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 418 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
364 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 419 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 420 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
365 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 421 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
366 new LayerTreeHostForTesting(test_hooks, client, settings)); | 422 new LayerTreeHostForTesting(test_hooks, client, settings)); |
367 if (impl_task_runner.get()) { | 423 if (impl_task_runner.get()) { |
368 layer_tree_host->InitializeForTesting( | 424 layer_tree_host->InitializeForTesting( |
369 ThreadProxyForTest::Create(test_hooks, | 425 ThreadProxyForTest::Create(test_hooks, |
370 layer_tree_host.get(), | 426 layer_tree_host.get(), |
371 main_task_runner, | 427 main_task_runner, |
372 impl_task_runner)); | 428 impl_task_runner, |
| 429 external_begin_frame_source.Pass())); |
373 } else { | 430 } else { |
374 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 431 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( |
375 layer_tree_host.get(), client, main_task_runner)); | 432 layer_tree_host.get(), |
| 433 client, |
| 434 main_task_runner, |
| 435 external_begin_frame_source.Pass())); |
376 } | 436 } |
377 return layer_tree_host.Pass(); | 437 return layer_tree_host.Pass(); |
378 } | 438 } |
379 | 439 |
380 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 440 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
381 LayerTreeHostImplClient* host_impl_client) override { | 441 LayerTreeHostImplClient* host_impl_client) override { |
382 return LayerTreeHostImplForTesting::Create( | 442 return LayerTreeHostImplForTesting::Create( |
383 test_hooks_, | 443 test_hooks_, |
384 settings(), | 444 settings(), |
385 host_impl_client, | 445 host_impl_client, |
(...skipping 24 matching lines...) Expand all Loading... |
410 test_started_(false) {} | 470 test_started_(false) {} |
411 | 471 |
412 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 472 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
413 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 473 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
414 TestHooks* test_hooks_; | 474 TestHooks* test_hooks_; |
415 bool test_started_; | 475 bool test_started_; |
416 }; | 476 }; |
417 | 477 |
418 LayerTreeTest::LayerTreeTest() | 478 LayerTreeTest::LayerTreeTest() |
419 : output_surface_(nullptr), | 479 : output_surface_(nullptr), |
| 480 external_begin_frame_source_(nullptr), |
420 beginning_(false), | 481 beginning_(false), |
421 end_when_begin_returns_(false), | 482 end_when_begin_returns_(false), |
422 timed_out_(false), | 483 timed_out_(false), |
423 scheduled_(false), | 484 scheduled_(false), |
424 started_(false), | 485 started_(false), |
425 ended_(false), | 486 ended_(false), |
426 delegating_renderer_(false), | 487 delegating_renderer_(false), |
427 timeout_seconds_(0), | 488 timeout_seconds_(0), |
428 weak_factory_(this) { | 489 weak_factory_(this) { |
429 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 490 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 main_thread_weak_ptr_)); | 600 main_thread_weak_ptr_)); |
540 } | 601 } |
541 | 602 |
542 void LayerTreeTest::WillBeginTest() { | 603 void LayerTreeTest::WillBeginTest() { |
543 layer_tree_host_->SetLayerTreeHostClientReady(); | 604 layer_tree_host_->SetLayerTreeHostClientReady(); |
544 } | 605 } |
545 | 606 |
546 void LayerTreeTest::DoBeginTest() { | 607 void LayerTreeTest::DoBeginTest() { |
547 client_ = LayerTreeHostClientForTesting::Create(this); | 608 client_ = LayerTreeHostClientForTesting::Create(this); |
548 | 609 |
| 610 scoped_ptr<ExternalBeginFrameSourceForTest> external_begin_frame_source; |
| 611 if (settings_.begin_frame_scheduling_enabled && |
| 612 settings_.throttle_frame_production) { |
| 613 external_begin_frame_source.reset( |
| 614 new ExternalBeginFrameSourceForTest(settings_.refresh_rate)); |
| 615 external_begin_frame_source_ = external_begin_frame_source.get(); |
| 616 } |
| 617 |
549 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); | 618 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); |
550 layer_tree_host_ = LayerTreeHostForTesting::Create( | 619 layer_tree_host_ = LayerTreeHostForTesting::Create( |
551 this, | 620 this, |
552 client_.get(), | 621 client_.get(), |
553 settings_, | 622 settings_, |
554 base::MessageLoopProxy::current(), | 623 base::MessageLoopProxy::current(), |
555 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); | 624 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL, |
| 625 external_begin_frame_source.Pass()); |
556 ASSERT_TRUE(layer_tree_host_); | 626 ASSERT_TRUE(layer_tree_host_); |
557 | 627 |
558 started_ = true; | 628 started_ = true; |
559 beginning_ = true; | 629 beginning_ = true; |
560 SetupTree(); | 630 SetupTree(); |
561 WillBeginTest(); | 631 WillBeginTest(); |
562 BeginTest(); | 632 BeginTest(); |
563 beginning_ = false; | 633 beginning_ = false; |
564 if (end_when_begin_returns_) | 634 if (end_when_begin_returns_) |
565 RealEndTest(); | 635 RealEndTest(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 783 } |
714 | 784 |
715 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { | 785 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
716 scoped_ptr<FakeOutputSurface> output_surface = | 786 scoped_ptr<FakeOutputSurface> output_surface = |
717 CreateFakeOutputSurface(fallback); | 787 CreateFakeOutputSurface(fallback); |
718 if (output_surface) { | 788 if (output_surface) { |
719 DCHECK_EQ(delegating_renderer_, | 789 DCHECK_EQ(delegating_renderer_, |
720 output_surface->capabilities().delegated_rendering); | 790 output_surface->capabilities().delegated_rendering); |
721 } | 791 } |
722 output_surface_ = output_surface.get(); | 792 output_surface_ = output_surface.get(); |
| 793 |
| 794 if (settings_.begin_frame_scheduling_enabled && |
| 795 settings_.throttle_frame_production) { |
| 796 DCHECK(external_begin_frame_source_); |
| 797 DCHECK(external_begin_frame_source_->is_ready()); |
| 798 } |
723 return output_surface.Pass(); | 799 return output_surface.Pass(); |
724 } | 800 } |
725 | 801 |
726 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( | 802 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( |
727 bool fallback) { | 803 bool fallback) { |
728 if (delegating_renderer_) | 804 if (delegating_renderer_) |
729 return FakeOutputSurface::CreateDelegating3d(); | 805 return FakeOutputSurface::CreateDelegating3d(); |
730 else | 806 else |
731 return FakeOutputSurface::Create3d(); | 807 return FakeOutputSurface::Create3d(); |
732 } | 808 } |
(...skipping 13 matching lines...) Expand all Loading... |
746 return -1; | 822 return -1; |
747 } | 823 } |
748 | 824 |
749 void LayerTreeTest::DestroyLayerTreeHost() { | 825 void LayerTreeTest::DestroyLayerTreeHost() { |
750 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 826 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
751 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 827 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
752 layer_tree_host_ = nullptr; | 828 layer_tree_host_ = nullptr; |
753 } | 829 } |
754 | 830 |
755 } // namespace cc | 831 } // namespace cc |
OLD | NEW |