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 <map> | 5 #include <map> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "cc/resources/picture_pile.h" | 8 #include "cc/resources/picture_pile.h" |
9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
10 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 typedef PicturePile::PictureMapKey PictureMapKey; | 32 typedef PicturePile::PictureMapKey PictureMapKey; |
33 typedef PicturePile::PictureMap PictureMap; | 33 typedef PicturePile::PictureMap PictureMap; |
34 | 34 |
35 protected: | 35 protected: |
36 virtual ~TestPicturePile() {} | 36 virtual ~TestPicturePile() {} |
37 }; | 37 }; |
38 | 38 |
39 class PicturePileTestBase { | 39 class PicturePileTestBase { |
40 public: | 40 public: |
41 PicturePileTestBase() | 41 PicturePileTestBase() |
42 : pile_(new TestPicturePile()), | 42 : background_color_(SK_ColorBLUE), |
43 background_color_(SK_ColorBLUE), | |
44 min_scale_(0.125), | 43 min_scale_(0.125), |
45 frame_number_(0), | 44 frame_number_(0), |
46 contents_opaque_(false) { | 45 contents_opaque_(false) {} |
| 46 |
| 47 void InitializeData() { |
| 48 pile_ = make_scoped_refptr(new TestPicturePile()); |
47 pile_->SetTileGridSize(gfx::Size(1000, 1000)); | 49 pile_->SetTileGridSize(gfx::Size(1000, 1000)); |
48 pile_->SetMinContentsScale(min_scale_); | 50 pile_->SetMinContentsScale(min_scale_); |
| 51 client_ = FakeContentLayerClient(); |
49 SetTilingSize(pile_->tiling().max_texture_size()); | 52 SetTilingSize(pile_->tiling().max_texture_size()); |
50 } | 53 } |
51 | 54 |
52 void SetTilingSize(const gfx::Size& tiling_size) { | 55 void SetTilingSize(const gfx::Size& tiling_size) { |
53 Region invalidation; | 56 Region invalidation; |
54 gfx::Rect viewport_rect(tiling_size); | 57 gfx::Rect viewport_rect(tiling_size); |
55 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); | 58 UpdateAndExpandInvalidation(&invalidation, tiling_size, viewport_rect); |
56 } | 59 } |
57 | 60 |
58 gfx::Size tiling_size() const { return pile_->tiling_size(); } | 61 gfx::Size tiling_size() const { return pile_->tiling_size(); } |
(...skipping 25 matching lines...) Expand all Loading... |
84 | 87 |
85 FakeContentLayerClient client_; | 88 FakeContentLayerClient client_; |
86 FakeRenderingStatsInstrumentation stats_instrumentation_; | 89 FakeRenderingStatsInstrumentation stats_instrumentation_; |
87 scoped_refptr<TestPicturePile> pile_; | 90 scoped_refptr<TestPicturePile> pile_; |
88 SkColor background_color_; | 91 SkColor background_color_; |
89 float min_scale_; | 92 float min_scale_; |
90 int frame_number_; | 93 int frame_number_; |
91 bool contents_opaque_; | 94 bool contents_opaque_; |
92 }; | 95 }; |
93 | 96 |
94 class PicturePileTest : public PicturePileTestBase, public testing::Test {}; | 97 class PicturePileTest : public PicturePileTestBase, public testing::Test { |
| 98 public: |
| 99 virtual void SetUp() OVERRIDE { InitializeData(); } |
| 100 }; |
95 | 101 |
96 TEST_F(PicturePileTest, SmallInvalidateInflated) { | 102 TEST_F(PicturePileTest, SmallInvalidateInflated) { |
97 // Invalidate something inside a tile. | 103 // Invalidate something inside a tile. |
98 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); | 104 Region invalidate_rect(gfx::Rect(50, 50, 1, 1)); |
99 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); | 105 UpdateAndExpandInvalidation(&invalidate_rect, tiling_size(), tiling_rect()); |
100 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); | 106 EXPECT_EQ(gfx::Rect(50, 50, 1, 1).ToString(), invalidate_rect.ToString()); |
101 | 107 |
102 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); | 108 EXPECT_EQ(1, pile_->tiling().num_tiles_x()); |
103 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); | 109 EXPECT_EQ(1, pile_->tiling().num_tiles_y()); |
104 | 110 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 enum Corner { | 395 enum Corner { |
390 TOP_LEFT, | 396 TOP_LEFT, |
391 TOP_RIGHT, | 397 TOP_RIGHT, |
392 BOTTOM_LEFT, | 398 BOTTOM_LEFT, |
393 BOTTOM_RIGHT, | 399 BOTTOM_RIGHT, |
394 }; | 400 }; |
395 | 401 |
396 class PicturePileResizeCornerTest : public PicturePileTestBase, | 402 class PicturePileResizeCornerTest : public PicturePileTestBase, |
397 public testing::TestWithParam<Corner> { | 403 public testing::TestWithParam<Corner> { |
398 protected: | 404 protected: |
| 405 virtual void SetUp() OVERRIDE { InitializeData(); } |
| 406 |
399 static gfx::Rect CornerSinglePixelRect(Corner corner, const gfx::Size& s) { | 407 static gfx::Rect CornerSinglePixelRect(Corner corner, const gfx::Size& s) { |
400 switch (corner) { | 408 switch (corner) { |
401 case TOP_LEFT: | 409 case TOP_LEFT: |
402 return gfx::Rect(0, 0, 1, 1); | 410 return gfx::Rect(0, 0, 1, 1); |
403 case TOP_RIGHT: | 411 case TOP_RIGHT: |
404 return gfx::Rect(s.width() - 1, 0, 1, 1); | 412 return gfx::Rect(s.width() - 1, 0, 1, 1); |
405 case BOTTOM_LEFT: | 413 case BOTTOM_LEFT: |
406 return gfx::Rect(0, s.height() - 1, 1, 1); | 414 return gfx::Rect(0, s.height() - 1, 1, 1); |
407 case BOTTOM_RIGHT: | 415 case BOTTOM_RIGHT: |
408 return gfx::Rect(s.width() - 1, s.height() - 1, 1, 1); | 416 return gfx::Rect(s.width() - 1, s.height() - 1, 1, 1); |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 TestPicturePile::PictureMap::iterator it = map.find(key); | 1192 TestPicturePile::PictureMap::iterator it = map.find(key); |
1185 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1193 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
1186 } | 1194 } |
1187 } | 1195 } |
1188 | 1196 |
1189 // No invalidation when shrinking. | 1197 // No invalidation when shrinking. |
1190 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1198 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
1191 invalidation.Clear(); | 1199 invalidation.Clear(); |
1192 } | 1200 } |
1193 | 1201 |
| 1202 TEST_F(PicturePileTest, SolidRectangleIsSolid) { |
| 1203 // If the client has no contents, the solid state will be true. |
| 1204 Region invalidation1(tiling_rect()); |
| 1205 UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect()); |
| 1206 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1207 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), pile_->GetSolidColor()); |
| 1208 |
| 1209 // If there is a single rect that covers the view, the solid |
| 1210 // state will be true. |
| 1211 SkPaint paint; |
| 1212 paint.setColor(SK_ColorCYAN); |
| 1213 client_.add_draw_rect(tiling_rect(), paint); |
| 1214 Region invalidation2(tiling_rect()); |
| 1215 UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect()); |
| 1216 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1217 EXPECT_EQ(SK_ColorCYAN, pile_->GetSolidColor()); |
| 1218 |
| 1219 // If a second smaller rect is draw that doesn't cover the viewport |
| 1220 // completely, the solid state will be false. |
| 1221 gfx::Rect smallRect = tiling_rect(); |
| 1222 smallRect.Inset(10, 10, 10, 10); |
| 1223 client_.add_draw_rect(smallRect, paint); |
| 1224 Region invalidation3(tiling_rect()); |
| 1225 UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect()); |
| 1226 EXPECT_FALSE(pile_->IsSolidColor()); |
| 1227 |
| 1228 // If a third rect is drawn over everything, we should be solid again. |
| 1229 paint.setColor(SK_ColorRED); |
| 1230 client_.add_draw_rect(tiling_rect(), paint); |
| 1231 Region invalidation4(tiling_rect()); |
| 1232 UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect()); |
| 1233 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1234 EXPECT_EQ(SK_ColorRED, pile_->GetSolidColor()); |
| 1235 |
| 1236 // If we draw too many, we don't bother doing the analysis and we should no |
| 1237 // longer be in a solid state. There are 8 rects, two clips and a translate. |
| 1238 client_.add_draw_rect(tiling_rect(), paint); |
| 1239 client_.add_draw_rect(tiling_rect(), paint); |
| 1240 client_.add_draw_rect(tiling_rect(), paint); |
| 1241 client_.add_draw_rect(tiling_rect(), paint); |
| 1242 client_.add_draw_rect(tiling_rect(), paint); |
| 1243 Region invalidation5(tiling_rect()); |
| 1244 UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect()); |
| 1245 EXPECT_FALSE(pile_->IsSolidColor()); |
| 1246 } |
| 1247 |
1194 } // namespace | 1248 } // namespace |
1195 } // namespace cc | 1249 } // namespace cc |
OLD | NEW |