OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 FakeRasterSource::CreateFilled(layer_bounds); | 410 FakeRasterSource::CreateFilled(layer_bounds); |
411 scoped_refptr<FakeRasterSource> active_raster_source = | 411 scoped_refptr<FakeRasterSource> active_raster_source = |
412 FakeRasterSource::CreateFilled(layer_bounds); | 412 FakeRasterSource::CreateFilled(layer_bounds); |
413 scoped_refptr<FakeRasterSource> lost_raster_source = | 413 scoped_refptr<FakeRasterSource> lost_raster_source = |
414 FakeRasterSource::CreateFilled(layer_bounds); | 414 FakeRasterSource::CreateFilled(layer_bounds); |
415 | 415 |
416 SetupPendingTreeWithFixedTileSize(lost_raster_source, gfx::Size(50, 50), | 416 SetupPendingTreeWithFixedTileSize(lost_raster_source, gfx::Size(50, 50), |
417 Region()); | 417 Region()); |
418 ActivateTree(); | 418 ActivateTree(); |
419 // Add a unique tiling on the active tree. | 419 // Add a unique tiling on the active tree. |
420 PictureLayerTiling* tiling = active_layer()->AddTiling(3.f); | 420 PictureLayerTiling* tiling = |
| 421 active_layer()->AddTiling(gfx::AxisTransform2d(3.f, gfx::Vector2dF())); |
421 tiling->set_resolution(HIGH_RESOLUTION); | 422 tiling->set_resolution(HIGH_RESOLUTION); |
422 tiling->CreateAllTilesForTesting(); | 423 tiling->CreateAllTilesForTesting(); |
423 | 424 |
424 // Ensure UpdateTiles won't remove any tilings. | 425 // Ensure UpdateTiles won't remove any tilings. |
425 active_layer()->MarkAllTilingsUsed(); | 426 active_layer()->MarkAllTilingsUsed(); |
426 | 427 |
427 // Then setup a new pending tree and activate it. | 428 // Then setup a new pending tree and activate it. |
428 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, | 429 SetupTreesWithFixedTileSize(pending_raster_source, active_raster_source, |
429 gfx::Size(50, 50), layer_invalidation); | 430 gfx::Size(50, 50), layer_invalidation); |
430 | 431 |
(...skipping 3499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3930 pending_layer()->test_properties()->AddChild( | 3931 pending_layer()->test_properties()->AddChild( |
3931 LayerImpl::Create(host_impl()->pending_tree(), 1)); | 3932 LayerImpl::Create(host_impl()->pending_tree(), 1)); |
3932 LayerImpl* layer1 = pending_layer()->test_properties()->children[0]; | 3933 LayerImpl* layer1 = pending_layer()->test_properties()->children[0]; |
3933 layer1->SetBounds(layer_bounds); | 3934 layer1->SetBounds(layer_bounds); |
3934 layer1->SetDrawsContent(true); | 3935 layer1->SetDrawsContent(true); |
3935 layer1->SetContentsOpaque(true); | 3936 layer1->SetContentsOpaque(true); |
3936 layer1->SetPosition(occluding_layer_position); | 3937 layer1->SetPosition(occluding_layer_position); |
3937 | 3938 |
3938 pending_layer()->tilings()->RemoveAllTilings(); | 3939 pending_layer()->tilings()->RemoveAllTilings(); |
3939 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; | 3940 float low_res_factor = host_impl()->settings().low_res_contents_scale_factor; |
3940 pending_layer()->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION); | 3941 pending_layer() |
3941 pending_layer()->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION); | 3942 ->AddTiling(gfx::AxisTransform2d(low_res_factor, gfx::Vector2dF())) |
3942 pending_layer()->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION); | 3943 ->set_resolution(LOW_RESOLUTION); |
3943 pending_layer()->AddTiling(1.0f)->set_resolution(HIGH_RESOLUTION); | 3944 pending_layer() |
3944 pending_layer()->AddTiling(2.0f)->set_resolution(HIGH_RESOLUTION); | 3945 ->AddTiling(gfx::AxisTransform2d(0.3f, gfx::Vector2dF())) |
| 3946 ->set_resolution(HIGH_RESOLUTION); |
| 3947 pending_layer() |
| 3948 ->AddTiling(gfx::AxisTransform2d(0.7f, gfx::Vector2dF())) |
| 3949 ->set_resolution(HIGH_RESOLUTION); |
| 3950 pending_layer() |
| 3951 ->AddTiling(gfx::AxisTransform2d(1.0f, gfx::Vector2dF())) |
| 3952 ->set_resolution(HIGH_RESOLUTION); |
| 3953 pending_layer() |
| 3954 ->AddTiling(gfx::AxisTransform2d(2.0f, gfx::Vector2dF())) |
| 3955 ->set_resolution(HIGH_RESOLUTION); |
3945 | 3956 |
3946 RebuildPropertyTreesOnPendingTree(); | 3957 RebuildPropertyTreesOnPendingTree(); |
3947 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | 3958 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); |
3948 // UpdateDrawProperties with the occluding layer. | 3959 // UpdateDrawProperties with the occluding layer. |
3949 bool update_lcd_text = false; | 3960 bool update_lcd_text = false; |
3950 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); | 3961 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); |
3951 | 3962 |
3952 EXPECT_EQ(5u, pending_layer()->num_tilings()); | 3963 EXPECT_EQ(5u, pending_layer()->num_tilings()); |
3953 | 3964 |
3954 int occluded_tile_count = 0; | 3965 int occluded_tile_count = 0; |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5001 SetupDrawPropertiesAndUpdateTiles(pending_layer_ptr, ideal_contents_scale, | 5012 SetupDrawPropertiesAndUpdateTiles(pending_layer_ptr, ideal_contents_scale, |
5002 1.f, 1.f, 1.f, 1.f, false); | 5013 1.f, 1.f, 1.f, 1.f, false); |
5003 EXPECT_FLOAT_EQ(expected_contents_scale, | 5014 EXPECT_FLOAT_EQ(expected_contents_scale, |
5004 pending_layer_ptr->picture_layer_tiling_set() | 5015 pending_layer_ptr->picture_layer_tiling_set() |
5005 ->FindTilingWithResolution(HIGH_RESOLUTION) | 5016 ->FindTilingWithResolution(HIGH_RESOLUTION) |
5006 ->contents_scale_key()) | 5017 ->contents_scale_key()) |
5007 << "ideal_contents_scale: " << ideal_contents_scale; | 5018 << "ideal_contents_scale: " << ideal_contents_scale; |
5008 } | 5019 } |
5009 } | 5020 } |
5010 | 5021 |
| 5022 TEST_F(PictureLayerImplTest, ChangeRasterTranslationNukePendingLayerTiles) { |
| 5023 gfx::Size layer_bounds(200, 200); |
| 5024 gfx::Size tile_size(256, 256); |
| 5025 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); |
| 5026 pending_layer()->SetUseTransformedRasterization(true); |
| 5027 |
| 5028 // Start with scale & translation of * 2.25 + (0.25, 0.5). |
| 5029 SetupDrawProperties(pending_layer(), 2.25f, 1.5f, 1.f, 2.25f, 2.25f, false); |
| 5030 gfx::Transform translate1; |
| 5031 translate1.Translate(0.25f, 0.5f); |
| 5032 pending_layer()->draw_properties().screen_space_transform.ConcatTransform( |
| 5033 translate1); |
| 5034 pending_layer()->draw_properties().target_space_transform = |
| 5035 pending_layer()->draw_properties().screen_space_transform; |
| 5036 pending_layer()->UpdateTiles(); |
| 5037 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); |
| 5038 { |
| 5039 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(0); |
| 5040 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.25f, 0.5f)), |
| 5041 tiling->raster_transform()); |
| 5042 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5043 for (auto* tile : tiling->AllTilesForTesting()) |
| 5044 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5045 } |
| 5046 |
| 5047 // Change to scale & translation of * 2.25 + (0.75, 0.25). |
| 5048 // Verifies there is a hysteresis that simple layer movement doesn't update |
| 5049 // raster translation. |
| 5050 SetupDrawProperties(pending_layer(), 2.25f, 1.5f, 1.f, 2.25f, 2.25f, false); |
| 5051 gfx::Transform translate2; |
| 5052 translate2.Translate(0.75f, 0.25f); |
| 5053 pending_layer()->draw_properties().screen_space_transform.ConcatTransform( |
| 5054 translate2); |
| 5055 pending_layer()->draw_properties().target_space_transform = |
| 5056 pending_layer()->draw_properties().screen_space_transform; |
| 5057 pending_layer()->UpdateTiles(); |
| 5058 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); |
| 5059 { |
| 5060 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(0); |
| 5061 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.25f, 0.5f)), |
| 5062 tiling->raster_transform()); |
| 5063 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5064 for (auto* tile : tiling->AllTilesForTesting()) |
| 5065 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5066 } |
| 5067 |
| 5068 // Now change the device scale factor but keep the same total scale. |
| 5069 // Our policy recomputes raster translation only if raster scale is |
| 5070 // recomputed. Even if the recomputed scale remains the same, we still |
| 5071 // updates to new translation value. Old tiles with the same scale but |
| 5072 // different translation would become non-ideal and deleted on pending |
| 5073 // layers (in fact, delete ahead due to slot conflict with the new tiling). |
| 5074 SetupDrawProperties(pending_layer(), 2.25f, 1.0f, 1.f, 2.25f, 2.25f, false); |
| 5075 pending_layer()->draw_properties().screen_space_transform.ConcatTransform( |
| 5076 translate2); |
| 5077 pending_layer()->draw_properties().target_space_transform = |
| 5078 pending_layer()->draw_properties().screen_space_transform; |
| 5079 pending_layer()->UpdateTiles(); |
| 5080 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); |
| 5081 { |
| 5082 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(0); |
| 5083 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.75f, 0.25f)), |
| 5084 tiling->raster_transform()); |
| 5085 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5086 for (auto* tile : tiling->AllTilesForTesting()) |
| 5087 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5088 } |
| 5089 } |
| 5090 |
| 5091 TEST_F(PictureLayerImplTest, ChangeRasterTranslationNukeActiveLayerTiles) { |
| 5092 gfx::Size layer_bounds(200, 200); |
| 5093 gfx::Size tile_size(256, 256); |
| 5094 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size, Region()); |
| 5095 active_layer()->SetUseTransformedRasterization(true); |
| 5096 pending_layer()->SetUseTransformedRasterization(true); |
| 5097 |
| 5098 // Start with scale & translation of * 2.25 + (0.25, 0.5) on the active layer. |
| 5099 SetupDrawProperties(active_layer(), 2.25f, 1.5f, 1.f, 2.25f, 2.25f, false); |
| 5100 gfx::Transform translate1; |
| 5101 translate1.Translate(0.25f, 0.5f); |
| 5102 active_layer()->draw_properties().screen_space_transform.ConcatTransform( |
| 5103 translate1); |
| 5104 active_layer()->draw_properties().target_space_transform = |
| 5105 active_layer()->draw_properties().screen_space_transform; |
| 5106 active_layer()->UpdateTiles(); |
| 5107 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); |
| 5108 { |
| 5109 PictureLayerTiling* tiling = |
| 5110 active_layer()->tilings()->FindTilingWithScaleKey(2.25f); |
| 5111 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.25f, 0.5f)), |
| 5112 tiling->raster_transform()); |
| 5113 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5114 for (auto* tile : tiling->AllTilesForTesting()) |
| 5115 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5116 } |
| 5117 |
| 5118 // Create a pending layer with the same scale but different translation. |
| 5119 SetupDrawProperties(pending_layer(), 2.25f, 1.5f, 1.f, 2.25f, 2.25f, false); |
| 5120 gfx::Transform translate2; |
| 5121 translate2.Translate(0.75f, 0.25f); |
| 5122 pending_layer()->draw_properties().screen_space_transform.ConcatTransform( |
| 5123 translate2); |
| 5124 pending_layer()->draw_properties().target_space_transform = |
| 5125 pending_layer()->draw_properties().screen_space_transform; |
| 5126 pending_layer()->UpdateTiles(); |
| 5127 ASSERT_EQ(1u, pending_layer()->tilings()->num_tilings()); |
| 5128 { |
| 5129 PictureLayerTiling* tiling = pending_layer()->tilings()->tiling_at(0); |
| 5130 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.75f, 0.25f)), |
| 5131 tiling->raster_transform()); |
| 5132 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5133 for (auto* tile : tiling->AllTilesForTesting()) |
| 5134 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5135 } |
| 5136 |
| 5137 // Now push to the active layer. |
| 5138 // Verifies the active tiles get evicted due to slot conflict. |
| 5139 host_impl()->ActivateSyncTree(); |
| 5140 ASSERT_EQ(3u, active_layer()->tilings()->num_tilings()); |
| 5141 { |
| 5142 PictureLayerTiling* tiling = |
| 5143 active_layer()->tilings()->FindTilingWithScaleKey(2.25f); |
| 5144 EXPECT_EQ(gfx::AxisTransform2d(2.25f, gfx::Vector2dF(0.75f, 0.25f)), |
| 5145 tiling->raster_transform()); |
| 5146 EXPECT_EQ(4u, tiling->AllTilesForTesting().size()); |
| 5147 for (auto* tile : tiling->AllTilesForTesting()) |
| 5148 EXPECT_EQ(tile->raster_transform(), tiling->raster_transform()); |
| 5149 } |
| 5150 } |
| 5151 |
5011 } // namespace | 5152 } // namespace |
5012 } // namespace cc | 5153 } // namespace cc |
OLD | NEW |