OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_ptr.h" | |
6 #include "cc/test/fake_picture_pile_impl.h" | |
7 #include "cc/test/skia_common.h" | |
8 #include "skia/ext/refptr.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "third_party/skia/include/core/SkPixelRef.h" | |
11 #include "third_party/skia/include/core/SkShader.h" | |
12 #include "ui/gfx/geometry/rect.h" | |
13 #include "ui/gfx/geometry/size_conversions.h" | |
14 | |
15 namespace cc { | |
16 namespace { | |
17 | |
18 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { | |
19 gfx::Size tile_size(100, 100); | |
20 gfx::Size layer_bounds(400, 400); | |
21 | |
22 scoped_ptr<FakePicturePile> recording_source = | |
23 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
24 | |
25 SkPaint solid_paint; | |
26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | |
27 solid_paint.setColor(solid_color); | |
28 | |
29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | |
30 SkPaint non_solid_paint; | |
31 non_solid_paint.setColor(non_solid_color); | |
32 | |
33 recording_source->add_draw_rect_with_paint(gfx::Rect(400, 400), solid_paint); | |
34 recording_source->Rerecord(); | |
35 | |
36 scoped_refptr<FakePicturePileImpl> pile = | |
37 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
38 | |
39 // Ensure everything is solid. | |
40 for (int y = 0; y <= 300; y += 100) { | |
41 for (int x = 0; x <= 300; x += 100) { | |
42 RasterSource::SolidColorAnalysis analysis; | |
43 gfx::Rect rect(x, y, 100, 100); | |
44 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis); | |
45 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | |
46 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | |
47 } | |
48 } | |
49 | |
50 // Add one non-solid pixel and recreate the raster source. | |
51 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | |
52 non_solid_paint); | |
53 recording_source->Rerecord(); | |
54 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
55 | |
56 RasterSource::SolidColorAnalysis analysis; | |
57 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); | |
58 EXPECT_FALSE(analysis.is_solid_color); | |
59 | |
60 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); | |
61 EXPECT_TRUE(analysis.is_solid_color); | |
62 EXPECT_EQ(analysis.solid_color, solid_color); | |
63 | |
64 // Boundaries should be clipped. | |
65 analysis.is_solid_color = false; | |
66 pile->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0, &analysis); | |
67 EXPECT_TRUE(analysis.is_solid_color); | |
68 EXPECT_EQ(analysis.solid_color, solid_color); | |
69 | |
70 analysis.is_solid_color = false; | |
71 pile->PerformSolidColorAnalysis(gfx::Rect(0, 350, 100, 100), 1.0, &analysis); | |
72 EXPECT_TRUE(analysis.is_solid_color); | |
73 EXPECT_EQ(analysis.solid_color, solid_color); | |
74 | |
75 analysis.is_solid_color = false; | |
76 pile->PerformSolidColorAnalysis(gfx::Rect(350, 350, 100, 100), 1.0, | |
77 &analysis); | |
78 EXPECT_TRUE(analysis.is_solid_color); | |
79 EXPECT_EQ(analysis.solid_color, solid_color); | |
80 } | |
81 | |
82 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { | |
83 gfx::Size tile_size(100, 100); | |
84 gfx::Size layer_bounds(400, 400); | |
85 | |
86 scoped_ptr<FakePicturePile> recording_source = | |
87 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
88 | |
89 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | |
90 SkPaint solid_paint; | |
91 solid_paint.setColor(solid_color); | |
92 | |
93 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | |
94 SkPaint non_solid_paint; | |
95 non_solid_paint.setColor(non_solid_color); | |
96 | |
97 recording_source->add_draw_rect_with_paint(gfx::Rect(400, 400), solid_paint); | |
98 recording_source->Rerecord(); | |
99 | |
100 scoped_refptr<FakePicturePileImpl> pile = | |
101 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
102 | |
103 // Ensure everything is solid. | |
104 for (int y = 0; y <= 30; y += 10) { | |
105 for (int x = 0; x <= 30; x += 10) { | |
106 RasterSource::SolidColorAnalysis analysis; | |
107 gfx::Rect rect(x, y, 10, 10); | |
108 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis); | |
109 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | |
110 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | |
111 } | |
112 } | |
113 | |
114 // Add one non-solid pixel and recreate the raster source. | |
115 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | |
116 non_solid_paint); | |
117 recording_source->Rerecord(); | |
118 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
119 | |
120 RasterSource::SolidColorAnalysis analysis; | |
121 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); | |
122 EXPECT_FALSE(analysis.is_solid_color); | |
123 | |
124 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); | |
125 EXPECT_TRUE(analysis.is_solid_color); | |
126 EXPECT_EQ(analysis.solid_color, solid_color); | |
127 | |
128 // Boundaries should be clipped. | |
129 analysis.is_solid_color = false; | |
130 pile->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); | |
131 EXPECT_TRUE(analysis.is_solid_color); | |
132 EXPECT_EQ(analysis.solid_color, solid_color); | |
133 | |
134 analysis.is_solid_color = false; | |
135 pile->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); | |
136 EXPECT_TRUE(analysis.is_solid_color); | |
137 EXPECT_EQ(analysis.solid_color, solid_color); | |
138 | |
139 analysis.is_solid_color = false; | |
140 pile->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); | |
141 EXPECT_TRUE(analysis.is_solid_color); | |
142 EXPECT_EQ(analysis.solid_color, solid_color); | |
143 } | |
144 | |
145 TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) { | |
146 gfx::Size tile_size(100, 100); | |
147 gfx::Size layer_bounds(400, 400); | |
148 | |
149 scoped_refptr<FakePicturePileImpl> pile = | |
150 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
151 RasterSource::SolidColorAnalysis analysis; | |
152 EXPECT_FALSE(analysis.is_solid_color); | |
153 | |
154 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); | |
155 | |
156 EXPECT_TRUE(analysis.is_solid_color); | |
157 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); | |
158 } | |
159 | |
160 TEST(PicturePileImplTest, ImageIteratorDiscardableImagesOneTile) { | |
161 gfx::Size tile_size(256, 256); | |
162 gfx::Size layer_bounds(512, 512); | |
163 | |
164 scoped_ptr<FakePicturePile> recording_source = | |
165 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
166 | |
167 skia::RefPtr<SkImage> discardable_image[2][2]; | |
168 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); | |
169 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); | |
170 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); | |
171 | |
172 // Discardable pixel refs are found in the following cells: | |
173 // |---|---| | |
174 // | x | x | | |
175 // |---|---| | |
176 // | | x | | |
177 // |---|---| | |
178 recording_source->add_draw_image(discardable_image[0][0].get(), | |
179 gfx::Point(0, 0)); | |
180 recording_source->add_draw_image(discardable_image[0][1].get(), | |
181 gfx::Point(260, 0)); | |
182 recording_source->add_draw_image(discardable_image[1][1].get(), | |
183 gfx::Point(260, 260)); | |
184 recording_source->SetGatherDiscardableImages(true); | |
185 recording_source->Rerecord(); | |
186 | |
187 scoped_refptr<FakePicturePileImpl> pile = | |
188 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
189 | |
190 // Tile sized iterators. These should find only one pixel ref. | |
191 { | |
192 PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 256, 256), | |
193 pile.get()); | |
194 EXPECT_TRUE(iterator); | |
195 EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); | |
196 EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), | |
197 gfx::RectF(32, 32).ToString()); | |
198 EXPECT_FALSE(++iterator); | |
199 } | |
200 // Shifted tile sized iterators. These should find only one pixel ref. | |
201 { | |
202 PicturePileImpl::ImageIterator iterator(gfx::Rect(260, 260, 256, 256), | |
203 pile.get()); | |
204 EXPECT_TRUE(iterator); | |
205 EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); | |
206 EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), | |
207 gfx::RectF(260, 260, 32, 32).ToString()); | |
208 EXPECT_FALSE(++iterator); | |
209 } | |
210 // Ensure there's no discardable pixel refs in the empty cell | |
211 { | |
212 PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 256, 256, 256), | |
213 pile.get()); | |
214 EXPECT_FALSE(iterator); | |
215 } | |
216 // Layer sized iterators. These should find three pixel ref. | |
217 { | |
218 PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 512, 512), | |
219 pile.get()); | |
220 EXPECT_TRUE(iterator); | |
221 EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); | |
222 EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), | |
223 gfx::RectF(32, 32).ToString()); | |
224 EXPECT_TRUE(++iterator); | |
225 EXPECT_TRUE(iterator->image == discardable_image[0][1].get()); | |
226 EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), | |
227 gfx::RectF(260, 0, 32, 32).ToString()); | |
228 EXPECT_TRUE(++iterator); | |
229 EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); | |
230 EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), | |
231 gfx::RectF(260, 260, 32, 32).ToString()); | |
232 EXPECT_FALSE(++iterator); | |
233 } | |
234 | |
235 { | |
236 // Copy test. | |
237 PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 512, 512), | |
238 pile.get()); | |
239 EXPECT_TRUE(iterator); | |
240 EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); | |
241 EXPECT_EQ(gfx::RectF(32, 32).ToString(), | |
242 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
243 EXPECT_TRUE(++iterator); | |
244 EXPECT_TRUE(iterator->image == discardable_image[0][1].get()); | |
245 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), | |
246 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
247 | |
248 // copy now points to the same spot as iterator, | |
249 // but both can be incremented independently. | |
250 PicturePileImpl::ImageIterator copy = iterator; | |
251 EXPECT_TRUE(++iterator); | |
252 EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); | |
253 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), | |
254 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
255 EXPECT_FALSE(++iterator); | |
256 | |
257 EXPECT_TRUE(copy); | |
258 EXPECT_TRUE(copy->image == discardable_image[0][1].get()); | |
259 EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), | |
260 gfx::SkRectToRectF(copy->image_rect).ToString()); | |
261 EXPECT_TRUE(++copy); | |
262 EXPECT_TRUE(copy->image == discardable_image[1][1].get()); | |
263 EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), | |
264 gfx::SkRectToRectF(copy->image_rect).ToString()); | |
265 EXPECT_FALSE(++copy); | |
266 } | |
267 } | |
268 | |
269 TEST(PicturePileImplTest, RasterFullContents) { | |
270 gfx::Size tile_size(1000, 1000); | |
271 gfx::Size layer_bounds(3, 5); | |
272 float contents_scale = 1.5f; | |
273 float raster_divisions = 2.f; | |
274 | |
275 scoped_ptr<FakePicturePile> recording_source = | |
276 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
277 recording_source->SetBackgroundColor(SK_ColorBLACK); | |
278 recording_source->SetIsSolidColor(false); | |
279 recording_source->SetRequiresClear(false); | |
280 recording_source->SetClearCanvasWithDebugColor(false); | |
281 | |
282 // Because the caller sets content opaque, it also promises that it | |
283 // has at least filled in layer_bounds opaquely. | |
284 SkPaint white_paint; | |
285 white_paint.setColor(SK_ColorWHITE); | |
286 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | |
287 white_paint); | |
288 | |
289 recording_source->SetMinContentsScale(contents_scale); | |
290 recording_source->Rerecord(); | |
291 | |
292 scoped_refptr<FakePicturePileImpl> pile = | |
293 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
294 | |
295 gfx::Size content_bounds( | |
296 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | |
297 | |
298 // Simulate drawing into different tiles at different offsets. | |
299 int step_x = std::ceil(content_bounds.width() / raster_divisions); | |
300 int step_y = std::ceil(content_bounds.height() / raster_divisions); | |
301 for (int offset_x = 0; offset_x < content_bounds.width(); | |
302 offset_x += step_x) { | |
303 for (int offset_y = 0; offset_y < content_bounds.height(); | |
304 offset_y += step_y) { | |
305 gfx::Rect content_rect(offset_x, offset_y, step_x, step_y); | |
306 content_rect.Intersect(gfx::Rect(content_bounds)); | |
307 | |
308 // Simulate a canvas rect larger than the content rect. Every pixel | |
309 // up to one pixel outside the content rect is guaranteed to be opaque. | |
310 // Outside of that is undefined. | |
311 gfx::Rect canvas_rect(content_rect); | |
312 canvas_rect.Inset(0, 0, -1, -1); | |
313 | |
314 SkBitmap bitmap; | |
315 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | |
316 SkCanvas canvas(bitmap); | |
317 canvas.clear(SK_ColorTRANSPARENT); | |
318 | |
319 pile->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); | |
320 | |
321 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
322 int num_pixels = bitmap.width() * bitmap.height(); | |
323 bool all_white = true; | |
324 for (int i = 0; i < num_pixels; ++i) { | |
325 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); | |
326 all_white &= (SkColorGetR(pixels[i]) == 255); | |
327 all_white &= (SkColorGetG(pixels[i]) == 255); | |
328 all_white &= (SkColorGetB(pixels[i]) == 255); | |
329 } | |
330 | |
331 // If the canvas doesn't extend past the edge of the content, | |
332 // it should be entirely white. Otherwise, the edge of the content | |
333 // will be non-white. | |
334 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); | |
335 } | |
336 } | |
337 } | |
338 | |
339 TEST(PicturePileImpl, RasterContentsTransparent) { | |
340 gfx::Size tile_size(1000, 1000); | |
341 gfx::Size layer_bounds(5, 3); | |
342 float contents_scale = 0.5f; | |
343 | |
344 scoped_ptr<FakePicturePile> recording_source = | |
345 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
346 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | |
347 recording_source->SetRequiresClear(true); | |
348 recording_source->SetMinContentsScale(contents_scale); | |
349 recording_source->SetClearCanvasWithDebugColor(false); | |
350 recording_source->Rerecord(); | |
351 | |
352 scoped_refptr<FakePicturePileImpl> pile = | |
353 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
354 gfx::Size content_bounds( | |
355 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | |
356 | |
357 gfx::Rect canvas_rect(content_bounds); | |
358 canvas_rect.Inset(0, 0, -1, -1); | |
359 | |
360 SkBitmap bitmap; | |
361 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | |
362 SkCanvas canvas(bitmap); | |
363 | |
364 pile->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale); | |
365 | |
366 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | |
367 int num_pixels = bitmap.width() * bitmap.height(); | |
368 for (int i = 0; i < num_pixels; ++i) { | |
369 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | |
370 } | |
371 } | |
372 | |
373 class OverlapTest : public ::testing::TestWithParam<float> { | |
374 public: | |
375 static float MinContentsScale() { return 1.f / 4.f; } | |
376 }; | |
377 | |
378 TEST_P(OverlapTest, NoOverlap) { | |
379 gfx::Size tile_size(10, 10); | |
380 gfx::Size layer_bounds(30, 30); | |
381 gfx::Size bigger_than_layer_bounds(300, 300); | |
382 float contents_scale = GetParam(); | |
383 // Pick an opaque color to not have to deal with premultiplication off-by-one. | |
384 SkColor test_color = SkColorSetARGB(255, 45, 56, 67); | |
385 | |
386 scoped_ptr<FakePicturePile> recording_source = | |
387 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
388 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | |
389 recording_source->SetRequiresClear(true); | |
390 recording_source->SetMinContentsScale(MinContentsScale()); | |
391 recording_source->SetClearCanvasWithDebugColor(true); | |
392 | |
393 SkPaint color_paint; | |
394 color_paint.setColor(test_color); | |
395 // Additive paint, so that if two paints overlap, the color will change. | |
396 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); | |
397 // Paint outside the layer to make sure that blending works. | |
398 recording_source->add_draw_rect_with_paint( | |
399 gfx::Rect(bigger_than_layer_bounds), color_paint); | |
400 recording_source->Rerecord(); | |
401 | |
402 scoped_refptr<FakePicturePileImpl> pile = | |
403 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
404 gfx::Size content_bounds( | |
405 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); | |
406 | |
407 SkBitmap bitmap; | |
408 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | |
409 SkCanvas canvas(bitmap); | |
410 | |
411 pile->PlaybackToCanvas(&canvas, gfx::Rect(content_bounds), | |
412 gfx::Rect(content_bounds), contents_scale); | |
413 | |
414 for (int y = 0; y < bitmap.height(); y++) { | |
415 for (int x = 0; x < bitmap.width(); x++) { | |
416 SkColor color = bitmap.getColor(x, y); | |
417 EXPECT_EQ(SkColorGetR(test_color), SkColorGetR(color)) << "x: " << x | |
418 << ", y: " << y; | |
419 EXPECT_EQ(SkColorGetG(test_color), SkColorGetG(color)) << "x: " << x | |
420 << ", y: " << y; | |
421 EXPECT_EQ(SkColorGetB(test_color), SkColorGetB(color)) << "x: " << x | |
422 << ", y: " << y; | |
423 EXPECT_EQ(SkColorGetA(test_color), SkColorGetA(color)) << "x: " << x | |
424 << ", y: " << y; | |
425 if (test_color != color) | |
426 break; | |
427 } | |
428 } | |
429 } | |
430 | |
431 INSTANTIATE_TEST_CASE_P(PicturePileImpl, | |
432 OverlapTest, | |
433 ::testing::Values(1.f, 0.873f, 1.f / 4.f, 4.f)); | |
434 | |
435 TEST(PicturePileImplTest, ImageIteratorBorders) { | |
436 // 3 tile width / 1 tile height pile | |
437 gfx::Size tile_size(128, 128); | |
438 gfx::Size layer_bounds(320, 128); | |
439 | |
440 // Fake picture pile uses a tile grid the size of the tile. So, | |
441 // any iteration that intersects with a tile will return all pixel refs | |
442 // inside of it. | |
443 scoped_ptr<FakePicturePile> recording_source = | |
444 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); | |
445 recording_source->SetMinContentsScale(0.5f); | |
446 | |
447 // Bitmaps 0-2 are exactly on tiles 0-2, so that they overlap the borders | |
448 // of adjacent tiles. | |
449 gfx::Rect bitmap_rects[] = { | |
450 recording_source->tiling().TileBounds(0, 0), | |
451 recording_source->tiling().TileBounds(1, 0), | |
452 recording_source->tiling().TileBounds(2, 0), | |
453 }; | |
454 gfx::RectF expected_rects[] = { | |
455 gfx::RectF(recording_source->tiling().TileBounds(0, 0)), | |
456 gfx::RectF(recording_source->tiling().TileBounds(1, 0)), | |
457 gfx::RectF(recording_source->tiling().TileBounds(2, 0)), | |
458 }; | |
459 skia::RefPtr<SkImage> discardable_image[arraysize(bitmap_rects)]; | |
460 | |
461 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { | |
462 discardable_image[i] = CreateDiscardableImage(bitmap_rects[i].size()); | |
463 recording_source->add_draw_image(discardable_image[i].get(), | |
464 bitmap_rects[i].origin()); | |
465 } | |
466 | |
467 recording_source->SetGatherDiscardableImages(true); | |
468 recording_source->Rerecord(); | |
469 | |
470 scoped_refptr<FakePicturePileImpl> pile = | |
471 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); | |
472 | |
473 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent | |
474 // tiles, but not the actual tiles. | |
475 EXPECT_TRUE( | |
476 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); | |
477 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); | |
478 EXPECT_TRUE( | |
479 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(0, 0))); | |
480 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(0, 0))); | |
481 EXPECT_TRUE( | |
482 bitmap_rects[1].Intersects(pile->tiling().TileBoundsWithBorder(2, 0))); | |
483 EXPECT_FALSE(bitmap_rects[1].Intersects(pile->tiling().TileBounds(2, 0))); | |
484 EXPECT_TRUE( | |
485 bitmap_rects[2].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); | |
486 EXPECT_FALSE(bitmap_rects[2].Intersects(pile->tiling().TileBounds(1, 0))); | |
487 | |
488 // Tile-sized iterators. | |
489 { | |
490 // Because tile 0's borders extend onto tile 1, it will include both | |
491 // image 0 and 1. However, it should *not* include image 2. | |
492 PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(0, 0), | |
493 pile.get()); | |
494 EXPECT_TRUE(iterator); | |
495 EXPECT_TRUE(iterator->image == discardable_image[0].get()); | |
496 EXPECT_EQ(expected_rects[0].ToString(), | |
497 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
498 EXPECT_TRUE(++iterator); | |
499 EXPECT_TRUE(iterator->image == discardable_image[1].get()); | |
500 EXPECT_EQ(expected_rects[1].ToString(), | |
501 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
502 EXPECT_FALSE(++iterator); | |
503 } | |
504 { | |
505 // Tile 1 + borders hits all images. | |
506 PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(1, 0), | |
507 pile.get()); | |
508 EXPECT_TRUE(iterator); | |
509 EXPECT_TRUE(iterator->image == discardable_image[0].get()); | |
510 EXPECT_EQ(expected_rects[0].ToString(), | |
511 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
512 EXPECT_TRUE(++iterator); | |
513 EXPECT_TRUE(iterator->image == discardable_image[1].get()); | |
514 EXPECT_EQ(expected_rects[1].ToString(), | |
515 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
516 EXPECT_TRUE(++iterator); | |
517 EXPECT_TRUE(iterator->image == discardable_image[2].get()); | |
518 EXPECT_EQ(expected_rects[2].ToString(), | |
519 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
520 EXPECT_FALSE(++iterator); | |
521 } | |
522 { | |
523 // Tile 2 should not include image 0, which is only on tile 0 and the | |
524 // borders of tile 1. | |
525 PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(2, 0), | |
526 pile.get()); | |
527 EXPECT_TRUE(iterator); | |
528 EXPECT_TRUE(iterator->image == discardable_image[1].get()); | |
529 EXPECT_EQ(expected_rects[1].ToString(), | |
530 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
531 EXPECT_TRUE(++iterator); | |
532 EXPECT_TRUE(iterator->image == discardable_image[2].get()); | |
533 EXPECT_EQ(expected_rects[2].ToString(), | |
534 gfx::SkRectToRectF(iterator->image_rect).ToString()); | |
535 EXPECT_FALSE(++iterator); | |
536 } | |
537 } | |
538 | |
539 } // namespace | |
540 } // namespace cc | |
OLD | NEW |