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

Side by Side Diff: cc/playback/discardable_image_map_unittest.cc

Issue 2743203006: cc: Outset image rects by 1 for the purposes of the rtree. (Closed)
Patch Set: Created 3 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/playback/discardable_image_map.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/playback/discardable_image_map.h" 5 #include "cc/playback/discardable_image_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 PositionScaleDrawImage(image_map.all_images_[index].first.image(), 53 PositionScaleDrawImage(image_map.all_images_[index].first.image(),
54 image_map.all_images_[index].second, 54 image_map.all_images_[index].second,
55 image_map.all_images_[index].first.scale())); 55 image_map.all_images_[index].first.scale()));
56 } 56 }
57 57
58 EXPECT_EQ(draw_images.size(), position_draw_images.size()); 58 EXPECT_EQ(draw_images.size(), position_draw_images.size());
59 for (size_t i = 0; i < draw_images.size(); ++i) 59 for (size_t i = 0; i < draw_images.size(); ++i)
60 EXPECT_TRUE(draw_images[i].image() == position_draw_images[i].image); 60 EXPECT_TRUE(draw_images[i].image() == position_draw_images[i].image);
61 return position_draw_images; 61 return position_draw_images;
62 } 62 }
63
64 // Note that the image rtree outsets the images by 1, see the comment in
65 // DiscardableImagesMetadataCanvas::AddImage.
66 std::vector<gfx::Rect> InsetImageRects(
67 const std::vector<PositionScaleDrawImage>& images) {
68 std::vector<gfx::Rect> result;
69 for (auto& image : images) {
70 result.push_back(image.image_rect);
71 result.back().Inset(1, 1, 1, 1);
72 }
73 return result;
74 }
63 }; 75 };
64 76
65 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectTest) { 77 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectTest) {
66 gfx::Rect visible_rect(2048, 2048); 78 gfx::Rect visible_rect(2048, 2048);
67 FakeContentLayerClient content_layer_client; 79 FakeContentLayerClient content_layer_client;
68 content_layer_client.set_bounds(visible_rect.size()); 80 content_layer_client.set_bounds(visible_rect.size());
69 81
70 // Discardable pixel refs are found in the following grids: 82 // Discardable pixel refs are found in the following grids:
71 // |---|---|---|---| 83 // |---|---|---|---|
72 // | | x | | x | 84 // | | x | | x |
(...skipping 25 matching lines...) Expand all
98 { 110 {
99 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 111 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
100 visible_rect.size()); 112 visible_rect.size());
101 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); 113 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f);
102 } 114 }
103 115
104 for (int y = 0; y < 4; ++y) { 116 for (int y = 0; y < 4; ++y) {
105 for (int x = 0; x < 4; ++x) { 117 for (int x = 0; x < 4; ++x) {
106 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( 118 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect(
107 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); 119 image_map, gfx::Rect(x * 512, y * 512, 500, 500));
120 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
108 if ((x + y) & 1) { 121 if ((x + y) & 1) {
109 EXPECT_EQ(1u, images.size()) << x << " " << y; 122 EXPECT_EQ(1u, images.size()) << x << " " << y;
110 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " 123 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " "
111 << y; 124 << y;
112 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), 125 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500),
113 images[0].image_rect); 126 inset_rects[0]);
114 EXPECT_EQ(images[0].image_rect, 127 EXPECT_EQ(images[0].image_rect,
115 image_map.GetRectForImage(images[0].image->uniqueID())); 128 image_map.GetRectForImage(images[0].image->uniqueID()));
116 } else { 129 } else {
117 EXPECT_EQ(0u, images.size()) << x << " " << y; 130 EXPECT_EQ(0u, images.size()) << x << " " << y;
118 } 131 }
119 } 132 }
120 } 133 }
121 134
122 // Capture 4 pixel refs. 135 // Capture 4 pixel refs.
123 std::vector<PositionScaleDrawImage> images = 136 std::vector<PositionScaleDrawImage> images =
124 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); 137 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048));
138 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
125 EXPECT_EQ(4u, images.size()); 139 EXPECT_EQ(4u, images.size());
126 140
127 EXPECT_TRUE(images[0].image == discardable_image[1][2]); 141 EXPECT_TRUE(images[0].image == discardable_image[1][2]);
128 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), images[0].image_rect); 142 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]);
129 EXPECT_EQ(images[0].image_rect, 143 EXPECT_EQ(images[0].image_rect,
130 image_map.GetRectForImage(images[0].image->uniqueID())); 144 image_map.GetRectForImage(images[0].image->uniqueID()));
131 145
132 EXPECT_TRUE(images[1].image == discardable_image[2][1]); 146 EXPECT_TRUE(images[1].image == discardable_image[2][1]);
133 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), images[1].image_rect); 147 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]);
134 EXPECT_EQ(images[1].image_rect, 148 EXPECT_EQ(images[1].image_rect,
135 image_map.GetRectForImage(images[1].image->uniqueID())); 149 image_map.GetRectForImage(images[1].image->uniqueID()));
136 150
137 EXPECT_TRUE(images[2].image == discardable_image[2][3]); 151 EXPECT_TRUE(images[2].image == discardable_image[2][3]);
138 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), 152 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]);
139 images[2].image_rect);
140 EXPECT_EQ(images[2].image_rect, 153 EXPECT_EQ(images[2].image_rect,
141 image_map.GetRectForImage(images[2].image->uniqueID())); 154 image_map.GetRectForImage(images[2].image->uniqueID()));
142 155
143 EXPECT_TRUE(images[3].image == discardable_image[3][2]); 156 EXPECT_TRUE(images[3].image == discardable_image[3][2]);
144 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), 157 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]);
145 images[3].image_rect);
146 EXPECT_EQ(images[3].image_rect, 158 EXPECT_EQ(images[3].image_rect,
147 image_map.GetRectForImage(images[3].image->uniqueID())); 159 image_map.GetRectForImage(images[3].image->uniqueID()));
148 } 160 }
149 161
150 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) { 162 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) {
151 gfx::Rect visible_rect(1024, 0, 2048, 2048); 163 gfx::Rect visible_rect(1024, 0, 2048, 2048);
152 // Make sure visible rect fits into the layer size. 164 // Make sure visible rect fits into the layer size.
153 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); 165 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom());
154 FakeContentLayerClient content_layer_client; 166 FakeContentLayerClient content_layer_client;
155 content_layer_client.set_bounds(layer_size); 167 content_layer_client.set_bounds(layer_size);
(...skipping 29 matching lines...) Expand all
185 { 197 {
186 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 198 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
187 layer_size); 199 layer_size);
188 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); 200 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f);
189 } 201 }
190 202
191 for (int y = 0; y < 4; ++y) { 203 for (int y = 0; y < 4; ++y) {
192 for (int x = 0; x < 4; ++x) { 204 for (int x = 0; x < 4; ++x) {
193 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( 205 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect(
194 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); 206 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500));
207 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
195 if ((x + y) & 1) { 208 if ((x + y) & 1) {
196 EXPECT_EQ(1u, images.size()) << x << " " << y; 209 EXPECT_EQ(1u, images.size()) << x << " " << y;
197 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " 210 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " "
198 << y; 211 << y;
199 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500), 212 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500),
200 images[0].image_rect); 213 inset_rects[0]);
201 EXPECT_EQ(images[0].image_rect, 214 EXPECT_EQ(images[0].image_rect,
202 image_map.GetRectForImage(images[0].image->uniqueID())); 215 image_map.GetRectForImage(images[0].image->uniqueID()));
203 } else { 216 } else {
204 EXPECT_EQ(0u, images.size()) << x << " " << y; 217 EXPECT_EQ(0u, images.size()) << x << " " << y;
205 } 218 }
206 } 219 }
207 } 220 }
208 // Capture 4 pixel refs. 221 // Capture 4 pixel refs.
209 { 222 {
210 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( 223 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect(
211 image_map, gfx::Rect(1024 + 512, 512, 2048, 2048)); 224 image_map, gfx::Rect(1024 + 512, 512, 2048, 2048));
225 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
212 EXPECT_EQ(4u, images.size()); 226 EXPECT_EQ(4u, images.size());
213 227
214 EXPECT_TRUE(images[0].image == discardable_image[1][2]); 228 EXPECT_TRUE(images[0].image == discardable_image[1][2]);
215 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 512 + 6, 500, 500), 229 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]);
216 images[0].image_rect);
217 EXPECT_EQ(images[0].image_rect, 230 EXPECT_EQ(images[0].image_rect,
218 image_map.GetRectForImage(images[0].image->uniqueID())); 231 image_map.GetRectForImage(images[0].image->uniqueID()));
219 232
220 EXPECT_TRUE(images[1].image == discardable_image[2][1]); 233 EXPECT_TRUE(images[1].image == discardable_image[2][1]);
221 EXPECT_EQ(gfx::Rect(1024 + 512 + 6, 2 * 512 + 6, 500, 500), 234 EXPECT_EQ(gfx::Rect(1024 + 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]);
222 images[1].image_rect);
223 EXPECT_EQ(images[1].image_rect, 235 EXPECT_EQ(images[1].image_rect,
224 image_map.GetRectForImage(images[1].image->uniqueID())); 236 image_map.GetRectForImage(images[1].image->uniqueID()));
225 237
226 EXPECT_TRUE(images[2].image == discardable_image[2][3]); 238 EXPECT_TRUE(images[2].image == discardable_image[2][3]);
227 EXPECT_EQ(gfx::Rect(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500), 239 EXPECT_EQ(gfx::Rect(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500),
228 images[2].image_rect); 240 inset_rects[2]);
229 EXPECT_EQ(images[2].image_rect, 241 EXPECT_EQ(images[2].image_rect,
230 image_map.GetRectForImage(images[2].image->uniqueID())); 242 image_map.GetRectForImage(images[2].image->uniqueID()));
231 243
232 EXPECT_TRUE(images[3].image == discardable_image[3][2]); 244 EXPECT_TRUE(images[3].image == discardable_image[3][2]);
233 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500), 245 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500),
234 images[3].image_rect); 246 inset_rects[3]);
235 EXPECT_EQ(images[3].image_rect, 247 EXPECT_EQ(images[3].image_rect,
236 image_map.GetRectForImage(images[3].image->uniqueID())); 248 image_map.GetRectForImage(images[3].image->uniqueID()));
237 } 249 }
238 250
239 // Non intersecting rects 251 // Non intersecting rects
240 { 252 {
241 std::vector<PositionScaleDrawImage> images = 253 std::vector<PositionScaleDrawImage> images =
242 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1000, 1000)); 254 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1000, 1000));
243 EXPECT_EQ(0u, images.size()); 255 EXPECT_EQ(0u, images.size());
244 } 256 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 { 313 {
302 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 314 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
303 visible_rect.size()); 315 visible_rect.size());
304 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); 316 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f);
305 } 317 }
306 318
307 for (int y = 0; y < 4; ++y) { 319 for (int y = 0; y < 4; ++y) {
308 for (int x = 0; x < 4; ++x) { 320 for (int x = 0; x < 4; ++x) {
309 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( 321 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect(
310 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); 322 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1));
323 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
311 if ((x + y) & 1) { 324 if ((x + y) & 1) {
312 EXPECT_EQ(1u, images.size()) << x << " " << y; 325 EXPECT_EQ(1u, images.size()) << x << " " << y;
313 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " 326 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " "
314 << y; 327 << y;
315 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), 328 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500),
316 images[0].image_rect); 329 inset_rects[0]);
317 EXPECT_EQ(images[0].image_rect, 330 EXPECT_EQ(images[0].image_rect,
318 image_map.GetRectForImage(images[0].image->uniqueID())); 331 image_map.GetRectForImage(images[0].image->uniqueID()));
319 } else { 332 } else {
320 EXPECT_EQ(0u, images.size()) << x << " " << y; 333 EXPECT_EQ(0u, images.size()) << x << " " << y;
321 } 334 }
322 } 335 }
323 } 336 }
324 } 337 }
325 338
326 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) { 339 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) {
(...skipping 12 matching lines...) Expand all
339 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 352 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
340 353
341 DiscardableImageMap image_map; 354 DiscardableImageMap image_map;
342 { 355 {
343 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 356 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
344 visible_rect.size()); 357 visible_rect.size());
345 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); 358 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f);
346 } 359 }
347 std::vector<PositionScaleDrawImage> images = 360 std::vector<PositionScaleDrawImage> images =
348 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); 361 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1));
362 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
349 EXPECT_EQ(1u, images.size()); 363 EXPECT_EQ(1u, images.size());
350 EXPECT_TRUE(images[0].image == discardable_image); 364 EXPECT_TRUE(images[0].image == discardable_image);
351 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), images[0].image_rect); 365 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), inset_rects[0]);
352 EXPECT_EQ(images[0].image_rect, 366 EXPECT_EQ(images[0].image_rect,
353 image_map.GetRectForImage(images[0].image->uniqueID())); 367 image_map.GetRectForImage(images[0].image->uniqueID()));
354 } 368 }
355 369
356 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) { 370 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) {
357 gfx::Rect visible_rect(2048, 2048); 371 gfx::Rect visible_rect(2048, 2048);
358 FakeContentLayerClient content_layer_client; 372 FakeContentLayerClient content_layer_client;
359 content_layer_client.set_bounds(visible_rect.size()); 373 content_layer_client.set_bounds(visible_rect.size());
360 374
361 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); 375 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 410 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
397 411
398 DiscardableImageMap image_map; 412 DiscardableImageMap image_map;
399 { 413 {
400 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 414 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
401 visible_rect.size()); 415 visible_rect.size());
402 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); 416 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f);
403 } 417 }
404 std::vector<PositionScaleDrawImage> images = 418 std::vector<PositionScaleDrawImage> images =
405 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1)); 419 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1));
420 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
406 EXPECT_EQ(1u, images.size()); 421 EXPECT_EQ(1u, images.size());
407 EXPECT_TRUE(images[0].image == discardable_image); 422 EXPECT_TRUE(images[0].image == discardable_image);
408 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), images[0].image_rect); 423 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), inset_rects[0]);
409 EXPECT_EQ(images[0].image_rect, 424 EXPECT_EQ(images[0].image_rect,
410 image_map.GetRectForImage(images[0].image->uniqueID())); 425 image_map.GetRectForImage(images[0].image->uniqueID()));
411 } 426 }
412 427
413 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImageMaxLayer) { 428 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImageMaxLayer) {
414 // At large values of integer x, x != static_cast<int>(static_cast<float>(x)). 429 // At large values of integer x, x != static_cast<int>(static_cast<float>(x)).
415 // So, make sure the dimension can be converted back and forth for the 430 // So, make sure the dimension can be converted back and forth for the
416 // purposes of the unittest. Also, at near max int values, Skia seems to skip 431 // purposes of the unittest. Also, at near max int values, Skia seems to skip
417 // some draw calls, so we subtract 64 since we only care about "really large" 432 // some draw calls, so we subtract 64 since we only care about "really large"
418 // values, not necessarily max int values. 433 // values, not necessarily max int values.
(...skipping 18 matching lines...) Expand all
437 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 452 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
438 453
439 DiscardableImageMap image_map; 454 DiscardableImageMap image_map;
440 { 455 {
441 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 456 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
442 visible_rect.size()); 457 visible_rect.size());
443 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); 458 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f);
444 } 459 }
445 std::vector<PositionScaleDrawImage> images = 460 std::vector<PositionScaleDrawImage> images =
446 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); 461 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1));
462 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
447 EXPECT_EQ(1u, images.size()); 463 EXPECT_EQ(1u, images.size());
448 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect); 464 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]);
449 465
450 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1)); 466 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1));
467 inset_rects = InsetImageRects(images);
451 EXPECT_EQ(2u, images.size()); 468 EXPECT_EQ(2u, images.size());
452 EXPECT_EQ(gfx::Rect(10000, 0, dimension - 10000, dimension), 469 EXPECT_EQ(gfx::Rect(10000, 0, dimension - 10000, dimension), inset_rects[1]);
453 images[1].image_rect); 470 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]);
454 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect);
455 471
456 // Since we adjust negative offsets before using ToEnclosingRect, the expected 472 // Since we adjust negative offsets before using ToEnclosingRect, the expected
457 // width will be converted to float, which means that we lose some precision. 473 // width will be converted to float, which means that we lose some precision.
458 // The expected value is whatever the value is converted to float and then 474 // The expected value is whatever the value is converted to float and then
459 // back to int. 475 // back to int.
460 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000)); 476 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000));
461 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); 477 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1));
478 inset_rects = InsetImageRects(images);
462 EXPECT_EQ(2u, images.size()); 479 EXPECT_EQ(2u, images.size());
463 EXPECT_EQ(gfx::Rect(0, 500, expected10k, dimension - 500), 480 EXPECT_EQ(gfx::Rect(0, 500, expected10k, dimension - 500), inset_rects[1]);
464 images[1].image_rect); 481 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]);
465 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect);
466 482
467 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), 483 EXPECT_EQ(images[0].image_rect,
468 image_map.GetRectForImage(discardable_image->uniqueID())); 484 image_map.GetRectForImage(discardable_image->uniqueID()));
469 } 485 }
470 486
471 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) { 487 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) {
472 gfx::Rect visible_rect(1000, 1000); 488 gfx::Rect visible_rect(1000, 1000);
473 FakeContentLayerClient content_layer_client; 489 FakeContentLayerClient content_layer_client;
474 content_layer_client.set_bounds(visible_rect.size()); 490 content_layer_client.set_bounds(visible_rect.size());
475 491
476 sk_sp<SkImage> discardable_image = 492 sk_sp<SkImage> discardable_image =
477 CreateDiscardableImage(gfx::Size(100, 100)); 493 CreateDiscardableImage(gfx::Size(100, 100));
(...skipping 13 matching lines...) Expand all
491 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 507 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
492 508
493 DiscardableImageMap image_map; 509 DiscardableImageMap image_map;
494 { 510 {
495 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 511 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
496 visible_rect.size()); 512 visible_rect.size());
497 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); 513 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f);
498 } 514 }
499 std::vector<PositionScaleDrawImage> images = 515 std::vector<PositionScaleDrawImage> images =
500 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); 516 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1));
517 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
501 EXPECT_EQ(1u, images.size()); 518 EXPECT_EQ(1u, images.size());
502 EXPECT_EQ(gfx::Rect(0, 0, 90, 89), images[0].image_rect); 519 EXPECT_EQ(gfx::Rect(0, 0, 90, 89), inset_rects[0]);
503 520
504 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1)); 521 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1));
522 inset_rects = InsetImageRects(images);
505 EXPECT_EQ(1u, images.size()); 523 EXPECT_EQ(1u, images.size());
506 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), images[0].image_rect); 524 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), inset_rects[0]);
507 525
508 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); 526 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1));
527 inset_rects = InsetImageRects(images);
509 EXPECT_EQ(1u, images.size()); 528 EXPECT_EQ(1u, images.size());
510 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), images[0].image_rect); 529 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), inset_rects[0]);
511 530
512 gfx::Rect discardable_image_rect; 531 gfx::Rect discardable_image_rect;
513 discardable_image_rect.Union(gfx::Rect(0, 0, 90, 89)); 532 discardable_image_rect.Union(gfx::Rect(0, 0, 90, 89));
514 discardable_image_rect.Union(gfx::Rect(950, 951, 50, 49)); 533 discardable_image_rect.Union(gfx::Rect(950, 951, 50, 49));
534 discardable_image_rect.Inset(-1, -1, -1, -1);
515 EXPECT_EQ(discardable_image_rect, 535 EXPECT_EQ(discardable_image_rect,
516 image_map.GetRectForImage(discardable_image->uniqueID())); 536 image_map.GetRectForImage(discardable_image->uniqueID()));
517 537
518 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), 538 EXPECT_EQ(gfx::Rect(-1, 499, 1002, 102),
519 image_map.GetRectForImage(long_discardable_image->uniqueID())); 539 image_map.GetRectForImage(long_discardable_image->uniqueID()));
520 } 540 }
521 541
522 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) { 542 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) {
523 gfx::Rect visible_rect(2048, 2048); 543 gfx::Rect visible_rect(2048, 2048);
524 FakeContentLayerClient content_layer_client; 544 FakeContentLayerClient content_layer_client;
525 content_layer_client.set_bounds(visible_rect.size()); 545 content_layer_client.set_bounds(visible_rect.size());
526 546
527 // Discardable pixel refs are found in the following grids: 547 // Discardable pixel refs are found in the following grids:
528 // |---|---|---|---| 548 // |---|---|---|---|
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 { 583 {
564 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, 584 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map,
565 visible_rect.size()); 585 visible_rect.size());
566 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); 586 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f);
567 } 587 }
568 588
569 for (int y = 0; y < 4; ++y) { 589 for (int y = 0; y < 4; ++y) {
570 for (int x = 0; x < 4; ++x) { 590 for (int x = 0; x < 4; ++x) {
571 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( 591 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect(
572 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); 592 image_map, gfx::Rect(x * 512, y * 512, 500, 500));
593 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
573 if ((x + y) & 1) { 594 if ((x + y) & 1) {
574 EXPECT_EQ(1u, images.size()) << x << " " << y; 595 EXPECT_EQ(1u, images.size()) << x << " " << y;
575 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " 596 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " "
576 << y; 597 << y;
577 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), 598 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500),
578 images[0].image_rect); 599 inset_rects[0]);
579 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth); 600 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth);
580 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight); 601 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight);
581 } else { 602 } else {
582 EXPECT_EQ(0u, images.size()) << x << " " << y; 603 EXPECT_EQ(0u, images.size()) << x << " " << y;
583 } 604 }
584 } 605 }
585 } 606 }
586 607
587 // Capture 4 pixel refs. 608 // Capture 4 pixel refs.
588 std::vector<PositionScaleDrawImage> images = 609 std::vector<PositionScaleDrawImage> images =
589 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); 610 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048));
611 std::vector<gfx::Rect> inset_rects = InsetImageRects(images);
590 EXPECT_EQ(4u, images.size()); 612 EXPECT_EQ(4u, images.size());
591 EXPECT_TRUE(images[0].image == discardable_image[1][2]); 613 EXPECT_TRUE(images[0].image == discardable_image[1][2]);
592 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), images[0].image_rect); 614 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]);
593 EXPECT_TRUE(images[1].image == discardable_image[2][1]); 615 EXPECT_TRUE(images[1].image == discardable_image[2][1]);
594 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), images[1].image_rect); 616 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]);
595 EXPECT_TRUE(images[2].image == discardable_image[2][3]); 617 EXPECT_TRUE(images[2].image == discardable_image[2][3]);
596 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), 618 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]);
597 images[2].image_rect);
598 EXPECT_TRUE(images[3].image == discardable_image[3][2]); 619 EXPECT_TRUE(images[3].image == discardable_image[3][2]);
599 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), 620 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]);
600 images[3].image_rect);
601 } 621 }
602 622
603 } // namespace cc 623 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/discardable_image_map.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698