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 virtual void SetUp() OVERRIDE { |
| 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 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 TestPicturePile::PictureMap::iterator it = map.find(key); | 1187 TestPicturePile::PictureMap::iterator it = map.find(key); |
1185 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1188 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
1186 } | 1189 } |
1187 } | 1190 } |
1188 | 1191 |
1189 // No invalidation when shrinking. | 1192 // No invalidation when shrinking. |
1190 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1193 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
1191 invalidation.Clear(); | 1194 invalidation.Clear(); |
1192 } | 1195 } |
1193 | 1196 |
| 1197 TEST_F(PicturePileTest, SolidRectangleIsSolid) { |
| 1198 // If the client has no contents, the solid state will be true. |
| 1199 Region invalidation1(tiling_rect()); |
| 1200 UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect()); |
| 1201 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1202 EXPECT_EQ(SK_ColorTRANSPARENT, pile_->GetSolidColor()); |
| 1203 |
| 1204 // If there is a single rect that covers the view, the solid |
| 1205 // state will be true. |
| 1206 SkPaint paint; |
| 1207 paint.setColor(SK_ColorCYAN); |
| 1208 client_.add_draw_rect(tiling_rect(), paint); |
| 1209 Region invalidation2(tiling_rect()); |
| 1210 UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect()); |
| 1211 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1212 EXPECT_EQ(SK_ColorCYAN, pile_->GetSolidColor()); |
| 1213 |
| 1214 // If a second smaller rect is draw that doesn't cover the viewport |
| 1215 // completely, the solid state will be false. |
| 1216 gfx::Rect smallRect = tiling_rect(); |
| 1217 smallRect.Inset(10, 10, 10, 10); |
| 1218 client_.add_draw_rect(smallRect, paint); |
| 1219 Region invalidation3(tiling_rect()); |
| 1220 UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect()); |
| 1221 EXPECT_FALSE(pile_->IsSolidColor()); |
| 1222 |
| 1223 // If a third rect is drawn over everything, we should be solid again. |
| 1224 paint.setColor(SK_ColorRED); |
| 1225 client_.add_draw_rect(tiling_rect(), paint); |
| 1226 Region invalidation4(tiling_rect()); |
| 1227 UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect()); |
| 1228 EXPECT_TRUE(pile_->IsSolidColor()); |
| 1229 EXPECT_EQ(SK_ColorRED, pile_->GetSolidColor()); |
| 1230 |
| 1231 // If we draw too many, we don't bother doing the analysis and we should no |
| 1232 // longer be in a solid state. There are 8 rects, two clips and a translate. |
| 1233 client_.add_draw_rect(tiling_rect(), paint); |
| 1234 client_.add_draw_rect(tiling_rect(), paint); |
| 1235 client_.add_draw_rect(tiling_rect(), paint); |
| 1236 client_.add_draw_rect(tiling_rect(), paint); |
| 1237 client_.add_draw_rect(tiling_rect(), paint); |
| 1238 Region invalidation5(tiling_rect()); |
| 1239 UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect()); |
| 1240 EXPECT_FALSE(pile_->IsSolidColor()); |
| 1241 } |
| 1242 |
1194 } // namespace | 1243 } // namespace |
1195 } // namespace cc | 1244 } // namespace cc |
OLD | NEW |