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/resources/picture_pile.h" | |
6 #include "cc/test/fake_content_layer_client.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "ui/gfx/rect_conversions.h" | |
9 | |
10 namespace cc { | |
11 namespace { | |
12 | |
13 class TestPicturePile : public PicturePile { | |
14 public: | |
15 using PicturePile::buffer_pixels; | |
16 | |
17 PictureListMap& picture_list_map() { return picture_list_map_; } | |
18 | |
19 typedef PicturePile::PictureList PictureList; | |
20 typedef PicturePile::PictureListMapKey PictureListMapKey; | |
21 typedef PicturePile::PictureListMap PictureListMap; | |
22 | |
23 protected: | |
24 virtual ~TestPicturePile() {} | |
25 }; | |
26 | |
27 // Update this if the implementation changes. | |
28 const int kBasePictureSize = 3000; | |
enne (OOO)
2013/05/09 22:55:44
Maybe make this configurable from the test so you
danakj
2013/05/09 23:11:53
Hummm..!
Actually, I can just use the tiling().ma
| |
29 | |
30 TEST(PicturePileTest, SmallInvalidateInflated) { | |
31 FakeContentLayerClient client; | |
32 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
33 SkColor background_color = SK_ColorBLUE; | |
34 | |
35 float min_scale = 0.125; | |
36 | |
37 gfx::Size layer_size(kBasePictureSize, kBasePictureSize); | |
38 pile->Resize(layer_size); | |
39 pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | |
40 pile->SetMinContentsScale(min_scale); | |
41 | |
42 // Update the whole layer. | |
43 pile->Update(&client, | |
44 background_color, | |
45 gfx::Rect(layer_size), | |
46 gfx::Rect(layer_size), | |
47 NULL); | |
48 | |
49 // Invalidate something inside a tile. | |
50 gfx::Rect invalidate_rect(50, 50, 1, 1); | |
51 pile->Update(&client, | |
52 background_color, | |
53 invalidate_rect, | |
54 gfx::Rect(layer_size), | |
55 NULL); | |
56 | |
57 EXPECT_EQ(1, pile->tiling().num_tiles_x()); | |
58 EXPECT_EQ(1, pile->tiling().num_tiles_y()); | |
59 | |
60 TestPicturePile::PictureList& picture_list = | |
61 pile->picture_list_map().find( | |
62 TestPicturePile::PictureListMapKey(0, 0))->second; | |
63 EXPECT_EQ(2u, picture_list.size()); | |
64 for (TestPicturePile::PictureList::iterator it = picture_list.begin(); | |
65 it != picture_list.end(); | |
66 ++it) { | |
67 scoped_refptr<Picture> picture = *it; | |
68 gfx::Rect picture_rect = gfx::ToEnclosedRect( | |
69 gfx::ScaleRect(picture->LayerRect(), min_scale)); | |
70 | |
71 // The invalidation in each tile should have been made large enough | |
72 // that scaling it never makes a rect smaller than 1 px wide or tall. | |
73 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | |
74 picture_rect.ToString(); | |
75 } | |
76 } | |
77 | |
78 TEST(PicturePileTest, LargeInvalidateInflated) { | |
79 FakeContentLayerClient client; | |
80 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
81 SkColor background_color = SK_ColorBLUE; | |
82 | |
83 float min_scale = 0.125; | |
84 | |
85 gfx::Size layer_size(kBasePictureSize, kBasePictureSize); | |
86 pile->Resize(layer_size); | |
87 pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | |
88 pile->SetMinContentsScale(min_scale); | |
89 | |
90 // Update the whole layer. | |
91 pile->Update(&client, | |
92 background_color, | |
93 gfx::Rect(layer_size), | |
94 gfx::Rect(layer_size), | |
95 NULL); | |
96 | |
97 // Invalidate something inside a tile. | |
98 gfx::Rect invalidate_rect(50, 50, 100, 100); | |
99 pile->Update(&client, | |
100 background_color, | |
101 invalidate_rect, | |
102 gfx::Rect(layer_size), | |
103 NULL); | |
104 | |
105 EXPECT_EQ(1, pile->tiling().num_tiles_x()); | |
106 EXPECT_EQ(1, pile->tiling().num_tiles_y()); | |
107 | |
108 TestPicturePile::PictureList& picture_list = | |
109 pile->picture_list_map().find( | |
110 TestPicturePile::PictureListMapKey(0, 0))->second; | |
111 EXPECT_EQ(2u, picture_list.size()); | |
112 | |
113 int expected_inflation = ceil(1.f / min_scale) - 1; | |
enne (OOO)
2013/05/09 22:55:44
Can you just ask for the buffer pixels?
danakj
2013/05/09 23:11:53
Done.
| |
114 | |
115 scoped_refptr<Picture> base_picture = *picture_list.begin(); | |
116 gfx::Rect base_picture_rect(layer_size); | |
117 base_picture_rect.Inset(-expected_inflation, -expected_inflation); | |
118 EXPECT_EQ(base_picture_rect.ToString(), | |
119 base_picture->LayerRect().ToString()); | |
120 | |
121 scoped_refptr<Picture> picture = *(++picture_list.begin()); | |
122 gfx::Rect picture_rect(invalidate_rect); | |
123 picture_rect.Inset(-expected_inflation, -expected_inflation); | |
124 EXPECT_EQ(picture_rect.ToString(), | |
125 picture->LayerRect().ToString()); | |
126 } | |
127 | |
128 TEST(PicturePileTest, InvalidateOnTileBoundaryInflated) { | |
129 FakeContentLayerClient client; | |
130 scoped_refptr<TestPicturePile> pile = new TestPicturePile; | |
131 SkColor background_color = SK_ColorBLUE; | |
132 | |
133 float min_scale = 0.125; | |
134 | |
135 gfx::Size layer_size(kBasePictureSize * 2, kBasePictureSize * 2); | |
136 pile->Resize(layer_size); | |
137 pile->SetTileGridSize(gfx::Size(kBasePictureSize, kBasePictureSize)); | |
138 pile->SetMinContentsScale(min_scale); | |
139 | |
140 // Verify kBasePictureSize matches our expectations. Update kBasePictureSize | |
141 // if these are wrong. | |
142 EXPECT_EQ(3, pile->tiling().num_tiles_x()); | |
143 EXPECT_EQ(3, pile->tiling().num_tiles_y()); | |
144 EXPECT_EQ(kBasePictureSize, pile->tiling().max_texture_size().width()); | |
145 EXPECT_EQ(kBasePictureSize, pile->tiling().max_texture_size().height()); | |
146 | |
147 // We should have 1/.125 - 1 = 7 border pixels. | |
148 EXPECT_EQ(7, pile->buffer_pixels()); | |
149 EXPECT_EQ(7, pile->tiling().border_texels()); | |
150 | |
151 // Update the whole layer. | |
152 pile->Update(&client, | |
153 background_color, | |
154 gfx::Rect(layer_size), | |
155 gfx::Rect(layer_size), | |
156 NULL); | |
157 | |
158 // Invalidate something just over a tile boundary by a single pixel. | |
159 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0). | |
160 gfx::Rect invalidate_rect( | |
161 pile->tiling().TileBoundsWithBorder(0, 0).right(), | |
162 pile->tiling().TileBoundsWithBorder(0, 0).bottom() - 1, | |
163 50, | |
164 50); | |
165 pile->Update(&client, | |
166 background_color, | |
167 invalidate_rect, | |
168 gfx::Rect(layer_size), | |
169 NULL); | |
170 | |
171 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) { | |
172 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) { | |
173 // (1, 0) and (1, 1) should be invalidated partially. | |
174 bool expect_invalidated = i == 1 && (j == 0 || j == 1); | |
175 | |
176 TestPicturePile::PictureList& picture_list = | |
177 pile->picture_list_map().find( | |
178 TestPicturePile::PictureListMapKey(i, j))->second; | |
179 if (!expect_invalidated) { | |
180 EXPECT_EQ(1u, picture_list.size()) << "For i,j " << i << "," << j; | |
181 continue; | |
182 } | |
183 | |
184 EXPECT_EQ(2u, picture_list.size()) << "For i,j " << i << "," << j; | |
185 for (TestPicturePile::PictureList::iterator it = picture_list.begin(); | |
186 it != picture_list.end(); | |
187 ++it) { | |
188 scoped_refptr<Picture> picture = *it; | |
189 gfx::Rect picture_rect = gfx::ToEnclosedRect( | |
190 gfx::ScaleRect(picture->LayerRect(), min_scale)); | |
191 | |
192 // The invalidation in each tile should have been made large enough | |
193 // that scaling it never makes a rect smaller than 1 px wide or tall. | |
194 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " << | |
195 picture_rect.ToString(); | |
196 } | |
197 } | |
198 } | |
199 } | |
200 | |
201 } // namespace | |
202 } // namespace cc | |
OLD | NEW |