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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 | 1234 |
1235 AppendQuadsData data; | 1235 AppendQuadsData data; |
1236 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); | 1236 active_layer_->WillDraw(DRAW_MODE_RESOURCELESS_SOFTWARE, NULL); |
1237 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 1237 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
1238 active_layer_->DidDraw(NULL); | 1238 active_layer_->DidDraw(NULL); |
1239 | 1239 |
1240 ASSERT_EQ(1U, render_pass->quad_list.size()); | 1240 ASSERT_EQ(1U, render_pass->quad_list.size()); |
1241 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, render_pass->quad_list[0]->material); | 1241 EXPECT_EQ(DrawQuad::PICTURE_CONTENT, render_pass->quad_list[0]->material); |
1242 } | 1242 } |
1243 | 1243 |
1244 TEST_F(PictureLayerImplTest, MarkRequiredNullTiles) { | |
1245 gfx::Size tile_size(100, 100); | |
1246 gfx::Size layer_bounds(1000, 1000); | |
1247 | |
1248 scoped_refptr<FakePicturePileImpl> pending_pile = | |
1249 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
1250 // Layers with entirely empty piles can't get tilings. | |
1251 pending_pile->AddRecordingAt(0, 0); | |
1252 | |
1253 SetupPendingTree(pending_pile); | |
1254 | |
1255 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | |
1256 pending_layer_->AddTiling(1.0f); | |
1257 pending_layer_->AddTiling(2.0f); | |
1258 | |
1259 // It should be safe to call this (and MarkVisibleResourcesAsRequired) | |
1260 // on a layer with no recordings. | |
1261 host_impl_.pending_tree()->UpdateDrawProperties(); | |
1262 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1263 } | |
1264 | |
1265 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) { | 1244 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) { |
1266 gfx::Size tile_size(100, 100); | 1245 gfx::Size tile_size(100, 100); |
1267 gfx::Size layer_bounds(200, 200); | 1246 gfx::Size layer_bounds(200, 200); |
1268 | 1247 |
1269 scoped_refptr<FakePicturePileImpl> pending_pile = | 1248 scoped_refptr<FakePicturePileImpl> pending_pile = |
1270 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1249 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1271 SetupPendingTree(pending_pile); | 1250 SetupPendingTree(pending_pile); |
1272 | 1251 |
1273 pending_layer_->set_fixed_tile_size(tile_size); | 1252 pending_layer_->set_fixed_tile_size(tile_size); |
1274 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | 1253 ASSERT_TRUE(pending_layer_->CanHaveTilings()); |
1275 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); | 1254 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); |
1276 host_impl_.pending_tree()->UpdateDrawProperties(); | 1255 host_impl_.pending_tree()->UpdateDrawProperties(); |
1277 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION); | |
1278 | |
1279 pending_layer_->draw_properties().visible_content_rect = | 1256 pending_layer_->draw_properties().visible_content_rect = |
1280 gfx::Rect(0, 0, 100, 200); | 1257 gfx::Rect(0, 0, 100, 200); |
| 1258 pending_layer_->UpdateTiles(NULL); |
1281 | 1259 |
1282 // Fake set priorities. | 1260 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION); |
1283 for (PictureLayerTiling::CoverageIterator iter( | |
1284 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds)); | |
1285 iter; | |
1286 ++iter) { | |
1287 if (!*iter) | |
1288 continue; | |
1289 Tile* tile = *iter; | |
1290 TilePriority priority; | |
1291 priority.resolution = HIGH_RESOLUTION; | |
1292 gfx::Rect tile_bounds = iter.geometry_rect(); | |
1293 if (pending_layer_->visible_content_rect().Intersects(tile_bounds)) { | |
1294 priority.priority_bin = TilePriority::NOW; | |
1295 priority.distance_to_visible = 0.f; | |
1296 } else { | |
1297 priority.priority_bin = TilePriority::SOON; | |
1298 priority.distance_to_visible = 1.f; | |
1299 } | |
1300 tile->SetPriority(PENDING_TREE, priority); | |
1301 } | |
1302 | |
1303 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1304 | 1261 |
1305 int num_visible = 0; | 1262 int num_visible = 0; |
1306 int num_offscreen = 0; | 1263 int num_offscreen = 0; |
1307 | 1264 |
1308 for (PictureLayerTiling::CoverageIterator iter( | 1265 for (PictureLayerTiling::TilingRasterTileIterator iter(tiling, PENDING_TREE); |
1309 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds)); | |
1310 iter; | 1266 iter; |
1311 ++iter) { | 1267 ++iter) { |
1312 if (!*iter) | |
1313 continue; | |
1314 const Tile* tile = *iter; | 1268 const Tile* tile = *iter; |
1315 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) { | 1269 if (tile->priority(PENDING_TREE).distance_to_visible == 0.f) { |
1316 EXPECT_TRUE(tile->required_for_activation()); | 1270 EXPECT_TRUE(tile->required_for_activation()); |
1317 num_visible++; | 1271 num_visible++; |
1318 } else { | 1272 } else { |
1319 EXPECT_FALSE(tile->required_for_activation()); | 1273 EXPECT_FALSE(tile->required_for_activation()); |
1320 num_offscreen++; | 1274 num_offscreen++; |
1321 } | 1275 } |
1322 } | 1276 } |
1323 | 1277 |
1324 EXPECT_GT(num_visible, 0); | 1278 EXPECT_GT(num_visible, 0); |
1325 EXPECT_GT(num_offscreen, 0); | 1279 EXPECT_GT(num_offscreen, 0); |
1326 } | 1280 } |
1327 | 1281 // |
1328 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { | 1282 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { |
1329 gfx::Size layer_bounds(400, 400); | 1283 gfx::Size layer_bounds(400, 400); |
1330 gfx::Size tile_size(100, 100); | 1284 gfx::Size tile_size(100, 100); |
1331 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1285 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
1332 | 1286 |
1333 // No tiles shared. | 1287 // No tiles shared. |
1334 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); | 1288 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); |
1335 | 1289 |
1336 CreateHighLowResAndSetAllTilesVisible(); | 1290 CreateHighLowResAndSetAllTilesVisible(); |
1337 | 1291 |
1338 active_layer_->SetAllTilesReady(); | 1292 active_layer_->SetAllTilesReady(); |
1339 | 1293 |
1340 // No shared tiles and all active tiles ready, so pending can only | 1294 // No shared tiles and all active tiles ready, so pending can only |
1341 // activate with all high res tiles. | 1295 // activate with all high res tiles. |
1342 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1343 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1296 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
1344 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1297 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1345 } | 1298 } |
1346 | 1299 |
1347 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { | 1300 TEST_F(PictureLayerImplTest, HighResRequiredWhenMissingHighResFlagOn) { |
1348 gfx::Size layer_bounds(400, 400); | 1301 gfx::Size layer_bounds(400, 400); |
1349 gfx::Size tile_size(100, 100); | 1302 gfx::Size tile_size(100, 100); |
1350 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1303 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
1351 | 1304 |
| 1305 host_impl_.active_tree()->SetRequiresHighResToDraw(); |
| 1306 |
1352 // All tiles shared (no invalidation). | 1307 // All tiles shared (no invalidation). |
1353 CreateHighLowResAndSetAllTilesVisible(); | 1308 CreateHighLowResAndSetAllTilesVisible(); |
1354 | 1309 |
1355 // Verify active tree not ready. | 1310 // Verify active tree not ready. |
1356 Tile* some_active_tile = | 1311 Tile* some_active_tile = |
1357 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | 1312 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
1358 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | 1313 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
1359 | 1314 |
1360 // When high res are required, even if the active tree is not ready, | 1315 // When high res are required, even if the active tree is not ready, |
1361 // the high res tiles must be ready. | 1316 // the high res tiles must be ready. |
1362 host_impl_.active_tree()->SetRequiresHighResToDraw(); | |
1363 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1364 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1317 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
1365 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1318 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1366 } | 1319 } |
1367 | 1320 |
1368 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { | 1321 TEST_F(PictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { |
1369 gfx::Size layer_bounds(400, 400); | 1322 gfx::Size layer_bounds(400, 400); |
1370 gfx::Size tile_size(100, 100); | 1323 gfx::Size tile_size(100, 100); |
1371 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1324 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
1372 | 1325 |
1373 CreateHighLowResAndSetAllTilesVisible(); | 1326 CreateHighLowResAndSetAllTilesVisible(); |
1374 | 1327 |
1375 Tile* some_active_tile = | 1328 Tile* some_active_tile = |
1376 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | 1329 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
1377 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | 1330 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
1378 | 1331 |
1379 // All tiles shared (no invalidation), so even though the active tree's | 1332 // All tiles shared (no invalidation), so even though the active tree's |
1380 // tiles aren't ready, there is nothing required. | 1333 // tiles aren't ready, there is nothing required. |
1381 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1382 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 1334 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
1383 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1335 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1384 } | 1336 } |
1385 | 1337 |
1386 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { | 1338 TEST_F(PictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { |
1387 gfx::Size layer_bounds(400, 400); | 1339 gfx::Size layer_bounds(400, 400); |
1388 gfx::Size tile_size(100, 100); | 1340 gfx::Size tile_size(100, 100); |
1389 scoped_refptr<FakePicturePileImpl> pending_pile = | 1341 scoped_refptr<FakePicturePileImpl> pending_pile = |
1390 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1342 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1391 // This pile will create tilings, but has no recordings so will not create any | 1343 // This pile will create tilings, but has no recordings so will not create any |
1392 // tiles. This is attempting to simulate scrolling past the end of recorded | 1344 // tiles. This is attempting to simulate scrolling past the end of recorded |
1393 // content on the active layer, where the recordings are so far away that | 1345 // content on the active layer, where the recordings are so far away that |
1394 // no tiles are created. | 1346 // no tiles are created. |
1395 scoped_refptr<FakePicturePileImpl> active_pile = | 1347 scoped_refptr<FakePicturePileImpl> active_pile = |
1396 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | 1348 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
1397 tile_size, layer_bounds); | 1349 tile_size, layer_bounds); |
1398 SetupTrees(pending_pile, active_pile); | 1350 SetupTrees(pending_pile, active_pile); |
1399 pending_layer_->set_fixed_tile_size(tile_size); | 1351 pending_layer_->set_fixed_tile_size(tile_size); |
1400 active_layer_->set_fixed_tile_size(tile_size); | 1352 active_layer_->set_fixed_tile_size(tile_size); |
1401 | 1353 |
1402 CreateHighLowResAndSetAllTilesVisible(); | 1354 CreateHighLowResAndSetAllTilesVisible(); |
1403 | 1355 |
1404 // Active layer has tilings, but no tiles due to missing recordings. | 1356 // Active layer has tilings, but no tiles due to missing recordings. |
1405 EXPECT_TRUE(active_layer_->CanHaveTilings()); | 1357 EXPECT_TRUE(active_layer_->CanHaveTilings()); |
1406 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); | 1358 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); |
1407 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 1359 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); |
1408 | 1360 |
1409 // Since the active layer has no tiles at all, the pending layer doesn't | 1361 // Since the active layer has no tiles at all, the pending layer doesn't |
1410 // need content in order to activate. | 1362 // need content in order to activate. |
1411 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1412 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 1363 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
1413 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1364 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1414 } | 1365 } |
1415 | 1366 |
1416 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { | 1367 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { |
1417 gfx::Size layer_bounds(400, 400); | 1368 gfx::Size layer_bounds(400, 400); |
1418 gfx::Size tile_size(100, 100); | 1369 gfx::Size tile_size(100, 100); |
1419 scoped_refptr<FakePicturePileImpl> pending_pile = | 1370 scoped_refptr<FakePicturePileImpl> pending_pile = |
1420 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1371 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1421 scoped_refptr<FakePicturePileImpl> active_pile = | 1372 scoped_refptr<FakePicturePileImpl> active_pile = |
1422 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | 1373 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); |
1423 SetupTrees(pending_pile, active_pile); | 1374 SetupTrees(pending_pile, active_pile); |
1424 pending_layer_->set_fixed_tile_size(tile_size); | 1375 pending_layer_->set_fixed_tile_size(tile_size); |
1425 active_layer_->set_fixed_tile_size(tile_size); | 1376 active_layer_->set_fixed_tile_size(tile_size); |
1426 | 1377 |
1427 CreateHighLowResAndSetAllTilesVisible(); | 1378 CreateHighLowResAndSetAllTilesVisible(); |
1428 | 1379 |
1429 // Active layer can't have tiles. | 1380 // Active layer can't have tiles. |
1430 EXPECT_FALSE(active_layer_->CanHaveTilings()); | 1381 EXPECT_FALSE(active_layer_->CanHaveTilings()); |
1431 | 1382 |
1432 // All high res tiles required. This should be considered identical | 1383 // All high res tiles required. This should be considered identical |
1433 // to the case where there is no active layer, to avoid flashing content. | 1384 // to the case where there is no active layer, to avoid flashing content. |
1434 // This can happen if a layer exists for a while and switches from | 1385 // This can happen if a layer exists for a while and switches from |
1435 // not being able to have content to having content. | 1386 // not being able to have content to having content. |
1436 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1437 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1387 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
1438 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1388 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1439 } | 1389 } |
1440 | 1390 |
1441 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) { | 1391 TEST_F(PictureLayerImplTest, HighResRequiredWhenActiveHasDifferentBounds) { |
1442 gfx::Size layer_bounds(200, 200); | 1392 gfx::Size layer_bounds(200, 200); |
1443 gfx::Size tile_size(100, 100); | 1393 gfx::Size tile_size(100, 100); |
1444 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1394 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
1445 | 1395 |
1446 gfx::Size pending_layer_bounds(400, 400); | 1396 gfx::Size pending_layer_bounds(400, 400); |
1447 pending_layer_->SetBounds(pending_layer_bounds); | 1397 pending_layer_->SetBounds(pending_layer_bounds); |
1448 | 1398 |
1449 CreateHighLowResAndSetAllTilesVisible(); | 1399 CreateHighLowResAndSetAllTilesVisible(); |
| 1400 pending_layer_->HighResTiling()->SetLayerBounds(pending_layer_bounds); |
| 1401 pending_layer_->HighResTiling()->UpdateTilePriorities( |
| 1402 PENDING_TREE, |
| 1403 gfx::Rect(pending_layer_bounds), |
| 1404 1.f, |
| 1405 1.f, |
| 1406 NULL, |
| 1407 NULL, |
| 1408 gfx::Transform()); |
| 1409 pending_layer_->HighResTiling()->CreateAllTilesForTesting(); |
1450 | 1410 |
1451 active_layer_->SetAllTilesReady(); | 1411 active_layer_->SetAllTilesReady(); |
1452 | 1412 |
1453 // Since the active layer has different bounds, the pending layer needs all | 1413 // Since the active layer has different bounds, the pending layer needs all |
1454 // high res tiles in order to activate. | 1414 // high res tiles in order to activate. |
1455 pending_layer_->MarkVisibleResourcesAsRequired(); | |
1456 AssertAllTilesRequired(pending_layer_->HighResTiling()); | 1415 AssertAllTilesRequired(pending_layer_->HighResTiling()); |
1457 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1416 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
1458 } | 1417 } |
1459 | 1418 |
1460 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { | 1419 TEST_F(PictureLayerImplTest, ActivateUninitializedLayer) { |
1461 gfx::Size tile_size(100, 100); | 1420 gfx::Size tile_size(100, 100); |
1462 gfx::Size layer_bounds(400, 400); | 1421 gfx::Size layer_bounds(400, 400); |
1463 scoped_refptr<FakePicturePileImpl> pending_pile = | 1422 scoped_refptr<FakePicturePileImpl> pending_pile = |
1464 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1423 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
1465 | 1424 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 tilings.push_back(pending_layer_->AddTiling(2.0f)); | 1930 tilings.push_back(pending_layer_->AddTiling(2.0f)); |
1972 | 1931 |
1973 host_impl_.SetViewportSize(gfx::Size(500, 500)); | 1932 host_impl_.SetViewportSize(gfx::Size(500, 500)); |
1974 host_impl_.pending_tree()->UpdateDrawProperties(); | 1933 host_impl_.pending_tree()->UpdateDrawProperties(); |
1975 | 1934 |
1976 std::vector<Tile*> all_tiles; | 1935 std::vector<Tile*> all_tiles; |
1977 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 1936 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
1978 tilings.begin(); | 1937 tilings.begin(); |
1979 tiling_iterator != tilings.end(); | 1938 tiling_iterator != tilings.end(); |
1980 ++tiling_iterator) { | 1939 ++tiling_iterator) { |
| 1940 (*tiling_iterator)->CreateAllTilesForTesting(); |
1981 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 1941 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
1982 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); | 1942 std::copy(tiles.begin(), tiles.end(), std::back_inserter(all_tiles)); |
1983 } | 1943 } |
1984 | 1944 |
1985 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); | 1945 std::set<Tile*> all_tiles_set(all_tiles.begin(), all_tiles.end()); |
1986 | 1946 |
1987 bool mark_required = false; | 1947 bool mark_required = false; |
1988 size_t number_of_marked_tiles = 0u; | 1948 size_t number_of_marked_tiles = 0u; |
1989 size_t number_of_unmarked_tiles = 0u; | 1949 size_t number_of_unmarked_tiles = 0u; |
1990 for (size_t i = 0; i < tilings.size(); ++i) { | 1950 for (size_t i = 0; i < tilings.size(); ++i) { |
1991 PictureLayerTiling* tiling = tilings.at(i); | 1951 PictureLayerTiling* tiling = tilings.at(i); |
1992 for (PictureLayerTiling::CoverageIterator iter( | 1952 for (PictureLayerTiling::CoverageIterator iter( |
1993 tiling, | 1953 tiling, |
1994 pending_layer_->contents_scale_x(), | 1954 pending_layer_->contents_scale_x(), |
1995 pending_layer_->visible_content_rect()); | 1955 pending_layer_->visible_content_rect()); |
1996 iter; | 1956 iter; |
1997 ++iter) { | 1957 ++iter) { |
1998 if (mark_required) { | 1958 if (mark_required) { |
1999 number_of_marked_tiles++; | 1959 number_of_marked_tiles++; |
2000 iter->MarkRequiredForActivation(); | 1960 iter->set_required_for_activation(true); |
2001 } else { | 1961 } else { |
2002 number_of_unmarked_tiles++; | 1962 number_of_unmarked_tiles++; |
2003 } | 1963 } |
2004 mark_required = !mark_required; | 1964 mark_required = !mark_required; |
2005 } | 1965 } |
2006 } | 1966 } |
2007 | 1967 |
2008 // Sanity checks. | 1968 // Sanity checks. |
2009 EXPECT_EQ(91u, all_tiles.size()); | 1969 EXPECT_EQ(91u, all_tiles.size()); |
2010 EXPECT_EQ(91u, all_tiles_set.size()); | 1970 EXPECT_EQ(91u, all_tiles_set.size()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2114 scoped_refptr<FakePicturePileImpl> pending_pile = | 2074 scoped_refptr<FakePicturePileImpl> pending_pile = |
2115 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds); | 2075 FakePicturePileImpl::CreateFilledPile(layer_bounds, layer_bounds); |
2116 SetupPendingTree(pending_pile); | 2076 SetupPendingTree(pending_pile); |
2117 pending_layer_->SetBounds(layer_bounds); | 2077 pending_layer_->SetBounds(layer_bounds); |
2118 ActivateTree(); | 2078 ActivateTree(); |
2119 active_layer_->set_fixed_tile_size(tile_size); | 2079 active_layer_->set_fixed_tile_size(tile_size); |
2120 | 2080 |
2121 host_impl_.SetViewportSize(viewport_size); | 2081 host_impl_.SetViewportSize(viewport_size); |
2122 host_impl_.active_tree()->UpdateDrawProperties(); | 2082 host_impl_.active_tree()->UpdateDrawProperties(); |
2123 | 2083 |
| 2084 active_layer_->HighResTiling()->CreateAllTilesForTesting(); |
2124 std::vector<Tile*> tiles = | 2085 std::vector<Tile*> tiles = |
2125 active_layer_->HighResTiling()->AllTilesForTesting(); | 2086 active_layer_->HighResTiling()->AllTilesForTesting(); |
2126 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); | 2087 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); |
2127 | 2088 |
2128 { | 2089 { |
2129 SCOPED_TRACE("No occlusion"); | 2090 SCOPED_TRACE("No occlusion"); |
2130 gfx::Rect occluded; | 2091 gfx::Rect occluded; |
2131 impl.AppendQuadsWithOcclusion(active_layer_, occluded); | 2092 impl.AppendQuadsWithOcclusion(active_layer_, occluded); |
2132 | 2093 |
2133 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 2094 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2205 gfx::Size tile_size(100, 100); | 2166 gfx::Size tile_size(100, 100); |
2206 gfx::Size layer_bounds(1000, 1000); | 2167 gfx::Size layer_bounds(1000, 1000); |
2207 | 2168 |
2208 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 2169 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
2209 | 2170 |
2210 // Make sure some tiles are not shared. | 2171 // Make sure some tiles are not shared. |
2211 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); | 2172 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); |
2212 | 2173 |
2213 CreateHighLowResAndSetAllTilesVisible(); | 2174 CreateHighLowResAndSetAllTilesVisible(); |
2214 active_layer_->SetAllTilesReady(); | 2175 active_layer_->SetAllTilesReady(); |
2215 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2216 | 2176 |
2217 // All pending layer tiles required are not ready. | 2177 // All pending layer tiles required are not ready. |
2218 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2178 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2219 | 2179 |
2220 // Initialize all low-res tiles. | 2180 // Initialize all low-res tiles. |
2221 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling()); | 2181 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->LowResTiling()); |
2222 | 2182 |
2223 // Low-res tiles should not be enough. | 2183 // Low-res tiles should not be enough. |
2224 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2184 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2225 | 2185 |
2226 // Initialize remaining tiles. | 2186 // Initialize remaining tiles. |
2227 pending_layer_->SetAllTilesReady(); | 2187 pending_layer_->SetAllTilesReady(); |
2228 | 2188 |
2229 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | 2189 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
2230 } | 2190 } |
2231 | 2191 |
2232 TEST_F(PictureLayerImplTest, HighResReadyToDrawNotEnoughToActivate) { | |
2233 gfx::Size tile_size(100, 100); | |
2234 gfx::Size layer_bounds(1000, 1000); | |
2235 | |
2236 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | |
2237 | |
2238 // Make sure some tiles are not shared. | |
2239 pending_layer_->set_invalidation(gfx::Rect(gfx::Point(50, 50), tile_size)); | |
2240 | |
2241 CreateHighLowResAndSetAllTilesVisible(); | |
2242 active_layer_->SetAllTilesReady(); | |
2243 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2244 | |
2245 // All pending layer tiles required are not ready. | |
2246 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | |
2247 | |
2248 // Initialize all high-res tiles. | |
2249 pending_layer_->SetAllTilesReadyInTiling(pending_layer_->HighResTiling()); | |
2250 | |
2251 // High-res tiles should not be enough. | |
2252 EXPECT_FALSE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | |
2253 | |
2254 // Initialize remaining tiles. | |
2255 pending_layer_->SetAllTilesReady(); | |
2256 | |
2257 EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); | |
2258 } | |
2259 | |
2260 class NoLowResTilingsSettings : public ImplSidePaintingSettings { | 2192 class NoLowResTilingsSettings : public ImplSidePaintingSettings { |
2261 public: | 2193 public: |
2262 NoLowResTilingsSettings() { create_low_res_tiling = false; } | 2194 NoLowResTilingsSettings() { create_low_res_tiling = false; } |
2263 }; | 2195 }; |
2264 | 2196 |
2265 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { | 2197 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { |
2266 public: | 2198 public: |
2267 NoLowResPictureLayerImplTest() | 2199 NoLowResPictureLayerImplTest() |
2268 : PictureLayerImplTest(NoLowResTilingsSettings()) {} | 2200 : PictureLayerImplTest(NoLowResTilingsSettings()) {} |
2269 }; | 2201 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 7.26f, // ideal contents scale | 2253 7.26f, // ideal contents scale |
2322 2.2f, // device scale | 2254 2.2f, // device scale |
2323 3.3f, // page scale | 2255 3.3f, // page scale |
2324 1.f, // maximum animation scale | 2256 1.f, // maximum animation scale |
2325 false); | 2257 false); |
2326 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); | 2258 ASSERT_EQ(3u, pending_layer_->tilings()->num_tilings()); |
2327 EXPECT_FLOAT_EQ(7.26f, | 2259 EXPECT_FLOAT_EQ(7.26f, |
2328 pending_layer_->tilings()->tiling_at(0)->contents_scale()); | 2260 pending_layer_->tilings()->tiling_at(0)->contents_scale()); |
2329 } | 2261 } |
2330 | 2262 |
2331 TEST_F(NoLowResPictureLayerImplTest, MarkRequiredNullTiles) { | |
2332 gfx::Size tile_size(100, 100); | |
2333 gfx::Size layer_bounds(1000, 1000); | |
2334 | |
2335 scoped_refptr<FakePicturePileImpl> pending_pile = | |
2336 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
2337 // Layers with entirely empty piles can't get tilings. | |
2338 pending_pile->AddRecordingAt(0, 0); | |
2339 | |
2340 SetupPendingTree(pending_pile); | |
2341 | |
2342 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | |
2343 pending_layer_->AddTiling(1.0f); | |
2344 pending_layer_->AddTiling(2.0f); | |
2345 | |
2346 // It should be safe to call this (and MarkVisibleResourcesAsRequired) | |
2347 // on a layer with no recordings. | |
2348 host_impl_.pending_tree()->UpdateDrawProperties(); | |
2349 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2350 } | |
2351 | |
2352 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { | 2263 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfAllHighResTilesShared) { |
2353 gfx::Size layer_bounds(400, 400); | 2264 gfx::Size layer_bounds(400, 400); |
2354 gfx::Size tile_size(100, 100); | 2265 gfx::Size tile_size(100, 100); |
2355 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 2266 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
2356 | 2267 |
2357 CreateHighLowResAndSetAllTilesVisible(); | 2268 CreateHighLowResAndSetAllTilesVisible(); |
2358 | 2269 |
2359 Tile* some_active_tile = | 2270 Tile* some_active_tile = |
2360 active_layer_->HighResTiling()->AllTilesForTesting()[0]; | 2271 active_layer_->HighResTiling()->AllTilesForTesting()[0]; |
2361 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); | 2272 EXPECT_FALSE(some_active_tile->IsReadyToDraw()); |
2362 | 2273 |
2363 // All tiles shared (no invalidation), so even though the active tree's | 2274 // All tiles shared (no invalidation), so even though the active tree's |
2364 // tiles aren't ready, there is nothing required. | 2275 // tiles aren't ready, there is nothing required. |
2365 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2366 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 2276 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
2367 if (host_impl_.settings().create_low_res_tiling) { | 2277 if (host_impl_.settings().create_low_res_tiling) { |
2368 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 2278 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
2369 } | 2279 } |
2370 } | 2280 } |
2371 | 2281 |
2372 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { | 2282 TEST_F(NoLowResPictureLayerImplTest, NothingRequiredIfActiveMissingTiles) { |
2373 gfx::Size layer_bounds(400, 400); | 2283 gfx::Size layer_bounds(400, 400); |
2374 gfx::Size tile_size(100, 100); | 2284 gfx::Size tile_size(100, 100); |
2375 scoped_refptr<FakePicturePileImpl> pending_pile = | 2285 scoped_refptr<FakePicturePileImpl> pending_pile = |
(...skipping 12 matching lines...) Expand all Loading... |
2388 CreateHighLowResAndSetAllTilesVisible(); | 2298 CreateHighLowResAndSetAllTilesVisible(); |
2389 | 2299 |
2390 // Active layer has tilings, but no tiles due to missing recordings. | 2300 // Active layer has tilings, but no tiles due to missing recordings. |
2391 EXPECT_TRUE(active_layer_->CanHaveTilings()); | 2301 EXPECT_TRUE(active_layer_->CanHaveTilings()); |
2392 EXPECT_EQ(active_layer_->tilings()->num_tilings(), | 2302 EXPECT_EQ(active_layer_->tilings()->num_tilings(), |
2393 host_impl_.settings().create_low_res_tiling ? 2u : 1u); | 2303 host_impl_.settings().create_low_res_tiling ? 2u : 1u); |
2394 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 2304 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); |
2395 | 2305 |
2396 // Since the active layer has no tiles at all, the pending layer doesn't | 2306 // Since the active layer has no tiles at all, the pending layer doesn't |
2397 // need content in order to activate. | 2307 // need content in order to activate. |
2398 pending_layer_->MarkVisibleResourcesAsRequired(); | |
2399 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 2308 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
2400 if (host_impl_.settings().create_low_res_tiling) | 2309 if (host_impl_.settings().create_low_res_tiling) |
2401 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 2310 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
2402 } | 2311 } |
2403 | 2312 |
2404 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | 2313 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { |
2405 base::TimeTicks time_ticks; | 2314 base::TimeTicks time_ticks; |
2406 host_impl_.SetCurrentFrameTimeTicks(time_ticks); | 2315 host_impl_.SetCurrentFrameTimeTicks(time_ticks); |
2407 | 2316 |
2408 gfx::Size tile_size(100, 100); | 2317 gfx::Size tile_size(100, 100); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2958 layer1->SetBounds(layer_bounds); | 2867 layer1->SetBounds(layer_bounds); |
2959 layer1->SetContentBounds(layer_bounds); | 2868 layer1->SetContentBounds(layer_bounds); |
2960 layer1->SetDrawsContent(true); | 2869 layer1->SetDrawsContent(true); |
2961 layer1->SetContentsOpaque(true); | 2870 layer1->SetContentsOpaque(true); |
2962 layer1->SetPosition(occluding_layer_position); | 2871 layer1->SetPosition(occluding_layer_position); |
2963 | 2872 |
2964 host_impl_.pending_tree()->UpdateDrawProperties(); | 2873 host_impl_.pending_tree()->UpdateDrawProperties(); |
2965 | 2874 |
2966 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 2875 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
2967 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 2876 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
| 2877 tiling->CreateAllTilesForTesting(); |
2968 | 2878 |
2969 occluded_tile_count = 0; | 2879 occluded_tile_count = 0; |
2970 for (PictureLayerTiling::CoverageIterator iter( | 2880 for (PictureLayerTiling::CoverageIterator iter( |
2971 tiling, | 2881 tiling, |
2972 pending_layer_->contents_scale_x(), | 2882 pending_layer_->contents_scale_x(), |
2973 gfx::Rect(layer_bounds)); | 2883 gfx::Rect(layer_bounds)); |
2974 iter; | 2884 iter; |
2975 ++iter) { | 2885 ++iter) { |
2976 if (!*iter) | 2886 if (!*iter) |
2977 continue; | 2887 continue; |
(...skipping 16 matching lines...) Expand all Loading... |
2994 } | 2904 } |
2995 } | 2905 } |
2996 | 2906 |
2997 // Full occlusion. | 2907 // Full occlusion. |
2998 layer1->SetPosition(gfx::PointF(0, 0)); | 2908 layer1->SetPosition(gfx::PointF(0, 0)); |
2999 | 2909 |
3000 host_impl_.pending_tree()->UpdateDrawProperties(); | 2910 host_impl_.pending_tree()->UpdateDrawProperties(); |
3001 | 2911 |
3002 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { | 2912 for (size_t i = 0; i < pending_layer_->num_tilings(); ++i) { |
3003 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); | 2913 PictureLayerTiling* tiling = pending_layer_->tilings()->tiling_at(i); |
| 2914 tiling->CreateAllTilesForTesting(); |
3004 | 2915 |
3005 occluded_tile_count = 0; | 2916 occluded_tile_count = 0; |
3006 for (PictureLayerTiling::CoverageIterator iter( | 2917 for (PictureLayerTiling::CoverageIterator iter( |
3007 tiling, | 2918 tiling, |
3008 pending_layer_->contents_scale_x(), | 2919 pending_layer_->contents_scale_x(), |
3009 gfx::Rect(layer_bounds)); | 2920 gfx::Rect(layer_bounds)); |
3010 iter; | 2921 iter; |
3011 ++iter) { | 2922 ++iter) { |
3012 if (!*iter) | 2923 if (!*iter) |
3013 continue; | 2924 continue; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3063 | 2974 |
3064 host_impl_.SetViewportSize(viewport_size); | 2975 host_impl_.SetViewportSize(viewport_size); |
3065 host_impl_.pending_tree()->UpdateDrawProperties(); | 2976 host_impl_.pending_tree()->UpdateDrawProperties(); |
3066 | 2977 |
3067 int tiling_count = 0; | 2978 int tiling_count = 0; |
3068 int occluded_tile_count = 0; | 2979 int occluded_tile_count = 0; |
3069 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = | 2980 for (std::vector<PictureLayerTiling*>::iterator tiling_iterator = |
3070 tilings.begin(); | 2981 tilings.begin(); |
3071 tiling_iterator != tilings.end(); | 2982 tiling_iterator != tilings.end(); |
3072 ++tiling_iterator) { | 2983 ++tiling_iterator) { |
| 2984 (*tiling_iterator)->CreateAllTilesForTesting(); |
3073 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); | 2985 std::vector<Tile*> tiles = (*tiling_iterator)->AllTilesForTesting(); |
3074 | 2986 |
3075 occluded_tile_count = 0; | 2987 occluded_tile_count = 0; |
3076 for (size_t i = 0; i < tiles.size(); ++i) { | 2988 for (size_t i = 0; i < tiles.size(); ++i) { |
3077 if (tiles[i]->is_occluded(PENDING_TREE)) { | 2989 if (tiles[i]->is_occluded(PENDING_TREE)) { |
3078 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( | 2990 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
3079 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); | 2991 tiles[i]->content_rect(), 1.0f / tiles[i]->contents_scale()); |
3080 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); | 2992 EXPECT_GE(scaled_content_rect.x(), occluding_layer_position.x()); |
3081 occluded_tile_count++; | 2993 occluded_tile_count++; |
3082 } | 2994 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3203 // Unshared tiles are occluded on the active tree iff they lie beneath | 3115 // Unshared tiles are occluded on the active tree iff they lie beneath |
3204 // the occluding layer. | 3116 // the occluding layer. |
3205 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), | 3117 EXPECT_EQ(tile->is_occluded(ACTIVE_TREE), |
3206 scaled_content_rect.x() >= occluding_layer_position.x()); | 3118 scaled_content_rect.x() >= occluding_layer_position.x()); |
3207 } | 3119 } |
3208 } | 3120 } |
3209 } | 3121 } |
3210 } | 3122 } |
3211 } // namespace | 3123 } // namespace |
3212 } // namespace cc | 3124 } // namespace cc |
OLD | NEW |