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 |
| 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 } |
| 451 // Layer sized iterators. These should find all 3 pixel refs. |
| 452 { |
| 453 PicturePileImpl::PixelRefIterator iterator( |
| 454 gfx::Rect(0, 0, 256, 256), |
| 455 1.0, |
| 456 pile); |
| 457 EXPECT_TRUE(iterator); |
| 458 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 459 EXPECT_TRUE(++iterator); |
| 460 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 461 EXPECT_TRUE(++iterator); |
| 462 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 463 EXPECT_FALSE(++iterator); |
| 464 } |
| 465 { |
| 466 PicturePileImpl::PixelRefIterator iterator( |
| 467 gfx::Rect(0, 0, 512, 512), |
| 468 2.0, |
| 469 pile); |
| 470 EXPECT_TRUE(iterator); |
| 471 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 472 EXPECT_TRUE(++iterator); |
| 473 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 474 EXPECT_TRUE(++iterator); |
| 475 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 476 EXPECT_FALSE(++iterator); |
| 477 } |
| 478 { |
| 479 PicturePileImpl::PixelRefIterator iterator( |
| 480 gfx::Rect(0, 0, 128, 128), |
| 481 0.5, |
| 482 pile); |
| 483 EXPECT_TRUE(iterator); |
| 484 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 485 EXPECT_TRUE(++iterator); |
| 486 EXPECT_TRUE(*iterator == lazy_bitmap[1][0].pixelRef()); |
| 487 EXPECT_TRUE(++iterator); |
| 488 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 489 EXPECT_FALSE(++iterator); |
| 490 } |
| 491 } |
| 492 |
| 493 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsOneTile) { |
| 494 gfx::Size tile_size(256, 256); |
| 495 gfx::Size layer_bounds(512, 512); |
| 496 |
| 497 scoped_refptr<FakePicturePileImpl> pile = |
| 498 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 499 |
| 500 SkBitmap lazy_bitmap[2][2]; |
| 501 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); |
| 502 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][1]); |
| 503 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); |
| 504 |
| 505 // Lazy pixel refs are found in the following cells: |
| 506 // |---|---| |
| 507 // | x | x | |
| 508 // |---|---| |
| 509 // | | x | |
| 510 // |---|---| |
| 511 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); |
| 512 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); |
| 513 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 514 |
| 515 RerecordPile(pile); |
| 516 |
| 517 // Tile sized iterators. These should find only one pixel ref. |
| 518 { |
| 519 PicturePileImpl::PixelRefIterator iterator( |
| 520 gfx::Rect(0, 0, 256, 256), |
| 521 1.0, |
| 522 pile); |
| 523 EXPECT_TRUE(iterator); |
| 524 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 525 EXPECT_FALSE(++iterator); |
| 526 } |
| 527 { |
| 528 PicturePileImpl::PixelRefIterator iterator( |
| 529 gfx::Rect(0, 0, 512, 512), |
| 530 2.0, |
| 531 pile); |
| 532 EXPECT_TRUE(iterator); |
| 533 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 534 EXPECT_FALSE(++iterator); |
| 535 } |
| 536 { |
| 537 PicturePileImpl::PixelRefIterator iterator( |
| 538 gfx::Rect(0, 0, 128, 128), |
| 539 0.5, |
| 540 pile); |
| 541 EXPECT_TRUE(iterator); |
| 542 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 543 EXPECT_FALSE(++iterator); |
| 544 } |
| 545 // Shifted tile sized iterators. These should find only one pixel ref. |
| 546 { |
| 547 PicturePileImpl::PixelRefIterator iterator( |
| 548 gfx::Rect(260, 260, 256, 256), |
| 549 1.0, |
| 550 pile); |
| 551 EXPECT_TRUE(iterator); |
| 552 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 553 EXPECT_FALSE(++iterator); |
| 554 } |
| 555 { |
| 556 PicturePileImpl::PixelRefIterator iterator( |
| 557 gfx::Rect(520, 520, 512, 512), |
| 558 2.0, |
| 559 pile); |
| 560 EXPECT_TRUE(iterator); |
| 561 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 562 EXPECT_FALSE(++iterator); |
| 563 } |
| 564 { |
| 565 PicturePileImpl::PixelRefIterator iterator( |
| 566 gfx::Rect(130, 130, 128, 128), |
| 567 0.5, |
| 568 pile); |
| 569 EXPECT_TRUE(iterator); |
| 570 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 571 EXPECT_FALSE(++iterator); |
| 572 } |
| 573 // Ensure there's no lazy pixel refs in the empty cell |
| 574 { |
| 575 PicturePileImpl::PixelRefIterator iterator( |
| 576 gfx::Rect(0, 256, 256, 256), |
| 577 1.0, |
| 578 pile); |
| 579 EXPECT_FALSE(iterator); |
| 580 } |
| 581 // Layer sized iterators. These should find three pixel ref. |
| 582 { |
| 583 PicturePileImpl::PixelRefIterator iterator( |
| 584 gfx::Rect(0, 0, 512, 512), |
| 585 1.0, |
| 586 pile); |
| 587 EXPECT_TRUE(iterator); |
| 588 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 589 EXPECT_TRUE(++iterator); |
| 590 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 591 EXPECT_TRUE(++iterator); |
| 592 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 593 EXPECT_FALSE(++iterator); |
| 594 } |
| 595 { |
| 596 PicturePileImpl::PixelRefIterator iterator( |
| 597 gfx::Rect(0, 0, 1024, 1024), |
| 598 2.0, |
| 599 pile); |
| 600 EXPECT_TRUE(iterator); |
| 601 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 602 EXPECT_TRUE(++iterator); |
| 603 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 604 EXPECT_TRUE(++iterator); |
| 605 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 606 EXPECT_FALSE(++iterator); |
| 607 } |
| 608 { |
| 609 PicturePileImpl::PixelRefIterator iterator( |
| 610 gfx::Rect(0, 0, 256, 256), |
| 611 0.5, |
| 612 pile); |
| 613 EXPECT_TRUE(iterator); |
| 614 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 615 EXPECT_TRUE(++iterator); |
| 616 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 617 EXPECT_TRUE(++iterator); |
| 618 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 619 EXPECT_FALSE(++iterator); |
| 620 } |
| 621 |
| 622 // Copy test. |
| 623 PicturePileImpl::PixelRefIterator iterator( |
| 624 gfx::Rect(0, 0, 512, 512), |
| 625 1.0, |
| 626 pile); |
| 627 EXPECT_TRUE(iterator); |
| 628 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 629 EXPECT_TRUE(++iterator); |
| 630 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 631 |
| 632 // copy now points to the same spot as iterator, |
| 633 // but both can be incremented independently. |
| 634 PicturePileImpl::PixelRefIterator copy = iterator; |
| 635 EXPECT_TRUE(++iterator); |
| 636 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 637 EXPECT_FALSE(++iterator); |
| 638 |
| 639 EXPECT_TRUE(copy); |
| 640 EXPECT_TRUE(*copy == lazy_bitmap[0][1].pixelRef()); |
| 641 EXPECT_TRUE(++copy); |
| 642 EXPECT_TRUE(*copy == lazy_bitmap[1][1].pixelRef()); |
| 643 EXPECT_FALSE(++copy); |
| 644 } |
| 645 |
| 646 TEST(PicturePileImplTest, PixelRefIteratorLazyRefsBaseNonLazy) { |
| 647 gfx::Size tile_size(256, 256); |
| 648 gfx::Size layer_bounds(512, 512); |
| 649 |
| 650 scoped_refptr<FakePicturePileImpl> pile = |
| 651 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 652 |
| 653 SkBitmap non_lazy_bitmap; |
| 654 CreateBitmap(gfx::Size(512, 512), "notlazy", &non_lazy_bitmap); |
| 655 |
| 656 SkBitmap lazy_bitmap[2][2]; |
| 657 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][0]); |
| 658 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[0][1]); |
| 659 CreateBitmap(gfx::Size(128, 128), "lazy", &lazy_bitmap[1][1]); |
| 660 |
| 661 // One large non-lazy bitmap covers the whole grid. |
| 662 // Lazy pixel refs are found in the following cells: |
| 663 // |---|---| |
| 664 // | x | x | |
| 665 // |---|---| |
| 666 // | | x | |
| 667 // |---|---| |
| 668 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); |
| 669 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); |
| 670 pile->add_draw_bitmap(lazy_bitmap[0][1], gfx::Point(260, 0)); |
| 671 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 672 |
| 673 RerecordPile(pile); |
| 674 |
| 675 // Tile sized iterators. These should find only one pixel ref. |
| 676 { |
| 677 PicturePileImpl::PixelRefIterator iterator( |
| 678 gfx::Rect(0, 0, 256, 256), |
| 679 1.0, |
| 680 pile); |
| 681 EXPECT_TRUE(iterator); |
| 682 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 683 EXPECT_FALSE(++iterator); |
| 684 } |
| 685 { |
| 686 PicturePileImpl::PixelRefIterator iterator( |
| 687 gfx::Rect(0, 0, 512, 512), |
| 688 2.0, |
| 689 pile); |
| 690 EXPECT_TRUE(iterator); |
| 691 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 692 EXPECT_FALSE(++iterator); |
| 693 } |
| 694 { |
| 695 PicturePileImpl::PixelRefIterator iterator( |
| 696 gfx::Rect(0, 0, 128, 128), |
| 697 0.5, |
| 698 pile); |
| 699 EXPECT_TRUE(iterator); |
| 700 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 701 EXPECT_FALSE(++iterator); |
| 702 } |
| 703 // Shifted tile sized iterators. These should find only one pixel ref. |
| 704 { |
| 705 PicturePileImpl::PixelRefIterator iterator( |
| 706 gfx::Rect(260, 260, 256, 256), |
| 707 1.0, |
| 708 pile); |
| 709 EXPECT_TRUE(iterator); |
| 710 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 711 EXPECT_FALSE(++iterator); |
| 712 } |
| 713 { |
| 714 PicturePileImpl::PixelRefIterator iterator( |
| 715 gfx::Rect(520, 520, 512, 512), |
| 716 2.0, |
| 717 pile); |
| 718 EXPECT_TRUE(iterator); |
| 719 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 720 EXPECT_FALSE(++iterator); |
| 721 } |
| 722 { |
| 723 PicturePileImpl::PixelRefIterator iterator( |
| 724 gfx::Rect(130, 130, 128, 128), |
| 725 0.5, |
| 726 pile); |
| 727 EXPECT_TRUE(iterator); |
| 728 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 729 EXPECT_FALSE(++iterator); |
| 730 } |
| 731 // Ensure there's no lazy pixel refs in the empty cell |
| 732 { |
| 733 PicturePileImpl::PixelRefIterator iterator( |
| 734 gfx::Rect(0, 256, 256, 256), |
| 735 1.0, |
| 736 pile); |
| 737 EXPECT_FALSE(iterator); |
| 738 } |
| 739 // Layer sized iterators. These should find three pixel ref. |
| 740 { |
| 741 PicturePileImpl::PixelRefIterator iterator( |
| 742 gfx::Rect(0, 0, 512, 512), |
| 743 1.0, |
| 744 pile); |
| 745 EXPECT_TRUE(iterator); |
| 746 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 747 EXPECT_TRUE(++iterator); |
| 748 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 749 EXPECT_TRUE(++iterator); |
| 750 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 751 EXPECT_FALSE(++iterator); |
| 752 } |
| 753 { |
| 754 PicturePileImpl::PixelRefIterator iterator( |
| 755 gfx::Rect(0, 0, 1024, 1024), |
| 756 2.0, |
| 757 pile); |
| 758 EXPECT_TRUE(iterator); |
| 759 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 760 EXPECT_TRUE(++iterator); |
| 761 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 762 EXPECT_TRUE(++iterator); |
| 763 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 764 EXPECT_FALSE(++iterator); |
| 765 } |
| 766 { |
| 767 PicturePileImpl::PixelRefIterator iterator( |
| 768 gfx::Rect(0, 0, 256, 256), |
| 769 0.5, |
| 770 pile); |
| 771 EXPECT_TRUE(iterator); |
| 772 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 773 EXPECT_TRUE(++iterator); |
| 774 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 775 EXPECT_TRUE(++iterator); |
| 776 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 777 EXPECT_FALSE(++iterator); |
| 778 } |
| 779 } |
| 780 |
| 781 TEST(PicturePileImplTest, PixelRefIteratorMultiplePictures) { |
| 782 gfx::Size tile_size(256, 256); |
| 783 gfx::Size layer_bounds(256, 256); |
| 784 |
| 785 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 786 tile_grid_info.fTileInterval = SkISize::Make(256, 256); |
| 787 tile_grid_info.fMargin.setEmpty(); |
| 788 tile_grid_info.fOffset.setZero(); |
| 789 |
| 790 scoped_refptr<FakePicturePileImpl> pile = |
| 791 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 792 |
| 793 SkBitmap lazy_bitmap[2][2]; |
| 794 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][0]); |
| 795 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[0][1]); |
| 796 CreateBitmap(gfx::Size(32, 32), "lazy", &lazy_bitmap[1][1]); |
| 797 SkBitmap non_lazy_bitmap; |
| 798 CreateBitmap(gfx::Size(256, 256), "notlazy", &non_lazy_bitmap); |
| 799 |
| 800 // Each bitmap goes into its own picture, the final layout |
| 801 // has lazy pixel refs in the following regions: |
| 802 // ||=======|| |
| 803 // ||x| |x|| |
| 804 // ||-- --|| |
| 805 // || |x|| |
| 806 // ||=======|| |
| 807 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); |
| 808 RerecordPile(pile); |
| 809 |
| 810 FakeContentLayerClient content_layer_clients[2][2]; |
| 811 scoped_refptr<Picture> pictures[2][2]; |
| 812 for (int y = 0; y < 2; ++y) { |
| 813 for (int x = 0; x < 2; ++x) { |
| 814 if (x == 0 && y == 1) |
| 815 continue; |
| 816 content_layer_clients[y][x].add_draw_bitmap( |
| 817 lazy_bitmap[y][x], |
| 818 gfx::Point(x * 128 + 10, y * 128 + 10)); |
| 819 pictures[y][x] = Picture::Create( |
| 820 gfx::Rect(x * 128 + 10, y * 128 + 10, 64, 64)); |
| 821 pictures[y][x]->Record( |
| 822 &content_layer_clients[y][x], |
| 823 NULL, |
| 824 tile_grid_info); |
| 825 pile->AddPictureToRecording(0, 0, pictures[y][x]); |
| 826 } |
| 827 } |
| 828 |
| 829 // These should find only one pixel ref. |
| 830 { |
| 831 PicturePileImpl::PixelRefIterator iterator( |
| 832 gfx::Rect(0, 0, 128, 128), |
| 833 1.0, |
| 834 pile); |
| 835 EXPECT_TRUE(iterator); |
| 836 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 837 EXPECT_FALSE(++iterator); |
| 838 } |
| 839 { |
| 840 PicturePileImpl::PixelRefIterator iterator( |
| 841 gfx::Rect(128, 0, 128, 128), |
| 842 1.0, |
| 843 pile); |
| 844 EXPECT_TRUE(iterator); |
| 845 EXPECT_TRUE(*iterator == lazy_bitmap[0][1].pixelRef()); |
| 846 EXPECT_FALSE(++iterator); |
| 847 } |
| 848 { |
| 849 PicturePileImpl::PixelRefIterator iterator( |
| 850 gfx::Rect(128, 128, 128, 128), |
| 851 1.0, |
| 852 pile); |
| 853 EXPECT_TRUE(iterator); |
| 854 EXPECT_TRUE(*iterator == lazy_bitmap[1][1].pixelRef()); |
| 855 EXPECT_FALSE(++iterator); |
| 856 } |
| 857 // This one should not find any refs |
| 858 { |
| 859 PicturePileImpl::PixelRefIterator iterator( |
| 860 gfx::Rect(0, 128, 128, 128), |
| 861 1.0, |
| 862 pile); |
| 863 EXPECT_FALSE(iterator); |
| 864 } |
| 865 } |
137 | 866 |
138 } // namespace | 867 } // namespace |
139 } // namespace cc | 868 } // namespace cc |
OLD | NEW |