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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 12378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12389 EXPECT_FALSE(host_impl_->GetRasterColorSpace().IsValid()); | 12389 EXPECT_FALSE(host_impl_->GetRasterColorSpace().IsValid()); |
12390 } | 12390 } |
12391 | 12391 |
12392 TEST_F(LayerTreeHostImplTest, RasterColorSpace) { | 12392 TEST_F(LayerTreeHostImplTest, RasterColorSpace) { |
12393 LayerTreeSettings settings = DefaultSettings(); | 12393 LayerTreeSettings settings = DefaultSettings(); |
12394 settings.enable_color_correct_rasterization = true; | 12394 settings.enable_color_correct_rasterization = true; |
12395 CreateHostImpl(settings, CreateCompositorFrameSink()); | 12395 CreateHostImpl(settings, CreateCompositorFrameSink()); |
12396 EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB()); | 12396 EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB()); |
12397 } | 12397 } |
12398 | 12398 |
| 12399 TEST_F(LayerTreeHostImplTest, UpdatedTilingsForNonDrawingLayers) { |
| 12400 gfx::Size layer_bounds(500, 500); |
| 12401 |
| 12402 host_impl_->SetViewportSize(layer_bounds); |
| 12403 host_impl_->CreatePendingTree(); |
| 12404 std::unique_ptr<LayerImpl> scoped_root = |
| 12405 LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 12406 scoped_root->SetBounds(layer_bounds); |
| 12407 LayerImpl* root = scoped_root.get(); |
| 12408 host_impl_->pending_tree()->SetRootLayerForTesting(std::move(scoped_root)); |
| 12409 |
| 12410 scoped_refptr<FakeRasterSource> raster_source( |
| 12411 FakeRasterSource::CreateFilled(layer_bounds)); |
| 12412 std::unique_ptr<FakePictureLayerImpl> scoped_animated_transform_layer = |
| 12413 FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 12414 2, raster_source); |
| 12415 scoped_animated_transform_layer->SetBounds(layer_bounds); |
| 12416 scoped_animated_transform_layer->SetDrawsContent(true); |
| 12417 gfx::Transform singular; |
| 12418 singular.Scale3d(6.f, 6.f, 0.f); |
| 12419 scoped_animated_transform_layer->test_properties()->transform = singular; |
| 12420 FakePictureLayerImpl* animated_transform_layer = |
| 12421 scoped_animated_transform_layer.get(); |
| 12422 root->test_properties()->AddChild(std::move(scoped_animated_transform_layer)); |
| 12423 |
| 12424 // A layer with a non-invertible transform is not drawn or rasterized. Since |
| 12425 // this layer is not rasterized, we shouldn't be creating any tilings for it. |
| 12426 host_impl_->pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 12427 EXPECT_FALSE(animated_transform_layer->HasValidTilePriorities()); |
| 12428 EXPECT_EQ(animated_transform_layer->tilings()->num_tilings(), 0u); |
| 12429 host_impl_->pending_tree()->UpdateDrawProperties(false); |
| 12430 EXPECT_FALSE(animated_transform_layer->raster_even_if_not_drawn()); |
| 12431 EXPECT_FALSE(animated_transform_layer->contributes_to_drawn_render_surface()); |
| 12432 EXPECT_EQ(animated_transform_layer->tilings()->num_tilings(), 0u); |
| 12433 |
| 12434 // Now add a transform animation to this layer. While we don't drawn layers |
| 12435 // with non-invertible transforms, we still raster them if there is a |
| 12436 // transform animation. |
| 12437 host_impl_->pending_tree()->SetElementIdsForTesting(); |
| 12438 TransformOperations start_transform_operations; |
| 12439 start_transform_operations.AppendMatrix(singular); |
| 12440 TransformOperations end_transform_operations; |
| 12441 AddAnimatedTransformToElementWithPlayer( |
| 12442 animated_transform_layer->element_id(), timeline(), 10.0, |
| 12443 start_transform_operations, end_transform_operations); |
| 12444 |
| 12445 // The layer is still not drawn, but it will be rasterized. Since the layer is |
| 12446 // rasterized, we should be creating tilings for it in UpdateDrawProperties. |
| 12447 // However, none of these tiles should be required for activation. |
| 12448 host_impl_->pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 12449 host_impl_->pending_tree()->UpdateDrawProperties(false); |
| 12450 EXPECT_TRUE(animated_transform_layer->raster_even_if_not_drawn()); |
| 12451 EXPECT_FALSE(animated_transform_layer->contributes_to_drawn_render_surface()); |
| 12452 EXPECT_EQ(animated_transform_layer->tilings()->num_tilings(), 1u); |
| 12453 EXPECT_FALSE(animated_transform_layer->tilings() |
| 12454 ->tiling_at(0) |
| 12455 ->can_require_tiles_for_activation()); |
| 12456 } |
| 12457 |
| 12458 TEST_F(LayerTreeHostImplTest, RasterTilePrioritizationForNonDrawingLayers) { |
| 12459 gfx::Size layer_bounds(500, 500); |
| 12460 |
| 12461 host_impl_->SetViewportSize(layer_bounds); |
| 12462 host_impl_->CreatePendingTree(); |
| 12463 std::unique_ptr<LayerImpl> scoped_root = |
| 12464 LayerImpl::Create(host_impl_->pending_tree(), 1); |
| 12465 scoped_root->SetBounds(layer_bounds); |
| 12466 LayerImpl* root = scoped_root.get(); |
| 12467 host_impl_->pending_tree()->SetRootLayerForTesting(std::move(scoped_root)); |
| 12468 |
| 12469 scoped_refptr<FakeRasterSource> raster_source( |
| 12470 FakeRasterSource::CreateFilled(layer_bounds)); |
| 12471 |
| 12472 std::unique_ptr<FakePictureLayerImpl> scoped_hidden_layer = |
| 12473 FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 12474 2, raster_source); |
| 12475 scoped_hidden_layer->SetBounds(layer_bounds); |
| 12476 scoped_hidden_layer->SetDrawsContent(true); |
| 12477 scoped_hidden_layer->set_contributes_to_drawn_render_surface(true); |
| 12478 FakePictureLayerImpl* hidden_layer = scoped_hidden_layer.get(); |
| 12479 root->test_properties()->AddChild(std::move(scoped_hidden_layer)); |
| 12480 |
| 12481 std::unique_ptr<FakePictureLayerImpl> scoped_drawing_layer = |
| 12482 FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 12483 3, raster_source); |
| 12484 scoped_drawing_layer->SetBounds(layer_bounds); |
| 12485 scoped_drawing_layer->SetDrawsContent(true); |
| 12486 scoped_drawing_layer->set_contributes_to_drawn_render_surface(true); |
| 12487 FakePictureLayerImpl* drawing_layer = scoped_drawing_layer.get(); |
| 12488 root->test_properties()->AddChild(std::move(scoped_drawing_layer)); |
| 12489 |
| 12490 gfx::Rect layer_rect(0, 0, 500, 500); |
| 12491 gfx::Rect empty_rect(0, 0, 0, 0); |
| 12492 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
| 12493 |
| 12494 hidden_layer->tilings()->AddTiling(gfx::AxisTransform2d(), raster_source); |
| 12495 PictureLayerTiling* hidden_tiling = hidden_layer->tilings()->tiling_at(0); |
| 12496 hidden_tiling->set_resolution(TileResolution::LOW_RESOLUTION); |
| 12497 hidden_tiling->CreateAllTilesForTesting(); |
| 12498 hidden_tiling->SetTilePriorityRectsForTesting( |
| 12499 layer_rect, // Visible rect. |
| 12500 layer_rect, // Skewport rect. |
| 12501 layer_rect, // Soon rect. |
| 12502 layer_rect); // Eventually rect. |
| 12503 |
| 12504 drawing_layer->tilings()->AddTiling(gfx::AxisTransform2d(), raster_source); |
| 12505 PictureLayerTiling* drawing_tiling = drawing_layer->tilings()->tiling_at(0); |
| 12506 drawing_tiling->set_resolution(TileResolution::HIGH_RESOLUTION); |
| 12507 drawing_tiling->CreateAllTilesForTesting(); |
| 12508 drawing_tiling->SetTilePriorityRectsForTesting( |
| 12509 layer_rect, // Visible rect. |
| 12510 layer_rect, // Skewport rect. |
| 12511 layer_rect, // Soon rect. |
| 12512 layer_rect); // Eventually rect. |
| 12513 |
| 12514 // Both layers are drawn. Since the hidden layer has a low resolution tiling, |
| 12515 // in smoothness priority mode its tile is higher priority. |
| 12516 std::unique_ptr<RasterTilePriorityQueue> queue = |
| 12517 host_impl_->BuildRasterQueue(TreePriority::SMOOTHNESS_TAKES_PRIORITY, |
| 12518 RasterTilePriorityQueue::Type::ALL); |
| 12519 EXPECT_EQ(queue->Top().tile()->layer_id(), 2); |
| 12520 |
| 12521 // Hide the hidden layer and set it to so it still rasters. Now the drawing |
| 12522 // layer should be prioritized over the hidden layer. |
| 12523 hidden_layer->set_contributes_to_drawn_render_surface(false); |
| 12524 hidden_layer->set_raster_even_if_not_drawn(true); |
| 12525 queue = host_impl_->BuildRasterQueue(TreePriority::SMOOTHNESS_TAKES_PRIORITY, |
| 12526 RasterTilePriorityQueue::Type::ALL); |
| 12527 EXPECT_EQ(queue->Top().tile()->layer_id(), 3); |
| 12528 } |
| 12529 |
12399 } // namespace | 12530 } // namespace |
12400 } // namespace cc | 12531 } // namespace cc |
OLD | NEW |