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 4377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4388 } | 4388 } |
4389 | 4389 |
4390 // Make sure damage tracking propagates all the way to the graphics context, | 4390 // Make sure damage tracking propagates all the way to the graphics context, |
4391 // where it should request to swap only the sub-buffer that is damaged. | 4391 // where it should request to swap only the sub-buffer that is damaged. |
4392 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { | 4392 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { |
4393 scoped_refptr<TestContextProvider> context_provider( | 4393 scoped_refptr<TestContextProvider> context_provider( |
4394 TestContextProvider::Create()); | 4394 TestContextProvider::Create()); |
4395 context_provider->BindToCurrentThread(); | 4395 context_provider->BindToCurrentThread(); |
4396 context_provider->TestContext3d()->set_have_post_sub_buffer(true); | 4396 context_provider->TestContext3d()->set_have_post_sub_buffer(true); |
4397 | 4397 |
4398 scoped_ptr<OutputSurface> output_surface( | 4398 scoped_ptr<FakeOutputSurface> output_surface( |
4399 FakeOutputSurface::Create3d(context_provider)); | 4399 FakeOutputSurface::Create3d(context_provider)); |
| 4400 FakeOutputSurface* fake_output_surface = output_surface.get(); |
4400 | 4401 |
4401 // This test creates its own LayerTreeHostImpl, so | 4402 // This test creates its own LayerTreeHostImpl, so |
4402 // that we can force partial swap enabled. | 4403 // that we can force partial swap enabled. |
4403 LayerTreeSettings settings; | 4404 LayerTreeSettings settings; |
4404 settings.partial_swap_enabled = true; | 4405 settings.partial_swap_enabled = true; |
4405 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 4406 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
4406 new TestSharedBitmapManager()); | 4407 new TestSharedBitmapManager()); |
4407 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = | 4408 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
4408 LayerTreeHostImpl::Create(settings, | 4409 LayerTreeHostImpl::Create(settings, |
4409 this, | 4410 this, |
(...skipping 18 matching lines...) Expand all Loading... |
4428 root->AddChild(child.Pass()); | 4429 root->AddChild(child.Pass()); |
4429 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass()); | 4430 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass()); |
4430 | 4431 |
4431 LayerTreeHostImpl::FrameData frame; | 4432 LayerTreeHostImpl::FrameData frame; |
4432 | 4433 |
4433 // First frame, the entire screen should get swapped. | 4434 // First frame, the entire screen should get swapped. |
4434 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); | 4435 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
4435 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 4436 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
4436 layer_tree_host_impl->DidDrawAllLayers(frame); | 4437 layer_tree_host_impl->DidDrawAllLayers(frame); |
4437 layer_tree_host_impl->SwapBuffers(frame); | 4438 layer_tree_host_impl->SwapBuffers(frame); |
4438 EXPECT_EQ(TestContextSupport::SWAP, | 4439 gfx::Rect expected_swap_rect(0, 0, 500, 500); |
4439 context_provider->support()->last_swap_type()); | 4440 EXPECT_EQ(expected_swap_rect.ToString(), |
| 4441 fake_output_surface->last_swap_rect().ToString()); |
4440 | 4442 |
4441 // Second frame, only the damaged area should get swapped. Damage should be | 4443 // Second frame, only the damaged area should get swapped. Damage should be |
4442 // the union of old and new child rects. | 4444 // the union of old and new child rects. |
4443 // expected damage rect: gfx::Rect(26, 28); | 4445 // expected damage rect: gfx::Rect(26, 28); |
4444 // expected swap rect: vertically flipped, with origin at bottom left corner. | 4446 // expected swap rect: vertically flipped, with origin at bottom left corner. |
4445 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition( | 4447 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition( |
4446 gfx::PointF()); | 4448 gfx::PointF()); |
4447 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); | 4449 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
4448 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 4450 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
4449 host_impl_->DidDrawAllLayers(frame); | 4451 host_impl_->DidDrawAllLayers(frame); |
4450 layer_tree_host_impl->SwapBuffers(frame); | 4452 layer_tree_host_impl->SwapBuffers(frame); |
4451 | 4453 |
4452 // Make sure that partial swap is constrained to the viewport dimensions | 4454 // Make sure that partial swap is constrained to the viewport dimensions |
4453 // expected damage rect: gfx::Rect(500, 500); | 4455 // expected damage rect: gfx::Rect(500, 500); |
4454 // expected swap rect: flipped damage rect, but also clamped to viewport | 4456 // expected swap rect: flipped damage rect, but also clamped to viewport |
4455 EXPECT_EQ(TestContextSupport::PARTIAL_SWAP, | 4457 expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); |
4456 context_provider->support()->last_swap_type()); | |
4457 gfx::Rect expected_swap_rect(0, 500-28, 26, 28); | |
4458 EXPECT_EQ(expected_swap_rect.ToString(), | 4458 EXPECT_EQ(expected_swap_rect.ToString(), |
4459 context_provider->support()-> | 4459 fake_output_surface->last_swap_rect().ToString()); |
4460 last_partial_swap_rect().ToString()); | |
4461 | 4460 |
4462 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); | 4461 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); |
4463 // This will damage everything. | 4462 // This will damage everything. |
4464 layer_tree_host_impl->active_tree()->root_layer()->SetBackgroundColor( | 4463 layer_tree_host_impl->active_tree()->root_layer()->SetBackgroundColor( |
4465 SK_ColorBLACK); | 4464 SK_ColorBLACK); |
4466 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); | 4465 EXPECT_EQ(DRAW_SUCCESS, layer_tree_host_impl->PrepareToDraw(&frame)); |
4467 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 4466 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
4468 host_impl_->DidDrawAllLayers(frame); | 4467 host_impl_->DidDrawAllLayers(frame); |
4469 layer_tree_host_impl->SwapBuffers(frame); | 4468 layer_tree_host_impl->SwapBuffers(frame); |
4470 | 4469 |
4471 EXPECT_EQ(TestContextSupport::SWAP, | 4470 expected_swap_rect = gfx::Rect(0, 0, 10, 10); |
4472 context_provider->support()->last_swap_type()); | 4471 EXPECT_EQ(expected_swap_rect.ToString(), |
| 4472 fake_output_surface->last_swap_rect().ToString()); |
4473 } | 4473 } |
4474 | 4474 |
4475 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { | 4475 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { |
4476 scoped_ptr<LayerImpl> root = | 4476 scoped_ptr<LayerImpl> root = |
4477 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); | 4477 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); |
4478 scoped_ptr<LayerImpl> child = | 4478 scoped_ptr<LayerImpl> child = |
4479 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); | 4479 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); |
4480 child->SetBounds(gfx::Size(10, 10)); | 4480 child->SetBounds(gfx::Size(10, 10)); |
4481 child->SetContentBounds(gfx::Size(10, 10)); | 4481 child->SetContentBounds(gfx::Size(10, 10)); |
4482 child->SetDrawsContent(true); | 4482 child->SetDrawsContent(true); |
(...skipping 2784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7267 // surface. | 7267 // surface. |
7268 EXPECT_EQ(0, num_lost_surfaces_); | 7268 EXPECT_EQ(0, num_lost_surfaces_); |
7269 host_impl_->DidLoseOutputSurface(); | 7269 host_impl_->DidLoseOutputSurface(); |
7270 EXPECT_EQ(1, num_lost_surfaces_); | 7270 EXPECT_EQ(1, num_lost_surfaces_); |
7271 host_impl_->DidLoseOutputSurface(); | 7271 host_impl_->DidLoseOutputSurface(); |
7272 EXPECT_LE(1, num_lost_surfaces_); | 7272 EXPECT_LE(1, num_lost_surfaces_); |
7273 } | 7273 } |
7274 | 7274 |
7275 } // namespace | 7275 } // namespace |
7276 } // namespace cc | 7276 } // namespace cc |
OLD | NEW |