| 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 5498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5509 output_surface_ = output_surface.get(); | 5509 output_surface_ = output_surface.get(); |
| 5510 | 5510 |
| 5511 EXPECT_TRUE(CreateHostImpl(DefaultSettings(), | 5511 EXPECT_TRUE(CreateHostImpl(DefaultSettings(), |
| 5512 output_surface.PassAs<OutputSurface>())); | 5512 output_surface.PassAs<OutputSurface>())); |
| 5513 | 5513 |
| 5514 scoped_ptr<SolidColorLayerImpl> root_layer = | 5514 scoped_ptr<SolidColorLayerImpl> root_layer = |
| 5515 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5515 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| 5516 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); | 5516 SetupRootLayerImpl(root_layer.PassAs<LayerImpl>()); |
| 5517 | 5517 |
| 5518 onscreen_context_provider_ = TestContextProvider::Create(); | 5518 onscreen_context_provider_ = TestContextProvider::Create(); |
| 5519 offscreen_context_provider_ = TestContextProvider::Create(); | |
| 5520 } | 5519 } |
| 5521 | 5520 |
| 5522 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE { | 5521 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE { |
| 5523 did_update_renderer_capabilities_ = true; | 5522 did_update_renderer_capabilities_ = true; |
| 5524 } | 5523 } |
| 5525 | 5524 |
| 5526 FakeOutputSurface* output_surface_; | 5525 FakeOutputSurface* output_surface_; |
| 5527 scoped_refptr<TestContextProvider> onscreen_context_provider_; | 5526 scoped_refptr<TestContextProvider> onscreen_context_provider_; |
| 5528 scoped_refptr<TestContextProvider> offscreen_context_provider_; | |
| 5529 bool did_update_renderer_capabilities_; | 5527 bool did_update_renderer_capabilities_; |
| 5530 }; | 5528 }; |
| 5531 | 5529 |
| 5532 | 5530 |
| 5533 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { | 5531 TEST_F(LayerTreeHostImplTestDeferredInitialize, Success) { |
| 5534 // Software draw. | 5532 // Software draw. |
| 5535 DrawFrame(); | 5533 DrawFrame(); |
| 5536 | 5534 |
| 5537 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5535 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5538 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5539 | 5536 |
| 5540 // DeferredInitialize and hardware draw. | 5537 // DeferredInitialize and hardware draw. |
| 5541 did_update_renderer_capabilities_ = false; | 5538 did_update_renderer_capabilities_ = false; |
| 5542 EXPECT_TRUE(output_surface_->InitializeAndSetContext3d( | 5539 EXPECT_TRUE( |
| 5543 onscreen_context_provider_, offscreen_context_provider_)); | 5540 output_surface_->InitializeAndSetContext3d(onscreen_context_provider_)); |
| 5544 EXPECT_EQ(onscreen_context_provider_, | 5541 EXPECT_EQ(onscreen_context_provider_, |
| 5545 host_impl_->output_surface()->context_provider()); | 5542 host_impl_->output_surface()->context_provider()); |
| 5546 EXPECT_EQ(offscreen_context_provider_, | |
| 5547 host_impl_->offscreen_context_provider()); | |
| 5548 EXPECT_TRUE(did_update_renderer_capabilities_); | 5543 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5549 | 5544 |
| 5550 // Defer intialized GL draw. | 5545 // Defer intialized GL draw. |
| 5551 DrawFrame(); | 5546 DrawFrame(); |
| 5552 | 5547 |
| 5553 // Revert back to software. | 5548 // Revert back to software. |
| 5554 did_update_renderer_capabilities_ = false; | 5549 did_update_renderer_capabilities_ = false; |
| 5555 output_surface_->ReleaseGL(); | 5550 output_surface_->ReleaseGL(); |
| 5556 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5551 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5557 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5558 EXPECT_TRUE(did_update_renderer_capabilities_); | 5552 EXPECT_TRUE(did_update_renderer_capabilities_); |
| 5559 | 5553 |
| 5560 // Software draw again. | 5554 // Software draw again. |
| 5561 DrawFrame(); | 5555 DrawFrame(); |
| 5562 } | 5556 } |
| 5563 | 5557 |
| 5564 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_0) { | 5558 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails) { |
| 5565 // Software draw. | 5559 // Software draw. |
| 5566 DrawFrame(); | 5560 DrawFrame(); |
| 5567 | 5561 |
| 5568 // Fail initialization of the onscreen context before the OutputSurface binds | 5562 // Fail initialization of the onscreen context before the OutputSurface binds |
| 5569 // it to the thread. | 5563 // it to the thread. |
| 5570 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | 5564 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); |
| 5571 | 5565 |
| 5572 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5566 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5573 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5574 | 5567 |
| 5575 // DeferredInitialize fails. | 5568 // DeferredInitialize fails. |
| 5576 did_update_renderer_capabilities_ = false; | 5569 did_update_renderer_capabilities_ = false; |
| 5577 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | 5570 EXPECT_FALSE( |
| 5578 onscreen_context_provider_, offscreen_context_provider_)); | 5571 output_surface_->InitializeAndSetContext3d(onscreen_context_provider_)); |
| 5579 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | 5572 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); |
| 5580 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5581 EXPECT_FALSE(did_update_renderer_capabilities_); | 5573 EXPECT_FALSE(did_update_renderer_capabilities_); |
| 5582 | 5574 |
| 5583 // Software draw again. | 5575 // Software draw again. |
| 5584 DrawFrame(); | 5576 DrawFrame(); |
| 5585 } | 5577 } |
| 5586 | 5578 |
| 5587 // TODO(boliu): After r239415, fails_OnscreenContext_1 and 2 are exactly the | |
| 5588 // same as 0. They were supposed to test makeCurrent failing in the | |
| 5589 // OutputSurface, LayerTreeHostImpl, and GLRenderer respectively. | |
| 5590 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_1) { | |
| 5591 // Software draw. | |
| 5592 DrawFrame(); | |
| 5593 | |
| 5594 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5595 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5596 | |
| 5597 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | |
| 5598 | |
| 5599 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5600 // DeferredInitialize fails. | |
| 5601 did_update_renderer_capabilities_ = false; | |
| 5602 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | |
| 5603 onscreen_context_provider_, offscreen_context_provider_)); | |
| 5604 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5605 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5606 EXPECT_FALSE(did_update_renderer_capabilities_); | |
| 5607 } | |
| 5608 | |
| 5609 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OnscreenContext_2) { | |
| 5610 // Software draw. | |
| 5611 DrawFrame(); | |
| 5612 | |
| 5613 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5614 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5615 | |
| 5616 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | |
| 5617 | |
| 5618 // DeferredInitialize fails. | |
| 5619 did_update_renderer_capabilities_ = false; | |
| 5620 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | |
| 5621 onscreen_context_provider_, offscreen_context_provider_)); | |
| 5622 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5623 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5624 EXPECT_FALSE(did_update_renderer_capabilities_); | |
| 5625 } | |
| 5626 | |
| 5627 TEST_F(LayerTreeHostImplTestDeferredInitialize, Fails_OffscreenContext) { | |
| 5628 // Software draw. | |
| 5629 DrawFrame(); | |
| 5630 | |
| 5631 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5632 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5633 | |
| 5634 // Fail initialization of the offscreen context. | |
| 5635 onscreen_context_provider_->UnboundTestContext3d()->set_context_lost(true); | |
| 5636 | |
| 5637 // DeferredInitialize fails. | |
| 5638 did_update_renderer_capabilities_ = false; | |
| 5639 EXPECT_FALSE(output_surface_->InitializeAndSetContext3d( | |
| 5640 onscreen_context_provider_, offscreen_context_provider_)); | |
| 5641 EXPECT_FALSE(host_impl_->output_surface()->context_provider()); | |
| 5642 EXPECT_FALSE(host_impl_->offscreen_context_provider()); | |
| 5643 EXPECT_FALSE(did_update_renderer_capabilities_); | |
| 5644 } | |
| 5645 | |
| 5646 // Checks that we have a non-0 default allocation if we pass a context that | 5579 // Checks that we have a non-0 default allocation if we pass a context that |
| 5647 // doesn't support memory management extensions. | 5580 // doesn't support memory management extensions. |
| 5648 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { | 5581 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { |
| 5649 LayerTreeSettings settings; | 5582 LayerTreeSettings settings; |
| 5650 host_impl_ = LayerTreeHostImpl::Create(settings, | 5583 host_impl_ = LayerTreeHostImpl::Create(settings, |
| 5651 this, | 5584 this, |
| 5652 &proxy_, | 5585 &proxy_, |
| 5653 &stats_instrumentation_, | 5586 &stats_instrumentation_, |
| 5654 shared_bitmap_manager_.get(), | 5587 shared_bitmap_manager_.get(), |
| 5655 0); | 5588 0); |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6386 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, | 6319 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
| 6387 300u * 1024u * 1024u); | 6320 300u * 1024u * 1024u); |
| 6388 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, | 6321 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
| 6389 150u * 1024u * 1024u); | 6322 150u * 1024u * 1024u); |
| 6390 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, | 6323 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, |
| 6391 75u * 1024u * 1024u); | 6324 75u * 1024u * 1024u); |
| 6392 } | 6325 } |
| 6393 | 6326 |
| 6394 } // namespace | 6327 } // namespace |
| 6395 } // namespace cc | 6328 } // namespace cc |
| OLD | NEW |