| 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 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 EXPECT_FALSE(pending_layer()->LowResTiling()); | 1139 EXPECT_FALSE(pending_layer()->LowResTiling()); |
| 1140 EXPECT_EQ(active_layer()->num_tilings(), 2u); | 1140 EXPECT_EQ(active_layer()->num_tilings(), 2u); |
| 1141 EXPECT_EQ(pending_layer()->num_tilings(), 1u); | 1141 EXPECT_EQ(pending_layer()->num_tilings(), 1u); |
| 1142 | 1142 |
| 1143 // Mask layers dont create low res since they always fit on one tile. | 1143 // Mask layers dont create low res since they always fit on one tile. |
| 1144 std::unique_ptr<FakePictureLayerImpl> mask = | 1144 std::unique_ptr<FakePictureLayerImpl> mask = |
| 1145 FakePictureLayerImpl::CreateMaskWithRasterSource( | 1145 FakePictureLayerImpl::CreateMaskWithRasterSource( |
| 1146 host_impl()->pending_tree(), 3, pending_raster_source); | 1146 host_impl()->pending_tree(), 3, pending_raster_source); |
| 1147 mask->SetBounds(layer_bounds); | 1147 mask->SetBounds(layer_bounds); |
| 1148 mask->SetDrawsContent(true); | 1148 mask->SetDrawsContent(true); |
| 1149 pending_layer()->SetMaskLayer(std::move(mask)); | 1149 pending_layer()->test_properties()->SetMaskLayer(std::move(mask)); |
| 1150 pending_layer()->SetHasRenderSurface(true); | 1150 pending_layer()->SetHasRenderSurface(true); |
| 1151 RebuildPropertyTreesOnPendingTree(); | 1151 RebuildPropertyTreesOnPendingTree(); |
| 1152 host_impl()->pending_tree()->UpdateDrawProperties(false); | 1152 host_impl()->pending_tree()->UpdateDrawProperties(false); |
| 1153 | 1153 |
| 1154 FakePictureLayerImpl* mask_raw = | 1154 FakePictureLayerImpl* mask_raw = static_cast<FakePictureLayerImpl*>( |
| 1155 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); | 1155 pending_layer()->test_properties()->mask_layer); |
| 1156 // We did an UpdateDrawProperties above, which will set a contents scale on | 1156 // We did an UpdateDrawProperties above, which will set a contents scale on |
| 1157 // the mask layer, so allow us to reset the contents scale. | 1157 // the mask layer, so allow us to reset the contents scale. |
| 1158 mask_raw->ReleaseResources(); | 1158 mask_raw->ReleaseResources(); |
| 1159 mask_raw->RecreateResources(); | 1159 mask_raw->RecreateResources(); |
| 1160 | 1160 |
| 1161 SetupDrawPropertiesAndUpdateTiles( | 1161 SetupDrawPropertiesAndUpdateTiles( |
| 1162 mask_raw, contents_scale, device_scale, page_scale, | 1162 mask_raw, contents_scale, device_scale, page_scale, |
| 1163 maximum_animation_scale, starting_animation_scale, animating_transform); | 1163 maximum_animation_scale, starting_animation_scale, animating_transform); |
| 1164 EXPECT_EQ(mask_raw->HighResTiling()->contents_scale(), contents_scale); | 1164 EXPECT_EQ(mask_raw->HighResTiling()->contents_scale(), contents_scale); |
| 1165 EXPECT_EQ(mask_raw->num_tilings(), 1u); | 1165 EXPECT_EQ(mask_raw->num_tilings(), 1u); |
| 1166 } | 1166 } |
| 1167 | 1167 |
| 1168 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { | 1168 TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { |
| 1169 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | 1169 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); |
| 1170 | 1170 |
| 1171 gfx::Size layer_bounds(1000, 1000); | 1171 gfx::Size layer_bounds(1000, 1000); |
| 1172 | 1172 |
| 1173 scoped_refptr<FakeRasterSource> valid_raster_source = | 1173 scoped_refptr<FakeRasterSource> valid_raster_source = |
| 1174 FakeRasterSource::CreateFilled(layer_bounds); | 1174 FakeRasterSource::CreateFilled(layer_bounds); |
| 1175 SetupPendingTree(valid_raster_source); | 1175 SetupPendingTree(valid_raster_source); |
| 1176 | 1176 |
| 1177 std::unique_ptr<FakePictureLayerImpl> mask_ptr = | 1177 std::unique_ptr<FakePictureLayerImpl> mask_ptr = |
| 1178 FakePictureLayerImpl::CreateMaskWithRasterSource( | 1178 FakePictureLayerImpl::CreateMaskWithRasterSource( |
| 1179 host_impl()->pending_tree(), 3, valid_raster_source); | 1179 host_impl()->pending_tree(), 3, valid_raster_source); |
| 1180 mask_ptr->SetBounds(layer_bounds); | 1180 mask_ptr->SetBounds(layer_bounds); |
| 1181 mask_ptr->SetDrawsContent(true); | 1181 mask_ptr->SetDrawsContent(true); |
| 1182 pending_layer()->SetMaskLayer(std::move(mask_ptr)); | 1182 pending_layer()->test_properties()->SetMaskLayer(std::move(mask_ptr)); |
| 1183 pending_layer()->test_properties()->force_render_surface = true; | 1183 pending_layer()->test_properties()->force_render_surface = true; |
| 1184 | 1184 |
| 1185 RebuildPropertyTreesOnPendingTree(); | 1185 RebuildPropertyTreesOnPendingTree(); |
| 1186 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | 1186 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); |
| 1187 bool update_lcd_text = false; | 1187 bool update_lcd_text = false; |
| 1188 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); | 1188 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 1189 | 1189 |
| 1190 FakePictureLayerImpl* pending_mask = | 1190 FakePictureLayerImpl* pending_mask = static_cast<FakePictureLayerImpl*>( |
| 1191 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); | 1191 pending_layer()->test_properties()->mask_layer); |
| 1192 | 1192 |
| 1193 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale()); | 1193 EXPECT_EQ(1.f, pending_mask->HighResTiling()->contents_scale()); |
| 1194 EXPECT_EQ(1u, pending_mask->num_tilings()); | 1194 EXPECT_EQ(1u, pending_mask->num_tilings()); |
| 1195 | 1195 |
| 1196 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( | 1196 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( |
| 1197 pending_mask->HighResTiling()->AllTilesForTesting()); | 1197 pending_mask->HighResTiling()->AllTilesForTesting()); |
| 1198 | 1198 |
| 1199 ActivateTree(); | 1199 ActivateTree(); |
| 1200 | 1200 |
| 1201 FakePictureLayerImpl* active_mask = | 1201 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>( |
| 1202 static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer()); | 1202 host_impl()->active_tree()->LayerById(pending_mask->id())); |
| 1203 | 1203 |
| 1204 // Mask layers have a tiling with a single tile in it. | 1204 // Mask layers have a tiling with a single tile in it. |
| 1205 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); | 1205 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); |
| 1206 // The mask resource exists. | 1206 // The mask resource exists. |
| 1207 ResourceId mask_resource_id; | 1207 ResourceId mask_resource_id; |
| 1208 gfx::Size mask_texture_size; | 1208 gfx::Size mask_texture_size; |
| 1209 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); | 1209 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); |
| 1210 EXPECT_NE(0u, mask_resource_id); | 1210 EXPECT_NE(0u, mask_resource_id); |
| 1211 EXPECT_EQ(active_mask->bounds(), mask_texture_size); | 1211 EXPECT_EQ(active_mask->bounds(), mask_texture_size); |
| 1212 | 1212 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 | 1302 |
| 1303 scoped_refptr<FakeRasterSource> valid_raster_source = | 1303 scoped_refptr<FakeRasterSource> valid_raster_source = |
| 1304 FakeRasterSource::CreateFilled(layer_bounds); | 1304 FakeRasterSource::CreateFilled(layer_bounds); |
| 1305 SetupPendingTree(valid_raster_source); | 1305 SetupPendingTree(valid_raster_source); |
| 1306 | 1306 |
| 1307 std::unique_ptr<FakePictureLayerImpl> mask_ptr = | 1307 std::unique_ptr<FakePictureLayerImpl> mask_ptr = |
| 1308 FakePictureLayerImpl::CreateMaskWithRasterSource( | 1308 FakePictureLayerImpl::CreateMaskWithRasterSource( |
| 1309 host_impl()->pending_tree(), 3, valid_raster_source); | 1309 host_impl()->pending_tree(), 3, valid_raster_source); |
| 1310 mask_ptr->SetBounds(layer_bounds); | 1310 mask_ptr->SetBounds(layer_bounds); |
| 1311 mask_ptr->SetDrawsContent(true); | 1311 mask_ptr->SetDrawsContent(true); |
| 1312 pending_layer()->SetMaskLayer(std::move(mask_ptr)); | 1312 pending_layer()->test_properties()->SetMaskLayer(std::move(mask_ptr)); |
| 1313 pending_layer()->test_properties()->force_render_surface = true; | 1313 pending_layer()->test_properties()->force_render_surface = true; |
| 1314 | 1314 |
| 1315 RebuildPropertyTreesOnPendingTree(); | 1315 RebuildPropertyTreesOnPendingTree(); |
| 1316 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); | 1316 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); |
| 1317 bool update_lcd_text = false; | 1317 bool update_lcd_text = false; |
| 1318 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); | 1318 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); |
| 1319 | 1319 |
| 1320 FakePictureLayerImpl* pending_mask = | 1320 FakePictureLayerImpl* pending_mask = static_cast<FakePictureLayerImpl*>( |
| 1321 static_cast<FakePictureLayerImpl*>(pending_layer()->mask_layer()); | 1321 pending_layer()->test_properties()->mask_layer); |
| 1322 | 1322 |
| 1323 // Masks are scaled, and do not have a low res tiling. | 1323 // Masks are scaled, and do not have a low res tiling. |
| 1324 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale()); | 1324 EXPECT_EQ(1.3f, pending_mask->HighResTiling()->contents_scale()); |
| 1325 EXPECT_EQ(1u, pending_mask->num_tilings()); | 1325 EXPECT_EQ(1u, pending_mask->num_tilings()); |
| 1326 | 1326 |
| 1327 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( | 1327 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( |
| 1328 pending_mask->HighResTiling()->AllTilesForTesting()); | 1328 pending_mask->HighResTiling()->AllTilesForTesting()); |
| 1329 | 1329 |
| 1330 ActivateTree(); | 1330 ActivateTree(); |
| 1331 | 1331 |
| 1332 FakePictureLayerImpl* active_mask = | 1332 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>( |
| 1333 static_cast<FakePictureLayerImpl*>(active_layer()->mask_layer()); | 1333 host_impl()->active_tree()->LayerById(pending_mask->id())); |
| 1334 | 1334 |
| 1335 // Mask layers have a tiling with a single tile in it. | 1335 // Mask layers have a tiling with a single tile in it. |
| 1336 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); | 1336 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); |
| 1337 // The mask resource exists. | 1337 // The mask resource exists. |
| 1338 ResourceId mask_resource_id; | 1338 ResourceId mask_resource_id; |
| 1339 gfx::Size mask_texture_size; | 1339 gfx::Size mask_texture_size; |
| 1340 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); | 1340 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); |
| 1341 EXPECT_NE(0u, mask_resource_id); | 1341 EXPECT_NE(0u, mask_resource_id); |
| 1342 gfx::Size expected_mask_texture_size = | 1342 gfx::Size expected_mask_texture_size = |
| 1343 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f); | 1343 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f); |
| (...skipping 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4765 // New low res tiling. | 4765 // New low res tiling. |
| 4766 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); | 4766 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); |
| 4767 | 4767 |
| 4768 // This tiling will be high res now, it won't contain low res content since it | 4768 // This tiling will be high res now, it won't contain low res content since it |
| 4769 // was all destroyed. | 4769 // was all destroyed. |
| 4770 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); | 4770 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); |
| 4771 } | 4771 } |
| 4772 | 4772 |
| 4773 } // namespace | 4773 } // namespace |
| 4774 } // namespace cc | 4774 } // namespace cc |
| OLD | NEW |