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 DrawResult TestHooks::PrepareToDrawOnThread( | 39 DrawResult TestHooks::PrepareToDrawOnThread( |
39 LayerTreeHostImpl* host_impl, | 40 LayerTreeHostImpl* host_impl, |
40 LayerTreeHostImpl::FrameData* frame_data, | 41 LayerTreeHostImpl::FrameData* frame_data, |
41 DrawResult draw_result) { | 42 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 void test() { |
| 66 test_hooks_->Layout(); |
| 67 } |
| 68 |
| 69 private: |
| 70 TestHooks* test_hooks_; |
| 71 |
| 72 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE { |
| 73 ThreadProxy::ScheduledActionBeginOutputSurfaceCreation(); |
| 74 test_hooks_->ScheduledActionBeginOutputSurfaceCreation(); |
| 75 } |
| 76 |
| 77 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 78 ThreadProxy::ScheduledActionSendBeginMainFrame(); |
| 79 test_hooks_->ScheduledActionSendBeginMainFrame(); |
| 80 } |
| 81 |
| 82 virtual void ScheduledActionCommit() OVERRIDE { |
| 83 ThreadProxy::ScheduledActionCommit(); |
| 84 test_hooks_->ScheduledActionCommit(); |
| 85 } |
| 86 |
| 87 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
| 88 DrawResult result = ThreadProxy::ScheduledActionDrawAndSwapIfPossible(); |
| 89 test_hooks_->ScheduledActionDrawAndSwapIfPossible(); |
| 90 return result; |
| 91 } |
| 92 |
| 93 ThreadProxyForTest( |
| 94 TestHooks* test_hooks, |
| 95 LayerTreeHost* host, |
| 96 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 97 : ThreadProxy(host, impl_task_runner), |
| 98 test_hooks_(test_hooks) { |
| 99 } |
| 100 }; |
| 101 |
49 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 102 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
50 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 103 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
51 public: | 104 public: |
52 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 105 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
53 TestHooks* test_hooks, | 106 TestHooks* test_hooks, |
54 const LayerTreeSettings& settings, | 107 const LayerTreeSettings& settings, |
55 LayerTreeHostImplClient* host_impl_client, | 108 LayerTreeHostImplClient* host_impl_client, |
56 Proxy* proxy, | 109 Proxy* proxy, |
57 SharedBitmapManager* manager, | 110 SharedBitmapManager* manager, |
58 RenderingStatsInstrumentation* stats_instrumentation) { | 111 RenderingStatsInstrumentation* stats_instrumentation) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 331 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
279 class LayerTreeHostForTesting : public LayerTreeHost { | 332 class LayerTreeHostForTesting : public LayerTreeHost { |
280 public: | 333 public: |
281 static scoped_ptr<LayerTreeHostForTesting> Create( | 334 static scoped_ptr<LayerTreeHostForTesting> Create( |
282 TestHooks* test_hooks, | 335 TestHooks* test_hooks, |
283 LayerTreeHostClientForTesting* client, | 336 LayerTreeHostClientForTesting* client, |
284 const LayerTreeSettings& settings, | 337 const LayerTreeSettings& settings, |
285 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 338 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
286 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 339 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
287 new LayerTreeHostForTesting(test_hooks, client, settings)); | 340 new LayerTreeHostForTesting(test_hooks, client, settings)); |
288 if (impl_task_runner.get()) | 341 if (impl_task_runner.get()) { |
289 layer_tree_host->InitializeThreaded(impl_task_runner); | 342 layer_tree_host->InitializeForTesting( |
290 else | 343 ThreadProxyForTest::Create(test_hooks, |
291 layer_tree_host->InitializeSingleThreaded(client); | 344 layer_tree_host.get(), |
| 345 impl_task_runner)); |
| 346 } else { |
| 347 layer_tree_host->InitializeForTesting( |
| 348 SingleThreadProxy::Create(layer_tree_host.get(), client)); |
| 349 } |
292 return layer_tree_host.Pass(); | 350 return layer_tree_host.Pass(); |
293 } | 351 } |
294 | 352 |
295 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 353 virtual scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
296 LayerTreeHostImplClient* host_impl_client) OVERRIDE { | 354 LayerTreeHostImplClient* host_impl_client) OVERRIDE { |
297 return LayerTreeHostImplForTesting::Create( | 355 return LayerTreeHostImplForTesting::Create( |
298 test_hooks_, | 356 test_hooks_, |
299 settings(), | 357 settings(), |
300 host_impl_client, | 358 host_impl_client, |
301 proxy(), | 359 proxy(), |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 return -1; | 737 return -1; |
680 } | 738 } |
681 | 739 |
682 void LayerTreeTest::DestroyLayerTreeHost() { | 740 void LayerTreeTest::DestroyLayerTreeHost() { |
683 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 741 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
684 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 742 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
685 layer_tree_host_.reset(); | 743 layer_tree_host_.reset(); |
686 } | 744 } |
687 | 745 |
688 } // namespace cc | 746 } // namespace cc |
OLD | NEW |