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 "cc/picture_layer_impl.h" | 5 #include "cc/picture_layer_impl.h" |
6 | 6 |
7 #include "cc/layer_tree_impl.h" | 7 #include "cc/layer_tree_impl.h" |
8 #include "cc/picture_layer.h" | |
8 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
9 #include "cc/test/fake_impl_proxy.h" | 10 #include "cc/test/fake_impl_proxy.h" |
10 #include "cc/test/fake_layer_tree_host_impl.h" | 11 #include "cc/test/fake_layer_tree_host_impl.h" |
11 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 namespace { | 17 namespace { |
17 | 18 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 void AddRecordingAt(int x, int y) { | 83 void AddRecordingAt(int x, int y) { |
83 EXPECT_GE(x, 0); | 84 EXPECT_GE(x, 0); |
84 EXPECT_GE(y, 0); | 85 EXPECT_GE(y, 0); |
85 EXPECT_LT(x, tiling_.num_tiles_x()); | 86 EXPECT_LT(x, tiling_.num_tiles_x()); |
86 EXPECT_LT(y, tiling_.num_tiles_y()); | 87 EXPECT_LT(y, tiling_.num_tiles_y()); |
87 | 88 |
88 if (HasRecordingAt(x, y)) | 89 if (HasRecordingAt(x, y)) |
89 return; | 90 return; |
90 gfx::Rect bounds(tiling().TileBounds(x, y)); | 91 gfx::Rect bounds(tiling().TileBounds(x, y)); |
91 scoped_refptr<Picture> picture(Picture::Create(bounds)); | 92 scoped_refptr<Picture> picture(Picture::Create(bounds)); |
92 FakeContentLayerClient client; | 93 picture->Record(&client_, NULL, tile_grid_info_); |
93 picture->Record(&client, NULL); | |
94 picture_list_map_[std::pair<int, int>(x, y)].push_back(picture); | 94 picture_list_map_[std::pair<int, int>(x, y)].push_back(picture); |
95 EXPECT_TRUE(HasRecordingAt(x, y)); | 95 EXPECT_TRUE(HasRecordingAt(x, y)); |
96 | 96 |
97 UpdateRecordedRegion(); | 97 UpdateRecordedRegion(); |
98 } | 98 } |
99 | 99 |
100 void RemoveRecordingAt(int x, int y) { | 100 void RemoveRecordingAt(int x, int y) { |
101 EXPECT_GE(x, 0); | 101 EXPECT_GE(x, 0); |
102 EXPECT_GE(y, 0); | 102 EXPECT_GE(y, 0); |
103 EXPECT_LT(x, tiling_.num_tiles_x()); | 103 EXPECT_LT(x, tiling_.num_tiles_x()); |
104 EXPECT_LT(y, tiling_.num_tiles_y()); | 104 EXPECT_LT(y, tiling_.num_tiles_y()); |
105 | 105 |
106 if (!HasRecordingAt(x, y)) | 106 if (!HasRecordingAt(x, y)) |
107 return; | 107 return; |
108 picture_list_map_.erase(std::pair<int, int>(x, y)); | 108 picture_list_map_.erase(std::pair<int, int>(x, y)); |
109 EXPECT_FALSE(HasRecordingAt(x, y)); | 109 EXPECT_FALSE(HasRecordingAt(x, y)); |
110 | 110 |
111 UpdateRecordedRegion(); | 111 UpdateRecordedRegion(); |
112 } | 112 } |
113 | 113 |
114 void addDrawRect(const gfx::Rect& rect) { | |
115 client_.addDrawRect(rect); | |
116 } | |
117 | |
114 protected: | 118 protected: |
115 virtual ~TestablePicturePileImpl() { | 119 virtual ~TestablePicturePileImpl() { |
116 } | 120 } |
121 | |
122 FakeContentLayerClient client_; | |
117 }; | 123 }; |
118 | 124 |
119 class ImplSidePaintingSettings : public LayerTreeSettings { | 125 class ImplSidePaintingSettings : public LayerTreeSettings { |
120 public: | 126 public: |
121 ImplSidePaintingSettings() { | 127 ImplSidePaintingSettings() { |
122 implSidePainting = true; | 128 implSidePainting = true; |
123 } | 129 } |
124 }; | 130 }; |
125 | 131 |
132 class MockCanvas : public SkCanvas { | |
133 public: | |
134 explicit MockCanvas(SkDevice* device) : SkCanvas(device) { } | |
135 | |
136 virtual void drawRect(const SkRect& rect, const SkPaint& paint) { | |
137 // Capture calls before SkCanvas quickReject kicks in | |
138 rects_.push_back(rect); | |
139 } | |
140 | |
141 std::vector<SkRect> rects_; | |
142 }; | |
143 | |
126 class PictureLayerImplTest : public testing::Test { | 144 class PictureLayerImplTest : public testing::Test { |
127 public: | 145 public: |
128 PictureLayerImplTest() | 146 PictureLayerImplTest() |
129 : host_impl_(ImplSidePaintingSettings(), &proxy_), | 147 : host_impl_(ImplSidePaintingSettings(), &proxy_), |
130 id_(7) { | 148 id_(7) { |
131 host_impl_.initializeRenderer(createFakeOutputSurface()); | 149 host_impl_.initializeRenderer(createFakeOutputSurface()); |
132 } | 150 } |
133 | 151 |
134 virtual ~PictureLayerImplTest() { | 152 virtual ~PictureLayerImplTest() { |
135 } | 153 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 gfx::Size result_bounds; | 205 gfx::Size result_bounds; |
188 pending_layer_->calculateContentsScale( | 206 pending_layer_->calculateContentsScale( |
189 scale, animating_transform, | 207 scale, animating_transform, |
190 &result_scale_x, &result_scale_y, &result_bounds); | 208 &result_scale_x, &result_scale_y, &result_bounds); |
191 active_layer_->calculateContentsScale( | 209 active_layer_->calculateContentsScale( |
192 scale, animating_transform, | 210 scale, animating_transform, |
193 &result_scale_x, &result_scale_y, &result_bounds); | 211 &result_scale_x, &result_scale_y, &result_bounds); |
194 } | 212 } |
195 | 213 |
196 protected: | 214 protected: |
215 void TestTileGridAlignmentCommon() { | |
216 gfx::Size tile_size(1000, 1000); | |
217 gfx::Size layer_bounds(1000, 1000); | |
218 | |
219 scoped_refptr<TestablePicturePileImpl> pending_pile = | |
220 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
221 scoped_refptr<TestablePicturePileImpl> active_pile = | |
222 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
223 pending_pile->ApplyLayerTreeSettings(&host_impl_); | |
224 active_pile->ApplyLayerTreeSettings(&host_impl_); | |
225 | |
226 SetupTrees(pending_pile, active_pile); | |
227 | |
228 host_impl_.activeTree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f); | |
229 float result_scale_x, result_scale_y; | |
230 gfx::Size result_bounds; | |
231 active_layer_->calculateContentsScale( | |
232 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
233 | |
234 // Add 1x1 rects at the centers of each tile, then re-record pile contents | |
235 std::vector<Tile*> tiles = | |
236 active_layer_->tilings().tiling_at(0)->AllTilesForTesting(); | |
237 EXPECT_EQ(16, tiles.size()); | |
238 std::vector<SkRect> rects; | |
239 std::vector<Tile*>::const_iterator tile_iter; | |
240 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | |
241 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint(); | |
242 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1); | |
243 active_pile->addDrawRect(rect); | |
244 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1)); | |
245 } | |
246 // Force re-record with newly injected content | |
247 active_pile->RemoveRecordingAt(0, 0); | |
248 active_pile->AddRecordingAt(0, 0); | |
249 | |
250 SkBitmap store; | |
251 store.setConfig(SkBitmap::kNo_Config, 1000, 1000); | |
252 SkDevice device(store); | |
253 int64 pixelsRasterized; | |
254 | |
255 std::vector<SkRect>::const_iterator rect_iter = rects.begin(); | |
256 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | |
257 MockCanvas mock_canvas(&device); | |
258 active_pile->Raster(&mock_canvas, (*tile_iter)->content_rect(), | |
259 1.0f, &pixelsRasterized); | |
260 | |
261 // This test verifies that when drawing the contents of a specific tile | |
262 // at content scale 1.0, the playback canvas never receives content from | |
263 // neighboring tiles which indicates that the tile grid embedded in | |
264 // SkPicture is perfectly aligned with the compositor's tiles. | |
265 // Note: There are two rects: the initial clear and the explicitly | |
266 // recorded rect. We only care about the second one. | |
267 EXPECT_EQ(2, mock_canvas.rects_.size()); | |
enne (OOO)
2013/02/25 23:59:15
This is great. Thanks for the tests.
| |
268 EXPECT_EQ(*rect_iter, mock_canvas.rects_[1]); | |
269 rect_iter++; | |
270 } | |
271 } | |
272 | |
197 FakeImplProxy proxy_; | 273 FakeImplProxy proxy_; |
198 FakeLayerTreeHostImpl host_impl_; | 274 FakeLayerTreeHostImpl host_impl_; |
199 int id_; | 275 int id_; |
200 TestablePictureLayerImpl* pending_layer_; | 276 TestablePictureLayerImpl* pending_layer_; |
201 TestablePictureLayerImpl* active_layer_; | 277 TestablePictureLayerImpl* active_layer_; |
202 | 278 |
203 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); | 279 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); |
204 }; | 280 }; |
205 | 281 |
282 TEST_F(PictureLayerImplTest, tileGridAlignment) { | |
283 host_impl_.setDeviceScaleFactor(1.f); | |
284 TestTileGridAlignmentCommon(); | |
285 } | |
286 | |
287 TEST_F(PictureLayerImplTest, tileGridAlignmentHiDPI) { | |
288 host_impl_.setDeviceScaleFactor(2.f); | |
289 TestTileGridAlignmentCommon(); | |
290 } | |
291 | |
206 TEST_F(PictureLayerImplTest, cloneNoInvalidation) { | 292 TEST_F(PictureLayerImplTest, cloneNoInvalidation) { |
207 gfx::Size tile_size(100, 100); | 293 gfx::Size tile_size(100, 100); |
208 gfx::Size layer_bounds(400, 400); | 294 gfx::Size layer_bounds(400, 400); |
209 | 295 |
210 scoped_refptr<TestablePicturePileImpl> pending_pile = | 296 scoped_refptr<TestablePicturePileImpl> pending_pile = |
211 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 297 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
212 scoped_refptr<TestablePicturePileImpl> active_pile = | 298 scoped_refptr<TestablePicturePileImpl> active_pile = |
213 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 299 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
214 | 300 |
215 SetupTrees(pending_pile, active_pile); | 301 SetupTrees(pending_pile, active_pile); |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 689 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
604 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); | 690 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); |
605 used_tilings.clear(); | 691 used_tilings.clear(); |
606 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); | 692 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); |
607 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); | 693 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); |
608 | 694 |
609 } | 695 } |
610 | 696 |
611 } // namespace | 697 } // namespace |
612 } // namespace cc | 698 } // namespace cc |
OLD | NEW |