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 18 matching lines...) Expand all Loading... |
46 | 47 |
47 void TestHooks::CreateResourceAndRasterWorkerPool( | 48 void TestHooks::CreateResourceAndRasterWorkerPool( |
48 LayerTreeHostImpl* host_impl, | 49 LayerTreeHostImpl* host_impl, |
49 scoped_ptr<RasterWorkerPool>* raster_worker_pool, | 50 scoped_ptr<RasterWorkerPool>* raster_worker_pool, |
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 |
| 57 class ExternalBeginFrameSourceForTest |
| 58 : public BeginFrameSourceMixIn, |
| 59 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 60 public: |
| 61 explicit ExternalBeginFrameSourceForTest(double refresh_rate) |
| 62 : milliseconds_per_frame_(1000.0 / refresh_rate), |
| 63 is_ready_(false), |
| 64 weak_ptr_factory_(this) { |
| 65 DetachFromThread(); |
| 66 } |
| 67 |
| 68 virtual ~ExternalBeginFrameSourceForTest() { |
| 69 DCHECK(CalledOnValidThread()); |
| 70 } |
| 71 |
| 72 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 73 DCHECK(CalledOnValidThread()); |
| 74 if (needs_begin_frames) { |
| 75 base::MessageLoop::current()->PostDelayedTask( |
| 76 FROM_HERE, |
| 77 base::Bind(&ExternalBeginFrameSourceForTest::TestOnBeginFrame, |
| 78 weak_ptr_factory_.GetWeakPtr()), |
| 79 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_)); |
| 80 } |
| 81 } |
| 82 |
| 83 virtual void SetClientReady() override { |
| 84 DCHECK(CalledOnValidThread()); |
| 85 is_ready_ = true; |
| 86 } |
| 87 |
| 88 bool is_ready() const { |
| 89 return is_ready_; |
| 90 } |
| 91 |
| 92 void TestOnBeginFrame() { |
| 93 DCHECK(CalledOnValidThread()); |
| 94 CallOnBeginFrame(CreateBeginFrameArgsForTesting()); |
| 95 } |
| 96 |
| 97 private: |
| 98 double milliseconds_per_frame_; |
| 99 bool is_ready_; |
| 100 base::WeakPtrFactory<ExternalBeginFrameSourceForTest> weak_ptr_factory_; |
| 101 }; |
| 102 |
56 // Adapts ThreadProxy for test. Injects test hooks for testing. | 103 // Adapts ThreadProxy for test. Injects test hooks for testing. |
57 class ThreadProxyForTest : public ThreadProxy { | 104 class ThreadProxyForTest : public ThreadProxy { |
58 public: | 105 public: |
59 static scoped_ptr<Proxy> Create( | 106 static scoped_ptr<Proxy> Create( |
60 TestHooks* test_hooks, | 107 TestHooks* test_hooks, |
61 LayerTreeHost* host, | 108 LayerTreeHost* host, |
62 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 109 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
63 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 110 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 111 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
64 return make_scoped_ptr(new ThreadProxyForTest( | 112 return make_scoped_ptr(new ThreadProxyForTest( |
65 test_hooks, host, main_task_runner, impl_task_runner)); | 113 test_hooks, |
| 114 host, |
| 115 main_task_runner, |
| 116 impl_task_runner, |
| 117 external_begin_frame_source.Pass())); |
66 } | 118 } |
67 | 119 |
68 ~ThreadProxyForTest() override {} | 120 ~ThreadProxyForTest() override {} |
69 | 121 |
70 void test() { | 122 void test() { |
71 test_hooks_->Layout(); | 123 test_hooks_->Layout(); |
72 } | 124 } |
73 | 125 |
74 private: | 126 private: |
75 TestHooks* test_hooks_; | 127 TestHooks* test_hooks_; |
(...skipping 22 matching lines...) Expand all Loading... |
98 | 150 |
99 void ScheduledActionBeginOutputSurfaceCreation() override { | 151 void ScheduledActionBeginOutputSurfaceCreation() override { |
100 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); | 152 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
101 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); | 153 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
102 } | 154 } |
103 | 155 |
104 ThreadProxyForTest( | 156 ThreadProxyForTest( |
105 TestHooks* test_hooks, | 157 TestHooks* test_hooks, |
106 LayerTreeHost* host, | 158 LayerTreeHost* host, |
107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 159 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
108 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 160 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
109 : ThreadProxy(host, main_task_runner, impl_task_runner), | 161 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 162 : ThreadProxy(host, main_task_runner, |
| 163 impl_task_runner, |
| 164 external_begin_frame_source.Pass()), |
110 test_hooks_(test_hooks) {} | 165 test_hooks_(test_hooks) {} |
111 }; | 166 }; |
112 | 167 |
113 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 168 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
114 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 169 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
115 public: | 170 public: |
116 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 171 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
117 TestHooks* test_hooks, | 172 TestHooks* test_hooks, |
118 const LayerTreeSettings& settings, | 173 const LayerTreeSettings& settings, |
119 LayerTreeHostImplClient* host_impl_client, | 174 LayerTreeHostImplClient* host_impl_client, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 }; | 401 }; |
347 | 402 |
348 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 403 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
349 class LayerTreeHostForTesting : public LayerTreeHost { | 404 class LayerTreeHostForTesting : public LayerTreeHost { |
350 public: | 405 public: |
351 static scoped_ptr<LayerTreeHostForTesting> Create( | 406 static scoped_ptr<LayerTreeHostForTesting> Create( |
352 TestHooks* test_hooks, | 407 TestHooks* test_hooks, |
353 LayerTreeHostClientForTesting* client, | 408 LayerTreeHostClientForTesting* client, |
354 const LayerTreeSettings& settings, | 409 const LayerTreeSettings& settings, |
355 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 410 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
356 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 411 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 412 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
357 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 413 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
358 new LayerTreeHostForTesting(test_hooks, client, settings)); | 414 new LayerTreeHostForTesting(test_hooks, client, settings)); |
359 if (impl_task_runner.get()) { | 415 if (impl_task_runner.get()) { |
360 layer_tree_host->InitializeForTesting( | 416 layer_tree_host->InitializeForTesting( |
361 ThreadProxyForTest::Create(test_hooks, | 417 ThreadProxyForTest::Create(test_hooks, |
362 layer_tree_host.get(), | 418 layer_tree_host.get(), |
363 main_task_runner, | 419 main_task_runner, |
364 impl_task_runner)); | 420 impl_task_runner, |
| 421 external_begin_frame_source.Pass())); |
365 } else { | 422 } else { |
366 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( | 423 layer_tree_host->InitializeForTesting(SingleThreadProxy::Create( |
367 layer_tree_host.get(), client, main_task_runner)); | 424 layer_tree_host.get(), |
| 425 client, |
| 426 main_task_runner, |
| 427 external_begin_frame_source.Pass())); |
368 } | 428 } |
369 return layer_tree_host.Pass(); | 429 return layer_tree_host.Pass(); |
370 } | 430 } |
371 | 431 |
372 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 432 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
373 LayerTreeHostImplClient* host_impl_client) override { | 433 LayerTreeHostImplClient* host_impl_client) override { |
374 return LayerTreeHostImplForTesting::Create( | 434 return LayerTreeHostImplForTesting::Create( |
375 test_hooks_, | 435 test_hooks_, |
376 settings(), | 436 settings(), |
377 host_impl_client, | 437 host_impl_client, |
(...skipping 24 matching lines...) Expand all Loading... |
402 test_started_(false) {} | 462 test_started_(false) {} |
403 | 463 |
404 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; | 464 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
405 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 465 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
406 TestHooks* test_hooks_; | 466 TestHooks* test_hooks_; |
407 bool test_started_; | 467 bool test_started_; |
408 }; | 468 }; |
409 | 469 |
410 LayerTreeTest::LayerTreeTest() | 470 LayerTreeTest::LayerTreeTest() |
411 : output_surface_(nullptr), | 471 : output_surface_(nullptr), |
| 472 external_begin_frame_source_(nullptr), |
412 beginning_(false), | 473 beginning_(false), |
413 end_when_begin_returns_(false), | 474 end_when_begin_returns_(false), |
414 timed_out_(false), | 475 timed_out_(false), |
415 scheduled_(false), | 476 scheduled_(false), |
416 started_(false), | 477 started_(false), |
417 ended_(false), | 478 ended_(false), |
418 delegating_renderer_(false), | 479 delegating_renderer_(false), |
419 timeout_seconds_(0), | 480 timeout_seconds_(0), |
420 weak_factory_(this) { | 481 weak_factory_(this) { |
421 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 482 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 main_thread_weak_ptr_)); | 592 main_thread_weak_ptr_)); |
532 } | 593 } |
533 | 594 |
534 void LayerTreeTest::WillBeginTest() { | 595 void LayerTreeTest::WillBeginTest() { |
535 layer_tree_host_->SetLayerTreeHostClientReady(); | 596 layer_tree_host_->SetLayerTreeHostClientReady(); |
536 } | 597 } |
537 | 598 |
538 void LayerTreeTest::DoBeginTest() { | 599 void LayerTreeTest::DoBeginTest() { |
539 client_ = LayerTreeHostClientForTesting::Create(this); | 600 client_ = LayerTreeHostClientForTesting::Create(this); |
540 | 601 |
| 602 scoped_ptr<ExternalBeginFrameSourceForTest> external_begin_frame_source; |
| 603 if (settings_.begin_frame_scheduling_enabled && |
| 604 settings_.throttle_frame_production) { |
| 605 external_begin_frame_source.reset( |
| 606 new ExternalBeginFrameSourceForTest(settings_.refresh_rate)); |
| 607 external_begin_frame_source_ = external_begin_frame_source.get(); |
| 608 } |
| 609 |
541 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); | 610 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); |
542 layer_tree_host_ = LayerTreeHostForTesting::Create( | 611 layer_tree_host_ = LayerTreeHostForTesting::Create( |
543 this, | 612 this, |
544 client_.get(), | 613 client_.get(), |
545 settings_, | 614 settings_, |
546 base::MessageLoopProxy::current(), | 615 base::MessageLoopProxy::current(), |
547 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); | 616 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL, |
| 617 external_begin_frame_source.Pass()); |
548 ASSERT_TRUE(layer_tree_host_); | 618 ASSERT_TRUE(layer_tree_host_); |
549 | 619 |
550 started_ = true; | 620 started_ = true; |
551 beginning_ = true; | 621 beginning_ = true; |
552 SetupTree(); | 622 SetupTree(); |
553 WillBeginTest(); | 623 WillBeginTest(); |
554 BeginTest(); | 624 BeginTest(); |
555 beginning_ = false; | 625 beginning_ = false; |
556 if (end_when_begin_returns_) | 626 if (end_when_begin_returns_) |
557 RealEndTest(); | 627 RealEndTest(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 } | 776 } |
707 | 777 |
708 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { | 778 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
709 scoped_ptr<FakeOutputSurface> output_surface = | 779 scoped_ptr<FakeOutputSurface> output_surface = |
710 CreateFakeOutputSurface(fallback); | 780 CreateFakeOutputSurface(fallback); |
711 if (output_surface) { | 781 if (output_surface) { |
712 DCHECK_EQ(delegating_renderer_, | 782 DCHECK_EQ(delegating_renderer_, |
713 output_surface->capabilities().delegated_rendering); | 783 output_surface->capabilities().delegated_rendering); |
714 } | 784 } |
715 output_surface_ = output_surface.get(); | 785 output_surface_ = output_surface.get(); |
| 786 |
| 787 if (settings_.begin_frame_scheduling_enabled && |
| 788 settings_.throttle_frame_production) { |
| 789 DCHECK(external_begin_frame_source_); |
| 790 DCHECK(external_begin_frame_source_->is_ready()); |
| 791 } |
716 return output_surface.Pass(); | 792 return output_surface.Pass(); |
717 } | 793 } |
718 | 794 |
719 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( | 795 scoped_ptr<FakeOutputSurface> LayerTreeTest::CreateFakeOutputSurface( |
720 bool fallback) { | 796 bool fallback) { |
721 if (delegating_renderer_) | 797 if (delegating_renderer_) |
722 return FakeOutputSurface::CreateDelegating3d(); | 798 return FakeOutputSurface::CreateDelegating3d(); |
723 else | 799 else |
724 return FakeOutputSurface::Create3d(); | 800 return FakeOutputSurface::Create3d(); |
725 } | 801 } |
(...skipping 13 matching lines...) Expand all Loading... |
739 return -1; | 815 return -1; |
740 } | 816 } |
741 | 817 |
742 void LayerTreeTest::DestroyLayerTreeHost() { | 818 void LayerTreeTest::DestroyLayerTreeHost() { |
743 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 819 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
744 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 820 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
745 layer_tree_host_ = nullptr; | 821 layer_tree_host_ = nullptr; |
746 } | 822 } |
747 | 823 |
748 } // namespace cc | 824 } // namespace cc |
OLD | NEW |