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

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: . 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 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 // Sanity checks. 2214 // Sanity checks.
2204 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings()); 2215 ASSERT_EQ(3u, active_layer_->tilings()->num_tilings());
2205 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f)); 2216 ASSERT_EQ(tiling, active_layer_->tilings()->TilingAtScale(0.5f));
2206 2217
2207 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes 2218 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2208 // 1.0f). Note that we should also ensure that the pending layer needs post 2219 // 1.0f). Note that we should also ensure that the pending layer needs post
2209 // commit initialization, since this is what would happen during commit. In 2220 // commit initialization, since this is what would happen during commit. In
2210 // other words we want the pending layer to sync from the active layer. 2221 // other words we want the pending layer to sync from the active layer.
2211 pending_layer_->SetBounds(gfx::Size(1, 1)); 2222 pending_layer_->SetBounds(gfx::Size(1, 1));
2212 pending_layer_->SetNeedsPostCommitInitialization(); 2223 pending_layer_->SetNeedsPostCommitInitialization();
2213 pending_layer_->set_twin_layer(nullptr);
2214 active_layer_->set_twin_layer(nullptr);
2215 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization()); 2224 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
2216 2225
2217 // Update the draw properties: sync from active tree should happen here. 2226 // Update the draw properties: sync from active tree should happen here.
2218 host_impl_.pending_tree()->UpdateDrawProperties(); 2227 host_impl_.pending_tree()->UpdateDrawProperties();
2228 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization());
2219 2229
2220 // Another sanity check. 2230 // Another sanity check.
2221 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); 2231 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale());
2222 2232
2223 // Now we should've synced 1.5f tiling, since that's the only one that doesn't 2233 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
2224 // violate minimum contents scale. At the same time, we should've created a 2234 // violate minimum contents scale. At the same time, we should've created a
2225 // new high res tiling at scale 1.0f. 2235 // new high res tiling at scale 1.0f.
2226 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2236 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2227 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); 2237 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f));
2228 EXPECT_EQ(HIGH_RESOLUTION, 2238 EXPECT_EQ(HIGH_RESOLUTION,
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after
4312 } 4322 }
4313 4323
4314 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); 4324 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4315 4325
4316 VerifyEvictionConsidersOcclusion(pending_layer_, 4326 VerifyEvictionConsidersOcclusion(pending_layer_,
4317 total_expected_occluded_tile_count); 4327 total_expected_occluded_tile_count);
4318 VerifyEvictionConsidersOcclusion(active_layer_, 4328 VerifyEvictionConsidersOcclusion(active_layer_,
4319 total_expected_occluded_tile_count); 4329 total_expected_occluded_tile_count);
4320 } 4330 }
4321 4331
4332 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4333 gfx::Size tile_size(102, 102);
4334 gfx::Size layer_bounds(1000, 1000);
4335
4336 scoped_refptr<FakePicturePileImpl> pile =
4337 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4338 SetupPendingTree(pile);
4339 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4340
4341 ActivateTree();
4342 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4343
4344 SetupPendingTree(pile);
4345 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4346 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4347 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4348 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4349
4350 ActivateTree();
4351 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4352
4353 // Make an empty pending tree.
4354 host_impl_.CreatePendingTree();
4355 host_impl_.pending_tree()->DetachLayerTree();
4356 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4357 }
4358
4322 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { 4359 TEST_F(PictureLayerImplTest, RecycledTwinLayer) {
4323 gfx::Size tile_size(102, 102); 4360 gfx::Size tile_size(102, 102);
4324 gfx::Size layer_bounds(1000, 1000); 4361 gfx::Size layer_bounds(1000, 1000);
4325 4362
4326 scoped_refptr<FakePicturePileImpl> pile = 4363 scoped_refptr<FakePicturePileImpl> pile =
4327 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4364 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4328 SetupPendingTree(pile); 4365 SetupPendingTree(pile);
4329 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4366 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4330 4367
4331 ActivateTree(); 4368 ActivateTree();
4332 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4369 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4333 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4370 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4334 4371
4335 SetupPendingTree(pile); 4372 SetupPendingTree(pile);
4336 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4373 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4337 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4374 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4338 4375
4339 ActivateTree(); 4376 ActivateTree();
4340 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4377 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4341 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4378 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4342 4379
4343 host_impl_.ResetRecycleTreeForTesting(); 4380 // Make an empty pending tree.
4381 host_impl_.CreatePendingTree();
4382 host_impl_.pending_tree()->DetachLayerTree();
vmpstr 2014/10/24 16:47:05 I'm not sure this tests the same thing since we no
danakj 2014/10/24 16:53:30 I think the only way the layer can be deleted from
4344 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4383 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4345 } 4384 }
4346 4385
4347 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { 4386 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4348 base::TimeTicks time_ticks; 4387 base::TimeTicks time_ticks;
4349 time_ticks += base::TimeDelta::FromMilliseconds(1); 4388 time_ticks += base::TimeDelta::FromMilliseconds(1);
4350 host_impl_.SetCurrentBeginFrameArgs( 4389 host_impl_.SetCurrentBeginFrameArgs(
4351 CreateBeginFrameArgsForTesting(time_ticks)); 4390 CreateBeginFrameArgsForTesting(time_ticks));
4352 4391
4353 gfx::Size tile_size(100, 100); 4392 gfx::Size tile_size(100, 100);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
4610 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4649 result = layer->CalculateTileSize(gfx::Size(447, 400));
4611 EXPECT_EQ(result.width(), 448); 4650 EXPECT_EQ(result.width(), 448);
4612 EXPECT_EQ(result.height(), 448); 4651 EXPECT_EQ(result.height(), 448);
4613 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4652 result = layer->CalculateTileSize(gfx::Size(500, 499));
4614 EXPECT_EQ(result.width(), 512); 4653 EXPECT_EQ(result.width(), 512);
4615 EXPECT_EQ(result.height(), 500 + 2); 4654 EXPECT_EQ(result.height(), 500 + 2);
4616 } 4655 }
4617 4656
4618 } // namespace 4657 } // namespace
4619 } // namespace cc 4658 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698