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

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

Issue 1801853002: Transfer LayerImpl ownership to LayerTreeImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more asan. Created 4 years, 9 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
« no previous file with comments | « cc/layers/picture_layer_impl_perftest.cc ('k') | cc/layers/render_surface_impl.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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 const gfx::Size& tile_size, 222 const gfx::Size& tile_size,
223 const Region& invalidation) { 223 const Region& invalidation) {
224 host_impl_.CreatePendingTree(); 224 host_impl_.CreatePendingTree();
225 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f, 225 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f,
226 100000.f); 226 100000.f);
227 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); 227 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
228 pending_tree->SetDeviceScaleFactor( 228 pending_tree->SetDeviceScaleFactor(
229 host_impl_.active_tree()->device_scale_factor()); 229 host_impl_.active_tree()->device_scale_factor());
230 230
231 // Steal from the recycled tree if possible. 231 // Steal from the recycled tree if possible.
232 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree(); 232 LayerImpl* pending_root = pending_tree->root_layer();
233 scoped_ptr<FakePictureLayerImpl> pending_layer; 233 scoped_ptr<FakePictureLayerImpl> pending_layer;
234 DCHECK(!pending_root || pending_root->id() == root_id_); 234 DCHECK(!pending_root || pending_root->id() == root_id_);
235 if (!pending_root) { 235 if (!pending_root) {
236 pending_root = LayerImpl::Create(pending_tree, root_id_); 236 scoped_ptr<LayerImpl> new_pending_root =
237 LayerImpl::Create(pending_tree, root_id_);
237 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_); 238 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
238 if (!tile_size.IsEmpty()) 239 if (!tile_size.IsEmpty())
239 pending_layer->set_fixed_tile_size(tile_size); 240 pending_layer->set_fixed_tile_size(tile_size);
240 pending_layer->SetDrawsContent(true); 241 pending_layer->SetDrawsContent(true);
241 pending_layer->SetScrollClipLayer(pending_root->id()); 242 pending_layer->SetScrollClipLayer(new_pending_root->id());
243 pending_root = new_pending_root.get();
244 pending_tree->SetRootLayer(std::move(new_pending_root));
242 } else { 245 } else {
243 pending_layer.reset(static_cast<FakePictureLayerImpl*>( 246 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
244 pending_root->RemoveChild(pending_root->children()[0].get()) 247 pending_root->RemoveChild(pending_root->children()[0]).release()));
245 .release()));
246 if (!tile_size.IsEmpty()) 248 if (!tile_size.IsEmpty())
247 pending_layer->set_fixed_tile_size(tile_size); 249 pending_layer->set_fixed_tile_size(tile_size);
248 } 250 }
249 pending_root->SetForceRenderSurface(true); 251 pending_root->SetForceRenderSurface(true);
250 // The bounds() just mirror the raster source size. 252 // The bounds() just mirror the raster source size.
251 pending_layer->SetBounds(raster_source->GetSize()); 253 pending_layer->SetBounds(raster_source->GetSize());
252 pending_layer->SetRasterSourceOnPending(raster_source, invalidation); 254 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
253 255
254 pending_root->AddChild(std::move(pending_layer)); 256 pending_root->AddChild(std::move(pending_layer));
255 pending_tree->SetRootLayer(std::move(pending_root));
256 pending_tree->SetViewportLayersFromIds( 257 pending_tree->SetViewportLayersFromIds(
257 Layer::INVALID_ID, pending_tree->root_layer()->id(), Layer::INVALID_ID, 258 Layer::INVALID_ID, pending_tree->root_layer()->id(), Layer::INVALID_ID,
258 Layer::INVALID_ID); 259 Layer::INVALID_ID);
259 260
260 pending_layer_ = static_cast<FakePictureLayerImpl*>( 261 pending_layer_ = static_cast<FakePictureLayerImpl*>(
261 host_impl_.pending_tree()->LayerById(id_)); 262 host_impl_.pending_tree()->LayerById(id_));
262 263
263 // Add tilings/tiles for the layer. 264 // Add tilings/tiles for the layer.
264 bool update_lcd_text = false; 265 bool update_lcd_text = false;
265 RebuildPropertyTreesOnPendingTree(); 266 RebuildPropertyTreesOnPendingTree();
(...skipping 3587 matching lines...) Expand 10 before | Expand all | Expand 10 after
3853 bool tile_is_visible = 3854 bool tile_is_visible =
3854 tile->content_rect().Intersects(pending_layer_->visible_layer_rect()); 3855 tile->content_rect().Intersects(pending_layer_->visible_layer_rect());
3855 if (tile_is_visible) 3856 if (tile_is_visible)
3856 unoccluded_tile_count++; 3857 unoccluded_tile_count++;
3857 queue->Pop(); 3858 queue->Pop();
3858 } 3859 }
3859 EXPECT_EQ(unoccluded_tile_count, 25); 3860 EXPECT_EQ(unoccluded_tile_count, 25);
3860 3861
3861 // Partial occlusion. 3862 // Partial occlusion.
3862 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 3863 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3863 LayerImpl* layer1 = pending_layer_->children()[0].get(); 3864 LayerImpl* layer1 = pending_layer_->children()[0];
3864 layer1->SetBounds(layer_bounds); 3865 layer1->SetBounds(layer_bounds);
3865 layer1->SetDrawsContent(true); 3866 layer1->SetDrawsContent(true);
3866 layer1->SetContentsOpaque(true); 3867 layer1->SetContentsOpaque(true);
3867 layer1->SetPosition(occluding_layer_position); 3868 layer1->SetPosition(occluding_layer_position);
3868 3869
3869 RebuildPropertyTreesOnPendingTree(); 3870 RebuildPropertyTreesOnPendingTree();
3870 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3871 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3871 bool update_lcd_text = false; 3872 bool update_lcd_text = false;
3872 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); 3873 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3873 3874
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 if (prioritized_tiles[tile].is_occluded()) { 3949 if (prioritized_tiles[tile].is_occluded()) {
3949 EXPECT_FALSE(tile->required_for_activation()); 3950 EXPECT_FALSE(tile->required_for_activation());
3950 occluded_tile_count++; 3951 occluded_tile_count++;
3951 } 3952 }
3952 } 3953 }
3953 EXPECT_EQ(occluded_tile_count, 0); 3954 EXPECT_EQ(occluded_tile_count, 0);
3954 } 3955 }
3955 3956
3956 // Partial occlusion. 3957 // Partial occlusion.
3957 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 3958 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
3958 LayerImpl* layer1 = pending_layer_->children()[0].get(); 3959 LayerImpl* layer1 = pending_layer_->children()[0];
3959 layer1->SetBounds(layer_bounds); 3960 layer1->SetBounds(layer_bounds);
3960 layer1->SetDrawsContent(true); 3961 layer1->SetDrawsContent(true);
3961 layer1->SetContentsOpaque(true); 3962 layer1->SetContentsOpaque(true);
3962 layer1->SetPosition(occluding_layer_position); 3963 layer1->SetPosition(occluding_layer_position);
3963 3964
3964 RebuildPropertyTreesOnPendingTree(); 3965 RebuildPropertyTreesOnPendingTree();
3965 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200)); 3966 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(200));
3966 bool update_lcd_text = false; 3967 bool update_lcd_text = false;
3967 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); 3968 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text);
3968 3969
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4045 4046
4046 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = 4047 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
4047 FakeDisplayListRasterSource::CreateFilled(layer_bounds); 4048 FakeDisplayListRasterSource::CreateFilled(layer_bounds);
4048 4049
4049 host_impl_.SetViewportSize(viewport_size); 4050 host_impl_.SetViewportSize(viewport_size);
4050 4051
4051 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region()); 4052 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
4052 ASSERT_TRUE(pending_layer_->CanHaveTilings()); 4053 ASSERT_TRUE(pending_layer_->CanHaveTilings());
4053 4054
4054 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1)); 4055 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 1));
4055 LayerImpl* layer1 = pending_layer_->children()[0].get(); 4056 LayerImpl* layer1 = pending_layer_->children()[0];
4056 layer1->SetBounds(layer_bounds); 4057 layer1->SetBounds(layer_bounds);
4057 layer1->SetDrawsContent(true); 4058 layer1->SetDrawsContent(true);
4058 layer1->SetContentsOpaque(true); 4059 layer1->SetContentsOpaque(true);
4059 layer1->SetPosition(occluding_layer_position); 4060 layer1->SetPosition(occluding_layer_position);
4060 4061
4061 pending_layer_->tilings()->RemoveAllTilings(); 4062 pending_layer_->tilings()->RemoveAllTilings();
4062 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 4063 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
4063 pending_layer_->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION); 4064 pending_layer_->AddTiling(low_res_factor)->set_resolution(LOW_RESOLUTION);
4064 pending_layer_->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION); 4065 pending_layer_->AddTiling(0.3f)->set_resolution(HIGH_RESOLUTION);
4065 pending_layer_->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION); 4066 pending_layer_->AddTiling(0.7f)->set_resolution(HIGH_RESOLUTION);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = 4121 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
4121 FakeDisplayListRasterSource::CreateFilled(layer_bounds); 4122 FakeDisplayListRasterSource::CreateFilled(layer_bounds);
4122 scoped_refptr<FakeDisplayListRasterSource> active_raster_source = 4123 scoped_refptr<FakeDisplayListRasterSource> active_raster_source =
4123 FakeDisplayListRasterSource::CreateFilled(layer_bounds); 4124 FakeDisplayListRasterSource::CreateFilled(layer_bounds);
4124 4125
4125 host_impl_.SetViewportSize(viewport_size); 4126 host_impl_.SetViewportSize(viewport_size);
4126 SetupPendingTree(active_raster_source); 4127 SetupPendingTree(active_raster_source);
4127 4128
4128 // Partially occlude the active layer. 4129 // Partially occlude the active layer.
4129 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2)); 4130 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4130 LayerImpl* layer1 = pending_layer_->children()[0].get(); 4131 LayerImpl* layer1 = pending_layer_->children()[0];
4131 layer1->SetBounds(layer_bounds); 4132 layer1->SetBounds(layer_bounds);
4132 layer1->SetDrawsContent(true); 4133 layer1->SetDrawsContent(true);
4133 layer1->SetContentsOpaque(true); 4134 layer1->SetContentsOpaque(true);
4134 layer1->SetPosition(occluding_layer_position); 4135 layer1->SetPosition(occluding_layer_position);
4135 4136
4136 ActivateTree(); 4137 ActivateTree();
4137 4138
4138 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) { 4139 for (size_t i = 0; i < active_layer_->num_tilings(); ++i) {
4139 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i); 4140 PictureLayerTiling* tiling = active_layer_->tilings()->tiling_at(i);
4140 auto prioritized_tiles = 4141 auto prioritized_tiles =
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4213 4214
4214 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source = 4215 scoped_refptr<FakeDisplayListRasterSource> pending_raster_source =
4215 FakeDisplayListRasterSource::CreateFilled(layer_bounds); 4216 FakeDisplayListRasterSource::CreateFilled(layer_bounds);
4216 scoped_refptr<FakeDisplayListRasterSource> active_raster_source = 4217 scoped_refptr<FakeDisplayListRasterSource> active_raster_source =
4217 FakeDisplayListRasterSource::CreateFilled(layer_bounds); 4218 FakeDisplayListRasterSource::CreateFilled(layer_bounds);
4218 4219
4219 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region()); 4220 SetupPendingTreeWithFixedTileSize(active_raster_source, tile_size, Region());
4220 4221
4221 // Partially occlude the active layer. 4222 // Partially occlude the active layer.
4222 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2)); 4223 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 2));
4223 LayerImpl* active_occluding_layer = pending_layer_->children()[0].get(); 4224 LayerImpl* active_occluding_layer = pending_layer_->children()[0];
4224 active_occluding_layer->SetBounds(layer_bounds); 4225 active_occluding_layer->SetBounds(layer_bounds);
4225 active_occluding_layer->SetDrawsContent(true); 4226 active_occluding_layer->SetDrawsContent(true);
4226 active_occluding_layer->SetContentsOpaque(true); 4227 active_occluding_layer->SetContentsOpaque(true);
4227 active_occluding_layer->SetPosition(active_occluding_layer_position); 4228 active_occluding_layer->SetPosition(active_occluding_layer_position);
4228 4229
4229 ActivateTree(); 4230 ActivateTree();
4230 4231
4231 // Partially invalidate the pending layer. Tiles inside the invalidation rect 4232 // Partially invalidate the pending layer. Tiles inside the invalidation rect
4232 // are created. 4233 // are created.
4233 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, 4234 SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size,
4234 invalidation_rect); 4235 invalidation_rect);
4235 4236
4236 // Partially occlude the pending layer in a different way. 4237 // Partially occlude the pending layer in a different way.
4237 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3)); 4238 pending_layer_->AddChild(LayerImpl::Create(host_impl_.pending_tree(), 3));
4238 LayerImpl* pending_occluding_layer = pending_layer_->children()[0].get(); 4239 LayerImpl* pending_occluding_layer = pending_layer_->children()[0];
4239 pending_occluding_layer->SetBounds(layer_bounds); 4240 pending_occluding_layer->SetBounds(layer_bounds);
4240 pending_occluding_layer->SetDrawsContent(true); 4241 pending_occluding_layer->SetDrawsContent(true);
4241 pending_occluding_layer->SetContentsOpaque(true); 4242 pending_occluding_layer->SetContentsOpaque(true);
4242 pending_occluding_layer->SetPosition(pending_occluding_layer_position); 4243 pending_occluding_layer->SetPosition(pending_occluding_layer_position);
4243 4244
4244 EXPECT_EQ(1u, pending_layer_->num_tilings()); 4245 EXPECT_EQ(1u, pending_layer_->num_tilings());
4245 EXPECT_EQ(2u, active_layer_->num_tilings()); 4246 EXPECT_EQ(2u, active_layer_->num_tilings());
4246 4247
4247 RebuildPropertyTreesOnPendingTree(); 4248 RebuildPropertyTreesOnPendingTree();
4248 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4249 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4362 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer()); 4363 EXPECT_TRUE(pending_layer_->GetPendingOrActiveTwinLayer());
4363 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer()); 4364 EXPECT_TRUE(active_layer_->GetPendingOrActiveTwinLayer());
4364 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer()); 4365 EXPECT_EQ(pending_layer_, active_layer_->GetPendingOrActiveTwinLayer());
4365 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer()); 4366 EXPECT_EQ(active_layer_, pending_layer_->GetPendingOrActiveTwinLayer());
4366 4367
4367 ActivateTree(); 4368 ActivateTree();
4368 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer()); 4369 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4369 4370
4370 // Make an empty pending tree. 4371 // Make an empty pending tree.
4371 host_impl_.CreatePendingTree(); 4372 host_impl_.CreatePendingTree();
4372 host_impl_.pending_tree()->DetachLayerTree(); 4373 host_impl_.pending_tree()->ClearLayers();
4373 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer()); 4374 EXPECT_FALSE(active_layer_->GetPendingOrActiveTwinLayer());
4374 } 4375 }
4375 4376
4376 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) { 4377 void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid) {
4377 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); 4378 host_impl_.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
4378 4379
4379 gfx::Size tile_size(100, 100); 4380 gfx::Size tile_size(100, 100);
4380 gfx::Size layer_bounds(200, 200); 4381 gfx::Size layer_bounds(200, 200);
4381 gfx::Rect layer_rect(layer_bounds); 4382 gfx::Rect layer_rect(layer_bounds);
4382 4383
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
4922 // New low res tiling. 4923 // New low res tiling.
4923 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles()); 4924 EXPECT_TRUE(tilings->tiling_at(2)->may_contain_low_resolution_tiles());
4924 4925
4925 // This tiling will be high res now, it won't contain low res content since it 4926 // This tiling will be high res now, it won't contain low res content since it
4926 // was all destroyed. 4927 // was all destroyed.
4927 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles()); 4928 EXPECT_FALSE(tilings->tiling_at(1)->may_contain_low_resolution_tiles());
4928 } 4929 }
4929 4930
4930 } // namespace 4931 } // namespace
4931 } // namespace cc 4932 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl_perftest.cc ('k') | cc/layers/render_surface_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698