OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 // If a layer has a non-invertible transform, then the starting rect | 1080 // If a layer has a non-invertible transform, then the starting rect |
1081 // for the layer would be empty. | 1081 // for the layer would be empty. |
1082 gfx::Rect in(40, 40, 0, 0); | 1082 gfx::Rect in(40, 40, 0, 0); |
1083 gfx::Rect bounds(0, 0, 10, 10); | 1083 gfx::Rect bounds(0, 0, 10, 10); |
1084 int64 target_area = 400 * 400; | 1084 int64 target_area = 400 * 400; |
1085 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1085 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
1086 in, target_area, bounds, NULL); | 1086 in, target_area, bounds, NULL); |
1087 EXPECT_TRUE(out.IsEmpty()); | 1087 EXPECT_TRUE(out.IsEmpty()); |
1088 } | 1088 } |
1089 | 1089 |
1090 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { | |
vmpstr
2015/01/06 19:53:50
This is moved to the tile manager unittests with t
| |
1091 FakePictureLayerTilingClient client; | |
1092 | |
1093 gfx::Rect viewport(50, 50, 100, 100); | |
1094 gfx::Size layer_bounds(800, 800); | |
1095 | |
1096 gfx::Rect soon_rect = viewport; | |
1097 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | |
1098 | |
1099 client.SetTileSize(gfx::Size(30, 30)); | |
1100 client.set_tree(ACTIVE_TREE); | |
1101 LayerTreeSettings settings; | |
1102 settings.max_tiles_for_interest_area = 10000; | |
1103 | |
1104 scoped_refptr<FakePicturePileImpl> pile = | |
1105 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
1106 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1107 TestablePictureLayerTiling::Create(1.0f, pile, &client, settings); | |
1108 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); | |
1109 tiling->UpdateAllTilePrioritiesForTesting(); | |
1110 | |
1111 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | |
1112 EXPECT_FALSE(empty_iterator); | |
1113 | |
1114 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | |
1115 | |
1116 // Sanity check. | |
1117 EXPECT_EQ(841u, all_tiles.size()); | |
1118 | |
1119 // The explanation of each iteration is as follows: | |
1120 // 1. First iteration tests that we can get all of the tiles correctly. | |
1121 // 2. Second iteration ensures that we can get all of the tiles again (first | |
1122 // iteration didn't change any tiles), as well set all tiles to be ready to | |
1123 // draw. | |
1124 // 3. Third iteration ensures that no tiles are returned, since they were all | |
1125 // marked as ready to draw. | |
1126 for (int i = 0; i < 3; ++i) { | |
1127 PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); | |
1128 | |
1129 // There are 3 bins in TilePriority. | |
1130 bool have_tiles[3] = {}; | |
1131 | |
1132 // On the third iteration, we should get no tiles since everything was | |
1133 // marked as ready to draw. | |
1134 if (i == 2) { | |
1135 EXPECT_FALSE(it); | |
1136 continue; | |
1137 } | |
1138 | |
1139 EXPECT_TRUE(it); | |
1140 std::set<Tile*> unique_tiles; | |
1141 unique_tiles.insert(*it); | |
1142 Tile* last_tile = *it; | |
1143 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true; | |
1144 | |
1145 // On the second iteration, mark everything as ready to draw (solid color). | |
1146 if (i == 1) { | |
1147 TileDrawInfo& draw_info = last_tile->draw_info(); | |
1148 draw_info.SetSolidColorForTesting(SK_ColorRED); | |
1149 } | |
1150 ++it; | |
1151 int eventually_bin_order_correct_count = 0; | |
1152 int eventually_bin_order_incorrect_count = 0; | |
1153 while (it) { | |
1154 Tile* new_tile = *it; | |
1155 ++it; | |
1156 unique_tiles.insert(new_tile); | |
1157 | |
1158 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); | |
1159 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); | |
1160 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); | |
1161 if (last_priority.priority_bin == new_priority.priority_bin) { | |
1162 if (last_priority.priority_bin == TilePriority::EVENTUALLY) { | |
1163 bool order_correct = last_priority.distance_to_visible <= | |
1164 new_priority.distance_to_visible; | |
1165 eventually_bin_order_correct_count += order_correct; | |
1166 eventually_bin_order_incorrect_count += !order_correct; | |
1167 } else if (!soon_rect.Intersects(new_tile->content_rect()) && | |
1168 !soon_rect.Intersects(last_tile->content_rect())) { | |
1169 EXPECT_LE(last_priority.distance_to_visible, | |
1170 new_priority.distance_to_visible); | |
1171 EXPECT_EQ(TilePriority::NOW, new_priority.priority_bin); | |
1172 } else if (new_priority.distance_to_visible > 0.f) { | |
1173 EXPECT_EQ(TilePriority::SOON, new_priority.priority_bin); | |
1174 } | |
1175 } | |
1176 have_tiles[new_priority.priority_bin] = true; | |
1177 | |
1178 last_tile = new_tile; | |
1179 | |
1180 // On the second iteration, mark everything as ready to draw (solid | |
1181 // color). | |
1182 if (i == 1) { | |
1183 TileDrawInfo& draw_info = last_tile->draw_info(); | |
1184 draw_info.SetSolidColorForTesting(SK_ColorRED); | |
1185 } | |
1186 } | |
1187 | |
1188 EXPECT_GT(eventually_bin_order_correct_count, | |
1189 eventually_bin_order_incorrect_count); | |
1190 | |
1191 // We should have now and eventually tiles, as well as soon tiles from | |
1192 // the border region. | |
1193 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | |
1194 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | |
1195 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | |
1196 | |
1197 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); | |
1198 } | |
1199 } | |
1200 | |
1201 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { | |
1202 FakePictureLayerTilingClient client; | |
1203 | |
1204 gfx::Rect viewport(50, 0, 100, 100); | |
1205 gfx::Rect moved_viewport(50, 0, 100, 500); | |
1206 gfx::Size layer_bounds(1000, 1000); | |
1207 | |
1208 client.SetTileSize(gfx::Size(30, 30)); | |
1209 client.set_tree(ACTIVE_TREE); | |
1210 LayerTreeSettings settings; | |
1211 settings.max_tiles_for_interest_area = 10000; | |
1212 | |
1213 scoped_refptr<FakePicturePileImpl> pile = | |
1214 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
1215 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1216 TestablePictureLayerTiling::Create(1.f, pile, &client, settings); | |
1217 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); | |
1218 tiling->ComputeTilePriorityRects(moved_viewport, 1.0f, 2.0, Occlusion()); | |
1219 tiling->UpdateAllTilePrioritiesForTesting(); | |
1220 | |
1221 gfx::Rect soon_rect = moved_viewport; | |
1222 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | |
1223 | |
1224 // There are 3 bins in TilePriority. | |
1225 bool have_tiles[3] = {}; | |
1226 Tile* last_tile = NULL; | |
1227 int eventually_bin_order_correct_count = 0; | |
1228 int eventually_bin_order_incorrect_count = 0; | |
1229 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it; | |
1230 ++it) { | |
1231 if (!last_tile) | |
1232 last_tile = *it; | |
1233 | |
1234 Tile* new_tile = *it; | |
1235 | |
1236 TilePriority last_priority = last_tile->priority(ACTIVE_TREE); | |
1237 TilePriority new_priority = new_tile->priority(ACTIVE_TREE); | |
1238 | |
1239 have_tiles[new_priority.priority_bin] = true; | |
1240 | |
1241 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin); | |
1242 if (last_priority.priority_bin == new_priority.priority_bin) { | |
1243 if (last_priority.priority_bin == TilePriority::EVENTUALLY) { | |
1244 bool order_correct = last_priority.distance_to_visible <= | |
1245 new_priority.distance_to_visible; | |
1246 eventually_bin_order_correct_count += order_correct; | |
1247 eventually_bin_order_incorrect_count += !order_correct; | |
1248 } else if (!soon_rect.Intersects(new_tile->content_rect()) && | |
1249 !soon_rect.Intersects(last_tile->content_rect())) { | |
1250 EXPECT_LE(last_priority.distance_to_visible, | |
1251 new_priority.distance_to_visible); | |
1252 } else if (new_priority.distance_to_visible > 0.f) { | |
1253 EXPECT_EQ(TilePriority::SOON, new_priority.priority_bin); | |
1254 } | |
1255 } | |
1256 last_tile = new_tile; | |
1257 } | |
1258 | |
1259 EXPECT_GT(eventually_bin_order_correct_count, | |
1260 eventually_bin_order_incorrect_count); | |
1261 | |
1262 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | |
1263 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | |
1264 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | |
1265 } | |
1266 | |
1267 static void TileExists(bool exists, Tile* tile, | 1090 static void TileExists(bool exists, Tile* tile, |
1268 const gfx::Rect& geometry_rect) { | 1091 const gfx::Rect& geometry_rect) { |
1269 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 1092 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
1270 } | 1093 } |
1271 | 1094 |
1272 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 1095 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
1273 gfx::Size layer_bounds(1099, 801); | 1096 gfx::Size layer_bounds(1099, 801); |
1274 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1097 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
1275 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1098 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
1276 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1099 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 tiling_->SetRasterSourceAndResize(pile); | 1888 tiling_->SetRasterSourceAndResize(pile); |
2066 | 1889 |
2067 // Tile size in the tiling should be resized to 250x200. | 1890 // Tile size in the tiling should be resized to 250x200. |
2068 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 1891 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
2069 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 1892 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
2070 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 1893 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
2071 } | 1894 } |
2072 | 1895 |
2073 } // namespace | 1896 } // namespace |
2074 } // namespace cc | 1897 } // namespace cc |
OLD | NEW |