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

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

Issue 547463002: cc: Don't make tiles for mask layers that are too big for a texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hugemasks: rebase-past-mask-analysis Created 6 years, 3 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.cc ('k') | cc/resources/picture_layer_tiling.cc » ('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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 pending_layer_->set_fixed_tile_size(tile_size); 102 pending_layer_->set_fixed_tile_size(tile_size);
103 active_layer_->set_fixed_tile_size(tile_size); 103 active_layer_->set_fixed_tile_size(tile_size);
104 } 104 }
105 105
106 void SetupTrees( 106 void SetupTrees(
107 scoped_refptr<PicturePileImpl> pending_pile, 107 scoped_refptr<PicturePileImpl> pending_pile,
108 scoped_refptr<PicturePileImpl> active_pile) { 108 scoped_refptr<PicturePileImpl> active_pile) {
109 SetupPendingTree(active_pile); 109 SetupPendingTree(active_pile);
110 ActivateTree(); 110 ActivateTree();
111 SetupPendingTree(pending_pile); 111 SetupPendingTree(pending_pile);
112 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
113 host_impl_.active_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
114 } 112 }
115 113
116 void CreateHighLowResAndSetAllTilesVisible() { 114 void CreateHighLowResAndSetAllTilesVisible() {
117 // Active layer must get updated first so pending layer can share from it. 115 // Active layer must get updated first so pending layer can share from it.
118 active_layer_->CreateDefaultTilingsAndTiles(); 116 active_layer_->CreateDefaultTilingsAndTiles();
119 active_layer_->SetAllTilesVisible(); 117 active_layer_->SetAllTilesVisible();
120 pending_layer_->CreateDefaultTilingsAndTiles(); 118 pending_layer_->CreateDefaultTilingsAndTiles();
121 pending_layer_->SetAllTilesVisible(); 119 pending_layer_->SetAllTilesVisible();
122 } 120 }
123 121
124 void AddDefaultTilingsWithInvalidation(const Region& invalidation) { 122 void AddDefaultTilingsWithInvalidation(const Region& invalidation) {
125 active_layer_->AddTiling(2.3f); 123 active_layer_->AddTiling(2.3f);
126 active_layer_->AddTiling(1.0f); 124 active_layer_->AddTiling(1.0f);
127 active_layer_->AddTiling(0.5f); 125 active_layer_->AddTiling(0.5f);
128 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i) 126 for (size_t i = 0; i < active_layer_->tilings()->num_tilings(); ++i)
129 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); 127 active_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
130 pending_layer_->set_invalidation(invalidation); 128 pending_layer_->set_invalidation(invalidation);
131 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i) 129 for (size_t i = 0; i < pending_layer_->tilings()->num_tilings(); ++i)
132 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting(); 130 pending_layer_->tilings()->tiling_at(i)->CreateAllTilesForTesting();
133 } 131 }
134 132
135 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { 133 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) {
136 host_impl_.CreatePendingTree(); 134 host_impl_.CreatePendingTree();
135 host_impl_.pending_tree()->SetPageScaleFactorAndLimits(1.f, 0.25f, 100.f);
137 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); 136 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
138 // Clear recycled tree. 137 // Clear recycled tree.
139 pending_tree->DetachLayerTree(); 138 pending_tree->DetachLayerTree();
140 139
141 scoped_ptr<FakePictureLayerImpl> pending_layer = 140 scoped_ptr<FakePictureLayerImpl> pending_layer =
142 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile); 141 FakePictureLayerImpl::CreateWithPile(pending_tree, id_, pile);
143 pending_layer->SetDrawsContent(true); 142 pending_layer->SetDrawsContent(true);
144 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>()); 143 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
145 144
146 pending_layer_ = static_cast<FakePictureLayerImpl*>( 145 pending_layer_ = static_cast<FakePictureLayerImpl*>(
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 1036 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
1038 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings()); 1037 ASSERT_EQ(2u, active_layer_->tilings()->num_tilings());
1039 } 1038 }
1040 1039
1041 #define EXPECT_BOTH_EQ(expression, x) \ 1040 #define EXPECT_BOTH_EQ(expression, x) \
1042 do { \ 1041 do { \
1043 EXPECT_EQ(x, pending_layer_->expression); \ 1042 EXPECT_EQ(x, pending_layer_->expression); \
1044 EXPECT_EQ(x, active_layer_->expression); \ 1043 EXPECT_EQ(x, active_layer_->expression); \
1045 } while (false) 1044 } while (false)
1046 1045
1046 #define EXPECT_BOTH_NE(expression, x) \
1047 do { \
1048 EXPECT_NE(x, pending_layer_->expression); \
1049 EXPECT_NE(x, active_layer_->expression); \
1050 } while (false)
1051
1047 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) { 1052 TEST_F(PictureLayerImplTest, DontAddLowResDuringAnimation) {
1048 // Make sure this layer covers multiple tiles, since otherwise low 1053 // Make sure this layer covers multiple tiles, since otherwise low
1049 // res won't get created because it is too small. 1054 // res won't get created because it is too small.
1050 gfx::Size tile_size(host_impl_.settings().default_tile_size); 1055 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1051 SetupDefaultTrees(gfx::Size(tile_size.width() + 1, tile_size.height() + 1)); 1056 SetupDefaultTrees(gfx::Size(tile_size.width() + 1, tile_size.height() + 1));
1052 // Avoid max untiled layer size heuristics via fixed tile size. 1057 // Avoid max untiled layer size heuristics via fixed tile size.
1053 pending_layer_->set_fixed_tile_size(tile_size); 1058 pending_layer_->set_fixed_tile_size(tile_size);
1054 active_layer_->set_fixed_tile_size(tile_size); 1059 active_layer_->set_fixed_tile_size(tile_size);
1055 1060
1056 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor; 1061 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 maximum_animation_scale, 1153 maximum_animation_scale,
1149 animating_transform); 1154 animating_transform);
1150 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); 1155 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1151 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(), 1156 EXPECT_BOTH_EQ(LowResTiling()->contents_scale(),
1152 contents_scale * low_res_factor); 1157 contents_scale * low_res_factor);
1153 EXPECT_BOTH_EQ(num_tilings(), 2u); 1158 EXPECT_BOTH_EQ(num_tilings(), 2u);
1154 1159
1155 ResetTilingsAndRasterScales(); 1160 ResetTilingsAndRasterScales();
1156 1161
1157 // Mask layers dont create low res since they always fit on one tile. 1162 // Mask layers dont create low res since they always fit on one tile.
1158 pending_layer_->SetIsMask(true); 1163 pending_layer_->pile()->set_is_mask(true);
1159 active_layer_->SetIsMask(true); 1164 active_layer_->pile()->set_is_mask(true);
1160 SetContentsScaleOnBothLayers(contents_scale, 1165 SetContentsScaleOnBothLayers(contents_scale,
1161 device_scale, 1166 device_scale,
1162 page_scale, 1167 page_scale,
1163 maximum_animation_scale, 1168 maximum_animation_scale,
1164 animating_transform); 1169 animating_transform);
1165 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale); 1170 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), contents_scale);
1166 EXPECT_BOTH_EQ(num_tilings(), 1u); 1171 EXPECT_BOTH_EQ(num_tilings(), 1u);
1167 } 1172 }
1168 1173
1174 TEST_F(PictureLayerImplTest, HugeMasksDontGetTiles) {
1175 gfx::Size tile_size(100, 100);
1176
1177 scoped_refptr<FakePicturePileImpl> valid_pile =
1178 FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000));
1179 valid_pile->set_is_mask(true);
1180 SetupPendingTree(valid_pile);
1181
1182 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1183 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1184 EXPECT_EQ(1u, pending_layer_->num_tilings());
1185
1186 pending_layer_->HighResTiling()->CreateAllTilesForTesting();
1187 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1188 pending_layer_->HighResTiling()->AllTilesForTesting());
1189
1190 ActivateTree();
1191
1192 // Mask layers have a tiling with a single tile in it.
1193 EXPECT_EQ(1u, active_layer_->HighResTiling()->AllTilesForTesting().size());
1194 // The mask resource exists.
1195 EXPECT_NE(0u, active_layer_->ContentsResourceId());
1196
1197 // Resize larger than the max texture size.
1198 int max_texture_size = host_impl_.GetRendererCapabilities().max_texture_size;
1199 scoped_refptr<FakePicturePileImpl> huge_pile =
1200 FakePicturePileImpl::CreateFilledPile(
1201 tile_size, gfx::Size(max_texture_size + 1, 10));
1202 huge_pile->set_is_mask(true);
1203 SetupPendingTree(huge_pile);
1204
1205 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false);
1206 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale());
1207 EXPECT_EQ(1u, pending_layer_->num_tilings());
1208
1209 pending_layer_->HighResTiling()->CreateAllTilesForTesting();
1210 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
1211 pending_layer_->HighResTiling()->AllTilesForTesting());
1212
1213 ActivateTree();
1214
1215 // Mask layers have a tiling, but there should be no tiles in it.
1216 EXPECT_EQ(0u, active_layer_->HighResTiling()->AllTilesForTesting().size());
1217 // The mask resource is empty.
1218 EXPECT_EQ(0u, active_layer_->ContentsResourceId());
1219 }
1220
1169 TEST_F(PictureLayerImplTest, ReleaseResources) { 1221 TEST_F(PictureLayerImplTest, ReleaseResources) {
1170 gfx::Size tile_size(400, 400); 1222 gfx::Size tile_size(400, 400);
1171 gfx::Size layer_bounds(1300, 1900); 1223 gfx::Size layer_bounds(1300, 1900);
1172 1224
1173 scoped_refptr<FakePicturePileImpl> pending_pile = 1225 scoped_refptr<FakePicturePileImpl> pending_pile =
1174 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1226 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1175 scoped_refptr<FakePicturePileImpl> active_pile = 1227 scoped_refptr<FakePicturePileImpl> active_pile =
1176 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1228 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
1177 1229
1178 SetupTrees(pending_pile, active_pile); 1230 SetupTrees(pending_pile, active_pile);
(...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1); 3442 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.pending_tree(), 1);
3391 3443
3392 scoped_ptr<FakePictureLayerImpl> layer_with_mask = 3444 scoped_ptr<FakePictureLayerImpl> layer_with_mask =
3393 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 2); 3445 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 2);
3394 3446
3395 layer_with_mask->SetBounds(bounds); 3447 layer_with_mask->SetBounds(bounds);
3396 layer_with_mask->SetContentBounds(bounds); 3448 layer_with_mask->SetContentBounds(bounds);
3397 3449
3398 scoped_refptr<FakePicturePileImpl> pending_pile = 3450 scoped_refptr<FakePicturePileImpl> pending_pile =
3399 FakePicturePileImpl::CreateFilledPile(tile_size, bounds); 3451 FakePicturePileImpl::CreateFilledPile(tile_size, bounds);
3452 pending_pile->set_is_mask(true);
3400 scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile( 3453 scoped_ptr<FakePictureLayerImpl> mask = FakePictureLayerImpl::CreateWithPile(
3401 host_impl_.pending_tree(), 3, pending_pile); 3454 host_impl_.pending_tree(), 3, pending_pile);
3402 3455
3403 mask->SetIsMask(true);
3404 mask->SetBounds(bounds); 3456 mask->SetBounds(bounds);
3405 mask->SetContentBounds(bounds); 3457 mask->SetContentBounds(bounds);
3406 mask->SetDrawsContent(true); 3458 mask->SetDrawsContent(true);
3407 3459
3408 FakePictureLayerImpl* pending_mask_content = mask.get(); 3460 FakePictureLayerImpl* pending_mask_content = mask.get();
3409 layer_with_mask->SetMaskLayer(mask.PassAs<LayerImpl>()); 3461 layer_with_mask->SetMaskLayer(mask.PassAs<LayerImpl>());
3410 3462
3411 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask = 3463 scoped_ptr<FakePictureLayerImpl> child_of_layer_with_mask =
3412 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4); 3464 FakePictureLayerImpl::Create(host_impl_.pending_tree(), 4);
3413 3465
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
4121 ActivateTree(); 4173 ActivateTree();
4122 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer()); 4174 EXPECT_TRUE(active_layer_->GetRecycledTwinLayer());
4123 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer()); 4175 EXPECT_EQ(old_pending_layer_, active_layer_->GetRecycledTwinLayer());
4124 4176
4125 host_impl_.ResetRecycleTreeForTesting(); 4177 host_impl_.ResetRecycleTreeForTesting();
4126 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer()); 4178 EXPECT_FALSE(active_layer_->GetRecycledTwinLayer());
4127 } 4179 }
4128 4180
4129 } // namespace 4181 } // namespace
4130 } // namespace cc 4182 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698