OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/test/fake_picture_pile_impl.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/gfx/rect.h" |
| 8 |
| 9 namespace cc { |
| 10 namespace { |
| 11 |
| 12 void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) { |
| 13 for (int y = 0; y < pile->num_tiles_y(); ++y) { |
| 14 for (int x = 0; x < pile->num_tiles_x(); ++x) { |
| 15 pile->RemoveRecordingAt(x, y); |
| 16 pile->AddRecordingAt(x, y); |
| 17 } |
| 18 } |
| 19 } |
| 20 |
| 21 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { |
| 22 gfx::Size tile_size(100, 100); |
| 23 gfx::Size layer_bounds(400, 400); |
| 24 |
| 25 scoped_refptr<FakePicturePileImpl> pile = |
| 26 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 27 |
| 28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 29 SkPaint solid_paint; |
| 30 solid_paint.setColor(solid_color); |
| 31 |
| 32 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 33 SkPaint non_solid_paint; |
| 34 non_solid_paint.setColor(non_solid_color); |
| 35 |
| 36 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 37 RerecordPile(pile); |
| 38 |
| 39 // Ensure everything is solid |
| 40 for (int y = 0; y <= 300; y += 100) { |
| 41 for (int x = 0; x <= 300; x += 100) { |
| 42 PicturePileImpl::Analysis analysis; |
| 43 gfx::Rect rect(x, y, 100, 100); |
| 44 pile->AnalyzeInRect(rect, 1.0, &analysis); |
| 45 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 46 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 47 } |
| 48 } |
| 49 |
| 50 // One pixel non solid |
| 51 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 52 RerecordPile(pile); |
| 53 |
| 54 PicturePileImpl::Analysis analysis; |
| 55 pile->AnalyzeInRect(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); |
| 56 EXPECT_FALSE(analysis.is_solid_color); |
| 57 |
| 58 pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis); |
| 59 EXPECT_TRUE(analysis.is_solid_color); |
| 60 EXPECT_EQ(analysis.solid_color, solid_color); |
| 61 |
| 62 // Boundaries should be clipped |
| 63 analysis.is_solid_color = false; |
| 64 pile->AnalyzeInRect(gfx::Rect(350, 0, 100, 100), 1.0, &analysis); |
| 65 EXPECT_TRUE(analysis.is_solid_color); |
| 66 EXPECT_EQ(analysis.solid_color, solid_color); |
| 67 |
| 68 analysis.is_solid_color = false; |
| 69 pile->AnalyzeInRect(gfx::Rect(0, 350, 100, 100), 1.0, &analysis); |
| 70 EXPECT_TRUE(analysis.is_solid_color); |
| 71 EXPECT_EQ(analysis.solid_color, solid_color); |
| 72 |
| 73 analysis.is_solid_color = false; |
| 74 pile->AnalyzeInRect(gfx::Rect(350, 350, 100, 100), 1.0, &analysis); |
| 75 EXPECT_TRUE(analysis.is_solid_color); |
| 76 EXPECT_EQ(analysis.solid_color, solid_color); |
| 77 } |
| 78 |
| 79 TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { |
| 80 gfx::Size tile_size(100, 100); |
| 81 gfx::Size layer_bounds(400, 400); |
| 82 |
| 83 scoped_refptr<FakePicturePileImpl> pile = |
| 84 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 85 |
| 86 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 87 SkPaint solid_paint; |
| 88 solid_paint.setColor(solid_color); |
| 89 |
| 90 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
| 91 SkPaint non_solid_paint; |
| 92 non_solid_paint.setColor(non_solid_color); |
| 93 |
| 94 pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint); |
| 95 RerecordPile(pile); |
| 96 |
| 97 // Ensure everything is solid |
| 98 for (int y = 0; y <= 30; y += 10) { |
| 99 for (int x = 0; x <= 30; x += 10) { |
| 100 PicturePileImpl::Analysis analysis; |
| 101 gfx::Rect rect(x, y, 10, 10); |
| 102 pile->AnalyzeInRect(rect, 0.1f, &analysis); |
| 103 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
| 104 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
| 105 } |
| 106 } |
| 107 |
| 108 // One pixel non solid |
| 109 pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint); |
| 110 RerecordPile(pile); |
| 111 |
| 112 PicturePileImpl::Analysis analysis; |
| 113 pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); |
| 114 EXPECT_FALSE(analysis.is_solid_color); |
| 115 |
| 116 pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); |
| 117 EXPECT_TRUE(analysis.is_solid_color); |
| 118 EXPECT_EQ(analysis.solid_color, solid_color); |
| 119 |
| 120 // Boundaries should be clipped |
| 121 analysis.is_solid_color = false; |
| 122 pile->AnalyzeInRect(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); |
| 123 EXPECT_TRUE(analysis.is_solid_color); |
| 124 EXPECT_EQ(analysis.solid_color, solid_color); |
| 125 |
| 126 analysis.is_solid_color = false; |
| 127 pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); |
| 128 EXPECT_TRUE(analysis.is_solid_color); |
| 129 EXPECT_EQ(analysis.solid_color, solid_color); |
| 130 |
| 131 analysis.is_solid_color = false; |
| 132 pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); |
| 133 EXPECT_TRUE(analysis.is_solid_color); |
| 134 EXPECT_EQ(analysis.solid_color, solid_color); |
| 135 } |
| 136 |
| 137 |
| 138 } // namespace |
| 139 } // namespace cc |
OLD | NEW |