| 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 settings.texture_id_allocation_chunk_size = 1; | 97 settings.texture_id_allocation_chunk_size = 1; |
| 98 return settings; | 98 return settings; |
| 99 } | 99 } |
| 100 | 100 |
| 101 virtual void SetUp() OVERRIDE { | 101 virtual void SetUp() OVERRIDE { |
| 102 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); | 102 CreateHostImpl(DefaultSettings(), CreateOutputSurface()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 virtual void TearDown() OVERRIDE {} | 105 virtual void TearDown() OVERRIDE {} |
| 106 | 106 |
| 107 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE {} |
| 107 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} | 108 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE {} |
| 108 virtual void DidSwapBuffersOnImplThread() OVERRIDE {} | 109 virtual void DidSwapBuffersOnImplThread() OVERRIDE {} |
| 109 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} | 110 virtual void OnSwapBuffersCompleteOnImplThread() OVERRIDE {} |
| 110 virtual void BeginImplFrame(const BeginFrameArgs& args) OVERRIDE {} | 111 virtual void BeginImplFrame(const BeginFrameArgs& args) OVERRIDE {} |
| 111 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { | 112 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE { |
| 112 on_can_draw_state_changed_called_ = true; | 113 on_can_draw_state_changed_called_ = true; |
| 113 } | 114 } |
| 114 virtual void NotifyReadyToActivate() OVERRIDE { | 115 virtual void NotifyReadyToActivate() OVERRIDE { |
| 115 did_notify_ready_to_activate_ = true; | 116 did_notify_ready_to_activate_ = true; |
| 116 host_impl_->ActivatePendingTree(); | 117 host_impl_->ActivatePendingTree(); |
| (...skipping 5123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5240 output_surface.PassAs<OutputSurface>())); | 5241 output_surface.PassAs<OutputSurface>())); |
| 5241 | 5242 |
| 5242 scoped_ptr<SolidColorLayerImpl> root_layer = | 5243 scoped_ptr<SolidColorLayerImpl> root_layer = |
| 5243 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5244 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 5244 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | 5245 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| 5245 | 5246 |
| 5246 onscreen_context_provider_ = TestContextProvider::Create(); | 5247 onscreen_context_provider_ = TestContextProvider::Create(); |
| 5247 offscreen_context_provider_ = TestContextProvider::Create(); | 5248 offscreen_context_provider_ = TestContextProvider::Create(); |
| 5248 } | 5249 } |
| 5249 | 5250 |
| 5251 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE { |
| 5252 did_update_renderer_capabilities_ = true; |
| 5253 } |
| 5254 |
| 5250 FakeOutputSurface* output_surface_; | 5255 FakeOutputSurface* output_surface_; |
| 5251 scoped_refptr<TestContextProvider> onscreen_context_provider_; | 5256 scoped_refptr<TestContextProvider> onscreen_context_provider_; |
| 5252 scoped_refptr<TestContextProvider> offscreen_context_provider_; | 5257 scoped_refptr<TestContextProvider> offscreen_context_provider_; |
| 5258 bool did_update_renderer_capabilities_; |
| 5253 }; | 5259 }; |
| 5254 | 5260 |
| 5255 | 5261 |
| 5256 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { | 5262 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { |
| 5257 // Software draw. | 5263 // Software draw. |
| 5258 DrawFrame(); | 5264 DrawFrame(); |
| 5259 | 5265 |
| 5260 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5266 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5261 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5267 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5262 | 5268 |
| 5263 // DeferredInitialize and hardware draw. | 5269 // DeferredInitialize and hardware draw. |
| 5270 did_update_renderer_capabilities_ = false; |
| 5264 EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( | 5271 EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( |
| 5265 onscreen_context_provider_, offscreen_context_provider_)); | 5272 onscreen_context_provider_, offscreen_context_provider_)); |
| 5266 EXPECT_EQ(onscreen_context_provider_, | 5273 EXPECT_EQ(onscreen_context_provider_, |
| 5267 host_impl_->output_surface()->context_provider()); | 5274 host_impl_->output_surface()->context_provider()); |
| 5268 EXPECT_EQ(offscreen_context_provider_, | 5275 EXPECT_EQ(offscreen_context_provider_, |
| 5269 host_impl_->offscreen_context_provider()); | 5276 host_impl_->offscreen_context_provider()); |
| 5277 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5270 | 5278 |
| 5271 // Defer intialized GL draw. | 5279 // Defer intialized GL draw. |
| 5272 DrawFrame(); | 5280 DrawFrame(); |
| 5273 | 5281 |
| 5274 // Revert back to software. | 5282 // Revert back to software. |
| 5283 did_update_renderer_capabilities_ = false; |
| 5275 output_surface_->ReleaseGL(); | 5284 output_surface_->ReleaseGL(); |
| 5276 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5285 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5277 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5286 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5287 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5278 | 5288 |
| 5279 // Software draw again. | 5289 // Software draw again. |
| 5280 DrawFrame(); | 5290 DrawFrame(); |
| 5281 } | 5291 } |
| 5282 | 5292 |
| 5283 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { | 5293 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { |
| 5284 // Software draw. | 5294 // Software draw. |
| 5285 DrawFrame(); | 5295 DrawFrame(); |
| 5286 | 5296 |
| 5287 // Fail initialization of the onscreen context before the OutputSurface binds | 5297 // Fail initialization of the onscreen context before the OutputSurface binds |
| 5288 // it to the thread. | 5298 // it to the thread. |
| 5289 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5299 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5290 | 5300 |
| 5291 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5301 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5292 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5302 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5293 | 5303 |
| 5294 // DeferredInitialize fails. | 5304 // DeferredInitialize fails. |
| 5305 did_update_renderer_capabilities_ = false; |
| 5295 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5306 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5296 onscreen_context_provider_, offscreen_context_provider_)); | 5307 onscreen_context_provider_, offscreen_context_provider_)); |
| 5297 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5308 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5298 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5309 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5310 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5299 | 5311 |
| 5300 // Software draw again. | 5312 // Software draw again. |
| 5301 DrawFrame(); | 5313 DrawFrame(); |
| 5302 } | 5314 } |
| 5303 | 5315 |
| 5316 // TODO(boliu): After r239415, fails_OnscreenContext_1 and 2 are exactly the |
| 5317 // same as 0. They were supposed to test makeCurrent failing in the |
| 5318 // OutputSurface, LayerTreeHostImpl, and GLRenderer respectively. |
| 5304 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { | 5319 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { |
| 5305 // Software draw. | 5320 // Software draw. |
| 5306 DrawFrame(); | 5321 DrawFrame(); |
| 5307 | 5322 |
| 5308 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5323 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5309 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5324 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5310 | 5325 |
| 5311 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5326 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5312 | 5327 |
| 5313 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5328 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5314 // DeferredInitialize fails. | 5329 // DeferredInitialize fails. |
| 5330 did_update_renderer_capabilities_ = false; |
| 5315 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5331 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5316 onscreen_context_provider_, offscreen_context_provider_)); | 5332 onscreen_context_provider_, offscreen_context_provider_)); |
| 5317 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5333 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5318 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5334 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5335 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5319 } | 5336 } |
| 5320 | 5337 |
| 5321 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { | 5338 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { |
| 5322 // Software draw. | 5339 // Software draw. |
| 5323 DrawFrame(); | 5340 DrawFrame(); |
| 5324 | 5341 |
| 5325 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5342 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5326 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5343 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5327 | 5344 |
| 5328 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5345 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5329 | 5346 |
| 5330 // DeferredInitialize fails. | 5347 // DeferredInitialize fails. |
| 5348 did_update_renderer_capabilities_ = false; |
| 5331 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5349 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5332 onscreen_context_provider_, offscreen_context_provider_)); | 5350 onscreen_context_provider_, offscreen_context_provider_)); |
| 5333 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5351 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5334 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5352 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5353 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5335 } | 5354 } |
| 5336 | 5355 |
| 5337 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { | 5356 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { |
| 5338 // Software draw. | 5357 // Software draw. |
| 5339 DrawFrame(); | 5358 DrawFrame(); |
| 5340 | 5359 |
| 5341 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5360 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5342 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5361 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5343 | 5362 |
| 5344 // Fail initialization of the offscreen context. | 5363 // Fail initialization of the offscreen context. |
| 5345 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5364 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5346 | 5365 |
| 5347 // DeferredInitialize fails. | 5366 // DeferredInitialize fails. |
| 5367 did_update_renderer_capabilities_ = false; |
| 5348 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5368 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5349 onscreen_context_provider_, offscreen_context_provider_)); | 5369 onscreen_context_provider_, offscreen_context_provider_)); |
| 5350 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5370 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5351 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5371 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5372 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5352 } | 5373 } |
| 5353 | 5374 |
| 5354 // Checks that we have a non-0 default allocation if we pass a context that | 5375 // Checks that we have a non-0 default allocation if we pass a context that |
| 5355 // doesn't support memory management extensions. | 5376 // doesn't support memory management extensions. |
| 5356 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { | 5377 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { |
| 5357 LayerTreeSettings settings; | 5378 LayerTreeSettings settings; |
| 5358 host_impl_ = LayerTreeHostImpl::Create( | 5379 host_impl_ = LayerTreeHostImpl::Create( |
| 5359 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); | 5380 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); |
| 5360 | 5381 |
| 5361 scoped_ptr<OutputSurface> output_surface( | 5382 scoped_ptr<OutputSurface> output_surface( |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5806 &set_needs_redraw_count)); | 5827 &set_needs_redraw_count)); |
| 5807 // Empty damage rect won't signal the monitor. | 5828 // Empty damage rect won't signal the monitor. |
| 5808 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 5829 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 5809 EXPECT_EQ(0, set_needs_commit_count); | 5830 EXPECT_EQ(0, set_needs_commit_count); |
| 5810 EXPECT_EQ(2, set_needs_redraw_count); | 5831 EXPECT_EQ(2, set_needs_redraw_count); |
| 5811 } | 5832 } |
| 5812 } | 5833 } |
| 5813 | 5834 |
| 5814 } // namespace | 5835 } // namespace |
| 5815 } // namespace cc | 5836 } // namespace cc |
| OLD | NEW |