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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); | 131 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); |
132 pending_layer_->set_invalidation(invalidation); | 132 pending_layer_->set_invalidation(invalidation); |
133 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i) | 133 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i) |
134 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); | 134 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); |
135 } | 135 } |
136 | 136 |
137 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { | 137 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { |
138 host_impl_.CreatePendingTree(); | 138 host_impl_.CreatePendingTree(); |
139 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f); | 139 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f); |
140 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 140 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
141 // Clear recycled tree. | |
142 pending_tree->DetachLayerTree(); | |
143 | 141 |
144 scoped_ptr<FakePictureLayerImpl> pending_layer = | 142 // Steal from the recycled tree. |
145 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); | 143 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); |
146 pending_layer->SetDrawsContent(true); | 144 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); |
| 145 |
| 146 scoped_ptr<FakePictureLayerImpl> pending_layer; |
| 147 if (old_pending_root) { |
| 148 pending_layer.reset( |
| 149 static_cast<FakePictureLayerImpl*>(old_pending_root.release())); |
| 150 pending_layer->SetPile(pile); |
| 151 } else { |
| 152 pending_layer = |
| 153 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); |
| 154 pending_layer->SetDrawsContent(true); |
| 155 } |
| 156 // The bounds() just mirror the pile size. |
| 157 pending_layer->SetBounds(pending_layer->pile()->tiling_size()); |
147 pending_tree->SetRootLayer(pending_layer.Pass()); | 158 pending_tree->SetRootLayer(pending_layer.Pass()); |
148 | 159 |
149 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 160 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
150 host_impl_.pending_tree()->LayerById(id_)); | 161 host_impl_.pending_tree()->LayerById(id_)); |
151 pending_layer_->DoPostCommitInitializationIfNeeded(); | 162 pending_layer_->DoPostCommitInitializationIfNeeded(); |
152 } | 163 } |
153 | 164 |
154 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, | 165 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, |
155 float ideal_contents_scale, | 166 float ideal_contents_scale, |
156 float device_scale_factor, | 167 float device_scale_factor, |
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 pending_layer_->set_invalidation(first_invalidate); | 2053 pending_layer_->set_invalidation(first_invalidate); |
2043 | 2054 |
2044 // Activate and make a pending tree with an invalidated raster tile 1,1. | 2055 // Activate and make a pending tree with an invalidated raster tile 1,1. |
2045 ActivateTree(); | 2056 ActivateTree(); |
2046 | 2057 |
2047 host_impl_.CreatePendingTree(); | 2058 host_impl_.CreatePendingTree(); |
2048 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 2059 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
2049 host_impl_.pending_tree()->root_layer()); | 2060 host_impl_.pending_tree()->root_layer()); |
2050 pending_layer_->set_invalidation(second_invalidate); | 2061 pending_layer_->set_invalidation(second_invalidate); |
2051 | 2062 |
2052 // TODO(danakj): Remove this when twins are set up better. | |
2053 // https://codereview.chromium.org/676953003/ | |
2054 pending_layer_->DoPostCommitInitializationIfNeeded(); | |
2055 | |
2056 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0); | 2063 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0); |
2057 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0); | 2064 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0); |
2058 | 2065 |
2059 pending_tiling->CreateAllTilesForTesting(); | 2066 pending_tiling->CreateAllTilesForTesting(); |
2060 | 2067 |
2061 // Tile 0,0 should be shared, but tile 1,1 should not be. | 2068 // Tile 0,0 should be shared, but tile 1,1 should not be. |
2062 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); | 2069 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0)); |
2063 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); | 2070 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0)); |
2064 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); | 2071 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1)); |
2065 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); | 2072 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1)); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes | 2313 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes |
2307 // 1.0f). Note that we should also ensure that the pending layer needs post | 2314 // 1.0f). Note that we should also ensure that the pending layer needs post |
2308 // commit initialization, since this is what would happen during commit. In | 2315 // commit initialization, since this is what would happen during commit. In |
2309 // other words we want the pending layer to sync from the active layer. | 2316 // other words we want the pending layer to sync from the active layer. |
2310 scoped_refptr<FakePicturePileImpl> pending_pile = | 2317 scoped_refptr<FakePicturePileImpl> pending_pile = |
2311 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1)); | 2318 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1, 1)); |
2312 SetupPendingTree(pending_pile); | 2319 SetupPendingTree(pending_pile); |
2313 | 2320 |
2314 // Update the draw properties: sync from active tree should happen here. | 2321 // Update the draw properties: sync from active tree should happen here. |
2315 host_impl_.pending_tree()->UpdateDrawProperties(); | 2322 host_impl_.pending_tree()->UpdateDrawProperties(); |
| 2323 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization()); |
2316 | 2324 |
2317 // Another sanity check. | 2325 // Another sanity check. |
2318 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); | 2326 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); |
2319 | 2327 |
2320 // Now we should've synced 1.5f tiling, since that's the only one that doesn't | 2328 // Now we should've synced 1.5f tiling, since that's the only one that doesn't |
2321 // violate minimum contents scale. At the same time, we should've created a | 2329 // violate minimum contents scale. At the same time, we should've created a |
2322 // new high res tiling at scale 1.0f. | 2330 // new high res tiling at scale 1.0f. |
2323 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 2331 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
2324 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); | 2332 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); |
2325 EXPECT_EQ(HIGH_RESOLUTION, | 2333 EXPECT_EQ(HIGH_RESOLUTION, |
(...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4195 gfx::Rect(layer_bounds)); | 4203 gfx::Rect(layer_bounds)); |
4196 iter; | 4204 iter; |
4197 ++iter) { | 4205 ++iter) { |
4198 if (!*iter) | 4206 if (!*iter) |
4199 continue; | 4207 continue; |
4200 const Tile* tile = *iter; | 4208 const Tile* tile = *iter; |
4201 | 4209 |
4202 // All tiles are unoccluded on the pending tree. | 4210 // All tiles are unoccluded on the pending tree. |
4203 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); | 4211 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); |
4204 | 4212 |
4205 Tile* twin_tile = | 4213 Tile* twin_tile = pending_layer_->GetPendingOrActiveTwinTiling(tiling) |
4206 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); | 4214 ->TileAt(iter.i(), iter.j()); |
4207 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( | 4215 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
4208 tile->content_rect(), 1.0f / tile->contents_scale()); | 4216 tile->content_rect(), 1.0f / tile->contents_scale()); |
4209 | 4217 |
4210 if (scaled_content_rect.Intersects(invalidation_rect)) { | 4218 if (scaled_content_rect.Intersects(invalidation_rect)) { |
4211 // Tiles inside the invalidation rect are only on the pending tree. | 4219 // Tiles inside the invalidation rect are only on the pending tree. |
4212 EXPECT_NE(tile, twin_tile); | 4220 EXPECT_NE(tile, twin_tile); |
4213 | 4221 |
4214 // Unshared tiles should be unoccluded on the active tree by default. | 4222 // Unshared tiles should be unoccluded on the active tree by default. |
4215 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE)); | 4223 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE)); |
4216 } else { | 4224 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
4230 for (PictureLayerTiling::CoverageIterator iter( | 4238 for (PictureLayerTiling::CoverageIterator iter( |
4231 tiling, | 4239 tiling, |
4232 active_layer_->contents_scale_x(), | 4240 active_layer_->contents_scale_x(), |
4233 gfx::Rect(layer_bounds)); | 4241 gfx::Rect(layer_bounds)); |
4234 iter; | 4242 iter; |
4235 ++iter) { | 4243 ++iter) { |
4236 if (!*iter) | 4244 if (!*iter) |
4237 continue; | 4245 continue; |
4238 const Tile* tile = *iter; | 4246 const Tile* tile = *iter; |
4239 | 4247 |
4240 Tile* twin_tile = | 4248 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling) |
4241 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); | 4249 ->TileAt(iter.i(), iter.j()); |
4242 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( | 4250 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( |
4243 tile->content_rect(), 1.0f / tile->contents_scale()); | 4251 tile->content_rect(), 1.0f / tile->contents_scale()); |
4244 | 4252 |
4245 // Since we've already checked the shared tiles, only consider tiles in | 4253 // Since we've already checked the shared tiles, only consider tiles in |
4246 // the invalidation rect. | 4254 // the invalidation rect. |
4247 if (scaled_content_rect.Intersects(invalidation_rect)) { | 4255 if (scaled_content_rect.Intersects(invalidation_rect)) { |
4248 // Tiles inside the invalidation rect are only on the active tree. | 4256 // Tiles inside the invalidation rect are only on the active tree. |
4249 EXPECT_NE(tile, twin_tile); | 4257 EXPECT_NE(tile, twin_tile); |
4250 | 4258 |
4251 // Unshared tiles should be unoccluded on the pending tree by default. | 4259 // Unshared tiles should be unoccluded on the pending tree by default. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4408 } | 4416 } |
4409 | 4417 |
4410 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 4418 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
4411 | 4419 |
4412 VerifyEvictionConsidersOcclusion(pending_layer_, | 4420 VerifyEvictionConsidersOcclusion(pending_layer_, |
4413 total_expected_occluded_tile_count); | 4421 total_expected_occluded_tile_count); |
4414 VerifyEvictionConsidersOcclusion(active_layer_, | 4422 VerifyEvictionConsidersOcclusion(active_layer_, |
4415 total_expected_occluded_tile_count); | 4423 total_expected_occluded_tile_count); |
4416 } | 4424 } |
4417 | 4425 |
| 4426 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) { |
| 4427 gfx::Size tile_size(102, 102); |
| 4428 gfx::Size layer_bounds(1000, 1000); |
| 4429 |
| 4430 scoped_refptr<FakePicturePileImpl> pile = |
| 4431 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 4432 SetupPendingTree(pile); |
| 4433 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer()); |
| 4434 |
| 4435 ActivateTree(); |
| 4436 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer()); |
| 4437 |
| 4438 SetupPendingTree(pile); |
| 4439 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer()); |
| 4440 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer()); |
| 4441 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer()); |
| 4442 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer()); |
| 4443 |
| 4444 ActivateTree(); |
| 4445 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer()); |
| 4446 |
| 4447 // Make an empty pending tree. |
| 4448 host_impl_.CreatePendingTree(); |
| 4449 host_impl_.pending_tree()->DetachLayerTree(); |
| 4450 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer()); |
| 4451 } |
| 4452 |
4418 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { | 4453 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { |
4419 gfx::Size tile_size(102, 102); | 4454 gfx::Size tile_size(102, 102); |
4420 gfx::Size layer_bounds(1000, 1000); | 4455 gfx::Size layer_bounds(1000, 1000); |
4421 | 4456 |
4422 scoped_refptr<FakePicturePileImpl> pile = | 4457 scoped_refptr<FakePicturePileImpl> pile = |
4423 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 4458 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
4424 SetupPendingTree(pile); | 4459 SetupPendingTree(pile); |
4425 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); | 4460 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); |
4426 | 4461 |
4427 ActivateTree(); | 4462 ActivateTree(); |
4428 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); | 4463 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); |
4429 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); | 4464 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); |
4430 | 4465 |
4431 SetupPendingTree(pile); | 4466 SetupPendingTree(pile); |
4432 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); | 4467 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); |
4433 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); | 4468 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); |
4434 | 4469 |
4435 ActivateTree(); | 4470 ActivateTree(); |
4436 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); | 4471 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); |
4437 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); | 4472 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); |
4438 | 4473 |
4439 host_impl_.ResetRecycleTreeForTesting(); | 4474 // Make an empty pending tree. |
| 4475 host_impl_.CreatePendingTree(); |
| 4476 host_impl_.pending_tree()->DetachLayerTree(); |
4440 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); | 4477 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); |
4441 } | 4478 } |
4442 | 4479 |
4443 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { | 4480 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { |
4444 base::TimeTicks time_ticks; | 4481 base::TimeTicks time_ticks; |
4445 time_ticks += base::TimeDelta::FromMilliseconds(1); | 4482 time_ticks += base::TimeDelta::FromMilliseconds(1); |
4446 host_impl_.SetCurrentBeginFrameArgs( | 4483 host_impl_.SetCurrentBeginFrameArgs( |
4447 CreateBeginFrameArgsForTesting(time_ticks)); | 4484 CreateBeginFrameArgsForTesting(time_ticks)); |
4448 | 4485 |
4449 gfx::Size tile_size(100, 100); | 4486 gfx::Size tile_size(100, 100); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4706 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4743 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4707 EXPECT_EQ(result.width(), 448); | 4744 EXPECT_EQ(result.width(), 448); |
4708 EXPECT_EQ(result.height(), 448); | 4745 EXPECT_EQ(result.height(), 448); |
4709 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4746 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4710 EXPECT_EQ(result.width(), 512); | 4747 EXPECT_EQ(result.width(), 512); |
4711 EXPECT_EQ(result.height(), 500 + 2); | 4748 EXPECT_EQ(result.height(), 500 + 2); |
4712 } | 4749 } |
4713 | 4750 |
4714 } // namespace | 4751 } // namespace |
4715 } // namespace cc | 4752 } // namespace cc |
OLD | NEW |