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

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

Issue 676953003: cc: Always keep the PictureLayerImpl::twin_layer_ pointer valid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: twins: add-test-case Created 6 years, 2 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
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 <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
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 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 2218
2208 pending_layer_->tilings()->RemoveAllTilings(); 2219 pending_layer_->tilings()->RemoveAllTilings();
2209 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2220 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
2210 2221
2211 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes 2222 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2212 // 1.0f). Note that we should also ensure that the pending layer needs post 2223 // 1.0f). Note that we should also ensure that the pending layer needs post
2213 // commit initialization, since this is what would happen during commit. In 2224 // commit initialization, since this is what would happen during commit. In
2214 // other words we want the pending layer to sync from the active layer. 2225 // other words we want the pending layer to sync from the active layer.
2215 pending_layer_->SetBounds(gfx::Size(1, 1)); 2226 pending_layer_->SetBounds(gfx::Size(1, 1));
2216 pending_layer_->SetNeedsPostCommitInitialization(); 2227 pending_layer_->SetNeedsPostCommitInitialization();
2217 pending_layer_->set_twin_layer(nullptr);
2218 active_layer_->set_twin_layer(nullptr);
2219 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization()); 2228 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
2220 2229
2221 // Update the draw properties: sync from active tree should happen here. 2230 // Update the draw properties: sync from active tree should happen here.
2222 host_impl_.pending_tree()->UpdateDrawProperties(); 2231 host_impl_.pending_tree()->UpdateDrawProperties();
2232 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization());
2223 2233
2224 // Another sanity check. 2234 // Another sanity check.
2225 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); 2235 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale());
2226 2236
2227 // Now we should've synced 1.5f tiling, since that's the only one that doesn't 2237 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
2228 // violate minimum contents scale. At the same time, we should've created a 2238 // violate minimum contents scale. At the same time, we should've created a
2229 // new high res tiling at scale 1.0f. 2239 // new high res tiling at scale 1.0f.
2230 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2240 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2231 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); 2241 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f));
2232 EXPECT_EQ(HIGH_RESOLUTION, 2242 EXPECT_EQ(HIGH_RESOLUTION,
(...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 gfx::Rect(layer_bounds)); 4112 gfx::Rect(layer_bounds));
4103 iter; 4113 iter;
4104 ++iter) { 4114 ++iter) {
4105 if (!*iter) 4115 if (!*iter)
4106 continue; 4116 continue;
4107 const Tile* tile = *iter; 4117 const Tile* tile = *iter;
4108 4118
4109 // All tiles are unoccluded on the pending tree. 4119 // All tiles are unoccluded on the pending tree.
4110 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); 4120 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
4111 4121
4112 Tile* twin_tile = 4122 Tile* twin_tile = pending_layer_->GetPendingOrActiveTwinTiling(tiling)
4113 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); 4123 ->TileAt(iter.i(), iter.j());
4114 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4124 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4115 tile->content_rect(), 1.0f / tile->contents_scale()); 4125 tile->content_rect(), 1.0f / tile->contents_scale());
4116 4126
4117 if (scaled_content_rect.Intersects(invalidation_rect)) { 4127 if (scaled_content_rect.Intersects(invalidation_rect)) {
4118 // Tiles inside the invalidation rect are only on the pending tree. 4128 // Tiles inside the invalidation rect are only on the pending tree.
4119 EXPECT_NE(tile, twin_tile); 4129 EXPECT_NE(tile, twin_tile);
4120 4130
4121 // Unshared tiles should be unoccluded on the active tree by default. 4131 // Unshared tiles should be unoccluded on the active tree by default.
4122 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE)); 4132 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE));
4123 } else { 4133 } else {
(...skipping 13 matching lines...) Expand all
4137 for (PictureLayerTiling::CoverageIterator iter( 4147 for (PictureLayerTiling::CoverageIterator iter(
4138 tiling, 4148 tiling,
4139 active_layer_->contents_scale_x(), 4149 active_layer_->contents_scale_x(),
4140 gfx::Rect(layer_bounds)); 4150 gfx::Rect(layer_bounds));
4141 iter; 4151 iter;
4142 ++iter) { 4152 ++iter) {
4143 if (!*iter) 4153 if (!*iter)
4144 continue; 4154 continue;
4145 const Tile* tile = *iter; 4155 const Tile* tile = *iter;
4146 4156
4147 Tile* twin_tile = 4157 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling)
4148 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j()); 4158 ->TileAt(iter.i(), iter.j());
4149 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4159 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4150 tile->content_rect(), 1.0f / tile->contents_scale()); 4160 tile->content_rect(), 1.0f / tile->contents_scale());
4151 4161
4152 // Since we've already checked the shared tiles, only consider tiles in 4162 // Since we've already checked the shared tiles, only consider tiles in
4153 // the invalidation rect. 4163 // the invalidation rect.
4154 if (scaled_content_rect.Intersects(invalidation_rect)) { 4164 if (scaled_content_rect.Intersects(invalidation_rect)) {
4155 // Tiles inside the invalidation rect are only on the active tree. 4165 // Tiles inside the invalidation rect are only on the active tree.
4156 EXPECT_NE(tile, twin_tile); 4166 EXPECT_NE(tile, twin_tile);
4157 4167
4158 // Unshared tiles should be unoccluded on the pending tree by default. 4168 // Unshared tiles should be unoccluded on the pending tree by default.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
4315 } 4325 }
4316 4326
4317 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); 4327 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4318 4328
4319 VerifyEvictionConsidersOcclusion(pending_layer_, 4329 VerifyEvictionConsidersOcclusion(pending_layer_,
4320 total_expected_occluded_tile_count); 4330 total_expected_occluded_tile_count);
4321 VerifyEvictionConsidersOcclusion(active_layer_, 4331 VerifyEvictionConsidersOcclusion(active_layer_,
4322 total_expected_occluded_tile_count); 4332 total_expected_occluded_tile_count);
4323 } 4333 }
4324 4334
4335 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4336 gfx::Size tile_size(102, 102);
4337 gfx::Size layer_bounds(1000, 1000);
4338
4339 scoped_refptr<FakePicturePileImpl> pile =
4340 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4341 SetupPendingTree(pile);
4342 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4343
4344 ActivateTree();
4345 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4346
4347 SetupPendingTree(pile);
4348 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4349 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4350 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4351 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4352
4353 ActivateTree();
4354 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4355
4356 // Make an empty pending tree.
4357 host_impl_.CreatePendingTree();
4358 host_impl_.pending_tree()->DetachLayerTree();
4359 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4360 }
4361
4325 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { 4362 TEST_F(PictureLayerImplTest, RecycledTwinLayer) {
4326 gfx::Size tile_size(102, 102); 4363 gfx::Size tile_size(102, 102);
4327 gfx::Size layer_bounds(1000, 1000); 4364 gfx::Size layer_bounds(1000, 1000);
4328 4365
4329 scoped_refptr<FakePicturePileImpl> pile = 4366 scoped_refptr<FakePicturePileImpl> pile =
4330 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4367 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4331 SetupPendingTree(pile); 4368 SetupPendingTree(pile);
4332 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4369 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4333 4370
4334 ActivateTree(); 4371 ActivateTree();
4335 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4372 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4336 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4373 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4337 4374
4338 SetupPendingTree(pile); 4375 SetupPendingTree(pile);
4339 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4376 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4340 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4377 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4341 4378
4342 ActivateTree(); 4379 ActivateTree();
4343 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4380 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4344 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4381 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4345 4382
4346 host_impl_.ResetRecycleTreeForTesting(); 4383 // Make an empty pending tree.
4384 host_impl_.CreatePendingTree();
4385 host_impl_.pending_tree()->DetachLayerTree();
4347 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4386 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4348 } 4387 }
4349 4388
4350 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { 4389 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4351 base::TimeTicks time_ticks; 4390 base::TimeTicks time_ticks;
4352 time_ticks += base::TimeDelta::FromMilliseconds(1); 4391 time_ticks += base::TimeDelta::FromMilliseconds(1);
4353 host_impl_.SetCurrentBeginFrameArgs( 4392 host_impl_.SetCurrentBeginFrameArgs(
4354 CreateBeginFrameArgsForTesting(time_ticks)); 4393 CreateBeginFrameArgsForTesting(time_ticks));
4355 4394
4356 gfx::Size tile_size(100, 100); 4395 gfx::Size tile_size(100, 100);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
4613 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4652 result = layer->CalculateTileSize(gfx::Size(447, 400));
4614 EXPECT_EQ(result.width(), 448); 4653 EXPECT_EQ(result.width(), 448);
4615 EXPECT_EQ(result.height(), 448); 4654 EXPECT_EQ(result.height(), 448);
4616 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4655 result = layer->CalculateTileSize(gfx::Size(500, 499));
4617 EXPECT_EQ(result.width(), 512); 4656 EXPECT_EQ(result.width(), 512);
4618 EXPECT_EQ(result.height(), 500 + 2); 4657 EXPECT_EQ(result.height(), 500 + 2);
4619 } 4658 }
4620 4659
4621 } // namespace 4660 } // namespace
4622 } // namespace cc 4661 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698