| 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 "skia/ext/lazy_pixel_ref.h" | 7 #include "skia/ext/lazy_pixel_ref.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkPixelRef.h" | 9 #include "third_party/skia/include/core/SkPixelRef.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; | 61 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; |
| 62 lazy_pixel_ref.reset(new TestLazyPixelRef(size.width(), size.height())); | 62 lazy_pixel_ref.reset(new TestLazyPixelRef(size.width(), size.height())); |
| 63 lazy_pixel_ref->setURI(uri); | 63 lazy_pixel_ref->setURI(uri); |
| 64 | 64 |
| 65 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 65 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 66 size.width(), | 66 size.width(), |
| 67 size.height()); | 67 size.height()); |
| 68 bitmap->setPixelRef(lazy_pixel_ref); | 68 bitmap->setPixelRef(lazy_pixel_ref); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) { | |
| 72 for (int y = 0; y < pile->num_tiles_y(); ++y) { | |
| 73 for (int x = 0; x < pile->num_tiles_x(); ++x) { | |
| 74 pile->RemoveRecordingAt(x, y); | |
| 75 pile->AddRecordingAt(x, y); | |
| 76 } | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { | 71 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { |
| 81 gfx::Size tile_size(100, 100); | 72 gfx::Size tile_size(100, 100); |
| 82 gfx::Size layer_bounds(400, 400); | 73 gfx::Size layer_bounds(400, 400); |
| 83 | 74 |
| 84 scoped_refptr<FakePicturePileImpl> pile = | 75 scoped_refptr<FakePicturePileImpl> pile = |
| 85 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 76 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 86 | 77 |
| 87 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 78 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 88 SkPaint solid_paint; | 79 SkPaint solid_paint; |
| 89 solid_paint.setColor(solid_color); | 80 solid_paint.setColor(solid_color); |
| 90 | 81 |
| 91 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 82 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 92 SkPaint non_solid_paint; | 83 SkPaint non_solid_paint; |
| 93 non_solid_paint.setColor(non_solid_color); | 84 non_solid_paint.setColor(non_solid_color); |
| 94 | 85 |
| 95 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); | 86 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 96 RerecordPile(pile); | 87 pile->RerecordPile(); |
| 97 | 88 |
| 98 // Ensure everything is solid | 89 // Ensure everything is solid |
| 99 for (int y = 0; y <= 300; y += 100) { | 90 for (int y = 0; y <= 300; y += 100) { |
| 100 for (int x = 0; x <= 300; x += 100) { | 91 for (int x = 0; x <= 300; x += 100) { |
| 101 PicturePileImpl::Analysis analysis; | 92 PicturePileImpl::Analysis analysis; |
| 102 gfx::Rect rect(x, y, 100, 100); | 93 gfx::Rect rect(x, y, 100, 100); |
| 103 pile->AnalyzeInRect(rect, 1.0, &analysis); | 94 pile->AnalyzeInRect(rect, 1.0, &analysis); |
| 104 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 95 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 105 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 96 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 106 } | 97 } |
| 107 } | 98 } |
| 108 | 99 |
| 109 // One pixel non solid | 100 // One pixel non solid |
| 110 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); | 101 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 111 RerecordPile(pile); | 102 pile->RerecordPile(); |
| 112 | 103 |
| 113 PicturePileImpl::Analysis analysis; | 104 PicturePileImpl::Analysis analysis; |
| 114 pile->AnalyzeInRect(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); | 105 pile->AnalyzeInRect(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); |
| 115 EXPECT_FALSE(analysis.is_solid_color); | 106 EXPECT_FALSE(analysis.is_solid_color); |
| 116 | 107 |
| 117 pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); | 108 pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); |
| 118 EXPECT_TRUE(analysis.is_solid_color); | 109 EXPECT_TRUE(analysis.is_solid_color); |
| 119 EXPECT_EQ(analysis.solid_color, solid_color); | 110 EXPECT_EQ(analysis.solid_color, solid_color); |
| 120 | 111 |
| 121 // Boundaries should be clipped | 112 // Boundaries should be clipped |
| (...skipping 22 matching lines...) Expand all Loading... |
| 144 | 135 |
| 145 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 136 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 146 SkPaint solid_paint; | 137 SkPaint solid_paint; |
| 147 solid_paint.setColor(solid_color); | 138 solid_paint.setColor(solid_color); |
| 148 | 139 |
| 149 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 140 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 150 SkPaint non_solid_paint; | 141 SkPaint non_solid_paint; |
| 151 non_solid_paint.setColor(non_solid_color); | 142 non_solid_paint.setColor(non_solid_color); |
| 152 | 143 |
| 153 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); | 144 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 154 RerecordPile(pile); | 145 pile->RerecordPile(); |
| 155 | 146 |
| 156 // Ensure everything is solid | 147 // Ensure everything is solid |
| 157 for (int y = 0; y <= 30; y += 10) { | 148 for (int y = 0; y <= 30; y += 10) { |
| 158 for (int x = 0; x <= 30; x += 10) { | 149 for (int x = 0; x <= 30; x += 10) { |
| 159 PicturePileImpl::Analysis analysis; | 150 PicturePileImpl::Analysis analysis; |
| 160 gfx::Rect rect(x, y, 10, 10); | 151 gfx::Rect rect(x, y, 10, 10); |
| 161 pile->AnalyzeInRect(rect, 0.1f, &analysis); | 152 pile->AnalyzeInRect(rect, 0.1f, &analysis); |
| 162 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 153 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 163 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 154 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 164 } | 155 } |
| 165 } | 156 } |
| 166 | 157 |
| 167 // One pixel non solid | 158 // One pixel non solid |
| 168 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); | 159 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 169 RerecordPile(pile); | 160 pile->RerecordPile(); |
| 170 | 161 |
| 171 PicturePileImpl::Analysis analysis; | 162 PicturePileImpl::Analysis analysis; |
| 172 pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); | 163 pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); |
| 173 EXPECT_FALSE(analysis.is_solid_color); | 164 EXPECT_FALSE(analysis.is_solid_color); |
| 174 | 165 |
| 175 pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); | 166 pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); |
| 176 EXPECT_TRUE(analysis.is_solid_color); | 167 EXPECT_TRUE(analysis.is_solid_color); |
| 177 EXPECT_EQ(analysis.solid_color, solid_color); | 168 EXPECT_EQ(analysis.solid_color, solid_color); |
| 178 | 169 |
| 179 // Boundaries should be clipped | 170 // Boundaries should be clipped |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 CreateBitmap(gfx::Size(128, 128), "notlazy", &non_lazy_bitmap); | 274 CreateBitmap(gfx::Size(128, 128), "notlazy", &non_lazy_bitmap); |
| 284 | 275 |
| 285 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); | 276 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); | 277 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); | 278 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); | 279 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)); | 280 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(128, 0)); |
| 290 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128)); | 281 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128)); |
| 291 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150)); | 282 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150)); |
| 292 | 283 |
| 293 RerecordPile(pile); | 284 pile->RerecordPile(); |
| 294 | 285 |
| 295 // Tile sized iterators. | 286 // Tile sized iterators. |
| 296 { | 287 { |
| 297 PicturePileImpl::PixelRefIterator iterator( | 288 PicturePileImpl::PixelRefIterator iterator( |
| 298 gfx::Rect(0, 0, 128, 128), | 289 gfx::Rect(0, 0, 128, 128), |
| 299 1.0, | 290 1.0, |
| 300 pile); | 291 pile); |
| 301 EXPECT_FALSE(iterator); | 292 EXPECT_FALSE(iterator); |
| 302 } | 293 } |
| 303 { | 294 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Lazy pixel refs are found in the following cells: | 366 // Lazy pixel refs are found in the following cells: |
| 376 // |---|---| | 367 // |---|---| |
| 377 // | x | | | 368 // | x | | |
| 378 // |---|---| | 369 // |---|---| |
| 379 // | x | x | | 370 // | x | x | |
| 380 // |---|---| | 371 // |---|---| |
| 381 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 372 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)); | 373 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)); | 374 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(140, 140)); |
| 384 | 375 |
| 385 RerecordPile(pile); | 376 pile->RerecordPile(); |
| 386 | 377 |
| 387 // Tile sized iterators. These should find only one pixel ref. | 378 // Tile sized iterators. These should find only one pixel ref. |
| 388 { | 379 { |
| 389 PicturePileImpl::PixelRefIterator iterator( | 380 PicturePileImpl::PixelRefIterator iterator( |
| 390 gfx::Rect(0, 0, 128, 128), | 381 gfx::Rect(0, 0, 128, 128), |
| 391 1.0, | 382 1.0, |
| 392 pile); | 383 pile); |
| 393 EXPECT_TRUE(iterator); | 384 EXPECT_TRUE(iterator); |
| 394 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 385 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 395 EXPECT_FALSE(++iterator); | 386 EXPECT_FALSE(++iterator); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 // Lazy pixel refs are found in the following cells: | 496 // Lazy pixel refs are found in the following cells: |
| 506 // |---|---| | 497 // |---|---| |
| 507 // | x | x | | 498 // | x | x | |
| 508 // |---|---| | 499 // |---|---| |
| 509 // | | x | | 500 // | | x | |
| 510 // |---|---| | 501 // |---|---| |
| 511 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 502 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)); | 503 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)); | 504 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 514 | 505 |
| 515 RerecordPile(pile); | 506 pile->RerecordPile(); |
| 516 | 507 |
| 517 // Tile sized iterators. These should find only one pixel ref. | 508 // Tile sized iterators. These should find only one pixel ref. |
| 518 { | 509 { |
| 519 PicturePileImpl::PixelRefIterator iterator( | 510 PicturePileImpl::PixelRefIterator iterator( |
| 520 gfx::Rect(0, 0, 256, 256), | 511 gfx::Rect(0, 0, 256, 256), |
| 521 1.0, | 512 1.0, |
| 522 pile); | 513 pile); |
| 523 EXPECT_TRUE(iterator); | 514 EXPECT_TRUE(iterator); |
| 524 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 515 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 525 EXPECT_FALSE(++iterator); | 516 EXPECT_FALSE(++iterator); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 // |---|---| | 654 // |---|---| |
| 664 // | x | x | | 655 // | x | x | |
| 665 // |---|---| | 656 // |---|---| |
| 666 // | | x | | 657 // | | x | |
| 667 // |---|---| | 658 // |---|---| |
| 668 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); | 659 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); |
| 669 pile->add_draw_bitmap(lazy_bitmap[0][0], gfx::Point(0, 0)); | 660 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)); | 661 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)); | 662 pile->add_draw_bitmap(lazy_bitmap[1][1], gfx::Point(260, 260)); |
| 672 | 663 |
| 673 RerecordPile(pile); | 664 pile->RerecordPile(); |
| 674 | 665 |
| 675 // Tile sized iterators. These should find only one pixel ref. | 666 // Tile sized iterators. These should find only one pixel ref. |
| 676 { | 667 { |
| 677 PicturePileImpl::PixelRefIterator iterator( | 668 PicturePileImpl::PixelRefIterator iterator( |
| 678 gfx::Rect(0, 0, 256, 256), | 669 gfx::Rect(0, 0, 256, 256), |
| 679 1.0, | 670 1.0, |
| 680 pile); | 671 pile); |
| 681 EXPECT_TRUE(iterator); | 672 EXPECT_TRUE(iterator); |
| 682 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); | 673 EXPECT_TRUE(*iterator == lazy_bitmap[0][0].pixelRef()); |
| 683 EXPECT_FALSE(++iterator); | 674 EXPECT_FALSE(++iterator); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 CreateBitmap(gfx::Size(256, 256), "notlazy", &non_lazy_bitmap); | 789 CreateBitmap(gfx::Size(256, 256), "notlazy", &non_lazy_bitmap); |
| 799 | 790 |
| 800 // Each bitmap goes into its own picture, the final layout | 791 // Each bitmap goes into its own picture, the final layout |
| 801 // has lazy pixel refs in the following regions: | 792 // has lazy pixel refs in the following regions: |
| 802 // ||=======|| | 793 // ||=======|| |
| 803 // ||x| |x|| | 794 // ||x| |x|| |
| 804 // ||-- --|| | 795 // ||-- --|| |
| 805 // || |x|| | 796 // || |x|| |
| 806 // ||=======|| | 797 // ||=======|| |
| 807 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); | 798 pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 0)); |
| 808 RerecordPile(pile); | 799 pile->RerecordPile(); |
| 809 | 800 |
| 810 FakeContentLayerClient content_layer_clients[2][2]; | 801 FakeContentLayerClient content_layer_clients[2][2]; |
| 811 scoped_refptr<Picture> pictures[2][2]; | 802 scoped_refptr<Picture> pictures[2][2]; |
| 812 for (int y = 0; y < 2; ++y) { | 803 for (int y = 0; y < 2; ++y) { |
| 813 for (int x = 0; x < 2; ++x) { | 804 for (int x = 0; x < 2; ++x) { |
| 814 if (x == 0 && y == 1) | 805 if (x == 0 && y == 1) |
| 815 continue; | 806 continue; |
| 816 content_layer_clients[y][x].add_draw_bitmap( | 807 content_layer_clients[y][x].add_draw_bitmap( |
| 817 lazy_bitmap[y][x], | 808 lazy_bitmap[y][x], |
| 818 gfx::Point(x * 128 + 10, y * 128 + 10)); | 809 gfx::Point(x * 128 + 10, y * 128 + 10)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 PicturePileImpl::PixelRefIterator iterator( | 850 PicturePileImpl::PixelRefIterator iterator( |
| 860 gfx::Rect(0, 128, 128, 128), | 851 gfx::Rect(0, 128, 128, 128), |
| 861 1.0, | 852 1.0, |
| 862 pile); | 853 pile); |
| 863 EXPECT_FALSE(iterator); | 854 EXPECT_FALSE(iterator); |
| 864 } | 855 } |
| 865 } | 856 } |
| 866 | 857 |
| 867 } // namespace | 858 } // namespace |
| 868 } // namespace cc | 859 } // namespace cc |
| OLD | NEW |