OLD | NEW |
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/fake_rendering_stats_instrumentation.h" | 7 #include "cc/test/fake_rendering_stats_instrumentation.h" |
8 #include "cc/test/skia_common.h" | 8 #include "cc/test/skia_common.h" |
9 #include "skia/ext/lazy_pixel_ref.h" | |
10 #include "skia/ext/refptr.h" | 9 #include "skia/ext/refptr.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/skia/include/core/SkPixelRef.h" | 11 #include "third_party/skia/include/core/SkPixelRef.h" |
13 #include "third_party/skia/include/core/SkShader.h" | 12 #include "third_party/skia/include/core/SkShader.h" |
14 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
16 | 15 |
17 namespace cc { | 16 namespace cc { |
18 namespace { | 17 namespace { |
19 | 18 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); | 198 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
200 EXPECT_FALSE(iterator); | 199 EXPECT_FALSE(iterator); |
201 } | 200 } |
202 { | 201 { |
203 PicturePileImpl::PixelRefIterator iterator( | 202 PicturePileImpl::PixelRefIterator iterator( |
204 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); | 203 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
205 EXPECT_FALSE(iterator); | 204 EXPECT_FALSE(iterator); |
206 } | 205 } |
207 } | 206 } |
208 | 207 |
209 TEST(PicturePileImplTest, PixelRefIteratorNoLazyRefs) { | 208 TEST(PicturePileImplTest, PixelRefIteratorNoDiscardableRefs) { |
210 gfx::Size tile_size(128, 128); | 209 gfx::Size tile_size(128, 128); |
211 gfx::Size layer_bounds(256, 256); | 210 gfx::Size layer_bounds(256, 256); |
212 | 211 |
213 scoped_refptr<FakePicturePileImpl> pile = | 212 scoped_refptr<FakePicturePileImpl> pile = |
214 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 213 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
215 | 214 |
216 SkPaint simple_paint; | 215 SkPaint simple_paint; |
217 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); | 216 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
218 | 217 |
219 SkBitmap non_lazy_bitmap; | 218 SkBitmap non_discardable_bitmap; |
220 CreateBitmap(gfx::Size(128, 128), "notlazy", &non_lazy_bitmap); | 219 CreateBitmap(gfx::Size(128, 128), "notdiscardable", &non_discardable_bitmap); |
221 | 220 |
222 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); | 221 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); |
223 pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint); | 222 pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint); |
224 pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint); | 223 pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint); |
225 pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); | 224 pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); |
226 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(128, 0)); | 225 pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0)); |
227 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128)); | 226 pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128)); |
228 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150)); | 227 pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(150, 150)); |
229 | 228 |
230 pile->RerecordPile(); | 229 pile->RerecordPile(); |
231 | 230 |
232 // Tile sized iterators. | 231 // Tile sized iterators. |
233 { | 232 { |
234 PicturePileImpl::PixelRefIterator iterator( | 233 PicturePileImpl::PixelRefIterator iterator( |
235 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); | 234 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); |
236 EXPECT_FALSE(iterator); | 235 EXPECT_FALSE(iterator); |
237 } | 236 } |
238 { | 237 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); | 271 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
273 EXPECT_FALSE(iterator); | 272 EXPECT_FALSE(iterator); |
274 } | 273 } |
275 { | 274 { |
276 PicturePileImpl::PixelRefIterator iterator( | 275 PicturePileImpl::PixelRefIterator iterator( |
277 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); | 276 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
278 EXPECT_FALSE(iterator); | 277 EXPECT_FALSE(iterator); |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 TEST(PicturePileImplTest, PixelRefIteratorLazyRefs) { | 281 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefs) { |
283 gfx::Size tile_size(128, 128); | 282 gfx::Size tile_size(128, 128); |
284 gfx::Size layer_bounds(256, 256); | 283 gfx::Size layer_bounds(256, 256); |
285 | 284 |
286 scoped_refptr<FakePicturePileImpl> pile = | 285 scoped_refptr<FakePicturePileImpl> pile = |
287 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 286 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
288 | 287 |
289 SkBitmap lazy_bitmap[2][2]; | 288 SkBitmap discardable_bitmap[2][2]; |
290 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); | 289 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
291 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][0]); | 290 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][0]); |
292 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); | 291 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
293 | 292 |
294 // Lazy pixel refs are found in the following cells: | 293 // Discardable pixel refs are found in the following cells: |
295 // |---|---| | 294 // |---|---| |
296 // | x | | | 295 // | x | | |
297 // |---|---| | 296 // |---|---| |
298 // | x | x | | 297 // | x | x | |
299 // |---|---| | 298 // |---|---| |
300 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 299 pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
301 pile->add_draw_bitmap(lazy_bitmap[1][0], gfx::Point(0, 130)); | 300 pile->add_draw_bitmap(discardable_bitmap[1][0], gfx::Point(0, 130)); |
302 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(140, 140)); | 301 pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(140, 140)); |
303 | 302 |
304 pile->RerecordPile(); | 303 pile->RerecordPile(); |
305 | 304 |
306 // Tile sized iterators. These should find only one pixel ref. | 305 // Tile sized iterators. These should find only one pixel ref. |
307 { | 306 { |
308 PicturePileImpl::PixelRefIterator iterator( | 307 PicturePileImpl::PixelRefIterator iterator( |
309 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); | 308 gfx::Rect(0, 0, 128, 128), 1.0, pile.get()); |
310 EXPECT_TRUE(iterator); | 309 EXPECT_TRUE(iterator); |
311 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 310 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
312 EXPECT_FALSE(++iterator); | 311 EXPECT_FALSE(++iterator); |
313 } | 312 } |
314 { | 313 { |
315 PicturePileImpl::PixelRefIterator iterator( | 314 PicturePileImpl::PixelRefIterator iterator( |
316 gfx::Rect(0, 0, 256, 256), 2.0, pile.get()); | 315 gfx::Rect(0, 0, 256, 256), 2.0, pile.get()); |
317 EXPECT_TRUE(iterator); | 316 EXPECT_TRUE(iterator); |
318 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 317 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
319 EXPECT_FALSE(++iterator); | 318 EXPECT_FALSE(++iterator); |
320 } | 319 } |
321 { | 320 { |
322 PicturePileImpl::PixelRefIterator iterator( | 321 PicturePileImpl::PixelRefIterator iterator( |
323 gfx::Rect(0, 0, 64, 64), 0.5, pile.get()); | 322 gfx::Rect(0, 0, 64, 64), 0.5, pile.get()); |
324 EXPECT_TRUE(iterator); | 323 EXPECT_TRUE(iterator); |
325 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 324 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
326 EXPECT_FALSE(++iterator); | 325 EXPECT_FALSE(++iterator); |
327 } | 326 } |
328 // Shifted tile sized iterators. These should find only one pixel ref. | 327 // Shifted tile sized iterators. These should find only one pixel ref. |
329 { | 328 { |
330 PicturePileImpl::PixelRefIterator iterator( | 329 PicturePileImpl::PixelRefIterator iterator( |
331 gfx::Rect(140, 140, 128, 128), 1.0, pile.get()); | 330 gfx::Rect(140, 140, 128, 128), 1.0, pile.get()); |
332 EXPECT_TRUE(iterator); | 331 EXPECT_TRUE(iterator); |
333 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 332 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
334 EXPECT_FALSE(++iterator); | 333 EXPECT_FALSE(++iterator); |
335 } | 334 } |
336 { | 335 { |
337 PicturePileImpl::PixelRefIterator iterator( | 336 PicturePileImpl::PixelRefIterator iterator( |
338 gfx::Rect(280, 280, 256, 256), 2.0, pile.get()); | 337 gfx::Rect(280, 280, 256, 256), 2.0, pile.get()); |
339 EXPECT_TRUE(iterator); | 338 EXPECT_TRUE(iterator); |
340 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 339 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
341 EXPECT_FALSE(++iterator); | 340 EXPECT_FALSE(++iterator); |
342 } | 341 } |
343 { | 342 { |
344 PicturePileImpl::PixelRefIterator iterator( | 343 PicturePileImpl::PixelRefIterator iterator( |
345 gfx::Rect(70, 70, 64, 64), 0.5, pile.get()); | 344 gfx::Rect(70, 70, 64, 64), 0.5, pile.get()); |
346 EXPECT_TRUE(iterator); | 345 EXPECT_TRUE(iterator); |
347 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 346 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
348 EXPECT_FALSE(++iterator); | 347 EXPECT_FALSE(++iterator); |
349 } | 348 } |
350 // Ensure there's no lazy pixel refs in the empty cell | 349 // Ensure there's no discardable pixel refs in the empty cell |
351 { | 350 { |
352 PicturePileImpl::PixelRefIterator iterator( | 351 PicturePileImpl::PixelRefIterator iterator( |
353 gfx::Rect(140, 0, 128, 128), 1.0, pile.get()); | 352 gfx::Rect(140, 0, 128, 128), 1.0, pile.get()); |
354 EXPECT_FALSE(iterator); | 353 EXPECT_FALSE(iterator); |
355 } | 354 } |
356 // Layer sized iterators. These should find all 3 pixel refs. | 355 // Layer sized iterators. These should find all 3 pixel refs. |
357 { | 356 { |
358 PicturePileImpl::PixelRefIterator iterator( | 357 PicturePileImpl::PixelRefIterator iterator( |
359 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); | 358 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
360 EXPECT_TRUE(iterator); | 359 EXPECT_TRUE(iterator); |
361 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 360 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
362 EXPECT_TRUE(++iterator); | 361 EXPECT_TRUE(++iterator); |
363 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); | 362 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
364 EXPECT_TRUE(++iterator); | 363 EXPECT_TRUE(++iterator); |
365 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 364 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
366 EXPECT_FALSE(++iterator); | 365 EXPECT_FALSE(++iterator); |
367 } | 366 } |
368 { | 367 { |
369 PicturePileImpl::PixelRefIterator iterator( | 368 PicturePileImpl::PixelRefIterator iterator( |
370 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); | 369 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
371 EXPECT_TRUE(iterator); | 370 EXPECT_TRUE(iterator); |
372 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 371 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
373 EXPECT_TRUE(++iterator); | 372 EXPECT_TRUE(++iterator); |
374 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); | 373 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
375 EXPECT_TRUE(++iterator); | 374 EXPECT_TRUE(++iterator); |
376 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 375 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
377 EXPECT_FALSE(++iterator); | 376 EXPECT_FALSE(++iterator); |
378 } | 377 } |
379 { | 378 { |
380 PicturePileImpl::PixelRefIterator iterator( | 379 PicturePileImpl::PixelRefIterator iterator( |
381 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); | 380 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
382 EXPECT_TRUE(iterator); | 381 EXPECT_TRUE(iterator); |
383 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 382 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
384 EXPECT_TRUE(++iterator); | 383 EXPECT_TRUE(++iterator); |
385 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); | 384 EXPECT_TRUE(*iterator == discardable_bitmap[1][0].pixelRef()); |
386 EXPECT_TRUE(++iterator); | 385 EXPECT_TRUE(++iterator); |
387 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 386 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
388 EXPECT_FALSE(++iterator); | 387 EXPECT_FALSE(++iterator); |
389 } | 388 } |
390 } | 389 } |
391 | 390 |
392 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsOneTile) { | 391 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { |
393 gfx::Size tile_size(256, 256); | 392 gfx::Size tile_size(256, 256); |
394 gfx::Size layer_bounds(512, 512); | 393 gfx::Size layer_bounds(512, 512); |
395 | 394 |
396 scoped_refptr<FakePicturePileImpl> pile = | 395 scoped_refptr<FakePicturePileImpl> pile = |
397 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 396 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
398 | 397 |
399 SkBitmap lazy_bitmap[2][2]; | 398 SkBitmap discardable_bitmap[2][2]; |
400 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); | 399 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][0]); |
401 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][1]); | 400 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[0][1]); |
402 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); | 401 CreateBitmap(gfx::Size(32, 32), "discardable", &discardable_bitmap[1][1]); |
403 | 402 |
404 // Lazy pixel refs are found in the following cells: | 403 // Discardable pixel refs are found in the following cells: |
405 // |---|---| | 404 // |---|---| |
406 // | x | x | | 405 // | x | x | |
407 // |---|---| | 406 // |---|---| |
408 // | | x | | 407 // | | x | |
409 // |---|---| | 408 // |---|---| |
410 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 409 pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
411 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); | 410 pile->add_draw_bitmap(discardable_bitmap[0][1], gfx::Point(260, 0)); |
412 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); | 411 pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(260, 260)); |
413 | 412 |
414 pile->RerecordPile(); | 413 pile->RerecordPile(); |
415 | 414 |
416 // Tile sized iterators. These should find only one pixel ref. | 415 // Tile sized iterators. These should find only one pixel ref. |
417 { | 416 { |
418 PicturePileImpl::PixelRefIterator iterator( | 417 PicturePileImpl::PixelRefIterator iterator( |
419 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); | 418 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
420 EXPECT_TRUE(iterator); | 419 EXPECT_TRUE(iterator); |
421 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 420 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
422 EXPECT_FALSE(++iterator); | 421 EXPECT_FALSE(++iterator); |
423 } | 422 } |
424 { | 423 { |
425 PicturePileImpl::PixelRefIterator iterator( | 424 PicturePileImpl::PixelRefIterator iterator( |
426 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); | 425 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
427 EXPECT_TRUE(iterator); | 426 EXPECT_TRUE(iterator); |
428 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 427 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
429 EXPECT_FALSE(++iterator); | 428 EXPECT_FALSE(++iterator); |
430 } | 429 } |
431 { | 430 { |
432 PicturePileImpl::PixelRefIterator iterator( | 431 PicturePileImpl::PixelRefIterator iterator( |
433 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); | 432 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
434 EXPECT_TRUE(iterator); | 433 EXPECT_TRUE(iterator); |
435 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 434 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
436 EXPECT_FALSE(++iterator); | 435 EXPECT_FALSE(++iterator); |
437 } | 436 } |
438 // Shifted tile sized iterators. These should find only one pixel ref. | 437 // Shifted tile sized iterators. These should find only one pixel ref. |
439 { | 438 { |
440 PicturePileImpl::PixelRefIterator iterator( | 439 PicturePileImpl::PixelRefIterator iterator( |
441 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); | 440 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); |
442 EXPECT_TRUE(iterator); | 441 EXPECT_TRUE(iterator); |
443 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 442 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
444 EXPECT_FALSE(++iterator); | 443 EXPECT_FALSE(++iterator); |
445 } | 444 } |
446 { | 445 { |
447 PicturePileImpl::PixelRefIterator iterator( | 446 PicturePileImpl::PixelRefIterator iterator( |
448 gfx::Rect(520, 520, 512, 512), 2.0, pile.get()); | 447 gfx::Rect(520, 520, 512, 512), 2.0, pile.get()); |
449 EXPECT_TRUE(iterator); | 448 EXPECT_TRUE(iterator); |
450 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 449 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
451 EXPECT_FALSE(++iterator); | 450 EXPECT_FALSE(++iterator); |
452 } | 451 } |
453 { | 452 { |
454 PicturePileImpl::PixelRefIterator iterator( | 453 PicturePileImpl::PixelRefIterator iterator( |
455 gfx::Rect(130, 130, 128, 128), 0.5, pile.get()); | 454 gfx::Rect(130, 130, 128, 128), 0.5, pile.get()); |
456 EXPECT_TRUE(iterator); | 455 EXPECT_TRUE(iterator); |
457 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 456 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
458 EXPECT_FALSE(++iterator); | 457 EXPECT_FALSE(++iterator); |
459 } | 458 } |
460 // Ensure there's no lazy pixel refs in the empty cell | 459 // Ensure there's no discardable pixel refs in the empty cell |
461 { | 460 { |
462 PicturePileImpl::PixelRefIterator iterator( | 461 PicturePileImpl::PixelRefIterator iterator( |
463 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); | 462 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); |
464 EXPECT_FALSE(iterator); | 463 EXPECT_FALSE(iterator); |
465 } | 464 } |
466 // Layer sized iterators. These should find three pixel ref. | 465 // Layer sized iterators. These should find three pixel ref. |
467 { | 466 { |
468 PicturePileImpl::PixelRefIterator iterator( | 467 PicturePileImpl::PixelRefIterator iterator( |
469 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); | 468 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); |
470 EXPECT_TRUE(iterator); | 469 EXPECT_TRUE(iterator); |
471 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 470 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
472 EXPECT_TRUE(++iterator); | 471 EXPECT_TRUE(++iterator); |
473 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 472 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
474 EXPECT_TRUE(++iterator); | 473 EXPECT_TRUE(++iterator); |
475 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 474 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
476 EXPECT_FALSE(++iterator); | 475 EXPECT_FALSE(++iterator); |
477 } | 476 } |
478 { | 477 { |
479 PicturePileImpl::PixelRefIterator iterator( | 478 PicturePileImpl::PixelRefIterator iterator( |
480 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get()); | 479 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get()); |
481 EXPECT_TRUE(iterator); | 480 EXPECT_TRUE(iterator); |
482 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 481 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
483 EXPECT_TRUE(++iterator); | 482 EXPECT_TRUE(++iterator); |
484 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 483 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
485 EXPECT_TRUE(++iterator); | 484 EXPECT_TRUE(++iterator); |
486 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 485 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
487 EXPECT_FALSE(++iterator); | 486 EXPECT_FALSE(++iterator); |
488 } | 487 } |
489 { | 488 { |
490 PicturePileImpl::PixelRefIterator iterator( | 489 PicturePileImpl::PixelRefIterator iterator( |
491 gfx::Rect(0, 0, 256, 256), 0.5, pile.get()); | 490 gfx::Rect(0, 0, 256, 256), 0.5, pile.get()); |
492 EXPECT_TRUE(iterator); | 491 EXPECT_TRUE(iterator); |
493 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 492 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
494 EXPECT_TRUE(++iterator); | 493 EXPECT_TRUE(++iterator); |
495 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 494 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
496 EXPECT_TRUE(++iterator); | 495 EXPECT_TRUE(++iterator); |
497 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 496 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
498 EXPECT_FALSE(++iterator); | 497 EXPECT_FALSE(++iterator); |
499 } | 498 } |
500 | 499 |
501 // Copy test. | 500 // Copy test. |
502 PicturePileImpl::PixelRefIterator iterator( | 501 PicturePileImpl::PixelRefIterator iterator( |
503 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); | 502 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); |
504 EXPECT_TRUE(iterator); | 503 EXPECT_TRUE(iterator); |
505 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 504 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
506 EXPECT_TRUE(++iterator); | 505 EXPECT_TRUE(++iterator); |
507 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 506 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
508 | 507 |
509 // copy now points to the same spot as iterator, | 508 // copy now points to the same spot as iterator, |
510 // but both can be incremented independently. | 509 // but both can be incremented independently. |
511 PicturePileImpl::PixelRefIterator copy = iterator; | 510 PicturePileImpl::PixelRefIterator copy = iterator; |
512 EXPECT_TRUE(++iterator); | 511 EXPECT_TRUE(++iterator); |
513 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 512 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
514 EXPECT_FALSE(++iterator); | 513 EXPECT_FALSE(++iterator); |
515 | 514 |
516 EXPECT_TRUE(copy); | 515 EXPECT_TRUE(copy); |
517 EXPECT_TRUE(*copy == lazy_bitmap[0][1].pixelRef()); | 516 EXPECT_TRUE(*copy == discardable_bitmap[0][1].pixelRef()); |
518 EXPECT_TRUE(++copy); | 517 EXPECT_TRUE(++copy); |
519 EXPECT_TRUE(*copy == lazy_bitmap[1][1].pixelRef()); | 518 EXPECT_TRUE(*copy == discardable_bitmap[1][1].pixelRef()); |
520 EXPECT_FALSE(++copy); | 519 EXPECT_FALSE(++copy); |
521 } | 520 } |
522 | 521 |
523 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsBaseNonLazy) { | 522 TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsBaseNonDiscardable) { |
524 gfx::Size tile_size(256, 256); | 523 gfx::Size tile_size(256, 256); |
525 gfx::Size layer_bounds(512, 512); | 524 gfx::Size layer_bounds(512, 512); |
526 | 525 |
527 scoped_refptr<FakePicturePileImpl> pile = | 526 scoped_refptr<FakePicturePileImpl> pile = |
528 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 527 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
529 | 528 |
530 SkBitmap non_lazy_bitmap; | 529 SkBitmap non_discardable_bitmap; |
531 CreateBitmap(gfx::Size(512, 512), "notlazy", &non_lazy_bitmap); | 530 CreateBitmap(gfx::Size(512, 512), "notdiscardable", &non_discardable_bitmap); |
532 | 531 |
533 SkBitmap lazy_bitmap[2][2]; | 532 SkBitmap discardable_bitmap[2][2]; |
534 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][0]); | 533 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][0]); |
535 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][1]); | 534 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[0][1]); |
536 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[1][1]); | 535 CreateBitmap(gfx::Size(128, 128), "discardable", &discardable_bitmap[1][1]); |
537 | 536 |
538 // One large non-lazy bitmap covers the whole grid. | 537 // One large non-discardable bitmap covers the whole grid. |
539 // Lazy pixel refs are found in the following cells: | 538 // Discardable pixel refs are found in the following cells: |
540 // |---|---| | 539 // |---|---| |
541 // | x | x | | 540 // | x | x | |
542 // |---|---| | 541 // |---|---| |
543 // | | x | | 542 // | | x | |
544 // |---|---| | 543 // |---|---| |
545 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); | 544 pile->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0)); |
546 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 545 pile->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); |
547 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); | 546 pile->add_draw_bitmap(discardable_bitmap[0][1], gfx::Point(260, 0)); |
548 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); | 547 pile->add_draw_bitmap(discardable_bitmap[1][1], gfx::Point(260, 260)); |
549 | 548 |
550 pile->RerecordPile(); | 549 pile->RerecordPile(); |
551 | 550 |
552 // Tile sized iterators. These should find only one pixel ref. | 551 // Tile sized iterators. These should find only one pixel ref. |
553 { | 552 { |
554 PicturePileImpl::PixelRefIterator iterator( | 553 PicturePileImpl::PixelRefIterator iterator( |
555 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); | 554 gfx::Rect(0, 0, 256, 256), 1.0, pile.get()); |
556 EXPECT_TRUE(iterator); | 555 EXPECT_TRUE(iterator); |
557 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 556 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
558 EXPECT_FALSE(++iterator); | 557 EXPECT_FALSE(++iterator); |
559 } | 558 } |
560 { | 559 { |
561 PicturePileImpl::PixelRefIterator iterator( | 560 PicturePileImpl::PixelRefIterator iterator( |
562 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); | 561 gfx::Rect(0, 0, 512, 512), 2.0, pile.get()); |
563 EXPECT_TRUE(iterator); | 562 EXPECT_TRUE(iterator); |
564 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 563 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
565 EXPECT_FALSE(++iterator); | 564 EXPECT_FALSE(++iterator); |
566 } | 565 } |
567 { | 566 { |
568 PicturePileImpl::PixelRefIterator iterator( | 567 PicturePileImpl::PixelRefIterator iterator( |
569 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); | 568 gfx::Rect(0, 0, 128, 128), 0.5, pile.get()); |
570 EXPECT_TRUE(iterator); | 569 EXPECT_TRUE(iterator); |
571 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 570 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
572 EXPECT_FALSE(++iterator); | 571 EXPECT_FALSE(++iterator); |
573 } | 572 } |
574 // Shifted tile sized iterators. These should find only one pixel ref. | 573 // Shifted tile sized iterators. These should find only one pixel ref. |
575 { | 574 { |
576 PicturePileImpl::PixelRefIterator iterator( | 575 PicturePileImpl::PixelRefIterator iterator( |
577 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); | 576 gfx::Rect(260, 260, 256, 256), 1.0, pile.get()); |
578 EXPECT_TRUE(iterator); | 577 EXPECT_TRUE(iterator); |
579 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 578 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
580 EXPECT_FALSE(++iterator); | 579 EXPECT_FALSE(++iterator); |
581 } | 580 } |
582 { | 581 { |
583 PicturePileImpl::PixelRefIterator iterator( | 582 PicturePileImpl::PixelRefIterator iterator( |
584 gfx::Rect(520, 520, 512, 512), 2.0, pile.get()); | 583 gfx::Rect(520, 520, 512, 512), 2.0, pile.get()); |
585 EXPECT_TRUE(iterator); | 584 EXPECT_TRUE(iterator); |
586 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 585 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
587 EXPECT_FALSE(++iterator); | 586 EXPECT_FALSE(++iterator); |
588 } | 587 } |
589 { | 588 { |
590 PicturePileImpl::PixelRefIterator iterator( | 589 PicturePileImpl::PixelRefIterator iterator( |
591 gfx::Rect(130, 130, 128, 128), 0.5, pile.get()); | 590 gfx::Rect(130, 130, 128, 128), 0.5, pile.get()); |
592 EXPECT_TRUE(iterator); | 591 EXPECT_TRUE(iterator); |
593 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 592 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
594 EXPECT_FALSE(++iterator); | 593 EXPECT_FALSE(++iterator); |
595 } | 594 } |
596 // Ensure there's no lazy pixel refs in the empty cell | 595 // Ensure there's no discardable pixel refs in the empty cell |
597 { | 596 { |
598 PicturePileImpl::PixelRefIterator iterator( | 597 PicturePileImpl::PixelRefIterator iterator( |
599 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); | 598 gfx::Rect(0, 256, 256, 256), 1.0, pile.get()); |
600 EXPECT_FALSE(iterator); | 599 EXPECT_FALSE(iterator); |
601 } | 600 } |
602 // Layer sized iterators. These should find three pixel ref. | 601 // Layer sized iterators. These should find three pixel ref. |
603 { | 602 { |
604 PicturePileImpl::PixelRefIterator iterator( | 603 PicturePileImpl::PixelRefIterator iterator( |
605 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); | 604 gfx::Rect(0, 0, 512, 512), 1.0, pile.get()); |
606 EXPECT_TRUE(iterator); | 605 EXPECT_TRUE(iterator); |
607 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 606 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
608 EXPECT_TRUE(++iterator); | 607 EXPECT_TRUE(++iterator); |
609 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 608 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
610 EXPECT_TRUE(++iterator); | 609 EXPECT_TRUE(++iterator); |
611 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 610 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
612 EXPECT_FALSE(++iterator); | 611 EXPECT_FALSE(++iterator); |
613 } | 612 } |
614 { | 613 { |
615 PicturePileImpl::PixelRefIterator iterator( | 614 PicturePileImpl::PixelRefIterator iterator( |
616 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get()); | 615 gfx::Rect(0, 0, 1024, 1024), 2.0, pile.get()); |
617 EXPECT_TRUE(iterator); | 616 EXPECT_TRUE(iterator); |
618 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 617 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
619 EXPECT_TRUE(++iterator); | 618 EXPECT_TRUE(++iterator); |
620 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 619 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
621 EXPECT_TRUE(++iterator); | 620 EXPECT_TRUE(++iterator); |
622 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 621 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
623 EXPECT_FALSE(++iterator); | 622 EXPECT_FALSE(++iterator); |
624 } | 623 } |
625 { | 624 { |
626 PicturePileImpl::PixelRefIterator iterator( | 625 PicturePileImpl::PixelRefIterator iterator( |
627 gfx::Rect(0, 0, 256, 256), 0.5, pile.get()); | 626 gfx::Rect(0, 0, 256, 256), 0.5, pile.get()); |
628 EXPECT_TRUE(iterator); | 627 EXPECT_TRUE(iterator); |
629 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 628 EXPECT_TRUE(*iterator == discardable_bitmap[0][0].pixelRef()); |
630 EXPECT_TRUE(++iterator); | 629 EXPECT_TRUE(++iterator); |
631 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); | 630 EXPECT_TRUE(*iterator == discardable_bitmap[0][1].pixelRef()); |
632 EXPECT_TRUE(++iterator); | 631 EXPECT_TRUE(++iterator); |
633 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); | 632 EXPECT_TRUE(*iterator == discardable_bitmap[1][1].pixelRef()); |
634 EXPECT_FALSE(++iterator); | 633 EXPECT_FALSE(++iterator); |
635 } | 634 } |
636 } | 635 } |
637 | 636 |
638 TEST(PicturePileImpl, RasterContentsOpaque) { | 637 TEST(PicturePileImpl, RasterContentsOpaque) { |
639 gfx::Size tile_size(1000, 1000); | 638 gfx::Size tile_size(1000, 1000); |
640 gfx::Size layer_bounds(3, 5); | 639 gfx::Size layer_bounds(3, 5); |
641 float contents_scale = 1.5f; | 640 float contents_scale = 1.5f; |
642 float raster_divisions = 2.f; | 641 float raster_divisions = 2.f; |
643 | 642 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 | 738 |
740 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 739 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
741 int num_pixels = bitmap.width() * bitmap.height(); | 740 int num_pixels = bitmap.width() * bitmap.height(); |
742 for (int i = 0; i < num_pixels; ++i) { | 741 for (int i = 0; i < num_pixels; ++i) { |
743 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 742 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
744 } | 743 } |
745 } | 744 } |
746 | 745 |
747 } // namespace | 746 } // namespace |
748 } // namespace cc | 747 } // namespace cc |
OLD | NEW |