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 "cc/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
| 7 #include "skia/ext/lazy_pixel_ref.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkPixelRef.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" |
7 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
8 | 12 |
9 namespace cc { | 13 namespace cc { |
10 namespace { | 14 namespace { |
11 | 15 |
| 16 class TestPixelRef : public SkPixelRef { |
| 17 public: |
| 18 // Pure virtual implementation. |
| 19 TestPixelRef(int width, int height) |
| 20 : pixels_(new char[4 * width * height]) {} |
| 21 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } |
| 22 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { |
| 23 return pixels_.get(); |
| 24 } |
| 25 virtual void onUnlockPixels() OVERRIDE {} |
| 26 virtual SkPixelRef* deepCopy( |
| 27 SkBitmap::Config config, |
| 28 const SkIRect* subset) OVERRIDE { |
| 29 this->ref(); |
| 30 return this; |
| 31 } |
| 32 private: |
| 33 scoped_ptr<char[]> pixels_; |
| 34 }; |
| 35 |
| 36 class TestLazyPixelRef : public skia::LazyPixelRef { |
| 37 public: |
| 38 // Pure virtual implementation. |
| 39 TestLazyPixelRef(int width, int height) |
| 40 : pixels_(new char[4 * width * height]) {} |
| 41 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } |
| 42 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { |
| 43 return pixels_.get(); |
| 44 } |
| 45 virtual void onUnlockPixels() OVERRIDE {} |
| 46 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE { |
| 47 return true; |
| 48 } |
| 49 virtual SkPixelRef* deepCopy( |
| 50 SkBitmap::Config config, |
| 51 const SkIRect* subset) OVERRIDE { |
| 52 this->ref(); |
| 53 return this; |
| 54 } |
| 55 virtual void Decode() OVERRIDE {} |
| 56 private: |
| 57 scoped_ptr<char[]> pixels_; |
| 58 }; |
| 59 |
| 60 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { |
| 61 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; |
| 62 lazy_pixel_ref.reset(new TestLazyPixelRef(size.width(), size.height())); |
| 63 lazy_pixel_ref->setURI(uri); |
| 64 |
| 65 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 66 size.width(), |
| 67 size.height()); |
| 68 bitmap->setPixelRef(lazy_pixel_ref); |
| 69 } |
| 70 |
12 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) { | 71 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) { |
13 for (int y = 0; y < pile->num_tiles_y(); ++y) { | 72 for (int y = 0; y < pile->num_tiles_y(); ++y) { |
14 for (int x = 0; x < pile->num_tiles_x(); ++x) { | 73 for (int x = 0; x < pile->num_tiles_x(); ++x) { |
15 pile->RemoveRecordingAt(x, y); | 74 pile->RemoveRecordingAt(x, y); |
16 pile->AddRecordingAt(x, y); | 75 pile->AddRecordingAt(x, y); |
17 } | 76 } |
18 } | 77 } |
19 } | 78 } |
20 | 79 |
21 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { | 80 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); | 186 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); |
128 EXPECT_TRUE(analysis.is_solid_color); | 187 EXPECT_TRUE(analysis.is_solid_color); |
129 EXPECT_EQ(analysis.solid_color, solid_color); | 188 EXPECT_EQ(analysis.solid_color, solid_color); |
130 | 189 |
131 analysis.is_solid_color = false; | 190 analysis.is_solid_color = false; |
132 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); | 191 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); |
133 EXPECT_TRUE(analysis.is_solid_color); | 192 EXPECT_TRUE(analysis.is_solid_color); |
134 EXPECT_EQ(analysis.solid_color, solid_color); | 193 EXPECT_EQ(analysis.solid_color, solid_color); |
135 } | 194 } |
136 | 195 |
137 | 196 TEST(PicturePileImplTest, PixelRefIteratorEmpty) { |
| 197 gfx::Size tile_size(128, 128); |
| 198 gfx::Size layer_bounds(256, 256); |
| 199 |
| 200 // Create a filled pile with no recording. |
| 201 scoped_refptr<FakePicturePileImpl> pile = |
| 202 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 203 |
| 204 // Tile sized iterators. |
| 205 { |
| 206 PicturePileImpl::PixelRefIterator iterator( |
| 207 gfx::Rect(0, 0, 128, 128), |
| 208 1.0, |
| 209 pile); |
| 210 EXPECT_FALSE(iterator); |
| 211 } |
| 212 { |
| 213 PicturePileImpl::PixelRefIterator iterator( |
| 214 gfx::Rect(0, 0, 256, 256), |
| 215 2.0, |
| 216 pile); |
| 217 EXPECT_FALSE(iterator); |
| 218 } |
| 219 { |
| 220 PicturePileImpl::PixelRefIterator iterator( |
| 221 gfx::Rect(0, 0, 64, 64), |
| 222 0.5, |
| 223 pile); |
| 224 EXPECT_FALSE(iterator); |
| 225 } |
| 226 // Shifted tile sized iterators. |
| 227 { |
| 228 PicturePileImpl::PixelRefIterator iterator( |
| 229 gfx::Rect(140, 140, 128, 128), |
| 230 1.0, |
| 231 pile); |
| 232 EXPECT_FALSE(iterator); |
| 233 } |
| 234 { |
| 235 PicturePileImpl::PixelRefIterator iterator( |
| 236 gfx::Rect(280, 280, 256, 256), |
| 237 2.0, |
| 238 pile); |
| 239 EXPECT_FALSE(iterator); |
| 240 } |
| 241 { |
| 242 PicturePileImpl::PixelRefIterator iterator( |
| 243 gfx::Rect(70, 70, 64, 64), |
| 244 0.5, |
| 245 pile); |
| 246 EXPECT_FALSE(iterator); |
| 247 } |
| 248 // Layer sized iterators. |
| 249 { |
| 250 PicturePileImpl::PixelRefIterator iterator( |
| 251 gfx::Rect(0, 0, 256, 256), |
| 252 1.0, |
| 253 pile); |
| 254 EXPECT_FALSE(iterator); |
| 255 } |
| 256 { |
| 257 PicturePileImpl::PixelRefIterator iterator( |
| 258 gfx::Rect(0, 0, 512, 512), |
| 259 2.0, |
| 260 pile); |
| 261 EXPECT_FALSE(iterator); |
| 262 } |
| 263 { |
| 264 PicturePileImpl::PixelRefIterator iterator( |
| 265 gfx::Rect(0, 0, 128, 128), |
| 266 0.5, |
| 267 pile); |
| 268 EXPECT_FALSE(iterator); |
| 269 } |
| 270 } |
| 271 |
| 272 TEST(PicturePileImplTest, PixelRefIteratorNoLazyRefs) { |
| 273 gfx::Size tile_size(128, 128); |
| 274 gfx::Size layer_bounds(256, 256); |
| 275 |
| 276 scoped_refptr<FakePicturePileImpl> pile = |
| 277 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 278 |
| 279 SkPaint simple_paint; |
| 280 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| 281 |
| 282 SkBitmap non_lazy_bitmap; |
| 283 CreateBitmap(gfx::Size(128, 128), "notlazy", &non_lazy_bitmap); |
| 284 |
| 285 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); |
| 286 pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint); |
| 287 pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint); |
| 288 pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); |
| 289 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(128, 0)); |
| 290 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128)); |
| 291 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150)); |
| 292 |
| 293 RerecordPile(pile); |
| 294 |
| 295 // Tile sized iterators. |
| 296 { |
| 297 PicturePileImpl::PixelRefIterator iterator( |
| 298 gfx::Rect(0, 0, 128, 128), |
| 299 1.0, |
| 300 pile); |
| 301 EXPECT_FALSE(iterator); |
| 302 } |
| 303 { |
| 304 PicturePileImpl::PixelRefIterator iterator( |
| 305 gfx::Rect(0, 0, 256, 256), |
| 306 2.0, |
| 307 pile); |
| 308 EXPECT_FALSE(iterator); |
| 309 } |
| 310 { |
| 311 PicturePileImpl::PixelRefIterator iterator( |
| 312 gfx::Rect(0, 0, 64, 64), |
| 313 0.5, |
| 314 pile); |
| 315 EXPECT_FALSE(iterator); |
| 316 } |
| 317 // Shifted tile sized iterators. |
| 318 { |
| 319 PicturePileImpl::PixelRefIterator iterator( |
| 320 gfx::Rect(140, 140, 128, 128), |
| 321 1.0, |
| 322 pile); |
| 323 EXPECT_FALSE(iterator); |
| 324 } |
| 325 { |
| 326 PicturePileImpl::PixelRefIterator iterator( |
| 327 gfx::Rect(280, 280, 256, 256), |
| 328 2.0, |
| 329 pile); |
| 330 EXPECT_FALSE(iterator); |
| 331 } |
| 332 { |
| 333 PicturePileImpl::PixelRefIterator iterator( |
| 334 gfx::Rect(70, 70, 64, 64), |
| 335 0.5, |
| 336 pile); |
| 337 EXPECT_FALSE(iterator); |
| 338 } |
| 339 // Layer sized iterators. |
| 340 { |
| 341 PicturePileImpl::PixelRefIterator iterator( |
| 342 gfx::Rect(0, 0, 256, 256), |
| 343 1.0, |
| 344 pile); |
| 345 EXPECT_FALSE(iterator); |
| 346 } |
| 347 { |
| 348 PicturePileImpl::PixelRefIterator iterator( |
| 349 gfx::Rect(0, 0, 512, 512), |
| 350 2.0, |
| 351 pile); |
| 352 EXPECT_FALSE(iterator); |
| 353 } |
| 354 { |
| 355 PicturePileImpl::PixelRefIterator iterator( |
| 356 gfx::Rect(0, 0, 128, 128), |
| 357 0.5, |
| 358 pile); |
| 359 EXPECT_FALSE(iterator); |
| 360 } |
| 361 } |
| 362 |
| 363 TEST(PicturePileImplTest, PixelRefIteratorLazyRefs) { |
| 364 gfx::Size tile_size(128, 128); |
| 365 gfx::Size layer_bounds(256, 256); |
| 366 |
| 367 scoped_refptr<FakePicturePileImpl> pile = |
| 368 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 369 |
| 370 SkBitmap lazy_bitmap[2][2]; |
| 371 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); |
| 372 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][0]); |
| 373 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); |
| 374 |
| 375 // Lazy pixel refs are found in the following cells: |
| 376 // |---|---| |
| 377 // | x | | |
| 378 // |---|---| |
| 379 // | x | x | |
| 380 // |---|---| |
| 381 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); |
| 382 pile->add_draw_bitmap(lazy_bitmap[1][0], gfx::Point(0, 130)); |
| 383 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(140, 140)); |
| 384 |
| 385 RerecordPile(pile); |
| 386 |
| 387 // Tile sized iterators. These should find only one pixel ref. |
| 388 { |
| 389 PicturePileImpl::PixelRefIterator iterator( |
| 390 gfx::Rect(0, 0, 128, 128), |
| 391 1.0, |
| 392 pile); |
| 393 EXPECT_TRUE(iterator); |
| 394 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 395 EXPECT_FALSE(++iterator); |
| 396 } |
| 397 { |
| 398 PicturePileImpl::PixelRefIterator iterator( |
| 399 gfx::Rect(0, 0, 256, 256), |
| 400 2.0, |
| 401 pile); |
| 402 EXPECT_TRUE(iterator); |
| 403 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 404 EXPECT_FALSE(++iterator); |
| 405 } |
| 406 { |
| 407 PicturePileImpl::PixelRefIterator iterator( |
| 408 gfx::Rect(0, 0, 64, 64), |
| 409 0.5, |
| 410 pile); |
| 411 EXPECT_TRUE(iterator); |
| 412 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 413 EXPECT_FALSE(++iterator); |
| 414 } |
| 415 // Shifted tile sized iterators. These should find only one pixel ref. |
| 416 { |
| 417 PicturePileImpl::PixelRefIterator iterator( |
| 418 gfx::Rect(140, 140, 128, 128), |
| 419 1.0, |
| 420 pile); |
| 421 EXPECT_TRUE(iterator); |
| 422 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 423 EXPECT_FALSE(++iterator); |
| 424 } |
| 425 { |
| 426 PicturePileImpl::PixelRefIterator iterator( |
| 427 gfx::Rect(280, 280, 256, 256), |
| 428 2.0, |
| 429 pile); |
| 430 EXPECT_TRUE(iterator); |
| 431 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 432 EXPECT_FALSE(++iterator); |
| 433 } |
| 434 { |
| 435 PicturePileImpl::PixelRefIterator iterator( |
| 436 gfx::Rect(70, 70, 64, 64), |
| 437 0.5, |
| 438 pile); |
| 439 EXPECT_TRUE(iterator); |
| 440 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 441 EXPECT_FALSE(++iterator); |
| 442 } |
| 443 // Ensure there's no lazy pixel refs in the empty cell |
| 444 { |
| 445 PicturePileImpl::PixelRefIterator iterator( |
| 446 gfx::Rect(140, 0, 128, 128), |
| 447 1.0, |
| 448 pile); |
| 449 EXPECT_FALSE(iterator); |
| 450 // Ensure we can increment the iterator with no change |
| 451 EXPECT_FALSE(++iterator); |
| 452 EXPECT_FALSE(++iterator); |
| 453 EXPECT_FALSE(++iterator); |
| 454 EXPECT_FALSE(++iterator); |
| 455 } |
| 456 // Layer sized iterators. These should find all 3 pixel refs. |
| 457 { |
| 458 PicturePileImpl::PixelRefIterator iterator( |
| 459 gfx::Rect(0, 0, 256, 256), |
| 460 1.0, |
| 461 pile); |
| 462 EXPECT_TRUE(iterator); |
| 463 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 464 EXPECT_TRUE(++iterator); |
| 465 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 466 EXPECT_TRUE(++iterator); |
| 467 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 468 EXPECT_FALSE(++iterator); |
| 469 } |
| 470 { |
| 471 PicturePileImpl::PixelRefIterator iterator( |
| 472 gfx::Rect(0, 0, 512, 512), |
| 473 2.0, |
| 474 pile); |
| 475 EXPECT_TRUE(iterator); |
| 476 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 477 EXPECT_TRUE(++iterator); |
| 478 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 479 EXPECT_TRUE(++iterator); |
| 480 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 481 EXPECT_FALSE(++iterator); |
| 482 } |
| 483 { |
| 484 PicturePileImpl::PixelRefIterator iterator( |
| 485 gfx::Rect(0, 0, 128, 128), |
| 486 0.5, |
| 487 pile); |
| 488 EXPECT_TRUE(iterator); |
| 489 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 490 EXPECT_TRUE(++iterator); |
| 491 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 492 EXPECT_TRUE(++iterator); |
| 493 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 494 EXPECT_FALSE(++iterator); |
| 495 } |
| 496 } |
| 497 |
| 498 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsOneTile) { |
| 499 gfx::Size tile_size(256, 256); |
| 500 gfx::Size layer_bounds(512, 512); |
| 501 |
| 502 scoped_refptr<FakePicturePileImpl> pile = |
| 503 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 504 |
| 505 SkBitmap lazy_bitmap[2][2]; |
| 506 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); |
| 507 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][1]); |
| 508 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); |
| 509 |
| 510 // Lazy pixel refs are found in the following cells: |
| 511 // |---|---| |
| 512 // | x | x | |
| 513 // |---|---| |
| 514 // | | x | |
| 515 // |---|---| |
| 516 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); |
| 517 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); |
| 518 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 519 |
| 520 RerecordPile(pile); |
| 521 |
| 522 // Tile sized iterators. These should find only one pixel ref. |
| 523 { |
| 524 PicturePileImpl::PixelRefIterator iterator( |
| 525 gfx::Rect(0, 0, 256, 256), |
| 526 1.0, |
| 527 pile); |
| 528 EXPECT_TRUE(iterator); |
| 529 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 530 EXPECT_FALSE(++iterator); |
| 531 } |
| 532 { |
| 533 PicturePileImpl::PixelRefIterator iterator( |
| 534 gfx::Rect(0, 0, 512, 512), |
| 535 2.0, |
| 536 pile); |
| 537 EXPECT_TRUE(iterator); |
| 538 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 539 EXPECT_FALSE(++iterator); |
| 540 } |
| 541 { |
| 542 PicturePileImpl::PixelRefIterator iterator( |
| 543 gfx::Rect(0, 0, 128, 128), |
| 544 0.5, |
| 545 pile); |
| 546 EXPECT_TRUE(iterator); |
| 547 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 548 EXPECT_FALSE(++iterator); |
| 549 } |
| 550 // Shifted tile sized iterators. These should find only one pixel ref. |
| 551 { |
| 552 PicturePileImpl::PixelRefIterator iterator( |
| 553 gfx::Rect(260, 260, 256, 256), |
| 554 1.0, |
| 555 pile); |
| 556 EXPECT_TRUE(iterator); |
| 557 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 558 EXPECT_FALSE(++iterator); |
| 559 } |
| 560 { |
| 561 PicturePileImpl::PixelRefIterator iterator( |
| 562 gfx::Rect(520, 520, 512, 512), |
| 563 2.0, |
| 564 pile); |
| 565 EXPECT_TRUE(iterator); |
| 566 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 567 EXPECT_FALSE(++iterator); |
| 568 } |
| 569 { |
| 570 PicturePileImpl::PixelRefIterator iterator( |
| 571 gfx::Rect(130, 130, 128, 128), |
| 572 0.5, |
| 573 pile); |
| 574 EXPECT_TRUE(iterator); |
| 575 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 576 EXPECT_FALSE(++iterator); |
| 577 } |
| 578 // Ensure there's no lazy pixel refs in the empty cell |
| 579 { |
| 580 PicturePileImpl::PixelRefIterator iterator( |
| 581 gfx::Rect(0, 256, 256, 256), |
| 582 1.0, |
| 583 pile); |
| 584 EXPECT_FALSE(iterator); |
| 585 // Ensure we can increment the iterator with no change |
| 586 EXPECT_FALSE(++iterator); |
| 587 EXPECT_FALSE(++iterator); |
| 588 EXPECT_FALSE(++iterator); |
| 589 EXPECT_FALSE(++iterator); |
| 590 } |
| 591 // Layer sized iterators. These should find three pixel ref. |
| 592 { |
| 593 PicturePileImpl::PixelRefIterator iterator( |
| 594 gfx::Rect(0, 0, 512, 512), |
| 595 1.0, |
| 596 pile); |
| 597 EXPECT_TRUE(iterator); |
| 598 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 599 EXPECT_TRUE(++iterator); |
| 600 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 601 EXPECT_TRUE(++iterator); |
| 602 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 603 EXPECT_FALSE(++iterator); |
| 604 } |
| 605 { |
| 606 PicturePileImpl::PixelRefIterator iterator( |
| 607 gfx::Rect(0, 0, 1024, 1024), |
| 608 2.0, |
| 609 pile); |
| 610 EXPECT_TRUE(iterator); |
| 611 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 612 EXPECT_TRUE(++iterator); |
| 613 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 614 EXPECT_TRUE(++iterator); |
| 615 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 616 EXPECT_FALSE(++iterator); |
| 617 } |
| 618 { |
| 619 PicturePileImpl::PixelRefIterator iterator( |
| 620 gfx::Rect(0, 0, 256, 256), |
| 621 0.5, |
| 622 pile); |
| 623 EXPECT_TRUE(iterator); |
| 624 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 625 EXPECT_TRUE(++iterator); |
| 626 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 627 EXPECT_TRUE(++iterator); |
| 628 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 629 EXPECT_FALSE(++iterator); |
| 630 } |
| 631 |
| 632 // Copy test. |
| 633 PicturePileImpl::PixelRefIterator iterator( |
| 634 gfx::Rect(0, 0, 512, 512), |
| 635 1.0, |
| 636 pile); |
| 637 EXPECT_TRUE(iterator); |
| 638 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 639 EXPECT_TRUE(++iterator); |
| 640 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 641 |
| 642 // copy now points to the same spot as iterator, |
| 643 // but both can be incremented independently. |
| 644 PicturePileImpl::PixelRefIterator copy = iterator; |
| 645 EXPECT_TRUE(++iterator); |
| 646 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 647 EXPECT_FALSE(++iterator); |
| 648 |
| 649 EXPECT_TRUE(copy); |
| 650 EXPECT_TRUE(*copy == lazy_bitmap[0][1].pixelRef()); |
| 651 EXPECT_TRUE(++copy); |
| 652 EXPECT_TRUE(*copy == lazy_bitmap[1][1].pixelRef()); |
| 653 EXPECT_FALSE(++copy); |
| 654 } |
| 655 |
| 656 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsBaseNonLazy) { |
| 657 gfx::Size tile_size(256, 256); |
| 658 gfx::Size layer_bounds(512, 512); |
| 659 |
| 660 scoped_refptr<FakePicturePileImpl> pile = |
| 661 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 662 |
| 663 SkBitmap non_lazy_bitmap; |
| 664 CreateBitmap(gfx::Size(512, 512), "notlazy", &non_lazy_bitmap); |
| 665 |
| 666 SkBitmap lazy_bitmap[2][2]; |
| 667 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][0]); |
| 668 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][1]); |
| 669 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[1][1]); |
| 670 |
| 671 // One large non-lazy bitmap covers the whole grid. |
| 672 // Lazy pixel refs are found in the following cells: |
| 673 // |---|---| |
| 674 // | x | x | |
| 675 // |---|---| |
| 676 // | | x | |
| 677 // |---|---| |
| 678 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); |
| 679 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); |
| 680 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); |
| 681 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 682 |
| 683 RerecordPile(pile); |
| 684 |
| 685 // Tile sized iterators. These should find only one pixel ref. |
| 686 { |
| 687 PicturePileImpl::PixelRefIterator iterator( |
| 688 gfx::Rect(0, 0, 256, 256), |
| 689 1.0, |
| 690 pile); |
| 691 EXPECT_TRUE(iterator); |
| 692 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 693 EXPECT_FALSE(++iterator); |
| 694 } |
| 695 { |
| 696 PicturePileImpl::PixelRefIterator iterator( |
| 697 gfx::Rect(0, 0, 512, 512), |
| 698 2.0, |
| 699 pile); |
| 700 EXPECT_TRUE(iterator); |
| 701 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 702 EXPECT_FALSE(++iterator); |
| 703 } |
| 704 { |
| 705 PicturePileImpl::PixelRefIterator iterator( |
| 706 gfx::Rect(0, 0, 128, 128), |
| 707 0.5, |
| 708 pile); |
| 709 EXPECT_TRUE(iterator); |
| 710 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 711 EXPECT_FALSE(++iterator); |
| 712 } |
| 713 // Shifted tile sized iterators. These should find only one pixel ref. |
| 714 { |
| 715 PicturePileImpl::PixelRefIterator iterator( |
| 716 gfx::Rect(260, 260, 256, 256), |
| 717 1.0, |
| 718 pile); |
| 719 EXPECT_TRUE(iterator); |
| 720 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 721 EXPECT_FALSE(++iterator); |
| 722 } |
| 723 { |
| 724 PicturePileImpl::PixelRefIterator iterator( |
| 725 gfx::Rect(520, 520, 512, 512), |
| 726 2.0, |
| 727 pile); |
| 728 EXPECT_TRUE(iterator); |
| 729 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 730 EXPECT_FALSE(++iterator); |
| 731 } |
| 732 { |
| 733 PicturePileImpl::PixelRefIterator iterator( |
| 734 gfx::Rect(130, 130, 128, 128), |
| 735 0.5, |
| 736 pile); |
| 737 EXPECT_TRUE(iterator); |
| 738 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 739 EXPECT_FALSE(++iterator); |
| 740 } |
| 741 // Ensure there's no lazy pixel refs in the empty cell |
| 742 { |
| 743 PicturePileImpl::PixelRefIterator iterator( |
| 744 gfx::Rect(0, 256, 256, 256), |
| 745 1.0, |
| 746 pile); |
| 747 EXPECT_FALSE(iterator); |
| 748 // Ensure we can increment the iterator with no change |
| 749 EXPECT_FALSE(++iterator); |
| 750 EXPECT_FALSE(++iterator); |
| 751 EXPECT_FALSE(++iterator); |
| 752 EXPECT_FALSE(++iterator); |
| 753 } |
| 754 // Layer sized iterators. These should find three pixel ref. |
| 755 { |
| 756 PicturePileImpl::PixelRefIterator iterator( |
| 757 gfx::Rect(0, 0, 512, 512), |
| 758 1.0, |
| 759 pile); |
| 760 EXPECT_TRUE(iterator); |
| 761 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 762 EXPECT_TRUE(++iterator); |
| 763 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 764 EXPECT_TRUE(++iterator); |
| 765 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 766 EXPECT_FALSE(++iterator); |
| 767 } |
| 768 { |
| 769 PicturePileImpl::PixelRefIterator iterator( |
| 770 gfx::Rect(0, 0, 1024, 1024), |
| 771 2.0, |
| 772 pile); |
| 773 EXPECT_TRUE(iterator); |
| 774 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 775 EXPECT_TRUE(++iterator); |
| 776 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 777 EXPECT_TRUE(++iterator); |
| 778 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 779 EXPECT_FALSE(++iterator); |
| 780 } |
| 781 { |
| 782 PicturePileImpl::PixelRefIterator iterator( |
| 783 gfx::Rect(0, 0, 256, 256), |
| 784 0.5, |
| 785 pile); |
| 786 EXPECT_TRUE(iterator); |
| 787 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 788 EXPECT_TRUE(++iterator); |
| 789 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 790 EXPECT_TRUE(++iterator); |
| 791 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 792 EXPECT_FALSE(++iterator); |
| 793 } |
| 794 } |
138 } // namespace | 795 } // namespace |
139 } // namespace cc | 796 } // namespace cc |
OLD | NEW |