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/fake_layer_tree_host_client.h" | 18 #include "cc/test/fake_layer_tree_host_client.h" |
19 #include "cc/test/fake_output_surface.h" | 19 #include "cc/test/fake_output_surface.h" |
20 #include "cc/test/test_context_provider.h" | 20 #include "cc/test/test_context_provider.h" |
21 #include "cc/test/test_shared_bitmap_manager.h" | 21 #include "cc/test/test_shared_bitmap_manager.h" |
22 #include "cc/test/tiled_layer_test_common.h" | 22 #include "cc/test/tiled_layer_test_common.h" |
23 #include "cc/trees/layer_tree_host_client.h" | 23 #include "cc/trees/layer_tree_host_client.h" |
24 #include "cc/trees/layer_tree_host_impl.h" | 24 #include "cc/trees/layer_tree_host_impl.h" |
25 #include "cc/trees/layer_tree_host_single_thread_client.h" | 25 #include "cc/trees/layer_tree_host_single_thread_client.h" |
26 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
27 #include "cc/trees/single_thread_proxy.h" | 27 #include "cc/trees/single_thread_proxy.h" |
| 28 #include "cc/trees/thread_proxy.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "ui/gfx/frame_time.h" | 30 #include "ui/gfx/frame_time.h" |
30 #include "ui/gfx/size_conversions.h" | 31 #include "ui/gfx/size_conversions.h" |
31 | 32 |
32 namespace cc { | 33 namespace cc { |
33 | 34 |
34 TestHooks::TestHooks() {} | 35 TestHooks::TestHooks() {} |
35 | 36 |
36 TestHooks::~TestHooks() {} | 37 TestHooks::~TestHooks() {} |
37 | 38 |
38 DrawSwapReadbackResult::DrawResult TestHooks::PrepareToDrawOnThread( | 39 DrawSwapReadbackResult::DrawResult TestHooks::PrepareToDrawOnThread( |
39 LayerTreeHostImpl* host_impl, | 40 LayerTreeHostImpl* host_impl, |
40 LayerTreeHostImpl::FrameData* frame_data, | 41 LayerTreeHostImpl::FrameData* frame_data, |
41 DrawSwapReadbackResult::DrawResult draw_result) { | 42 DrawSwapReadbackResult::DrawResult draw_result) { |
42 return draw_result; | 43 return draw_result; |
43 } | 44 } |
44 | 45 |
45 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { | 46 base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { |
46 return base::TimeDelta::FromMilliseconds(16); | 47 return base::TimeDelta::FromMilliseconds(16); |
47 } | 48 } |
48 | 49 |
| 50 // Adapts ThreadProxy for test. Injects test hooks for testing. |
| 51 class ThreadProxyForTest : public ThreadProxy { |
| 52 public: |
| 53 static scoped_ptr<Proxy> Create( |
| 54 TestHooks* test_hooks, |
| 55 LayerTreeHost* host, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| 57 return make_scoped_ptr( |
| 58 new ThreadProxyForTest(test_hooks, |
| 59 host, |
| 60 impl_task_runner)).PassAs<Proxy>(); |
| 61 } |
| 62 |
| 63 virtual ~ThreadProxyForTest() {} |
| 64 |
| 65 private: |
| 66 TestHooks* test_hooks_; |
| 67 |
| 68 ThreadProxyForTest( |
| 69 TestHooks* test_hooks, |
| 70 LayerTreeHost* host, |
| 71 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 72 : ThreadProxy(host, impl_task_runner), |
| 73 test_hooks_(test_hooks) { |
| 74 } |
| 75 }; |
| 76 |
49 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 77 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
50 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 78 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
51 public: | 79 public: |
52 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 80 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
53 TestHooks* test_hooks, | 81 TestHooks* test_hooks, |
54 const LayerTreeSettings& settings, | 82 const LayerTreeSettings& settings, |
55 LayerTreeHostImplClient* host_impl_client, | 83 LayerTreeHostImplClient* host_impl_client, |
56 Proxy* proxy, | 84 Proxy* proxy, |
57 SharedBitmapManager* manager, | 85 SharedBitmapManager* manager, |
58 RenderingStatsInstrumentation* stats_instrumentation) { | 86 RenderingStatsInstrumentation* stats_instrumentation) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 virtual void SetNeedsCommit() OVERRIDE { | 341 virtual void SetNeedsCommit() OVERRIDE { |
314 if (!test_started_) | 342 if (!test_started_) |
315 return; | 343 return; |
316 LayerTreeHost::SetNeedsCommit(); | 344 LayerTreeHost::SetNeedsCommit(); |
317 } | 345 } |
318 | 346 |
319 void set_test_started(bool started) { test_started_ = started; } | 347 void set_test_started(bool started) { test_started_ = started; } |
320 | 348 |
321 virtual void DidDeferCommit() OVERRIDE { test_hooks_->DidDeferCommit(); } | 349 virtual void DidDeferCommit() OVERRIDE { test_hooks_->DidDeferCommit(); } |
322 | 350 |
| 351 virtual void InitializeThreaded( |
| 352 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) OVERRIDE { |
| 353 InitializeProxy( |
| 354 ThreadProxyForTest::Create(test_hooks_, this, impl_task_runner)); |
| 355 } |
| 356 |
323 private: | 357 private: |
324 LayerTreeHostForTesting(TestHooks* test_hooks, | 358 LayerTreeHostForTesting(TestHooks* test_hooks, |
325 LayerTreeHostClient* client, | 359 LayerTreeHostClient* client, |
326 const LayerTreeSettings& settings) | 360 const LayerTreeSettings& settings) |
327 : LayerTreeHost(client, NULL, settings), | 361 : LayerTreeHost(client, NULL, settings), |
328 shared_bitmap_manager_(new TestSharedBitmapManager()), | 362 shared_bitmap_manager_(new TestSharedBitmapManager()), |
329 test_hooks_(test_hooks), | 363 test_hooks_(test_hooks), |
330 test_started_(false) {} | 364 test_started_(false) {} |
331 | 365 |
332 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 366 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 return -1; | 738 return -1; |
705 } | 739 } |
706 | 740 |
707 void LayerTreeTest::DestroyLayerTreeHost() { | 741 void LayerTreeTest::DestroyLayerTreeHost() { |
708 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 742 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
709 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 743 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
710 layer_tree_host_.reset(); | 744 layer_tree_host_.reset(); |
711 } | 745 } |
712 | 746 |
713 } // namespace cc | 747 } // namespace cc |
OLD | NEW |