| 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 5089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5206 output_surface.PassAs<OutputSurface>())); | 5207 output_surface.PassAs<OutputSurface>())); |
| 5207 | 5208 |
| 5208 scoped_ptr<SolidColorLayerImpl> root_layer = | 5209 scoped_ptr<SolidColorLayerImpl> root_layer = |
| 5209 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5210 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 5210 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | 5211 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| 5211 | 5212 |
| 5212 onscreen_context_provider_ = TestContextProvider::Create(); | 5213 onscreen_context_provider_ = TestContextProvider::Create(); |
| 5213 offscreen_context_provider_ = TestContextProvider::Create(); | 5214 offscreen_context_provider_ = TestContextProvider::Create(); |
| 5214 } | 5215 } |
| 5215 | 5216 |
| 5217 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE { |
| 5218 did_update_renderer_capabilities_ = true; |
| 5219 } |
| 5220 |
| 5216 FakeOutputSurface* output_surface_; | 5221 FakeOutputSurface* output_surface_; |
| 5217 scoped_refptr<TestContextProvider> onscreen_context_provider_; | 5222 scoped_refptr<TestContextProvider> onscreen_context_provider_; |
| 5218 scoped_refptr<TestContextProvider> offscreen_context_provider_; | 5223 scoped_refptr<TestContextProvider> offscreen_context_provider_; |
| 5224 bool did_update_renderer_capabilities_; |
| 5219 }; | 5225 }; |
| 5220 | 5226 |
| 5221 | 5227 |
| 5222 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { | 5228 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { |
| 5223 // Software draw. | 5229 // Software draw. |
| 5224 DrawFrame(); | 5230 DrawFrame(); |
| 5225 | 5231 |
| 5226 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5232 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5227 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5233 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5228 | 5234 |
| 5229 // DeferredInitialize and hardware draw. | 5235 // DeferredInitialize and hardware draw. |
| 5236 did_update_renderer_capabilities_ = false; |
| 5230 EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( | 5237 EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( |
| 5231 onscreen_context_provider_, offscreen_context_provider_)); | 5238 onscreen_context_provider_, offscreen_context_provider_)); |
| 5232 EXPECT_EQ(onscreen_context_provider_, | 5239 EXPECT_EQ(onscreen_context_provider_, |
| 5233 host_impl_->output_surface()->context_provider()); | 5240 host_impl_->output_surface()->context_provider()); |
| 5234 EXPECT_EQ(offscreen_context_provider_, | 5241 EXPECT_EQ(offscreen_context_provider_, |
| 5235 host_impl_->offscreen_context_provider()); | 5242 host_impl_->offscreen_context_provider()); |
| 5243 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5236 | 5244 |
| 5237 // Defer intialized GL draw. | 5245 // Defer intialized GL draw. |
| 5238 DrawFrame(); | 5246 DrawFrame(); |
| 5239 | 5247 |
| 5240 // Revert back to software. | 5248 // Revert back to software. |
| 5249 did_update_renderer_capabilities_ = false; |
| 5241 output_surface_->ReleaseGL(); | 5250 output_surface_->ReleaseGL(); |
| 5242 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5251 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5243 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5252 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5253 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5244 | 5254 |
| 5245 // Software draw again. | 5255 // Software draw again. |
| 5246 DrawFrame(); | 5256 DrawFrame(); |
| 5247 } | 5257 } |
| 5248 | 5258 |
| 5249 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { | 5259 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { |
| 5250 // Software draw. | 5260 // Software draw. |
| 5251 DrawFrame(); | 5261 DrawFrame(); |
| 5252 | 5262 |
| 5253 // Fail initialization of the onscreen context before the OutputSurface binds | 5263 // Fail initialization of the onscreen context before the OutputSurface binds |
| 5254 // it to the thread. | 5264 // it to the thread. |
| 5255 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5265 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5256 | 5266 |
| 5257 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5267 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5258 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5268 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5259 | 5269 |
| 5260 // DeferredInitialize fails. | 5270 // DeferredInitialize fails. |
| 5271 did_update_renderer_capabilities_ = false; |
| 5261 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5272 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5262 onscreen_context_provider_, offscreen_context_provider_)); | 5273 onscreen_context_provider_, offscreen_context_provider_)); |
| 5263 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5274 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5264 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5275 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5276 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5265 | 5277 |
| 5266 // Software draw again. | 5278 // Software draw again. |
| 5267 DrawFrame(); | 5279 DrawFrame(); |
| 5268 } | 5280 } |
| 5269 | 5281 |
| 5282 // TODO(boliu): After r239415, fails_OnscreenContext_1 and 2 are exactly the |
| 5283 // same as 0. They were supposed to test makeCurrent failing in the |
| 5284 // OutputSurface, LayerTreeHostImpl, and GLRenderer respectively. |
| 5270 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { | 5285 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { |
| 5271 // Software draw. | 5286 // Software draw. |
| 5272 DrawFrame(); | 5287 DrawFrame(); |
| 5273 | 5288 |
| 5274 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5289 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5275 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5290 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5276 | 5291 |
| 5277 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5292 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5278 | 5293 |
| 5279 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5294 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5280 // DeferredInitialize fails. | 5295 // DeferredInitialize fails. |
| 5296 did_update_renderer_capabilities_ = false; |
| 5281 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5297 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5282 onscreen_context_provider_, offscreen_context_provider_)); | 5298 onscreen_context_provider_, offscreen_context_provider_)); |
| 5283 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5299 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5284 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5300 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5301 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5285 } | 5302 } |
| 5286 | 5303 |
| 5287 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { | 5304 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { |
| 5288 // Software draw. | 5305 // Software draw. |
| 5289 DrawFrame(); | 5306 DrawFrame(); |
| 5290 | 5307 |
| 5291 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5308 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5292 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5309 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5293 | 5310 |
| 5294 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5311 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5295 | 5312 |
| 5296 // DeferredInitialize fails. | 5313 // DeferredInitialize fails. |
| 5314 did_update_renderer_capabilities_ = false; |
| 5297 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5315 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5298 onscreen_context_provider_, offscreen_context_provider_)); | 5316 onscreen_context_provider_, offscreen_context_provider_)); |
| 5299 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5317 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5300 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5318 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5319 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5301 } | 5320 } |
| 5302 | 5321 |
| 5303 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { | 5322 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { |
| 5304 // Software draw. | 5323 // Software draw. |
| 5305 DrawFrame(); | 5324 DrawFrame(); |
| 5306 | 5325 |
| 5307 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5326 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5308 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5327 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5309 | 5328 |
| 5310 // Fail initialization of the offscreen context. | 5329 // Fail initialization of the offscreen context. |
| 5311 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5330 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5312 | 5331 |
| 5313 // DeferredInitialize fails. | 5332 // DeferredInitialize fails. |
| 5333 did_update_renderer_capabilities_ = false; |
| 5314 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5334 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( |
| 5315 onscreen_context_provider_, offscreen_context_provider_)); | 5335 onscreen_context_provider_, offscreen_context_provider_)); |
| 5316 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5336 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5317 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | 5337 EXPECT_FALSE(host_impl_->offscreen_context_provider()); |
| 5338 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5318 } | 5339 } |
| 5319 | 5340 |
| 5320 // Checks that we have a non-0 default allocation if we pass a context that | 5341 // Checks that we have a non-0 default allocation if we pass a context that |
| 5321 // doesn't support memory management extensions. | 5342 // doesn't support memory management extensions. |
| 5322 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { | 5343 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { |
| 5323 LayerTreeSettings settings; | 5344 LayerTreeSettings settings; |
| 5324 host_impl_ = LayerTreeHostImpl::Create( | 5345 host_impl_ = LayerTreeHostImpl::Create( |
| 5325 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); | 5346 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); |
| 5326 | 5347 |
| 5327 scoped_ptr<OutputSurface> output_surface( | 5348 scoped_ptr<OutputSurface> output_surface( |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5772 &set_needs_redraw_count)); | 5793 &set_needs_redraw_count)); |
| 5773 // Empty damage rect won't signal the monitor. | 5794 // Empty damage rect won't signal the monitor. |
| 5774 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 5795 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
| 5775 EXPECT_EQ(0, set_needs_commit_count); | 5796 EXPECT_EQ(0, set_needs_commit_count); |
| 5776 EXPECT_EQ(2, set_needs_redraw_count); | 5797 EXPECT_EQ(2, set_needs_redraw_count); |
| 5777 } | 5798 } |
| 5778 } | 5799 } |
| 5779 | 5800 |
| 5780 } // namespace | 5801 } // namespace |
| 5781 } // namespace cc | 5802 } // namespace cc |
| OLD | NEW |