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" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 TestHooks::TestHooks() {} | 30 TestHooks::TestHooks() {} |
31 | 31 |
32 TestHooks::~TestHooks() {} | 32 TestHooks::~TestHooks() {} |
33 | 33 |
34 bool TestHooks::PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 34 bool TestHooks::PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
35 LayerTreeHostImpl::FrameData* frame_data, | 35 LayerTreeHostImpl::FrameData* frame_data, |
36 bool result) { | 36 bool result) { |
37 return true; | 37 return true; |
38 } | 38 } |
39 | 39 |
40 bool TestHooks::CanActivatePendingTree(LayerTreeHostImpl* host_impl) { | 40 class LayerTreeHostImplClientInterposer : public LayerTreeHostImplClient { |
41 return true; | 41 public: |
42 } | 42 LayerTreeHostImplClientInterposer(LayerTreeHostImplClient* client) |
43 : client_(client), | |
44 block_notify_ready_to_activate_(false), | |
45 notify_ready_to_activate_was_blocked_(false) { } | |
43 | 46 |
44 bool TestHooks::CanActivatePendingTreeIfNeeded(LayerTreeHostImpl* host_impl) { | 47 // LayerTreeHostImplClient interface |
45 return true; | 48 virtual void DidTryInitializeRendererOnImplThread( |
46 } | 49 bool success, |
50 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { | |
51 client_->DidTryInitializeRendererOnImplThread( | |
52 success, offscreen_context_provider); | |
53 } | |
54 | |
55 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE { | |
56 client_->DidLoseOutputSurfaceOnImplThread(); | |
57 } | |
58 | |
59 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE { | |
60 client_->OnSwapBuffersCompleteOnImplThread(); | |
61 } | |
62 | |
63 virtual void BeginFrameOnImplThread(const BeginFrameArgs& args) OVERRIDE { | |
64 client_->BeginFrameOnImplThread(args); | |
65 } | |
66 | |
67 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { | |
68 client_->OnCanDrawStateChanged(can_draw); | |
69 } | |
70 | |
71 virtual void NotifyReadyToActivate() OVERRIDE { | |
72 if (block_notify_ready_to_activate_) | |
73 notify_ready_to_activate_was_blocked_ = true; | |
74 else | |
75 client_->NotifyReadyToActivate(); | |
76 } | |
77 | |
78 virtual void SetNeedsRedrawOnImplThread() OVERRIDE { | |
79 client_->SetNeedsRedrawOnImplThread(); | |
80 } | |
81 | |
82 virtual void SetNeedsRedrawRectOnImplThread(gfx::Rect damage_rect) OVERRIDE { | |
83 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | |
84 } | |
85 | |
86 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE { | |
87 client_->DidInitializeVisibleTileOnImplThread(); | |
88 } | |
89 | |
90 virtual void SetNeedsCommitOnImplThread() OVERRIDE { | |
91 client_->SetNeedsCommitOnImplThread(); | |
92 } | |
93 | |
94 virtual void PostAnimationEventsToMainThreadOnImplThread( | |
95 scoped_ptr<AnimationEventsVector> events, | |
96 base::Time wall_clock_time) OVERRIDE { | |
97 client_->PostAnimationEventsToMainThreadOnImplThread( | |
98 events.Pass(), wall_clock_time); | |
99 } | |
100 | |
101 virtual bool ReduceContentsTextureMemoryOnImplThread( | |
102 size_t limit_bytes, | |
103 int priority_cutoff) OVERRIDE { | |
104 return client_->ReduceContentsTextureMemoryOnImplThread( | |
105 limit_bytes, priority_cutoff); | |
106 } | |
107 | |
108 virtual void ReduceWastedContentsTextureMemoryOnImplThread() { | |
109 client_->ReduceWastedContentsTextureMemoryOnImplThread(); | |
110 } | |
111 | |
112 virtual void SendManagedMemoryStats() OVERRIDE { | |
113 client_->SendManagedMemoryStats(); | |
114 } | |
115 | |
116 virtual bool IsInsideDraw() OVERRIDE { | |
117 return client_->IsInsideDraw(); | |
118 } | |
119 | |
120 virtual void RenewTreePriority() OVERRIDE { | |
121 client_->RenewTreePriority(); | |
122 } | |
123 | |
124 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) | |
125 OVERRIDE { | |
126 client_->RequestScrollbarAnimationOnImplThread(delay); | |
127 } | |
128 | |
129 virtual void DidActivatePendingTree() OVERRIDE { | |
130 client_->DidActivatePendingTree(); | |
131 } | |
132 | |
133 // Test hooks | |
134 void BlockNotifyReadyToActivate(bool block) { | |
135 block_notify_ready_to_activate_ = block; | |
136 if (!block && notify_ready_to_activate_was_blocked_) { | |
137 NotifyReadyToActivate(); | |
138 } | |
139 } | |
140 | |
141 private: | |
142 LayerTreeHostImplClient* client_; | |
143 bool block_notify_ready_to_activate_; | |
144 bool notify_ready_to_activate_was_blocked_; | |
145 }; | |
146 | |
47 | 147 |
48 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 148 // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
49 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { | 149 class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
50 public: | 150 public: |
51 static scoped_ptr<LayerTreeHostImplForTesting> Create( | 151 static scoped_ptr<LayerTreeHostImplForTesting> Create( |
52 TestHooks* test_hooks, | 152 TestHooks* test_hooks, |
53 const LayerTreeSettings& settings, | 153 const LayerTreeSettings& settings, |
54 LayerTreeHostImplClient* host_impl_client, | 154 LayerTreeHostImplClient* host_impl_client, |
55 Proxy* proxy, | 155 Proxy* proxy, |
56 RenderingStatsInstrumentation* stats_instrumentation) { | 156 RenderingStatsInstrumentation* stats_instrumentation) { |
(...skipping 11 matching lines...) Expand all Loading... | |
68 const LayerTreeSettings& settings, | 168 const LayerTreeSettings& settings, |
69 LayerTreeHostImplClient* host_impl_client, | 169 LayerTreeHostImplClient* host_impl_client, |
70 Proxy* proxy, | 170 Proxy* proxy, |
71 RenderingStatsInstrumentation* stats_instrumentation) | 171 RenderingStatsInstrumentation* stats_instrumentation) |
72 : LayerTreeHostImpl(settings, | 172 : LayerTreeHostImpl(settings, |
73 host_impl_client, | 173 host_impl_client, |
74 proxy, | 174 proxy, |
75 stats_instrumentation), | 175 stats_instrumentation), |
76 test_hooks_(test_hooks) {} | 176 test_hooks_(test_hooks) {} |
77 | 177 |
178 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE { | |
179 test_hooks_->WillBeginFrameOnThread(this, args); | |
180 LayerTreeHostImpl::BeginFrame(args); | |
181 } | |
182 | |
78 virtual void BeginCommit() OVERRIDE { | 183 virtual void BeginCommit() OVERRIDE { |
79 LayerTreeHostImpl::BeginCommit(); | 184 LayerTreeHostImpl::BeginCommit(); |
80 test_hooks_->BeginCommitOnThread(this); | 185 test_hooks_->BeginCommitOnThread(this); |
81 } | 186 } |
82 | 187 |
83 virtual void CommitComplete() OVERRIDE { | 188 virtual void CommitComplete() OVERRIDE { |
84 LayerTreeHostImpl::CommitComplete(); | 189 LayerTreeHostImpl::CommitComplete(); |
85 test_hooks_->CommitCompleteOnThread(this); | 190 test_hooks_->CommitCompleteOnThread(this); |
86 | 191 |
87 if (!settings().impl_side_painting) { | 192 if (!settings().impl_side_painting) { |
(...skipping 19 matching lines...) Expand all Loading... | |
107 bool result = LayerTreeHostImpl::SwapBuffers(frame); | 212 bool result = LayerTreeHostImpl::SwapBuffers(frame); |
108 test_hooks_->SwapBuffersOnThread(this, result); | 213 test_hooks_->SwapBuffersOnThread(this, result); |
109 return result; | 214 return result; |
110 } | 215 } |
111 | 216 |
112 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE { | 217 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE { |
113 LayerTreeHostImpl::OnSwapBuffersComplete(ack); | 218 LayerTreeHostImpl::OnSwapBuffersComplete(ack); |
114 test_hooks_->SwapBuffersCompleteOnThread(this); | 219 test_hooks_->SwapBuffersCompleteOnThread(this); |
115 } | 220 } |
116 | 221 |
117 virtual void ActivatePendingTreeIfNeeded() OVERRIDE { | |
118 if (!pending_tree()) | |
119 return; | |
120 | |
121 if (!test_hooks_->CanActivatePendingTreeIfNeeded(this)) | |
122 return; | |
123 | |
124 LayerTreeHostImpl::ActivatePendingTreeIfNeeded(); | |
125 } | |
126 | |
127 virtual void ActivatePendingTree() OVERRIDE { | 222 virtual void ActivatePendingTree() OVERRIDE { |
128 if (!test_hooks_->CanActivatePendingTree(this)) | |
129 return; | |
130 | |
131 test_hooks_->WillActivateTreeOnThread(this); | 223 test_hooks_->WillActivateTreeOnThread(this); |
132 LayerTreeHostImpl::ActivatePendingTree(); | 224 LayerTreeHostImpl::ActivatePendingTree(); |
133 DCHECK(!pending_tree()); | 225 DCHECK(!pending_tree()); |
134 test_hooks_->DidActivateTreeOnThread(this); | 226 test_hooks_->DidActivateTreeOnThread(this); |
135 } | 227 } |
136 | 228 |
137 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface) | 229 virtual bool InitializeRenderer(scoped_ptr<OutputSurface> output_surface) |
138 OVERRIDE { | 230 OVERRIDE { |
139 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass()); | 231 bool success = LayerTreeHostImpl::InitializeRenderer(output_surface.Pass()); |
140 test_hooks_->InitializedRendererOnThread(this, success); | 232 test_hooks_->InitializedRendererOnThread(this, success); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 private: | 266 private: |
175 TestHooks* test_hooks_; | 267 TestHooks* test_hooks_; |
176 }; | 268 }; |
177 | 269 |
178 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. | 270 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. |
179 class LayerTreeHostForTesting : public cc::LayerTreeHost { | 271 class LayerTreeHostForTesting : public cc::LayerTreeHost { |
180 public: | 272 public: |
181 static scoped_ptr<LayerTreeHostForTesting> Create( | 273 static scoped_ptr<LayerTreeHostForTesting> Create( |
182 TestHooks* test_hooks, | 274 TestHooks* test_hooks, |
183 cc::LayerTreeHostClient* host_client, | 275 cc::LayerTreeHostClient* host_client, |
276 scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer, | |
184 const cc::LayerTreeSettings& settings, | 277 const cc::LayerTreeSettings& settings, |
185 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 278 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
186 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( | 279 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
187 new LayerTreeHostForTesting(test_hooks, host_client, settings)); | 280 new LayerTreeHostForTesting( |
281 test_hooks, host_client, impl_client_interposer, settings)); | |
188 bool success = layer_tree_host->Initialize(impl_task_runner); | 282 bool success = layer_tree_host->Initialize(impl_task_runner); |
189 EXPECT_TRUE(success); | 283 EXPECT_TRUE(success); |
190 return layer_tree_host.Pass(); | 284 return layer_tree_host.Pass(); |
191 } | 285 } |
192 | 286 |
193 virtual scoped_ptr<cc::LayerTreeHostImpl> CreateLayerTreeHostImpl( | 287 virtual scoped_ptr<cc::LayerTreeHostImpl> CreateLayerTreeHostImpl( |
194 cc::LayerTreeHostImplClient* host_impl_client) OVERRIDE { | 288 cc::LayerTreeHostImplClient* host_impl_client) OVERRIDE { |
289 impl_client_interposer_.reset( | |
290 new LayerTreeHostImplClientInterposer(host_impl_client)); | |
brianderson
2013/08/24 02:33:29
I'm trying to think of a better way to do this...
enne (OOO)
2013/08/26 21:55:13
This seems fine to me. It's unfortunate that beca
| |
195 return LayerTreeHostImplForTesting::Create( | 291 return LayerTreeHostImplForTesting::Create( |
196 test_hooks_, | 292 test_hooks_, |
197 settings(), | 293 settings(), |
198 host_impl_client, | 294 impl_client_interposer_.get(), |
199 proxy(), | 295 proxy(), |
200 rendering_stats_instrumentation()).PassAs<cc::LayerTreeHostImpl>(); | 296 rendering_stats_instrumentation()).PassAs<cc::LayerTreeHostImpl>(); |
201 } | 297 } |
202 | 298 |
203 virtual void SetNeedsCommit() OVERRIDE { | 299 virtual void SetNeedsCommit() OVERRIDE { |
204 if (!test_started_) | 300 if (!test_started_) |
205 return; | 301 return; |
206 LayerTreeHost::SetNeedsCommit(); | 302 LayerTreeHost::SetNeedsCommit(); |
207 } | 303 } |
208 | 304 |
209 void set_test_started(bool started) { test_started_ = started; } | 305 void set_test_started(bool started) { test_started_ = started; } |
210 | 306 |
211 virtual void DidDeferCommit() OVERRIDE { | 307 virtual void DidDeferCommit() OVERRIDE { |
212 test_hooks_->DidDeferCommit(); | 308 test_hooks_->DidDeferCommit(); |
213 } | 309 } |
214 | 310 |
215 private: | 311 private: |
216 LayerTreeHostForTesting(TestHooks* test_hooks, | 312 LayerTreeHostForTesting( |
217 cc::LayerTreeHostClient* client, | 313 TestHooks* test_hooks, |
218 const cc::LayerTreeSettings& settings) | 314 cc::LayerTreeHostClient* client, |
219 : LayerTreeHost(client, settings), | 315 scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer, |
220 test_hooks_(test_hooks), | 316 const cc::LayerTreeSettings& settings) |
221 test_started_(false) {} | 317 : LayerTreeHost(client, settings), |
318 test_hooks_(test_hooks), | |
319 impl_client_interposer_(impl_client_interposer), | |
320 test_started_(false) {} | |
222 | 321 |
223 TestHooks* test_hooks_; | 322 TestHooks* test_hooks_; |
323 scoped_ptr<LayerTreeHostImplClientInterposer> &impl_client_interposer_; | |
224 bool test_started_; | 324 bool test_started_; |
225 }; | 325 }; |
226 | 326 |
227 // Implementation of LayerTreeHost callback interface. | 327 // Implementation of LayerTreeHost callback interface. |
228 class LayerTreeHostClientForTesting : public LayerTreeHostClient { | 328 class LayerTreeHostClientForTesting : public LayerTreeHostClient { |
229 public: | 329 public: |
230 static scoped_ptr<LayerTreeHostClientForTesting> Create( | 330 static scoped_ptr<LayerTreeHostClientForTesting> Create( |
231 TestHooks* test_hooks) { | 331 TestHooks* test_hooks) { |
232 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks)); | 332 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks)); |
233 } | 333 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 visible)); | 497 visible)); |
398 } | 498 } |
399 | 499 |
400 void LayerTreeTest::DoBeginTest() { | 500 void LayerTreeTest::DoBeginTest() { |
401 client_ = LayerTreeHostClientForTesting::Create(this); | 501 client_ = LayerTreeHostClientForTesting::Create(this); |
402 | 502 |
403 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); | 503 DCHECK(!impl_thread_ || impl_thread_->message_loop_proxy().get()); |
404 layer_tree_host_ = LayerTreeHostForTesting::Create( | 504 layer_tree_host_ = LayerTreeHostForTesting::Create( |
405 this, | 505 this, |
406 client_.get(), | 506 client_.get(), |
507 impl_client_, | |
407 settings_, | 508 settings_, |
408 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); | 509 impl_thread_ ? impl_thread_->message_loop_proxy() : NULL); |
409 ASSERT_TRUE(layer_tree_host_); | 510 ASSERT_TRUE(layer_tree_host_); |
410 | 511 |
411 started_ = true; | 512 started_ = true; |
412 beginning_ = true; | 513 beginning_ = true; |
413 SetupTree(); | 514 SetupTree(); |
414 layer_tree_host_->SetLayerTreeHostClientReady(); | 515 layer_tree_host_->SetLayerTreeHostClientReady(); |
415 BeginTest(); | 516 BeginTest(); |
416 beginning_ = false; | 517 beginning_ = false; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 | 695 |
595 ASSERT_FALSE(layer_tree_host_.get()); | 696 ASSERT_FALSE(layer_tree_host_.get()); |
596 client_.reset(); | 697 client_.reset(); |
597 if (timed_out_) { | 698 if (timed_out_) { |
598 FAIL() << "Test timed out"; | 699 FAIL() << "Test timed out"; |
599 return; | 700 return; |
600 } | 701 } |
601 AfterTest(); | 702 AfterTest(); |
602 } | 703 } |
603 | 704 |
705 void LayerTreeTest::BlockNotifyReadyToActivate(bool block) { | |
706 impl_client_->BlockNotifyReadyToActivate(block); | |
707 } | |
708 | |
604 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { | 709 scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
605 scoped_ptr<FakeOutputSurface> output_surface; | 710 scoped_ptr<FakeOutputSurface> output_surface; |
606 if (delegating_renderer_) | 711 if (delegating_renderer_) |
607 output_surface = FakeOutputSurface::CreateDelegating3d(); | 712 output_surface = FakeOutputSurface::CreateDelegating3d(); |
608 else | 713 else |
609 output_surface = FakeOutputSurface::Create3d(); | 714 output_surface = FakeOutputSurface::Create3d(); |
610 output_surface_ = output_surface.get(); | 715 output_surface_ = output_surface.get(); |
611 return output_surface.PassAs<OutputSurface>(); | 716 return output_surface.PassAs<OutputSurface>(); |
612 } | 717 } |
613 | 718 |
(...skipping 10 matching lines...) Expand all Loading... | |
624 | 729 |
625 scoped_refptr<cc::ContextProvider> LayerTreeTest:: | 730 scoped_refptr<cc::ContextProvider> LayerTreeTest:: |
626 OffscreenContextProviderForCompositorThread() { | 731 OffscreenContextProviderForCompositorThread() { |
627 if (!compositor_thread_contexts_.get() || | 732 if (!compositor_thread_contexts_.get() || |
628 compositor_thread_contexts_->DestroyedOnMainThread()) | 733 compositor_thread_contexts_->DestroyedOnMainThread()) |
629 compositor_thread_contexts_ = TestContextProvider::Create(); | 734 compositor_thread_contexts_ = TestContextProvider::Create(); |
630 return compositor_thread_contexts_; | 735 return compositor_thread_contexts_; |
631 } | 736 } |
632 | 737 |
633 } // namespace cc | 738 } // namespace cc |
OLD | NEW |