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 PicturePileTest : public testing::Test { | 39 class PicturePileTest : public testing::Test { |
40 public: | 40 public: |
41 PicturePileTest() | 41 PicturePileTest() |
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 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
996 TestPicturePile::PictureMap::iterator it = map.find(key); | 999 TestPicturePile::PictureMap::iterator it = map.find(key); |
997 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); | 1000 EXPECT_TRUE(it != map.end() && it->second.GetPicture()); |
998 } | 1001 } |
999 } | 1002 } |
1000 | 1003 |
1001 // No invalidation when shrinking. | 1004 // No invalidation when shrinking. |
1002 EXPECT_EQ(Region().ToString(), invalidation.ToString()); | 1005 EXPECT_EQ(Region().ToString(), invalidation.ToString()); |
1003 invalidation.Clear(); | 1006 invalidation.Clear(); |
1004 } | 1007 } |
1005 | 1008 |
1009 TEST_F(PicturePileTest, SolidRectangleIsSolid) { | |
1010 // If the client has no contents, the solid state will be true | |
1011 Region invalidation1(tiling_rect()); | |
1012 UpdateAndExpandInvalidation(&invalidation1, tiling_size(), tiling_rect()); | |
1013 EXPECT_TRUE(pile_->IsSolidColor()); | |
1014 EXPECT_EQ(SK_ColorTRANSPARENT, pile_->GetSolidColor()); | |
1015 | |
1016 // If there is a single rect that covers the view, the solid | |
1017 // state will be true | |
1018 SkPaint paint; | |
1019 paint.setColor(SK_ColorCYAN); | |
1020 client_.add_draw_rect(tiling_rect(), paint); | |
1021 Region invalidation2(tiling_rect()); | |
1022 UpdateAndExpandInvalidation(&invalidation2, tiling_size(), tiling_rect()); | |
1023 EXPECT_TRUE(pile_->IsSolidColor()); | |
1024 EXPECT_EQ(SK_ColorCYAN, pile_->GetSolidColor()); | |
1025 | |
1026 // if a second smaller rect is draw that doesn't cover the viewport | |
1027 // completely, the solid state will be false | |
1028 gfx::Rect smallRect = tiling_rect(); | |
1029 smallRect.Inset(10, 10, 10, 10); | |
1030 client_.add_draw_rect(smallRect, paint); | |
1031 Region invalidation3(tiling_rect()); | |
1032 UpdateAndExpandInvalidation(&invalidation3, tiling_size(), tiling_rect()); | |
1033 EXPECT_FALSE(pile_->IsSolidColor()); | |
1034 | |
1035 // if a third rect is drawn over everything, we should be solid again | |
1036 paint.setColor(SK_ColorRED); | |
1037 client_.add_draw_rect(tiling_rect(), paint); | |
1038 Region invalidation4(tiling_rect()); | |
1039 UpdateAndExpandInvalidation(&invalidation4, tiling_size(), tiling_rect()); | |
1040 EXPECT_TRUE(pile_->IsSolidColor()); | |
1041 EXPECT_EQ(SK_ColorRED, pile_->GetSolidColor()); | |
1042 | |
1043 // but if we draw too many, we don't bother doing the analysis and we should | |
1044 // no longer be in a solid state | |
1045 client_.add_draw_rect(tiling_rect(), paint); | |
1046 client_.add_draw_rect(tiling_rect(), paint); | |
1047 client_.add_draw_rect(tiling_rect(), paint); | |
1048 client_.add_draw_rect(tiling_rect(), paint); | |
1049 client_.add_draw_rect(tiling_rect(), paint); | |
vmpstr
2014/08/20 16:12:00
I only count 8 draw commands, the limit is 10. Did
hendrikw
2014/08/20 20:46:55
I've added a comment.
| |
1050 Region invalidation5(tiling_rect()); | |
1051 UpdateAndExpandInvalidation(&invalidation5, tiling_size(), tiling_rect()); | |
1052 EXPECT_FALSE(pile_->IsSolidColor()); | |
1053 } | |
1054 | |
1006 } // namespace | 1055 } // namespace |
1007 } // namespace cc | 1056 } // namespace cc |
OLD | NEW |