Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 2828353003: Determine mask UVs based on texture size (Closed)
Patch Set: nit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/render_surface_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 ActivateTree(); 1223 ActivateTree();
1224 1224
1225 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>( 1225 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>(
1226 host_impl()->active_tree()->LayerById(pending_mask->id())); 1226 host_impl()->active_tree()->LayerById(pending_mask->id()));
1227 1227
1228 // Mask layers have a tiling with a single tile in it. 1228 // Mask layers have a tiling with a single tile in it.
1229 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1229 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1230 // The mask resource exists. 1230 // The mask resource exists.
1231 ResourceId mask_resource_id; 1231 ResourceId mask_resource_id;
1232 gfx::Size mask_texture_size; 1232 gfx::Size mask_texture_size;
1233 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1233 gfx::SizeF mask_uv_size;
1234 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size,
1235 &mask_uv_size);
1234 EXPECT_NE(0u, mask_resource_id); 1236 EXPECT_NE(0u, mask_resource_id);
1235 EXPECT_EQ(active_mask->bounds(), mask_texture_size); 1237 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1238 EXPECT_EQ(gfx::SizeF(1.0f, 1.0f), mask_uv_size);
1236 1239
1237 // Drop resources and recreate them, still the same. 1240 // Drop resources and recreate them, still the same.
1238 pending_mask->ReleaseTileResources(); 1241 pending_mask->ReleaseTileResources();
1239 active_mask->ReleaseTileResources(); 1242 active_mask->ReleaseTileResources();
1240 pending_mask->RecreateTileResources(); 1243 pending_mask->RecreateTileResources();
1241 active_mask->RecreateTileResources(); 1244 active_mask->RecreateTileResources();
1242 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f, 1245 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1243 false); 1246 false);
1244 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1247 active_mask->HighResTiling()->CreateAllTilesForTesting();
1245 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1248 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1246 EXPECT_NE(0u, mask_resource_id);
1247 EXPECT_EQ(active_mask->bounds(), mask_texture_size);
1248 1249
1249 // Resize larger than the max texture size. 1250 // Resize larger than the max texture size.
1250 int max_texture_size = host_impl()->resource_provider()->max_texture_size(); 1251 int max_texture_size = host_impl()->resource_provider()->max_texture_size();
1251 gfx::Size huge_bounds(max_texture_size + 1, 10); 1252 gfx::Size huge_bounds(max_texture_size + 1, 10);
1252 scoped_refptr<FakeRasterSource> huge_raster_source = 1253 scoped_refptr<FakeRasterSource> huge_raster_source =
1253 FakeRasterSource::CreateFilled(huge_bounds); 1254 FakeRasterSource::CreateFilled(huge_bounds);
1254 1255
1255 SetupPendingTree(huge_raster_source); 1256 SetupPendingTree(huge_raster_source);
1256 pending_mask->SetBounds(huge_bounds); 1257 pending_mask->SetBounds(huge_bounds);
1257 pending_mask->SetRasterSourceOnPending(huge_raster_source, Region()); 1258 pending_mask->SetRasterSourceOnPending(huge_raster_source, Region());
1258 1259
1259 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 1260 host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
1260 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text); 1261 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text);
1261 1262
1262 // The mask tiling gets scaled down. 1263 // The mask tiling gets scaled down.
1263 EXPECT_LT(pending_mask->HighResTiling()->contents_scale_key(), 1.f); 1264 EXPECT_LT(pending_mask->HighResTiling()->contents_scale_key(), 1.f);
1264 EXPECT_EQ(1u, pending_mask->num_tilings()); 1265 EXPECT_EQ(1u, pending_mask->num_tilings());
1265 1266
1266 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting( 1267 host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
1267 pending_mask->HighResTiling()->AllTilesForTesting()); 1268 pending_mask->HighResTiling()->AllTilesForTesting());
1268 1269
1269 ActivateTree(); 1270 ActivateTree();
1270 1271
1271 // Mask layers have a tiling with a single tile in it. 1272 // Mask layers have a tiling with a single tile in it.
1272 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1273 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1273 // The mask resource exists. 1274 // The mask resource exists.
1274 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1275 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size,
1276 &mask_uv_size);
1275 EXPECT_NE(0u, mask_resource_id); 1277 EXPECT_NE(0u, mask_resource_id);
1276 gfx::Size expected_size = active_mask->bounds(); 1278 gfx::Size expected_size = active_mask->bounds();
1277 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size)); 1279 expected_size.SetToMin(gfx::Size(max_texture_size, max_texture_size));
1278 EXPECT_EQ(expected_size, mask_texture_size); 1280 EXPECT_EQ(expected_size, mask_texture_size);
1281 EXPECT_EQ(gfx::SizeF(1.0f, 1.0f), mask_uv_size);
1279 1282
1280 // Drop resources and recreate them, still the same. 1283 // Drop resources and recreate them, still the same.
1281 pending_mask->ReleaseTileResources(); 1284 pending_mask->ReleaseTileResources();
1282 active_mask->ReleaseTileResources(); 1285 active_mask->ReleaseTileResources();
1283 pending_mask->RecreateTileResources(); 1286 pending_mask->RecreateTileResources();
1284 active_mask->RecreateTileResources(); 1287 active_mask->RecreateTileResources();
1285 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f, 1288 SetupDrawPropertiesAndUpdateTiles(active_mask, 1.f, 1.f, 1.f, 1.f, 0.f,
1286 false); 1289 false);
1287 active_mask->HighResTiling()->CreateAllTilesForTesting(); 1290 active_mask->HighResTiling()->CreateAllTilesForTesting();
1288 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1291 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1289 EXPECT_NE(0u, mask_resource_id); 1292 EXPECT_NE(0u, mask_resource_id);
1290 EXPECT_EQ(expected_size, mask_texture_size); 1293 EXPECT_EQ(expected_size, mask_texture_size);
1291 1294
1292 // Do another activate, the same holds. 1295 // Do another activate, the same holds.
1293 SetupPendingTree(huge_raster_source); 1296 SetupPendingTree(huge_raster_source);
1294 ActivateTree(); 1297 ActivateTree();
1295 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1298 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1296 active_layer()->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1299 active_layer()->GetContentsResourceId(&mask_resource_id, &mask_texture_size,
1300 &mask_uv_size);
1297 EXPECT_EQ(expected_size, mask_texture_size); 1301 EXPECT_EQ(expected_size, mask_texture_size);
1298 EXPECT_EQ(0u, mask_resource_id); 1302 EXPECT_EQ(0u, mask_resource_id);
1303 EXPECT_EQ(gfx::SizeF(1.0f, 1.0f), mask_uv_size);
1299 1304
1300 // Resize even larger, so that the scale would be smaller than the minimum 1305 // Resize even larger, so that the scale would be smaller than the minimum
1301 // contents scale. Then the layer should no longer have any tiling. 1306 // contents scale. Then the layer should no longer have any tiling.
1302 float min_contents_scale = host_impl()->settings().minimum_contents_scale; 1307 float min_contents_scale = host_impl()->settings().minimum_contents_scale;
1303 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10); 1308 gfx::Size extra_huge_bounds(max_texture_size / min_contents_scale + 1, 10);
1304 scoped_refptr<FakeRasterSource> extra_huge_raster_source = 1309 scoped_refptr<FakeRasterSource> extra_huge_raster_source =
1305 FakeRasterSource::CreateFilled(extra_huge_bounds); 1310 FakeRasterSource::CreateFilled(extra_huge_bounds);
1306 1311
1307 SetupPendingTree(extra_huge_raster_source); 1312 SetupPendingTree(extra_huge_raster_source);
1308 pending_mask->SetBounds(extra_huge_bounds); 1313 pending_mask->SetBounds(extra_huge_bounds);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 ActivateTree(); 1358 ActivateTree();
1354 1359
1355 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>( 1360 FakePictureLayerImpl* active_mask = static_cast<FakePictureLayerImpl*>(
1356 host_impl()->active_tree()->LayerById(pending_mask->id())); 1361 host_impl()->active_tree()->LayerById(pending_mask->id()));
1357 1362
1358 // Mask layers have a tiling with a single tile in it. 1363 // Mask layers have a tiling with a single tile in it.
1359 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size()); 1364 EXPECT_EQ(1u, active_mask->HighResTiling()->AllTilesForTesting().size());
1360 // The mask resource exists. 1365 // The mask resource exists.
1361 ResourceId mask_resource_id; 1366 ResourceId mask_resource_id;
1362 gfx::Size mask_texture_size; 1367 gfx::Size mask_texture_size;
1363 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size); 1368 gfx::SizeF mask_uv_size;
1369 active_mask->GetContentsResourceId(&mask_resource_id, &mask_texture_size,
1370 &mask_uv_size);
1364 EXPECT_NE(0u, mask_resource_id); 1371 EXPECT_NE(0u, mask_resource_id);
1365 gfx::Size expected_mask_texture_size = 1372 gfx::Size expected_mask_texture_size =
1366 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f); 1373 gfx::ScaleToCeiledSize(active_mask->bounds(), 1.3f);
1367 EXPECT_EQ(mask_texture_size, expected_mask_texture_size); 1374 EXPECT_EQ(mask_texture_size, expected_mask_texture_size);
1375 EXPECT_EQ(gfx::SizeF(1.0f, 1.0f), mask_uv_size);
1368 } 1376 }
1369 1377
1370 TEST_F(PictureLayerImplTest, ReleaseTileResources) { 1378 TEST_F(PictureLayerImplTest, ReleaseTileResources) {
1371 gfx::Size layer_bounds(1300, 1900); 1379 gfx::Size layer_bounds(1300, 1900);
1372 SetupDefaultTrees(layer_bounds); 1380 SetupDefaultTrees(layer_bounds);
1373 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings()); 1381 EXPECT_EQ(1u, pending_layer()->tilings()->num_tilings());
1374 1382
1375 // All tilings should be removed when losing output surface. 1383 // All tilings should be removed when losing output surface.
1376 active_layer()->ReleaseTileResources(); 1384 active_layer()->ReleaseTileResources();
1377 EXPECT_FALSE(active_layer()->tilings()); 1385 EXPECT_FALSE(active_layer()->tilings());
(...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after
4995 EXPECT_FLOAT_EQ(expected_contents_scale, 5003 EXPECT_FLOAT_EQ(expected_contents_scale,
4996 pending_layer_ptr->picture_layer_tiling_set() 5004 pending_layer_ptr->picture_layer_tiling_set()
4997 ->FindTilingWithResolution(HIGH_RESOLUTION) 5005 ->FindTilingWithResolution(HIGH_RESOLUTION)
4998 ->contents_scale_key()) 5006 ->contents_scale_key())
4999 << "ideal_contents_scale: " << ideal_contents_scale; 5007 << "ideal_contents_scale: " << ideal_contents_scale;
5000 } 5008 }
5001 } 5009 }
5002 5010
5003 } // namespace 5011 } // namespace
5004 } // namespace cc 5012 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/render_surface_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698