| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/layers/append_quads_data.h" | 9 #include "cc/layers/append_quads_data.h" |
| 10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void SetupTrees( | 86 void SetupTrees( |
| 87 scoped_refptr<PicturePileImpl> pending_pile, | 87 scoped_refptr<PicturePileImpl> pending_pile, |
| 88 scoped_refptr<PicturePileImpl> active_pile) { | 88 scoped_refptr<PicturePileImpl> active_pile) { |
| 89 SetupPendingTree(active_pile); | 89 SetupPendingTree(active_pile); |
| 90 ActivateTree(); | 90 ActivateTree(); |
| 91 SetupPendingTree(pending_pile); | 91 SetupPendingTree(pending_pile); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void CreateHighLowResAndSetAllTilesVisible() { | 94 void CreateHighLowResAndSetAllTilesVisible() { |
| 95 // Active layer must get updated first so pending layer can share from it. | 95 // Active layer must get updated first so pending layer can share from it. |
| 96 active_layer_->CreateDefaultTilingsAndTiles(); | 96 active_layer_->CreateDefaultTilingsAndTiles(ACTIVE_TREE); |
| 97 active_layer_->SetAllTilesVisible(); | 97 active_layer_->SetAllTilesVisible(); |
| 98 pending_layer_->CreateDefaultTilingsAndTiles(); | 98 pending_layer_->CreateDefaultTilingsAndTiles(PENDING_TREE); |
| 99 pending_layer_->SetAllTilesVisible(); | 99 pending_layer_->SetAllTilesVisible(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { | 102 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { |
| 103 active_layer_->AddTiling(2.3f); | 103 active_layer_->AddTiling(2.3f); |
| 104 active_layer_->AddTiling(1.0f); | 104 active_layer_->AddTiling(1.0f); |
| 105 active_layer_->AddTiling(0.5f); | 105 active_layer_->AddTiling(0.5f); |
| 106 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i) | 106 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i) { |
| 107 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); | 107 active_layer_->tilings()->tiling_at(i)->CreateTilesForTesting( |
| 108 ACTIVE_TREE); |
| 109 } |
| 108 pending_layer_->set_invalidation(invalidation); | 110 pending_layer_->set_invalidation(invalidation); |
| 109 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i) | 111 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i) { |
| 110 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); | 112 pending_layer_->tilings() |
| 113 ->tiling_at(i) |
| 114 ->CreateTilesForTesting(PENDING_TREE); |
| 115 } |
| 111 } | 116 } |
| 112 | 117 |
| 113 void SetupPendingTree( | 118 void SetupPendingTree( |
| 114 scoped_refptr<PicturePileImpl> pile) { | 119 scoped_refptr<PicturePileImpl> pile) { |
| 115 host_impl_.CreatePendingTree(); | 120 host_impl_.CreatePendingTree(); |
| 116 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 121 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
| 117 // Clear recycled tree. | 122 // Clear recycled tree. |
| 118 pending_tree->DetachLayerTree(); | 123 pending_tree->DetachLayerTree(); |
| 119 | 124 |
| 120 scoped_ptr<FakePictureLayerImpl> pending_layer = | 125 scoped_ptr<FakePictureLayerImpl> pending_layer = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 &result_scale_y, | 167 &result_scale_y, |
| 163 &result_bounds); | 168 &result_bounds); |
| 164 } | 169 } |
| 165 | 170 |
| 166 void ResetTilingsAndRasterScales() { | 171 void ResetTilingsAndRasterScales() { |
| 167 pending_layer_->DidLoseOutputSurface(); | 172 pending_layer_->DidLoseOutputSurface(); |
| 168 active_layer_->DidLoseOutputSurface(); | 173 active_layer_->DidLoseOutputSurface(); |
| 169 } | 174 } |
| 170 | 175 |
| 171 void AssertAllTilesRequired(PictureLayerTiling* tiling) { | 176 void AssertAllTilesRequired(PictureLayerTiling* tiling) { |
| 172 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); | 177 std::vector<Tile*> tiles = tiling->TilesForTesting(PENDING_TREE); |
| 173 for (size_t i = 0; i < tiles.size(); ++i) | 178 for (size_t i = 0; i < tiles.size(); ++i) |
| 174 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i; | 179 EXPECT_TRUE(tiles[i]->required_for_activation()) << "i: " << i; |
| 175 EXPECT_GT(tiles.size(), 0u); | 180 EXPECT_GT(tiles.size(), 0u); |
| 176 } | 181 } |
| 177 | 182 |
| 178 void AssertNoTilesRequired(PictureLayerTiling* tiling) { | 183 void AssertNoTilesRequired(PictureLayerTiling* tiling) { |
| 179 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); | 184 std::vector<Tile*> tiles = tiling->TilesForTesting(PENDING_TREE); |
| 180 for (size_t i = 0; i < tiles.size(); ++i) | 185 for (size_t i = 0; i < tiles.size(); ++i) |
| 181 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; | 186 EXPECT_FALSE(tiles[i]->required_for_activation()) << "i: " << i; |
| 182 EXPECT_GT(tiles.size(), 0u); | 187 EXPECT_GT(tiles.size(), 0u); |
| 183 } | 188 } |
| 184 | 189 |
| 185 protected: | 190 protected: |
| 186 void TestTileGridAlignmentCommon() { | 191 void TestTileGridAlignmentCommon() { |
| 187 // Layer to span 4 raster tiles in x and in y | 192 // Layer to span 4 raster tiles in x and in y |
| 188 ImplSidePaintingSettings settings; | 193 ImplSidePaintingSettings settings; |
| 189 gfx::Size layer_size( | 194 gfx::Size layer_size( |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 // Fake set priorities. | 1215 // Fake set priorities. |
| 1211 int tile_count = 0; | 1216 int tile_count = 0; |
| 1212 for (PictureLayerTiling::CoverageIterator iter( | 1217 for (PictureLayerTiling::CoverageIterator iter( |
| 1213 tiling, | 1218 tiling, |
| 1214 pending_layer_->contents_scale_x(), | 1219 pending_layer_->contents_scale_x(), |
| 1215 gfx::Rect(pending_layer_->visible_content_rect())); | 1220 gfx::Rect(pending_layer_->visible_content_rect())); |
| 1216 iter; | 1221 iter; |
| 1217 ++iter) { | 1222 ++iter) { |
| 1218 if (!*iter) | 1223 if (!*iter) |
| 1219 continue; | 1224 continue; |
| 1220 Tile* tile = *iter; | |
| 1221 TilePriority priority; | 1225 TilePriority priority; |
| 1222 priority.resolution = HIGH_RESOLUTION; | 1226 priority.resolution = HIGH_RESOLUTION; |
| 1223 if (++tile_count % 2) { | 1227 if (++tile_count % 2) { |
| 1224 priority.time_to_visible_in_seconds = 0.f; | 1228 priority.time_to_visible_in_seconds = 0.f; |
| 1225 priority.distance_to_visible_in_pixels = 0.f; | 1229 priority.distance_to_visible_in_pixels = 0.f; |
| 1226 } else { | 1230 } else { |
| 1227 priority.time_to_visible_in_seconds = 1.f; | 1231 priority.time_to_visible_in_seconds = 1.f; |
| 1228 priority.distance_to_visible_in_pixels = 1.f; | 1232 priority.distance_to_visible_in_pixels = 1.f; |
| 1229 } | 1233 } |
| 1230 tile->SetPriority(PENDING_TREE, priority); | 1234 iter.SetPriorityForTesting(priority); |
| 1231 } | 1235 } |
| 1232 | 1236 |
| 1233 pending_layer_->MarkVisibleResourcesAsRequired(); | 1237 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1234 | 1238 |
| 1235 int num_visible = 0; | 1239 int num_visible = 0; |
| 1236 int num_offscreen = 0; | 1240 int num_offscreen = 0; |
| 1237 | 1241 |
| 1238 for (PictureLayerTiling::CoverageIterator iter( | 1242 for (PictureLayerTiling::CoverageIterator iter( |
| 1239 tiling, | 1243 tiling, |
| 1240 pending_layer_->contents_scale_x(), | 1244 pending_layer_->contents_scale_x(), |
| 1241 gfx::Rect(pending_layer_->visible_content_rect())); | 1245 gfx::Rect(pending_layer_->visible_content_rect())); |
| 1242 iter; | 1246 iter; |
| 1243 ++iter) { | 1247 ++iter) { |
| 1244 if (!*iter) | 1248 if (!*iter) |
| 1245 continue; | 1249 continue; |
| 1246 const Tile* tile = *iter; | 1250 const Tile* tile = *iter; |
| 1247 if (tile->priority(PENDING_TREE).distance_to_visible_in_pixels == 0.f) { | 1251 if (iter.priority().distance_to_visible_in_pixels == 0.f) { |
| 1248 EXPECT_TRUE(tile->required_for_activation()); | 1252 EXPECT_TRUE(tile->required_for_activation()); |
| 1249 num_visible++; | 1253 num_visible++; |
| 1250 } else { | 1254 } else { |
| 1251 EXPECT_FALSE(tile->required_for_activation()); | 1255 EXPECT_FALSE(tile->required_for_activation()); |
| 1252 num_offscreen++; | 1256 num_offscreen++; |
| 1253 } | 1257 } |
| 1254 } | 1258 } |
| 1255 | 1259 |
| 1256 EXPECT_GT(num_visible, 0); | 1260 EXPECT_GT(num_visible, 0); |
| 1257 EXPECT_GT(num_offscreen, 0); | 1261 EXPECT_GT(num_offscreen, 0); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 tile_size, layer_bounds, active_recorded_region); | 1312 tile_size, layer_bounds, active_recorded_region); |
| 1309 SetupTrees(pending_pile, active_pile); | 1313 SetupTrees(pending_pile, active_pile); |
| 1310 pending_layer_->set_fixed_tile_size(tile_size); | 1314 pending_layer_->set_fixed_tile_size(tile_size); |
| 1311 active_layer_->set_fixed_tile_size(tile_size); | 1315 active_layer_->set_fixed_tile_size(tile_size); |
| 1312 | 1316 |
| 1313 CreateHighLowResAndSetAllTilesVisible(); | 1317 CreateHighLowResAndSetAllTilesVisible(); |
| 1314 | 1318 |
| 1315 // Active layer has tilings, but no tiles due to missing recordings. | 1319 // Active layer has tilings, but no tiles due to missing recordings. |
| 1316 EXPECT_TRUE(active_layer_->CanHaveTilings()); | 1320 EXPECT_TRUE(active_layer_->CanHaveTilings()); |
| 1317 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); | 1321 EXPECT_EQ(active_layer_->tilings()->num_tilings(), 2u); |
| 1318 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 1322 EXPECT_EQ(active_layer_->HighResTiling()->TilesForTesting(ACTIVE_TREE).size(), |
| 1323 0u); |
| 1319 | 1324 |
| 1320 // Since the active layer has no tiles at all, the pending layer doesn't | 1325 // Since the active layer has no tiles at all, the pending layer doesn't |
| 1321 // need content in order to activate. This is attempting to simulate | 1326 // need content in order to activate. This is attempting to simulate |
| 1322 // scrolling past the end of recorded content on the active layer. | 1327 // scrolling past the end of recorded content on the active layer. |
| 1323 pending_layer_->MarkVisibleResourcesAsRequired(); | 1328 pending_layer_->MarkVisibleResourcesAsRequired(); |
| 1324 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 1329 AssertNoTilesRequired(pending_layer_->HighResTiling()); |
| 1325 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 1330 AssertNoTilesRequired(pending_layer_->LowResTiling()); |
| 1326 } | 1331 } |
| 1327 | 1332 |
| 1328 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { | 1333 TEST_F(PictureLayerImplTest, HighResRequiredIfActiveCantHaveTiles) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 TestContextProvider::Create(), NULL)); | 1469 TestContextProvider::Create(), NULL)); |
| 1465 | 1470 |
| 1466 // These will crash PictureLayerImpl if this is not true. | 1471 // These will crash PictureLayerImpl if this is not true. |
| 1467 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); | 1472 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); |
| 1468 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1473 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
| 1469 host_impl_.active_tree()->UpdateDrawProperties(); | 1474 host_impl_.active_tree()->UpdateDrawProperties(); |
| 1470 } | 1475 } |
| 1471 | 1476 |
| 1472 } // namespace | 1477 } // namespace |
| 1473 } // namespace cc | 1478 } // namespace cc |
| OLD | NEW |