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

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

Issue 680793002: Revert two cc patches due to crashes on canary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert both patches Created 6 years, 1 month 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
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
141 143
142 // Steal from the recycled tree. 144 scoped_ptr<FakePictureLayerImpl> pending_layer =
143 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); 145 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
144 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); 146 pending_layer->SetDrawsContent(true);
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());
158 pending_tree->SetRootLayer(pending_layer.Pass()); 147 pending_tree->SetRootLayer(pending_layer.Pass());
159 148
160 pending_layer_ = static_cast<FakePictureLayerImpl*>( 149 pending_layer_ = static_cast<FakePictureLayerImpl*>(
161 host_impl_.pending_tree()->LayerById(id_)); 150 host_impl_.pending_tree()->LayerById(id_));
162 pending_layer_->DoPostCommitInitializationIfNeeded(); 151 pending_layer_->DoPostCommitInitializationIfNeeded();
163 } 152 }
164 153
165 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, 154 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer,
166 float ideal_contents_scale, 155 float ideal_contents_scale,
167 float device_scale_factor, 156 float device_scale_factor,
(...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 host_impl_.ActivateSyncTree(); 2019 host_impl_.ActivateSyncTree();
2031 2020
2032 active_layer_ = static_cast<FakePictureLayerImpl*>( 2021 active_layer_ = static_cast<FakePictureLayerImpl*>(
2033 host_impl_.active_tree()->LayerById(id_)); 2022 host_impl_.active_tree()->LayerById(id_));
2034 2023
2035 EXPECT_EQ(0u, active_layer_->num_tilings()); 2024 EXPECT_EQ(0u, active_layer_->num_tilings());
2036 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale()); 2025 EXPECT_EQ(raster_page_scale, active_layer_->raster_page_scale());
2037 EXPECT_FALSE(active_layer_->needs_post_commit_initialization()); 2026 EXPECT_FALSE(active_layer_->needs_post_commit_initialization());
2038 } 2027 }
2039 2028
2040 TEST_F(PictureLayerImplTest, ShareTilesOnNextFrame) {
2041 SetupDefaultTrees(gfx::Size(1500, 1500));
2042
2043 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f);
2044 gfx::Rect first_invalidate = tiling->TilingDataForTesting().TileBounds(0, 0);
2045 first_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2046 tiling->TilingDataForTesting().border_texels());
2047 gfx::Rect second_invalidate = tiling->TilingDataForTesting().TileBounds(1, 1);
2048 second_invalidate.Inset(tiling->TilingDataForTesting().border_texels(),
2049 tiling->TilingDataForTesting().border_texels());
2050
2051 // Make a pending tree with an invalidated raster tile 0,0.
2052 tiling->CreateAllTilesForTesting();
2053 pending_layer_->set_invalidation(first_invalidate);
2054
2055 // Activate and make a pending tree with an invalidated raster tile 1,1.
2056 ActivateTree();
2057
2058 host_impl_.CreatePendingTree();
2059 pending_layer_ = static_cast<FakePictureLayerImpl*>(
2060 host_impl_.pending_tree()->root_layer());
2061 pending_layer_->set_invalidation(second_invalidate);
2062
2063 PictureLayerTiling* pending_tiling = pending_layer_->tilings()->tiling_at(0);
2064 PictureLayerTiling* active_tiling = active_layer_->tilings()->tiling_at(0);
2065
2066 pending_tiling->CreateAllTilesForTesting();
2067
2068 // Tile 0,0 should be shared, but tile 1,1 should not be.
2069 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2070 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2071 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2072 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2073 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared());
2074 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared());
2075 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared());
2076 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared());
2077
2078 // Drop the tiles on the active tree and recreate them. The same tiles
2079 // should be shared or not.
2080 active_tiling->ComputeTilePriorityRects(
2081 ACTIVE_TREE, gfx::Rect(), 1.f, 1.0, Occlusion());
2082 EXPECT_TRUE(active_tiling->AllTilesForTesting().empty());
2083 active_tiling->CreateAllTilesForTesting();
2084
2085 // Tile 0,0 should be shared, but tile 1,1 should not be.
2086 EXPECT_EQ(active_tiling->TileAt(0, 0), pending_tiling->TileAt(0, 0));
2087 EXPECT_EQ(active_tiling->TileAt(1, 0), pending_tiling->TileAt(1, 0));
2088 EXPECT_EQ(active_tiling->TileAt(0, 1), pending_tiling->TileAt(0, 1));
2089 EXPECT_NE(active_tiling->TileAt(1, 1), pending_tiling->TileAt(1, 1));
2090 EXPECT_TRUE(pending_tiling->TileAt(0, 0)->is_shared());
2091 EXPECT_TRUE(pending_tiling->TileAt(1, 0)->is_shared());
2092 EXPECT_TRUE(pending_tiling->TileAt(0, 1)->is_shared());
2093 EXPECT_FALSE(pending_tiling->TileAt(1, 1)->is_shared());
2094 }
2095
2096 TEST_F(PictureLayerImplTest, ShareTilesOnSync) { 2029 TEST_F(PictureLayerImplTest, ShareTilesOnSync) {
2097 SetupDefaultTrees(gfx::Size(1500, 1500)); 2030 SetupDefaultTrees(gfx::Size(1500, 1500));
2098 AddDefaultTilingsWithInvalidation(gfx::Rect()); 2031 AddDefaultTilingsWithInvalidation(gfx::Rect());
2099 2032
2100 host_impl_.ActivateSyncTree(); 2033 host_impl_.ActivateSyncTree();
2101 host_impl_.CreatePendingTree(); 2034 host_impl_.CreatePendingTree();
2102 active_layer_ = static_cast<FakePictureLayerImpl*>( 2035 active_layer_ = static_cast<FakePictureLayerImpl*>(
2103 host_impl_.active_tree()->LayerById(id_)); 2036 host_impl_.active_tree()->LayerById(id_));
2104 2037
2105 // Force the active tree to sync to the pending tree "post-commit". 2038 // Force the active tree to sync to the pending tree "post-commit".
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 2241
2309 pending_layer_->tilings()->RemoveAllTilings(); 2242 pending_layer_->tilings()->RemoveAllTilings();
2310 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings()); 2243 ASSERT_EQ(0u, pending_layer_->tilings()->num_tilings());
2311 2244
2312 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes 2245 // Now, set the bounds to be 1x1 (so that minimum contents scale becomes
2313 // 1.0f). Note that we should also ensure that the pending layer needs post 2246 // 1.0f). Note that we should also ensure that the pending layer needs post
2314 // commit initialization, since this is what would happen during commit. In 2247 // commit initialization, since this is what would happen during commit. In
2315 // other words we want the pending layer to sync from the active layer. 2248 // other words we want the pending layer to sync from the active layer.
2316 pending_layer_->SetBounds(gfx::Size(1, 1)); 2249 pending_layer_->SetBounds(gfx::Size(1, 1));
2317 pending_layer_->SetNeedsPostCommitInitialization(); 2250 pending_layer_->SetNeedsPostCommitInitialization();
2251 pending_layer_->set_twin_layer(nullptr);
2252 active_layer_->set_twin_layer(nullptr);
2318 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization()); 2253 EXPECT_TRUE(pending_layer_->needs_post_commit_initialization());
2319 2254
2320 // Update the draw properties: sync from active tree should happen here. 2255 // Update the draw properties: sync from active tree should happen here.
2321 host_impl_.pending_tree()->UpdateDrawProperties(); 2256 host_impl_.pending_tree()->UpdateDrawProperties();
2322 EXPECT_FALSE(pending_layer_->needs_post_commit_initialization());
2323 2257
2324 // Another sanity check. 2258 // Another sanity check.
2325 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale()); 2259 ASSERT_EQ(1.f, pending_layer_->MinimumContentsScale());
2326 2260
2327 // Now we should've synced 1.5f tiling, since that's the only one that doesn't 2261 // Now we should've synced 1.5f tiling, since that's the only one that doesn't
2328 // violate minimum contents scale. At the same time, we should've created a 2262 // violate minimum contents scale. At the same time, we should've created a
2329 // new high res tiling at scale 1.0f. 2263 // new high res tiling at scale 1.0f.
2330 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings()); 2264 EXPECT_EQ(2u, pending_layer_->tilings()->num_tilings());
2331 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f)); 2265 ASSERT_TRUE(pending_layer_->tilings()->TilingAtScale(1.0f));
2332 EXPECT_EQ(HIGH_RESOLUTION, 2266 EXPECT_EQ(HIGH_RESOLUTION,
(...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after
4202 gfx::Rect(layer_bounds)); 4136 gfx::Rect(layer_bounds));
4203 iter; 4137 iter;
4204 ++iter) { 4138 ++iter) {
4205 if (!*iter) 4139 if (!*iter)
4206 continue; 4140 continue;
4207 const Tile* tile = *iter; 4141 const Tile* tile = *iter;
4208 4142
4209 // All tiles are unoccluded on the pending tree. 4143 // All tiles are unoccluded on the pending tree.
4210 EXPECT_FALSE(tile->is_occluded(PENDING_TREE)); 4144 EXPECT_FALSE(tile->is_occluded(PENDING_TREE));
4211 4145
4212 Tile* twin_tile = pending_layer_->GetPendingOrActiveTwinTiling(tiling) 4146 Tile* twin_tile =
4213 ->TileAt(iter.i(), iter.j()); 4147 pending_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
4214 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4148 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4215 tile->content_rect(), 1.0f / tile->contents_scale()); 4149 tile->content_rect(), 1.0f / tile->contents_scale());
4216 4150
4217 if (scaled_content_rect.Intersects(invalidation_rect)) { 4151 if (scaled_content_rect.Intersects(invalidation_rect)) {
4218 // Tiles inside the invalidation rect are only on the pending tree. 4152 // Tiles inside the invalidation rect are only on the pending tree.
4219 EXPECT_NE(tile, twin_tile); 4153 EXPECT_NE(tile, twin_tile);
4220 4154
4221 // Unshared tiles should be unoccluded on the active tree by default. 4155 // Unshared tiles should be unoccluded on the active tree by default.
4222 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE)); 4156 EXPECT_FALSE(tile->is_occluded(ACTIVE_TREE));
4223 } else { 4157 } else {
(...skipping 13 matching lines...) Expand all
4237 for (PictureLayerTiling::CoverageIterator iter( 4171 for (PictureLayerTiling::CoverageIterator iter(
4238 tiling, 4172 tiling,
4239 active_layer_->contents_scale_x(), 4173 active_layer_->contents_scale_x(),
4240 gfx::Rect(layer_bounds)); 4174 gfx::Rect(layer_bounds));
4241 iter; 4175 iter;
4242 ++iter) { 4176 ++iter) {
4243 if (!*iter) 4177 if (!*iter)
4244 continue; 4178 continue;
4245 const Tile* tile = *iter; 4179 const Tile* tile = *iter;
4246 4180
4247 Tile* twin_tile = active_layer_->GetPendingOrActiveTwinTiling(tiling) 4181 Tile* twin_tile =
4248 ->TileAt(iter.i(), iter.j()); 4182 active_layer_->GetTwinTiling(tiling)->TileAt(iter.i(), iter.j());
4249 gfx::Rect scaled_content_rect = ScaleToEnclosingRect( 4183 gfx::Rect scaled_content_rect = ScaleToEnclosingRect(
4250 tile->content_rect(), 1.0f / tile->contents_scale()); 4184 tile->content_rect(), 1.0f / tile->contents_scale());
4251 4185
4252 // Since we've already checked the shared tiles, only consider tiles in 4186 // Since we've already checked the shared tiles, only consider tiles in
4253 // the invalidation rect. 4187 // the invalidation rect.
4254 if (scaled_content_rect.Intersects(invalidation_rect)) { 4188 if (scaled_content_rect.Intersects(invalidation_rect)) {
4255 // Tiles inside the invalidation rect are only on the active tree. 4189 // Tiles inside the invalidation rect are only on the active tree.
4256 EXPECT_NE(tile, twin_tile); 4190 EXPECT_NE(tile, twin_tile);
4257 4191
4258 // Unshared tiles should be unoccluded on the pending tree by default. 4192 // Unshared tiles should be unoccluded on the pending tree by default.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 } 4349 }
4416 4350
4417 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); 4351 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
4418 4352
4419 VerifyEvictionConsidersOcclusion(pending_layer_, 4353 VerifyEvictionConsidersOcclusion(pending_layer_,
4420 total_expected_occluded_tile_count); 4354 total_expected_occluded_tile_count);
4421 VerifyEvictionConsidersOcclusion(active_layer_, 4355 VerifyEvictionConsidersOcclusion(active_layer_,
4422 total_expected_occluded_tile_count); 4356 total_expected_occluded_tile_count);
4423 } 4357 }
4424 4358
4425 TEST_F(PictureLayerImplTest, PendingOrActiveTwinLayer) {
4426 gfx::Size tile_size(102, 102);
4427 gfx::Size layer_bounds(1000, 1000);
4428
4429 scoped_refptr<FakePicturePileImpl> pile =
4430 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4431 SetupPendingTree(pile);
4432 EXPECT_FALSE(pending_layer_->GetPendingOrActiveTwinLayer());
4433
4434 ActivateTree();
4435 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4436
4437 SetupPendingTree(pile);
4438 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4439 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4440 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4441 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4442
4443 ActivateTree();
4444 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4445
4446 // Make an empty pending tree.
4447 host_impl_.CreatePendingTree();
4448 host_impl_.pending_tree()->DetachLayerTree();
4449 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4450 }
4451
4452 TEST_F(PictureLayerImplTest, RecycledTwinLayer) { 4359 TEST_F(PictureLayerImplTest, RecycledTwinLayer) {
4453 gfx::Size tile_size(102, 102); 4360 gfx::Size tile_size(102, 102);
4454 gfx::Size layer_bounds(1000, 1000); 4361 gfx::Size layer_bounds(1000, 1000);
4455 4362
4456 scoped_refptr<FakePicturePileImpl> pile = 4363 scoped_refptr<FakePicturePileImpl> pile =
4457 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 4364 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
4458 SetupPendingTree(pile); 4365 SetupPendingTree(pile);
4459 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4366 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4460 4367
4461 ActivateTree(); 4368 ActivateTree();
4462 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4369 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4463 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4370 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4464 4371
4465 SetupPendingTree(pile); 4372 SetupPendingTree(pile);
4466 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer()); 4373 EXPECT_FALSE(pending_layer_->GetRecycledTwinLayer());
4467 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4374 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4468 4375
4469 ActivateTree(); 4376 ActivateTree();
4470 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4377 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4471 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4378 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4472 4379
4473 // Make an empty pending tree. 4380 host_impl_.ResetRecycleTreeForTesting();
4474 host_impl_.CreatePendingTree();
4475 host_impl_.pending_tree()->DetachLayerTree();
4476 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4381 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4477 } 4382 }
4478 4383
4479 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { 4384 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4480 base::TimeTicks time_ticks; 4385 base::TimeTicks time_ticks;
4481 time_ticks += base::TimeDelta::FromMilliseconds(1); 4386 time_ticks += base::TimeDelta::FromMilliseconds(1);
4482 host_impl_.SetCurrentBeginFrameArgs( 4387 host_impl_.SetCurrentBeginFrameArgs(
4483 CreateBeginFrameArgsForTesting(time_ticks)); 4388 CreateBeginFrameArgsForTesting(time_ticks));
4484 4389
4485 gfx::Size tile_size(100, 100); 4390 gfx::Size tile_size(100, 100);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
4742 result = layer->CalculateTileSize(gfx::Size(447, 400)); 4647 result = layer->CalculateTileSize(gfx::Size(447, 400));
4743 EXPECT_EQ(result.width(), 448); 4648 EXPECT_EQ(result.width(), 448);
4744 EXPECT_EQ(result.height(), 448); 4649 EXPECT_EQ(result.height(), 448);
4745 result = layer->CalculateTileSize(gfx::Size(500, 499)); 4650 result = layer->CalculateTileSize(gfx::Size(500, 499));
4746 EXPECT_EQ(result.width(), 512); 4651 EXPECT_EQ(result.width(), 512);
4747 EXPECT_EQ(result.height(), 500 + 2); 4652 EXPECT_EQ(result.height(), 500 + 2);
4748 } 4653 }
4749 4654
4750 } // namespace 4655 } // namespace
4751 } // namespace cc 4656 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698