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

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

Issue 1045953002: Implement DisplayList GatherPixelRefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix crash w/ unittest Created 5 years, 8 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/display_list_recording_source_unittest.cc ('k') | cc/resources/pixel_ref_map.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 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "cc/test/fake_picture_pile_impl.h" 6 #include "cc/test/fake_picture_pile_impl.h"
7 #include "cc/test/skia_common.h" 7 #include "cc/test/skia_common.h"
8 #include "skia/ext/refptr.h" 8 #include "skia/ext/refptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkPixelRef.h" 10 #include "third_party/skia/include/core/SkPixelRef.h"
(...skipping 14 matching lines...) Expand all
25 SkPaint solid_paint; 25 SkPaint solid_paint;
26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 26 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
27 solid_paint.setColor(solid_color); 27 solid_paint.setColor(solid_color);
28 28
29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 29 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
30 SkPaint non_solid_paint; 30 SkPaint non_solid_paint;
31 non_solid_paint.setColor(non_solid_color); 31 non_solid_paint.setColor(non_solid_color);
32 32
33 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), 33 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
34 solid_paint); 34 solid_paint);
35 recording_source->RerecordPile(); 35 recording_source->Rerecord();
36 36
37 scoped_refptr<FakePicturePileImpl> pile = 37 scoped_refptr<FakePicturePileImpl> pile =
38 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 38 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
39 39
40 // Ensure everything is solid. 40 // Ensure everything is solid.
41 for (int y = 0; y <= 300; y += 100) { 41 for (int y = 0; y <= 300; y += 100) {
42 for (int x = 0; x <= 300; x += 100) { 42 for (int x = 0; x <= 300; x += 100) {
43 RasterSource::SolidColorAnalysis analysis; 43 RasterSource::SolidColorAnalysis analysis;
44 gfx::Rect rect(x, y, 100, 100); 44 gfx::Rect rect(x, y, 100, 100);
45 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis); 45 pile->PerformSolidColorAnalysis(rect, 1.0, &analysis);
46 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); 46 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
47 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); 47 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
48 } 48 }
49 } 49 }
50 50
51 // Add one non-solid pixel and recreate the raster source. 51 // Add one non-solid pixel and recreate the raster source.
52 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 52 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
53 non_solid_paint); 53 non_solid_paint);
54 recording_source->RerecordPile(); 54 recording_source->Rerecord();
55 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 55 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
56 56
57 RasterSource::SolidColorAnalysis analysis; 57 RasterSource::SolidColorAnalysis analysis;
58 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); 58 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis);
59 EXPECT_FALSE(analysis.is_solid_color); 59 EXPECT_FALSE(analysis.is_solid_color);
60 60
61 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); 61 pile->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, &analysis);
62 EXPECT_TRUE(analysis.is_solid_color); 62 EXPECT_TRUE(analysis.is_solid_color);
63 EXPECT_EQ(analysis.solid_color, solid_color); 63 EXPECT_EQ(analysis.solid_color, solid_color);
64 64
(...skipping 25 matching lines...) Expand all
90 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 90 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
91 SkPaint solid_paint; 91 SkPaint solid_paint;
92 solid_paint.setColor(solid_color); 92 solid_paint.setColor(solid_color);
93 93
94 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 94 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
95 SkPaint non_solid_paint; 95 SkPaint non_solid_paint;
96 non_solid_paint.setColor(non_solid_color); 96 non_solid_paint.setColor(non_solid_color);
97 97
98 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), 98 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
99 solid_paint); 99 solid_paint);
100 recording_source->RerecordPile(); 100 recording_source->Rerecord();
101 101
102 scoped_refptr<FakePicturePileImpl> pile = 102 scoped_refptr<FakePicturePileImpl> pile =
103 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 103 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
104 104
105 // Ensure everything is solid. 105 // Ensure everything is solid.
106 for (int y = 0; y <= 30; y += 10) { 106 for (int y = 0; y <= 30; y += 10) {
107 for (int x = 0; x <= 30; x += 10) { 107 for (int x = 0; x <= 30; x += 10) {
108 RasterSource::SolidColorAnalysis analysis; 108 RasterSource::SolidColorAnalysis analysis;
109 gfx::Rect rect(x, y, 10, 10); 109 gfx::Rect rect(x, y, 10, 10);
110 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis); 110 pile->PerformSolidColorAnalysis(rect, 0.1f, &analysis);
111 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); 111 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
112 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); 112 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
113 } 113 }
114 } 114 }
115 115
116 // Add one non-solid pixel and recreate the raster source. 116 // Add one non-solid pixel and recreate the raster source.
117 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 117 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
118 non_solid_paint); 118 non_solid_paint);
119 recording_source->RerecordPile(); 119 recording_source->Rerecord();
120 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 120 pile = FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
121 121
122 RasterSource::SolidColorAnalysis analysis; 122 RasterSource::SolidColorAnalysis analysis;
123 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); 123 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis);
124 EXPECT_FALSE(analysis.is_solid_color); 124 EXPECT_FALSE(analysis.is_solid_color);
125 125
126 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); 126 pile->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis);
127 EXPECT_TRUE(analysis.is_solid_color); 127 EXPECT_TRUE(analysis.is_solid_color);
128 EXPECT_EQ(analysis.solid_color, solid_color); 128 EXPECT_EQ(analysis.solid_color, solid_color);
129 129
(...skipping 22 matching lines...) Expand all
152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 152 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
153 RasterSource::SolidColorAnalysis analysis; 153 RasterSource::SolidColorAnalysis analysis;
154 EXPECT_FALSE(analysis.is_solid_color); 154 EXPECT_FALSE(analysis.is_solid_color);
155 155
156 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); 156 pile->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis);
157 157
158 EXPECT_TRUE(analysis.is_solid_color); 158 EXPECT_TRUE(analysis.is_solid_color);
159 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); 159 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0));
160 } 160 }
161 161
162 TEST(PicturePileImplTest, PixelRefIteratorEmpty) {
163 gfx::Size tile_size(128, 128);
164 gfx::Size layer_bounds(256, 256);
165
166 // Create a filled pile with no recording.
167 scoped_refptr<FakePicturePileImpl> pile =
168 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
169
170 // Tile sized iterators.
171 {
172 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 1.0,
173 pile.get());
174 EXPECT_FALSE(iterator);
175 }
176 {
177 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 2.0,
178 pile.get());
179 EXPECT_FALSE(iterator);
180 }
181 {
182 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 64, 64), 0.5,
183 pile.get());
184 EXPECT_FALSE(iterator);
185 }
186 // Shifted tile sized iterators.
187 {
188 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(140, 140, 128, 128),
189 1.0, pile.get());
190 EXPECT_FALSE(iterator);
191 }
192 {
193 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(280, 280, 256, 256),
194 2.0, pile.get());
195 EXPECT_FALSE(iterator);
196 }
197 {
198 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(70, 70, 64, 64), 0.5,
199 pile.get());
200 EXPECT_FALSE(iterator);
201 }
202 // Layer sized iterators.
203 {
204 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 1.0,
205 pile.get());
206 EXPECT_FALSE(iterator);
207 }
208 {
209 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 2.0,
210 pile.get());
211 EXPECT_FALSE(iterator);
212 }
213 {
214 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 0.5,
215 pile.get());
216 EXPECT_FALSE(iterator);
217 }
218 }
219
220 TEST(PicturePileImplTest, PixelRefIteratorNoDiscardableRefs) {
221 gfx::Size tile_size(128, 128);
222 gfx::Size layer_bounds(256, 256);
223
224 scoped_ptr<FakePicturePile> recording_source =
225 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
226 SkPaint simple_paint;
227 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
228
229 SkBitmap non_discardable_bitmap;
230 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap);
231
232 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256),
233 simple_paint);
234 recording_source->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512),
235 simple_paint);
236 recording_source->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256),
237 simple_paint);
238 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256),
239 simple_paint);
240 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0));
241 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128));
242 recording_source->add_draw_bitmap(non_discardable_bitmap,
243 gfx::Point(150, 150));
244 recording_source->RerecordPile();
245
246 scoped_refptr<FakePicturePileImpl> pile =
247 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
248
249 // Tile sized iterators.
250 {
251 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 1.0,
252 pile.get());
253 EXPECT_FALSE(iterator);
254 }
255 {
256 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 2.0,
257 pile.get());
258 EXPECT_FALSE(iterator);
259 }
260 {
261 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 64, 64), 0.5,
262 pile.get());
263 EXPECT_FALSE(iterator);
264 }
265 // Shifted tile sized iterators.
266 {
267 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(140, 140, 128, 128),
268 1.0, pile.get());
269 EXPECT_FALSE(iterator);
270 }
271 {
272 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(280, 280, 256, 256),
273 2.0, pile.get());
274 EXPECT_FALSE(iterator);
275 }
276 {
277 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(70, 70, 64, 64), 0.5,
278 pile.get());
279 EXPECT_FALSE(iterator);
280 }
281 // Layer sized iterators.
282 {
283 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 1.0,
284 pile.get());
285 EXPECT_FALSE(iterator);
286 }
287 {
288 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 2.0,
289 pile.get());
290 EXPECT_FALSE(iterator);
291 }
292 {
293 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 0.5,
294 pile.get());
295 EXPECT_FALSE(iterator);
296 }
297 }
298
299 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) {
300 gfx::Size tile_size(128, 128);
301 gfx::Size layer_bounds(256, 256);
302
303 scoped_ptr<FakePicturePile> recording_source =
304 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
305
306 SkBitmap discardable_bitmap[2][2];
307 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
308 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]);
309 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
310
311 // Discardable pixel refs are found in the following cells:
312 // |---|---|
313 // | x | |
314 // |---|---|
315 // | x | x |
316 // |---|---|
317 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
318 recording_source->add_draw_bitmap(discardable_bitmap[1][0],
319 gfx::Point(0, 130));
320 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
321 gfx::Point(140, 140));
322 recording_source->RerecordPile();
323
324 scoped_refptr<FakePicturePileImpl> pile =
325 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
326
327 // Tile sized iterators. These should find only one pixel ref.
328 {
329 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 1.0,
330 pile.get());
331 EXPECT_TRUE(iterator);
332 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
333 EXPECT_FALSE(++iterator);
334 }
335 {
336 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 2.0,
337 pile.get());
338 EXPECT_TRUE(iterator);
339 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
340 EXPECT_FALSE(++iterator);
341 }
342 {
343 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 64, 64), 0.5,
344 pile.get());
345 EXPECT_TRUE(iterator);
346 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
347 EXPECT_FALSE(++iterator);
348 }
349 // Shifted tile sized iterators. These should find only one pixel ref.
350 {
351 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(140, 140, 128, 128),
352 1.0, pile.get());
353 EXPECT_TRUE(iterator);
354 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
355 EXPECT_FALSE(++iterator);
356 }
357 {
358 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(280, 280, 256, 256),
359 2.0, pile.get());
360 EXPECT_TRUE(iterator);
361 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
362 EXPECT_FALSE(++iterator);
363 }
364 {
365 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(70, 70, 64, 64), 0.5,
366 pile.get());
367 EXPECT_TRUE(iterator);
368 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
369 EXPECT_FALSE(++iterator);
370 }
371 // Ensure there's no discardable pixel refs in the empty cell
372 {
373 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(140, 0, 128, 128), 1.0,
374 pile.get());
375 EXPECT_FALSE(iterator);
376 }
377 // Layer sized iterators. These should find all 3 pixel refs.
378 {
379 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 1.0,
380 pile.get());
381 EXPECT_TRUE(iterator);
382 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
383 EXPECT_TRUE(++iterator);
384 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
385 EXPECT_TRUE(++iterator);
386 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
387 EXPECT_FALSE(++iterator);
388 }
389 {
390 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 2.0,
391 pile.get());
392 EXPECT_TRUE(iterator);
393 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
394 EXPECT_TRUE(++iterator);
395 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
396 EXPECT_TRUE(++iterator);
397 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
398 EXPECT_FALSE(++iterator);
399 }
400 {
401 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 0.5,
402 pile.get());
403 EXPECT_TRUE(iterator);
404 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
405 EXPECT_TRUE(++iterator);
406 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef());
407 EXPECT_TRUE(++iterator);
408 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
409 EXPECT_FALSE(++iterator);
410 }
411 }
412
413 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { 162 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) {
414 gfx::Size tile_size(256, 256); 163 gfx::Size tile_size(256, 256);
415 gfx::Size layer_bounds(512, 512); 164 gfx::Size layer_bounds(512, 512);
416 165
417 scoped_ptr<FakePicturePile> recording_source = 166 scoped_ptr<FakePicturePile> recording_source =
418 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); 167 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
419 168
420 SkBitmap discardable_bitmap[2][2]; 169 SkBitmap discardable_bitmap[2][2];
421 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); 170 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]);
422 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); 171 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]);
423 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); 172 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]);
424 173
425 // Discardable pixel refs are found in the following cells: 174 // Discardable pixel refs are found in the following cells:
426 // |---|---| 175 // |---|---|
427 // | x | x | 176 // | x | x |
428 // |---|---| 177 // |---|---|
429 // | | x | 178 // | | x |
430 // |---|---| 179 // |---|---|
431 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); 180 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
432 recording_source->add_draw_bitmap(discardable_bitmap[0][1], 181 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
433 gfx::Point(260, 0)); 182 gfx::Point(260, 0));
434 recording_source->add_draw_bitmap(discardable_bitmap[1][1], 183 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
435 gfx::Point(260, 260)); 184 gfx::Point(260, 260));
436 recording_source->RerecordPile(); 185 recording_source->SetGatherPixelRefs(true);
186 recording_source->Rerecord();
437 187
438 scoped_refptr<FakePicturePileImpl> pile = 188 scoped_refptr<FakePicturePileImpl> pile =
439 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 189 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
440 190
441 // Tile sized iterators. These should find only one pixel ref. 191 // Tile sized iterators. These should find only one pixel ref.
442 { 192 {
443 PicturePileImpl::PixelRefIterator iterator( 193 PicturePileImpl::PixelRefIterator iterator(
444 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); 194 gfx::Rect(0, 0, 256, 256), 1.0, pile.get());
445 EXPECT_TRUE(iterator); 195 EXPECT_TRUE(iterator);
446 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); 196 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); 288 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
539 EXPECT_FALSE(++iterator); 289 EXPECT_FALSE(++iterator);
540 290
541 EXPECT_TRUE(copy); 291 EXPECT_TRUE(copy);
542 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); 292 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef());
543 EXPECT_TRUE(++copy); 293 EXPECT_TRUE(++copy);
544 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); 294 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef());
545 EXPECT_FALSE(++copy); 295 EXPECT_FALSE(++copy);
546 } 296 }
547 297
548 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) {
549 gfx::Size tile_size(256, 256);
550 gfx::Size layer_bounds(512, 512);
551
552 scoped_ptr<FakePicturePile> recording_source =
553 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
554
555 SkBitmap non_discardable_bitmap;
556 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap);
557
558 SkBitmap discardable_bitmap[2][2];
559 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]);
560 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]);
561 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]);
562
563 // One large non-discardable bitmap covers the whole grid.
564 // Discardable pixel refs are found in the following cells:
565 // |---|---|
566 // | x | x |
567 // |---|---|
568 // | | x |
569 // |---|---|
570 recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0));
571 recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0));
572 recording_source->add_draw_bitmap(discardable_bitmap[0][1],
573 gfx::Point(260, 0));
574 recording_source->add_draw_bitmap(discardable_bitmap[1][1],
575 gfx::Point(260, 260));
576 recording_source->RerecordPile();
577
578 scoped_refptr<FakePicturePileImpl> pile =
579 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
580
581 // Tile sized iterators. These should find only one pixel ref.
582 {
583 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 1.0,
584 pile.get());
585 EXPECT_TRUE(iterator);
586 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
587 EXPECT_FALSE(++iterator);
588 }
589 {
590 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 2.0,
591 pile.get());
592 EXPECT_TRUE(iterator);
593 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
594 EXPECT_FALSE(++iterator);
595 }
596 {
597 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 128, 128), 0.5,
598 pile.get());
599 EXPECT_TRUE(iterator);
600 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
601 EXPECT_FALSE(++iterator);
602 }
603 // Shifted tile sized iterators. These should find only one pixel ref.
604 {
605 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(260, 260, 256, 256),
606 1.0, pile.get());
607 EXPECT_TRUE(iterator);
608 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
609 EXPECT_FALSE(++iterator);
610 }
611 {
612 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(520, 520, 512, 512),
613 2.0, pile.get());
614 EXPECT_TRUE(iterator);
615 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
616 EXPECT_FALSE(++iterator);
617 }
618 {
619 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(130, 130, 128, 128),
620 0.5, pile.get());
621 EXPECT_TRUE(iterator);
622 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
623 EXPECT_FALSE(++iterator);
624 }
625 // Ensure there's no discardable pixel refs in the empty cell
626 {
627 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 256, 256, 256), 1.0,
628 pile.get());
629 EXPECT_FALSE(iterator);
630 }
631 // Layer sized iterators. These should find three pixel ref.
632 {
633 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), 1.0,
634 pile.get());
635 EXPECT_TRUE(iterator);
636 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
637 EXPECT_TRUE(++iterator);
638 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
639 EXPECT_TRUE(++iterator);
640 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
641 EXPECT_FALSE(++iterator);
642 }
643 {
644 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 1024, 1024), 2.0,
645 pile.get());
646 EXPECT_TRUE(iterator);
647 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
648 EXPECT_TRUE(++iterator);
649 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
650 EXPECT_TRUE(++iterator);
651 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
652 EXPECT_FALSE(++iterator);
653 }
654 {
655 PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), 0.5,
656 pile.get());
657 EXPECT_TRUE(iterator);
658 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef());
659 EXPECT_TRUE(++iterator);
660 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef());
661 EXPECT_TRUE(++iterator);
662 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef());
663 EXPECT_FALSE(++iterator);
664 }
665 }
666
667 TEST(PicturePileImplTest, RasterFullContents) { 298 TEST(PicturePileImplTest, RasterFullContents) {
668 gfx::Size tile_size(1000, 1000); 299 gfx::Size tile_size(1000, 1000);
669 gfx::Size layer_bounds(3, 5); 300 gfx::Size layer_bounds(3, 5);
670 float contents_scale = 1.5f; 301 float contents_scale = 1.5f;
671 float raster_divisions = 2.f; 302 float raster_divisions = 2.f;
672 303
673 scoped_ptr<FakePicturePile> recording_source = 304 scoped_ptr<FakePicturePile> recording_source =
674 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); 305 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
675 recording_source->SetBackgroundColor(SK_ColorBLACK); 306 recording_source->SetBackgroundColor(SK_ColorBLACK);
676 recording_source->SetIsSolidColor(false); 307 recording_source->SetIsSolidColor(false);
677 recording_source->SetRequiresClear(false); 308 recording_source->SetRequiresClear(false);
678 recording_source->SetClearCanvasWithDebugColor(false); 309 recording_source->SetClearCanvasWithDebugColor(false);
679 310
680 // Because the caller sets content opaque, it also promises that it 311 // Because the caller sets content opaque, it also promises that it
681 // has at least filled in layer_bounds opaquely. 312 // has at least filled in layer_bounds opaquely.
682 SkPaint white_paint; 313 SkPaint white_paint;
683 white_paint.setColor(SK_ColorWHITE); 314 white_paint.setColor(SK_ColorWHITE);
684 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 315 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
685 white_paint); 316 white_paint);
686 317
687 recording_source->SetMinContentsScale(contents_scale); 318 recording_source->SetMinContentsScale(contents_scale);
688 recording_source->RerecordPile(); 319 recording_source->Rerecord();
689 320
690 scoped_refptr<FakePicturePileImpl> pile = 321 scoped_refptr<FakePicturePileImpl> pile =
691 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 322 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
692 323
693 gfx::Size content_bounds( 324 gfx::Size content_bounds(
694 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 325 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
695 326
696 // Simulate drawing into different tiles at different offsets. 327 // Simulate drawing into different tiles at different offsets.
697 int step_x = std::ceil(content_bounds.width() / raster_divisions); 328 int step_x = std::ceil(content_bounds.width() / raster_divisions);
698 int step_y = std::ceil(content_bounds.height() / raster_divisions); 329 int step_y = std::ceil(content_bounds.height() / raster_divisions);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 gfx::Size tile_size(1000, 1000); 369 gfx::Size tile_size(1000, 1000);
739 gfx::Size layer_bounds(5, 3); 370 gfx::Size layer_bounds(5, 3);
740 float contents_scale = 0.5f; 371 float contents_scale = 0.5f;
741 372
742 scoped_ptr<FakePicturePile> recording_source = 373 scoped_ptr<FakePicturePile> recording_source =
743 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); 374 FakePicturePile::CreateFilledPile(tile_size, layer_bounds);
744 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); 375 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
745 recording_source->SetRequiresClear(true); 376 recording_source->SetRequiresClear(true);
746 recording_source->SetMinContentsScale(contents_scale); 377 recording_source->SetMinContentsScale(contents_scale);
747 recording_source->SetClearCanvasWithDebugColor(false); 378 recording_source->SetClearCanvasWithDebugColor(false);
748 recording_source->RerecordPile(); 379 recording_source->Rerecord();
749 380
750 scoped_refptr<FakePicturePileImpl> pile = 381 scoped_refptr<FakePicturePileImpl> pile =
751 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 382 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
752 gfx::Size content_bounds( 383 gfx::Size content_bounds(
753 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 384 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
754 385
755 gfx::Rect canvas_rect(content_bounds); 386 gfx::Rect canvas_rect(content_bounds);
756 canvas_rect.Inset(0, 0, -1, -1); 387 canvas_rect.Inset(0, 0, -1, -1);
757 388
758 SkBitmap bitmap; 389 SkBitmap bitmap;
(...skipping 29 matching lines...) Expand all
788 recording_source->SetMinContentsScale(MinContentsScale()); 419 recording_source->SetMinContentsScale(MinContentsScale());
789 recording_source->SetClearCanvasWithDebugColor(true); 420 recording_source->SetClearCanvasWithDebugColor(true);
790 421
791 SkPaint color_paint; 422 SkPaint color_paint;
792 color_paint.setColor(test_color); 423 color_paint.setColor(test_color);
793 // Additive paint, so that if two paints overlap, the color will change. 424 // Additive paint, so that if two paints overlap, the color will change.
794 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode); 425 color_paint.setXfermodeMode(SkXfermode::kPlus_Mode);
795 // Paint outside the layer to make sure that blending works. 426 // Paint outside the layer to make sure that blending works.
796 recording_source->add_draw_rect_with_paint( 427 recording_source->add_draw_rect_with_paint(
797 gfx::RectF(bigger_than_layer_bounds), color_paint); 428 gfx::RectF(bigger_than_layer_bounds), color_paint);
798 recording_source->RerecordPile(); 429 recording_source->Rerecord();
799 430
800 scoped_refptr<FakePicturePileImpl> pile = 431 scoped_refptr<FakePicturePileImpl> pile =
801 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 432 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
802 gfx::Size content_bounds( 433 gfx::Size content_bounds(
803 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale))); 434 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
804 435
805 SkBitmap bitmap; 436 SkBitmap bitmap;
806 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); 437 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
807 SkCanvas canvas(bitmap); 438 SkCanvas canvas(bitmap);
808 439
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 recording_source->tiling().TileBounds(2, 0), 480 recording_source->tiling().TileBounds(2, 0),
850 }; 481 };
851 SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; 482 SkBitmap discardable_bitmap[arraysize(bitmap_rects)];
852 483
853 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { 484 for (size_t i = 0; i < arraysize(bitmap_rects); ++i) {
854 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]); 485 CreateBitmap(bitmap_rects[i].size(), "discardable", &discardable_bitmap[i]);
855 recording_source->add_draw_bitmap(discardable_bitmap[i], 486 recording_source->add_draw_bitmap(discardable_bitmap[i],
856 bitmap_rects[i].origin()); 487 bitmap_rects[i].origin());
857 } 488 }
858 489
859 recording_source->RerecordPile(); 490 recording_source->SetGatherPixelRefs(true);
491 recording_source->Rerecord();
860 492
861 scoped_refptr<FakePicturePileImpl> pile = 493 scoped_refptr<FakePicturePileImpl> pile =
862 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr); 494 FakePicturePileImpl::CreateFromPile(recording_source.get(), nullptr);
863 495
864 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent 496 // Sanity check that bitmaps 0-2 intersect the borders of their adjacent
865 // tiles, but not the actual tiles. 497 // tiles, but not the actual tiles.
866 EXPECT_TRUE( 498 EXPECT_TRUE(
867 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0))); 499 bitmap_rects[0].Intersects(pile->tiling().TileBoundsWithBorder(1, 0)));
868 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0))); 500 EXPECT_FALSE(bitmap_rects[0].Intersects(pile->tiling().TileBounds(1, 0)));
869 EXPECT_TRUE( 501 EXPECT_TRUE(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 EXPECT_TRUE(iterator); 540 EXPECT_TRUE(iterator);
909 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef()); 541 EXPECT_TRUE(*iterator == discardable_bitmap[1].pixelRef());
910 EXPECT_TRUE(++iterator); 542 EXPECT_TRUE(++iterator);
911 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef()); 543 EXPECT_TRUE(*iterator == discardable_bitmap[2].pixelRef());
912 EXPECT_FALSE(++iterator); 544 EXPECT_FALSE(++iterator);
913 } 545 }
914 } 546 }
915 547
916 } // namespace 548 } // namespace
917 } // namespace cc 549 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_list_recording_source_unittest.cc ('k') | cc/resources/pixel_ref_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698