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

Side by Side Diff: cc/resources/picture_layer_tiling_unittest.cc

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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/resources/picture_layer_tiling_set.cc ('k') | cc/resources/picture_pile_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 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 EXPECT_TRUE(expect_rect.Contains(geometry)); 123 EXPECT_TRUE(expect_rect.Contains(geometry));
124 EXPECT_TRUE(remaining.Contains(geometry)); 124 EXPECT_TRUE(remaining.Contains(geometry));
125 remaining.Subtract(geometry); 125 remaining.Subtract(geometry);
126 126
127 // Sanity check that texture coords are within the texture rect. 127 // Sanity check that texture coords are within the texture rect.
128 gfx::RectF texture_rect = iter.texture_rect(); 128 gfx::RectF texture_rect = iter.texture_rect();
129 EXPECT_GE(texture_rect.x(), 0); 129 EXPECT_GE(texture_rect.x(), 0);
130 EXPECT_GE(texture_rect.y(), 0); 130 EXPECT_GE(texture_rect.y(), 0);
131 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); 131 EXPECT_LE(texture_rect.right(), client_.TileSize().width());
132 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); 132 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height());
133
134 EXPECT_EQ(iter.texture_size(), client_.TileSize());
135 } 133 }
136 134
137 // The entire rect must be filled by geometry from the tiling. 135 // The entire rect must be filled by geometry from the tiling.
138 EXPECT_TRUE(remaining.IsEmpty()); 136 EXPECT_TRUE(remaining.IsEmpty());
139 } 137 }
140 138
141 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) { 139 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) {
142 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); 140 VerifyTilesExactlyCoverRect(rect_scale, rect, rect);
143 } 141 }
144 142
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 // 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
1083 // for the layer would be empty. 1081 // for the layer would be empty.
1084 gfx::Rect in(40, 40, 0, 0); 1082 gfx::Rect in(40, 40, 0, 0);
1085 gfx::Rect bounds(0, 0, 10, 10); 1083 gfx::Rect bounds(0, 0, 10, 10);
1086 int64 target_area = 400 * 400; 1084 int64 target_area = 400 * 400;
1087 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( 1085 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1088 in, target_area, bounds, NULL); 1086 in, target_area, bounds, NULL);
1089 EXPECT_TRUE(out.IsEmpty()); 1087 EXPECT_TRUE(out.IsEmpty());
1090 } 1088 }
1091 1089
1092 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) {
1093 FakePictureLayerTilingClient client;
1094
1095 gfx::Rect viewport(50, 50, 100, 100);
1096 gfx::Size layer_bounds(800, 800);
1097
1098 gfx::Rect soon_rect = viewport;
1099 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f);
1100
1101 client.SetTileSize(gfx::Size(30, 30));
1102 client.set_tree(ACTIVE_TREE);
1103 LayerTreeSettings settings;
1104 settings.max_tiles_for_interest_area = 10000;
1105
1106 scoped_refptr<FakePicturePileImpl> pile =
1107 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
1108 scoped_ptr<TestablePictureLayerTiling> tiling =
1109 TestablePictureLayerTiling::Create(1.0f, pile, &client, settings);
1110 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion());
1111 tiling->UpdateAllTilePrioritiesForTesting();
1112
1113 PictureLayerTiling::TilingRasterTileIterator empty_iterator;
1114 EXPECT_FALSE(empty_iterator);
1115
1116 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting();
1117
1118 // Sanity check.
1119 EXPECT_EQ(841u, all_tiles.size());
1120
1121 // The explanation of each iteration is as follows:
1122 // 1. First iteration tests that we can get all of the tiles correctly.
1123 // 2. Second iteration ensures that we can get all of the tiles again (first
1124 // iteration didn't change any tiles), as well set all tiles to be ready to
1125 // draw.
1126 // 3. Third iteration ensures that no tiles are returned, since they were all
1127 // marked as ready to draw.
1128 for (int i = 0; i < 3; ++i) {
1129 PictureLayerTiling::TilingRasterTileIterator it(tiling.get());
1130
1131 // There are 3 bins in TilePriority.
1132 bool have_tiles[3] = {};
1133
1134 // On the third iteration, we should get no tiles since everything was
1135 // marked as ready to draw.
1136 if (i == 2) {
1137 EXPECT_FALSE(it);
1138 continue;
1139 }
1140
1141 EXPECT_TRUE(it);
1142 std::set<Tile*> unique_tiles;
1143 unique_tiles.insert(*it);
1144 Tile* last_tile = *it;
1145 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true;
1146
1147 // On the second iteration, mark everything as ready to draw (solid color).
1148 if (i == 1) {
1149 TileDrawInfo& draw_info = last_tile->draw_info();
1150 draw_info.SetSolidColorForTesting(SK_ColorRED);
1151 }
1152 ++it;
1153 int eventually_bin_order_correct_count = 0;
1154 int eventually_bin_order_incorrect_count = 0;
1155 while (it) {
1156 Tile* new_tile = *it;
1157 ++it;
1158 unique_tiles.insert(new_tile);
1159
1160 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
1161 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
1162 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
1163 if (last_priority.priority_bin == new_priority.priority_bin) {
1164 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
1165 bool order_correct = last_priority.distance_to_visible <=
1166 new_priority.distance_to_visible;
1167 eventually_bin_order_correct_count += order_correct;
1168 eventually_bin_order_incorrect_count += !order_correct;
1169 } else if (!soon_rect.Intersects(new_tile->content_rect()) &&
1170 !soon_rect.Intersects(last_tile->content_rect())) {
1171 EXPECT_LE(last_priority.distance_to_visible,
1172 new_priority.distance_to_visible);
1173 EXPECT_EQ(TilePriority::NOW, new_priority.priority_bin);
1174 } else if (new_priority.distance_to_visible > 0.f) {
1175 EXPECT_EQ(TilePriority::SOON, new_priority.priority_bin);
1176 }
1177 }
1178 have_tiles[new_priority.priority_bin] = true;
1179
1180 last_tile = new_tile;
1181
1182 // On the second iteration, mark everything as ready to draw (solid
1183 // color).
1184 if (i == 1) {
1185 TileDrawInfo& draw_info = last_tile->draw_info();
1186 draw_info.SetSolidColorForTesting(SK_ColorRED);
1187 }
1188 }
1189
1190 EXPECT_GT(eventually_bin_order_correct_count,
1191 eventually_bin_order_incorrect_count);
1192
1193 // We should have now and eventually tiles, as well as soon tiles from
1194 // the border region.
1195 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
1196 EXPECT_TRUE(have_tiles[TilePriority::SOON]);
1197 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
1198
1199 EXPECT_EQ(unique_tiles.size(), all_tiles.size());
1200 }
1201 }
1202
1203 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) {
1204 FakePictureLayerTilingClient client;
1205
1206 gfx::Rect viewport(50, 0, 100, 100);
1207 gfx::Rect moved_viewport(50, 0, 100, 500);
1208 gfx::Size layer_bounds(1000, 1000);
1209
1210 client.SetTileSize(gfx::Size(30, 30));
1211 client.set_tree(ACTIVE_TREE);
1212 LayerTreeSettings settings;
1213 settings.max_tiles_for_interest_area = 10000;
1214
1215 scoped_refptr<FakePicturePileImpl> pile =
1216 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
1217 scoped_ptr<TestablePictureLayerTiling> tiling =
1218 TestablePictureLayerTiling::Create(1.f, pile, &client, settings);
1219 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion());
1220 tiling->ComputeTilePriorityRects(moved_viewport, 1.0f, 2.0, Occlusion());
1221 tiling->UpdateAllTilePrioritiesForTesting();
1222
1223 gfx::Rect soon_rect = moved_viewport;
1224 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f);
1225
1226 // There are 3 bins in TilePriority.
1227 bool have_tiles[3] = {};
1228 Tile* last_tile = NULL;
1229 int eventually_bin_order_correct_count = 0;
1230 int eventually_bin_order_incorrect_count = 0;
1231 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get()); it;
1232 ++it) {
1233 if (!last_tile)
1234 last_tile = *it;
1235
1236 Tile* new_tile = *it;
1237
1238 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
1239 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
1240
1241 have_tiles[new_priority.priority_bin] = true;
1242
1243 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
1244 if (last_priority.priority_bin == new_priority.priority_bin) {
1245 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
1246 bool order_correct = last_priority.distance_to_visible <=
1247 new_priority.distance_to_visible;
1248 eventually_bin_order_correct_count += order_correct;
1249 eventually_bin_order_incorrect_count += !order_correct;
1250 } else if (!soon_rect.Intersects(new_tile->content_rect()) &&
1251 !soon_rect.Intersects(last_tile->content_rect())) {
1252 EXPECT_LE(last_priority.distance_to_visible,
1253 new_priority.distance_to_visible);
1254 } else if (new_priority.distance_to_visible > 0.f) {
1255 EXPECT_EQ(TilePriority::SOON, new_priority.priority_bin);
1256 }
1257 }
1258 last_tile = new_tile;
1259 }
1260
1261 EXPECT_GT(eventually_bin_order_correct_count,
1262 eventually_bin_order_incorrect_count);
1263
1264 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
1265 EXPECT_TRUE(have_tiles[TilePriority::SOON]);
1266 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
1267 }
1268
1269 static void TileExists(bool exists, Tile* tile, 1090 static void TileExists(bool exists, Tile* tile,
1270 const gfx::Rect& geometry_rect) { 1091 const gfx::Rect& geometry_rect) {
1271 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); 1092 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString();
1272 } 1093 }
1273 1094
1274 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { 1095 TEST_F(PictureLayerTilingIteratorTest, TilesExist) {
1275 gfx::Size layer_bounds(1099, 801); 1096 gfx::Size layer_bounds(1099, 801);
1276 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); 1097 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
1277 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); 1098 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
1278 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
2067 tiling_->SetRasterSourceAndResize(pile); 1888 tiling_->SetRasterSourceAndResize(pile);
2068 1889
2069 // Tile size in the tiling should be resized to 250x200. 1890 // Tile size in the tiling should be resized to 250x200.
2070 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); 1891 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width());
2071 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); 1892 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height());
2072 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); 1893 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size());
2073 } 1894 }
2074 1895
2075 } // namespace 1896 } // namespace
2076 } // namespace cc 1897 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_layer_tiling_set.cc ('k') | cc/resources/picture_pile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698