OLD | NEW |
| (Empty) |
1 // Copyright 2012 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 <limits> | |
6 #include <set> | |
7 | |
8 #include "cc/base/math_util.h" | |
9 #include "cc/resources/picture_layer_tiling.h" | |
10 #include "cc/resources/picture_layer_tiling_set.h" | |
11 #include "cc/test/fake_output_surface.h" | |
12 #include "cc/test/fake_output_surface_client.h" | |
13 #include "cc/test/fake_picture_layer_tiling_client.h" | |
14 #include "cc/test/fake_picture_pile_impl.h" | |
15 #include "cc/test/test_context_provider.h" | |
16 #include "cc/test/test_shared_bitmap_manager.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "ui/gfx/geometry/quad_f.h" | |
19 #include "ui/gfx/geometry/rect_conversions.h" | |
20 #include "ui/gfx/geometry/size_conversions.h" | |
21 | |
22 namespace cc { | |
23 namespace { | |
24 | |
25 static gfx::Rect ViewportInLayerSpace( | |
26 const gfx::Transform& transform, | |
27 const gfx::Size& device_viewport) { | |
28 | |
29 gfx::Transform inverse; | |
30 if (!transform.GetInverse(&inverse)) | |
31 return gfx::Rect(); | |
32 | |
33 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | |
34 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | |
35 return ToEnclosingRect(viewport_in_layer_space); | |
36 } | |
37 | |
38 class TestablePictureLayerTiling : public PictureLayerTiling { | |
39 public: | |
40 using PictureLayerTiling::SetLiveTilesRect; | |
41 using PictureLayerTiling::TileAt; | |
42 | |
43 static scoped_ptr<TestablePictureLayerTiling> Create( | |
44 WhichTree tree, | |
45 float contents_scale, | |
46 scoped_refptr<RasterSource> raster_source, | |
47 PictureLayerTilingClient* client, | |
48 const LayerTreeSettings& settings) { | |
49 return make_scoped_ptr(new TestablePictureLayerTiling( | |
50 tree, contents_scale, raster_source, client, | |
51 settings.tiling_interest_area_viewport_multiplier, | |
52 settings.skewport_target_time_in_seconds, | |
53 settings.skewport_extrapolation_limit_in_content_pixels)); | |
54 } | |
55 | |
56 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | |
57 | |
58 using PictureLayerTiling::ComputeSkewport; | |
59 using PictureLayerTiling::RemoveTileAt; | |
60 | |
61 protected: | |
62 TestablePictureLayerTiling(WhichTree tree, | |
63 float contents_scale, | |
64 scoped_refptr<RasterSource> raster_source, | |
65 PictureLayerTilingClient* client, | |
66 float tiling_interest_area_viewport_multiplier, | |
67 float skewport_target_time, | |
68 int skewport_extrapolation_limit) | |
69 : PictureLayerTiling(tree, | |
70 contents_scale, | |
71 raster_source, | |
72 client, | |
73 tiling_interest_area_viewport_multiplier, | |
74 skewport_target_time, | |
75 skewport_extrapolation_limit) {} | |
76 }; | |
77 | |
78 class PictureLayerTilingIteratorTest : public testing::Test { | |
79 public: | |
80 PictureLayerTilingIteratorTest() {} | |
81 ~PictureLayerTilingIteratorTest() override {} | |
82 | |
83 void Initialize(const gfx::Size& tile_size, | |
84 float contents_scale, | |
85 const gfx::Size& layer_bounds) { | |
86 client_.SetTileSize(tile_size); | |
87 scoped_refptr<FakePicturePileImpl> pile = | |
88 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
89 tiling_ = TestablePictureLayerTiling::Create( | |
90 PENDING_TREE, contents_scale, pile, &client_, LayerTreeSettings()); | |
91 } | |
92 | |
93 void InitializeActive(const gfx::Size& tile_size, | |
94 float contents_scale, | |
95 const gfx::Size& layer_bounds) { | |
96 client_.SetTileSize(tile_size); | |
97 scoped_refptr<FakePicturePileImpl> pile = | |
98 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
99 tiling_ = TestablePictureLayerTiling::Create( | |
100 ACTIVE_TREE, contents_scale, pile, &client_, LayerTreeSettings()); | |
101 } | |
102 | |
103 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { | |
104 tiling_->SetLiveTilesRect(live_tiles_rect); | |
105 | |
106 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | |
107 for (std::vector<Tile*>::iterator iter = tiles.begin(); | |
108 iter != tiles.end(); | |
109 ++iter) { | |
110 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | |
111 } | |
112 } | |
113 | |
114 void VerifyTilesExactlyCoverRect( | |
115 float rect_scale, | |
116 const gfx::Rect& request_rect, | |
117 const gfx::Rect& expect_rect) { | |
118 EXPECT_TRUE(request_rect.Contains(expect_rect)); | |
119 | |
120 // Iterators are not valid if this ratio is too large (i.e. the | |
121 // tiling is too high-res for a low-res destination rect.) This is an | |
122 // artifact of snapping geometry to integer coordinates and then mapping | |
123 // back to floating point texture coordinates. | |
124 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | |
125 ASSERT_LE(dest_to_contents_scale, 2.0); | |
126 | |
127 Region remaining = expect_rect; | |
128 for (PictureLayerTiling::CoverageIterator | |
129 iter(tiling_.get(), rect_scale, request_rect); | |
130 iter; | |
131 ++iter) { | |
132 // Geometry cannot overlap previous geometry at all | |
133 gfx::Rect geometry = iter.geometry_rect(); | |
134 EXPECT_TRUE(expect_rect.Contains(geometry)); | |
135 EXPECT_TRUE(remaining.Contains(geometry)); | |
136 remaining.Subtract(geometry); | |
137 | |
138 // Sanity check that texture coords are within the texture rect. | |
139 gfx::RectF texture_rect = iter.texture_rect(); | |
140 EXPECT_GE(texture_rect.x(), 0); | |
141 EXPECT_GE(texture_rect.y(), 0); | |
142 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); | |
143 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); | |
144 } | |
145 | |
146 // The entire rect must be filled by geometry from the tiling. | |
147 EXPECT_TRUE(remaining.IsEmpty()); | |
148 } | |
149 | |
150 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) { | |
151 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); | |
152 } | |
153 | |
154 void VerifyTiles( | |
155 float rect_scale, | |
156 const gfx::Rect& rect, | |
157 base::Callback<void(Tile* tile, | |
158 const gfx::Rect& geometry_rect)> callback) { | |
159 VerifyTiles(tiling_.get(), | |
160 rect_scale, | |
161 rect, | |
162 callback); | |
163 } | |
164 | |
165 void VerifyTiles( | |
166 PictureLayerTiling* tiling, | |
167 float rect_scale, | |
168 const gfx::Rect& rect, | |
169 base::Callback<void(Tile* tile, | |
170 const gfx::Rect& geometry_rect)> callback) { | |
171 Region remaining = rect; | |
172 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect); | |
173 iter; | |
174 ++iter) { | |
175 remaining.Subtract(iter.geometry_rect()); | |
176 callback.Run(*iter, iter.geometry_rect()); | |
177 } | |
178 EXPECT_TRUE(remaining.IsEmpty()); | |
179 } | |
180 | |
181 void VerifyTilesCoverNonContainedRect(float rect_scale, | |
182 const gfx::Rect& dest_rect) { | |
183 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | |
184 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | |
185 gfx::Rect(tiling_->tiling_size()), 1.f / dest_to_contents_scale); | |
186 clamped_rect.Intersect(dest_rect); | |
187 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | |
188 } | |
189 | |
190 protected: | |
191 FakePictureLayerTilingClient client_; | |
192 scoped_ptr<TestablePictureLayerTiling> tiling_; | |
193 | |
194 private: | |
195 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | |
196 }; | |
197 | |
198 TEST_F(PictureLayerTilingIteratorTest, ResizeDeletesTiles) { | |
199 // Verifies that a resize with invalidation for newly exposed pixels will | |
200 // deletes tiles that intersect that invalidation. | |
201 gfx::Size tile_size(100, 100); | |
202 gfx::Size original_layer_size(10, 10); | |
203 InitializeActive(tile_size, 1.f, original_layer_size); | |
204 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | |
205 | |
206 // Tiling only has one tile, since its total size is less than one. | |
207 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
208 | |
209 // Stop creating tiles so that any invalidations are left as holes. | |
210 gfx::Size new_layer_size(200, 200); | |
211 scoped_refptr<FakePicturePileImpl> pile = | |
212 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size); | |
213 | |
214 Region invalidation = | |
215 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | |
216 tiling_->SetRasterSourceAndResize(pile); | |
217 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
218 tiling_->Invalidate(invalidation); | |
219 EXPECT_FALSE(tiling_->TileAt(0, 0)); | |
220 } | |
221 | |
222 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { | |
223 // The tiling has three rows and columns. | |
224 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 250)); | |
225 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
226 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
227 | |
228 // The live tiles rect is at the very edge of the right-most and | |
229 // bottom-most tiles. Their border pixels would still be inside the live | |
230 // tiles rect, but the tiles should not exist just for that. | |
231 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | |
232 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); | |
233 | |
234 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); | |
235 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
236 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
237 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
238 EXPECT_FALSE(tiling_->TileAt(1, 2)); | |
239 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
240 | |
241 // Verify CreateMissingTilesInLiveTilesRect respects this. | |
242 tiling_->CreateMissingTilesInLiveTilesRect(); | |
243 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
244 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
245 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
246 EXPECT_FALSE(tiling_->TileAt(1, 2)); | |
247 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
248 } | |
249 | |
250 TEST_F(PictureLayerTilingIteratorTest, ResizeTilingOverTileBorders) { | |
251 // The tiling has four rows and three columns. | |
252 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); | |
253 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
254 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | |
255 | |
256 // The live tiles rect covers the whole tiling. | |
257 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | |
258 | |
259 // Tiles in the bottom row and right column exist. | |
260 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
261 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
262 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
263 EXPECT_TRUE(tiling_->TileAt(2, 3)); | |
264 EXPECT_TRUE(tiling_->TileAt(1, 3)); | |
265 EXPECT_TRUE(tiling_->TileAt(0, 3)); | |
266 | |
267 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | |
268 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); | |
269 | |
270 // Shrink the tiling so that the last tile row/column is entirely in the | |
271 // border pixels of the interior tiles. That row/column is removed. | |
272 scoped_refptr<FakePicturePileImpl> pile = | |
273 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
274 gfx::Size(right + 1, bottom + 1)); | |
275 tiling_->SetRasterSourceAndResize(pile); | |
276 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); | |
277 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
278 | |
279 // The live tiles rect was clamped to the pile size. | |
280 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | |
281 | |
282 // Since the row/column is gone, the tiles should be gone too. | |
283 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
284 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
285 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
286 EXPECT_FALSE(tiling_->TileAt(2, 3)); | |
287 EXPECT_FALSE(tiling_->TileAt(1, 3)); | |
288 EXPECT_FALSE(tiling_->TileAt(0, 3)); | |
289 | |
290 // Growing outside the current right/bottom tiles border pixels should create | |
291 // the tiles again, even though the live rect has not changed size. | |
292 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
293 gfx::Size(right + 2, bottom + 2)); | |
294 tiling_->SetRasterSourceAndResize(pile); | |
295 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
296 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | |
297 | |
298 // Not changed. | |
299 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | |
300 | |
301 // The last row/column tiles are inside the live tiles rect. | |
302 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | |
303 tiling_->TilingDataForTesting().TileBounds(2, 0))); | |
304 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | |
305 tiling_->TilingDataForTesting().TileBounds(0, 3))); | |
306 | |
307 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
308 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
309 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
310 EXPECT_TRUE(tiling_->TileAt(2, 3)); | |
311 EXPECT_TRUE(tiling_->TileAt(1, 3)); | |
312 EXPECT_TRUE(tiling_->TileAt(0, 3)); | |
313 } | |
314 | |
315 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { | |
316 // The tiling has three rows and columns. | |
317 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); | |
318 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
319 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | |
320 | |
321 // The live tiles rect covers the whole tiling. | |
322 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | |
323 | |
324 // Tiles in the bottom row and right column exist. | |
325 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
326 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
327 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
328 EXPECT_TRUE(tiling_->TileAt(2, 3)); | |
329 EXPECT_TRUE(tiling_->TileAt(1, 3)); | |
330 EXPECT_TRUE(tiling_->TileAt(0, 3)); | |
331 | |
332 // Shrink the live tiles rect to the very edge of the right-most and | |
333 // bottom-most tiles. Their border pixels would still be inside the live | |
334 // tiles rect, but the tiles should not exist just for that. | |
335 int right = tiling_->TilingDataForTesting().TileBounds(2, 3).x(); | |
336 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); | |
337 | |
338 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); | |
339 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
340 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
341 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
342 EXPECT_FALSE(tiling_->TileAt(2, 3)); | |
343 EXPECT_FALSE(tiling_->TileAt(1, 3)); | |
344 EXPECT_FALSE(tiling_->TileAt(0, 3)); | |
345 | |
346 // Including the bottom row and right column again, should create the tiles. | |
347 SetLiveRectAndVerifyTiles(gfx::Rect(right + 1, bottom + 1)); | |
348 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
349 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
350 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
351 EXPECT_TRUE(tiling_->TileAt(2, 3)); | |
352 EXPECT_TRUE(tiling_->TileAt(1, 2)); | |
353 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
354 | |
355 // Shrink the live tiles rect to the very edge of the left-most and | |
356 // top-most tiles. Their border pixels would still be inside the live | |
357 // tiles rect, but the tiles should not exist just for that. | |
358 int left = tiling_->TilingDataForTesting().TileBounds(0, 0).right(); | |
359 int top = tiling_->TilingDataForTesting().TileBounds(0, 0).bottom(); | |
360 | |
361 SetLiveRectAndVerifyTiles(gfx::Rect(left, top, 250 - left, 350 - top)); | |
362 EXPECT_FALSE(tiling_->TileAt(0, 3)); | |
363 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
364 EXPECT_FALSE(tiling_->TileAt(0, 1)); | |
365 EXPECT_FALSE(tiling_->TileAt(0, 0)); | |
366 EXPECT_FALSE(tiling_->TileAt(1, 0)); | |
367 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
368 | |
369 // Including the top row and left column again, should create the tiles. | |
370 SetLiveRectAndVerifyTiles( | |
371 gfx::Rect(left - 1, top - 1, 250 - left, 350 - top)); | |
372 EXPECT_TRUE(tiling_->TileAt(0, 3)); | |
373 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
374 EXPECT_TRUE(tiling_->TileAt(0, 1)); | |
375 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
376 EXPECT_TRUE(tiling_->TileAt(1, 0)); | |
377 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
378 } | |
379 | |
380 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { | |
381 // The tiling has four rows and three columns. | |
382 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 350)); | |
383 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
384 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | |
385 | |
386 // The live tiles rect covers the whole tiling. | |
387 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350)); | |
388 | |
389 // All tiles exist. | |
390 for (int i = 0; i < 3; ++i) { | |
391 for (int j = 0; j < 4; ++j) | |
392 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
393 } | |
394 | |
395 // Shrink the live tiles rect, but still cover all the tiles. | |
396 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 349)); | |
397 | |
398 // All tiles still exist. | |
399 for (int i = 0; i < 3; ++i) { | |
400 for (int j = 0; j < 4; ++j) | |
401 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
402 } | |
403 | |
404 // Grow the live tiles rect, but still cover all the same tiles. | |
405 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 350)); | |
406 | |
407 // All tiles still exist. | |
408 for (int i = 0; i < 3; ++i) { | |
409 for (int j = 0; j < 4; ++j) | |
410 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
411 } | |
412 } | |
413 | |
414 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { | |
415 // Verifies that a resize with invalidation for newly exposed pixels will | |
416 // deletes tiles that intersect that invalidation. | |
417 gfx::Size tile_size(100, 100); | |
418 gfx::Size original_layer_size(99, 99); | |
419 InitializeActive(tile_size, 1.f, original_layer_size); | |
420 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | |
421 | |
422 // Tiling only has one tile, since its total size is less than one. | |
423 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
424 | |
425 // Stop creating tiles so that any invalidations are left as holes. | |
426 scoped_refptr<FakePicturePileImpl> pile = | |
427 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize( | |
428 gfx::Size(200, 200)); | |
429 tiling_->SetRasterSourceAndResize(pile); | |
430 | |
431 Region invalidation = | |
432 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | |
433 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
434 tiling_->Invalidate(invalidation); | |
435 EXPECT_FALSE(tiling_->TileAt(0, 0)); | |
436 | |
437 // The original tile was the same size after resize, but it would include new | |
438 // border pixels. | |
439 EXPECT_EQ(gfx::Rect(original_layer_size), | |
440 tiling_->TilingDataForTesting().TileBounds(0, 0)); | |
441 } | |
442 | |
443 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | |
444 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(1099, 801)); | |
445 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); | |
446 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99)); | |
447 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | |
448 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801)); | |
449 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1)); | |
450 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800)); | |
451 } | |
452 | |
453 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) { | |
454 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(1099, 801)); | |
455 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | |
456 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801)); | |
457 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412)); | |
458 | |
459 // With borders, a size of 3x3 = 1 pixel of content. | |
460 Initialize(gfx::Size(3, 3), 1.f, gfx::Size(10, 10)); | |
461 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | |
462 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | |
463 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); | |
464 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); | |
465 } | |
466 | |
467 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsTilingScale) { | |
468 Initialize(gfx::Size(200, 100), 2.0f, gfx::Size(1005, 2010)); | |
469 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | |
470 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); | |
471 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); | |
472 | |
473 Initialize(gfx::Size(3, 3), 2.0f, gfx::Size(10, 10)); | |
474 VerifyTilesExactlyCoverRect(1, gfx::Rect()); | |
475 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1)); | |
476 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2)); | |
477 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2)); | |
478 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2)); | |
479 | |
480 Initialize(gfx::Size(100, 200), 0.5f, gfx::Size(1005, 2010)); | |
481 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); | |
482 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); | |
483 | |
484 Initialize(gfx::Size(150, 250), 0.37f, gfx::Size(1005, 2010)); | |
485 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); | |
486 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); | |
487 | |
488 Initialize(gfx::Size(312, 123), 0.01f, gfx::Size(1005, 2010)); | |
489 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010)); | |
490 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381)); | |
491 } | |
492 | |
493 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsBothScale) { | |
494 Initialize(gfx::Size(50, 50), 4.0f, gfx::Size(800, 600)); | |
495 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect()); | |
496 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(0, 0, 1600, 1200)); | |
497 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(512, 365, 253, 182)); | |
498 | |
499 float scale = 6.7f; | |
500 gfx::Size bounds(800, 600); | |
501 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale))); | |
502 Initialize(gfx::Size(256, 512), 5.2f, bounds); | |
503 VerifyTilesExactlyCoverRect(scale, full_rect); | |
504 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033)); | |
505 } | |
506 | |
507 TEST_F(PictureLayerTilingIteratorTest, IteratorEmptyRect) { | |
508 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); | |
509 | |
510 gfx::Rect empty; | |
511 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.0f, empty); | |
512 EXPECT_FALSE(iter); | |
513 } | |
514 | |
515 TEST_F(PictureLayerTilingIteratorTest, NonIntersectingRect) { | |
516 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600)); | |
517 gfx::Rect non_intersecting(1000, 1000, 50, 50); | |
518 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1, non_intersecting); | |
519 EXPECT_FALSE(iter); | |
520 } | |
521 | |
522 TEST_F(PictureLayerTilingIteratorTest, LayerEdgeTextureCoordinates) { | |
523 Initialize(gfx::Size(300, 300), 1.0f, gfx::Size(256, 256)); | |
524 // All of these sizes are 256x256, scaled and ceiled. | |
525 VerifyTilesExactlyCoverRect(1.0f, gfx::Rect(0, 0, 256, 256)); | |
526 VerifyTilesExactlyCoverRect(0.8f, gfx::Rect(0, 0, 205, 205)); | |
527 VerifyTilesExactlyCoverRect(1.2f, gfx::Rect(0, 0, 308, 308)); | |
528 } | |
529 | |
530 TEST_F(PictureLayerTilingIteratorTest, NonContainedDestRect) { | |
531 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(400, 400)); | |
532 | |
533 // Too large in all dimensions | |
534 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); | |
535 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | |
536 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | |
537 | |
538 // Partially covering content, but too large | |
539 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); | |
540 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | |
541 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | |
542 } | |
543 | |
544 TEST(PictureLayerTilingTest, SkewportLimits) { | |
545 FakePictureLayerTilingClient client; | |
546 | |
547 gfx::Rect viewport(0, 0, 100, 100); | |
548 gfx::Size layer_bounds(200, 200); | |
549 | |
550 client.SetTileSize(gfx::Size(100, 100)); | |
551 LayerTreeSettings settings; | |
552 settings.skewport_extrapolation_limit_in_content_pixels = 75; | |
553 | |
554 scoped_refptr<FakePicturePileImpl> pile = | |
555 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
556 scoped_ptr<TestablePictureLayerTiling> tiling = | |
557 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
558 settings); | |
559 | |
560 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | |
561 | |
562 // Move viewport down 50 pixels in 0.5 seconds. | |
563 gfx::Rect down_skewport = | |
564 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | |
565 | |
566 EXPECT_EQ(0, down_skewport.x()); | |
567 EXPECT_EQ(50, down_skewport.y()); | |
568 EXPECT_EQ(100, down_skewport.width()); | |
569 EXPECT_EQ(175, down_skewport.height()); | |
570 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100))); | |
571 | |
572 // Move viewport down 50 and right 10 pixels. | |
573 gfx::Rect down_right_skewport = | |
574 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); | |
575 | |
576 EXPECT_EQ(10, down_right_skewport.x()); | |
577 EXPECT_EQ(50, down_right_skewport.y()); | |
578 EXPECT_EQ(120, down_right_skewport.width()); | |
579 EXPECT_EQ(175, down_right_skewport.height()); | |
580 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100))); | |
581 | |
582 // Move viewport left. | |
583 gfx::Rect left_skewport = | |
584 tiling->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100)); | |
585 | |
586 EXPECT_EQ(-125, left_skewport.x()); | |
587 EXPECT_EQ(0, left_skewport.y()); | |
588 EXPECT_EQ(175, left_skewport.width()); | |
589 EXPECT_EQ(100, left_skewport.height()); | |
590 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100))); | |
591 | |
592 // Expand viewport. | |
593 gfx::Rect expand_skewport = | |
594 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200)); | |
595 | |
596 // x and y moved by -75 (-50 - 75 = -125). | |
597 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75]. | |
598 EXPECT_EQ(-125, expand_skewport.x()); | |
599 EXPECT_EQ(-125, expand_skewport.y()); | |
600 EXPECT_EQ(350, expand_skewport.width()); | |
601 EXPECT_EQ(350, expand_skewport.height()); | |
602 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200))); | |
603 | |
604 // Expand the viewport past the limit in all directions. | |
605 gfx::Rect big_expand_skewport = | |
606 tiling->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500)); | |
607 | |
608 EXPECT_EQ(-575, big_expand_skewport.x()); | |
609 EXPECT_EQ(-575, big_expand_skewport.y()); | |
610 EXPECT_EQ(1650, big_expand_skewport.width()); | |
611 EXPECT_EQ(1650, big_expand_skewport.height()); | |
612 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); | |
613 | |
614 // Shrink the skewport in all directions. | |
615 gfx::Rect shrink_viewport = | |
616 tiling->ComputeSkewport(1.5, gfx::Rect(0, 0, 100, 100)); | |
617 EXPECT_EQ(0, shrink_viewport.x()); | |
618 EXPECT_EQ(0, shrink_viewport.y()); | |
619 EXPECT_EQ(100, shrink_viewport.width()); | |
620 EXPECT_EQ(100, shrink_viewport.height()); | |
621 | |
622 // Move the skewport really far in one direction. | |
623 gfx::Rect move_skewport_far = | |
624 tiling->ComputeSkewport(1.5, gfx::Rect(0, 5000, 100, 100)); | |
625 EXPECT_EQ(0, move_skewport_far.x()); | |
626 EXPECT_EQ(5000, move_skewport_far.y()); | |
627 EXPECT_EQ(100, move_skewport_far.width()); | |
628 EXPECT_EQ(175, move_skewport_far.height()); | |
629 EXPECT_TRUE(move_skewport_far.Contains(gfx::Rect(0, 5000, 100, 100))); | |
630 } | |
631 | |
632 TEST(PictureLayerTilingTest, ComputeSkewport) { | |
633 FakePictureLayerTilingClient client; | |
634 | |
635 gfx::Rect viewport(0, 0, 100, 100); | |
636 gfx::Size layer_bounds(200, 200); | |
637 | |
638 client.SetTileSize(gfx::Size(100, 100)); | |
639 | |
640 scoped_refptr<FakePicturePileImpl> pile = | |
641 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
642 scoped_ptr<TestablePictureLayerTiling> tiling = | |
643 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
644 LayerTreeSettings()); | |
645 | |
646 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | |
647 | |
648 // Move viewport down 50 pixels in 0.5 seconds. | |
649 gfx::Rect down_skewport = | |
650 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | |
651 | |
652 EXPECT_EQ(0, down_skewport.x()); | |
653 EXPECT_EQ(50, down_skewport.y()); | |
654 EXPECT_EQ(100, down_skewport.width()); | |
655 EXPECT_EQ(200, down_skewport.height()); | |
656 | |
657 // Shrink viewport. | |
658 gfx::Rect shrink_skewport = | |
659 tiling->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50)); | |
660 | |
661 EXPECT_EQ(25, shrink_skewport.x()); | |
662 EXPECT_EQ(25, shrink_skewport.y()); | |
663 EXPECT_EQ(50, shrink_skewport.width()); | |
664 EXPECT_EQ(50, shrink_skewport.height()); | |
665 | |
666 // Move viewport down 50 and right 10 pixels. | |
667 gfx::Rect down_right_skewport = | |
668 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); | |
669 | |
670 EXPECT_EQ(10, down_right_skewport.x()); | |
671 EXPECT_EQ(50, down_right_skewport.y()); | |
672 EXPECT_EQ(120, down_right_skewport.width()); | |
673 EXPECT_EQ(200, down_right_skewport.height()); | |
674 | |
675 // Move viewport left. | |
676 gfx::Rect left_skewport = | |
677 tiling->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100)); | |
678 | |
679 EXPECT_EQ(-60, left_skewport.x()); | |
680 EXPECT_EQ(0, left_skewport.y()); | |
681 EXPECT_EQ(140, left_skewport.width()); | |
682 EXPECT_EQ(100, left_skewport.height()); | |
683 | |
684 // Expand viewport in 0.2 seconds. | |
685 gfx::Rect expanded_skewport = | |
686 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); | |
687 | |
688 EXPECT_EQ(-30, expanded_skewport.x()); | |
689 EXPECT_EQ(-30, expanded_skewport.y()); | |
690 EXPECT_EQ(160, expanded_skewport.width()); | |
691 EXPECT_EQ(160, expanded_skewport.height()); | |
692 } | |
693 | |
694 TEST(PictureLayerTilingTest, SkewportThroughUpdateTilePriorities) { | |
695 FakePictureLayerTilingClient client; | |
696 | |
697 gfx::Rect viewport(0, 0, 100, 100); | |
698 gfx::Size layer_bounds(200, 200); | |
699 | |
700 client.SetTileSize(gfx::Size(100, 100)); | |
701 | |
702 scoped_refptr<FakePicturePileImpl> pile = | |
703 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
704 scoped_ptr<TestablePictureLayerTiling> tiling = | |
705 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
706 LayerTreeSettings()); | |
707 | |
708 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | |
709 | |
710 // Move viewport down 50 pixels in 0.5 seconds. | |
711 gfx::Rect viewport_50 = gfx::Rect(0, 50, 100, 100); | |
712 gfx::Rect skewport_50 = tiling->ComputeSkewport(1.5, viewport_50); | |
713 | |
714 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50); | |
715 tiling->ComputeTilePriorityRects(viewport_50, 1.f, 1.5, Occlusion()); | |
716 | |
717 gfx::Rect viewport_100 = gfx::Rect(0, 100, 100, 100); | |
718 gfx::Rect skewport_100 = tiling->ComputeSkewport(2.0, viewport_100); | |
719 | |
720 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100); | |
721 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 2.0, Occlusion()); | |
722 | |
723 // Advance time, but not the viewport. | |
724 gfx::Rect result = tiling->ComputeSkewport(2.5, viewport_100); | |
725 // Since the history did advance, we should still get a skewport but a smaller | |
726 // one. | |
727 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result); | |
728 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 2.5, Occlusion()); | |
729 | |
730 // Advance time again. | |
731 result = tiling->ComputeSkewport(3.0, viewport_100); | |
732 EXPECT_EQ(viewport_100, result); | |
733 tiling->ComputeTilePriorityRects(viewport_100, 1.f, 3.0, Occlusion()); | |
734 | |
735 // Ensure we have a skewport. | |
736 gfx::Rect viewport_150 = gfx::Rect(0, 150, 100, 100); | |
737 gfx::Rect skewport_150 = tiling->ComputeSkewport(3.5, viewport_150); | |
738 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150); | |
739 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); | |
740 | |
741 // Advance the viewport, but not the time. | |
742 gfx::Rect viewport_200 = gfx::Rect(0, 200, 100, 100); | |
743 gfx::Rect skewport_200 = tiling->ComputeSkewport(3.5, viewport_200); | |
744 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); | |
745 | |
746 // Ensure that continued calls with the same value, produce the same skewport. | |
747 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); | |
748 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); | |
749 tiling->ComputeTilePriorityRects(viewport_150, 1.f, 3.5, Occlusion()); | |
750 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200); | |
751 | |
752 tiling->ComputeTilePriorityRects(viewport_200, 1.f, 3.5, Occlusion()); | |
753 | |
754 // This should never happen, but advance the viewport yet again keeping the | |
755 // time the same. | |
756 gfx::Rect viewport_250 = gfx::Rect(0, 250, 100, 100); | |
757 gfx::Rect skewport_250 = tiling->ComputeSkewport(3.5, viewport_250); | |
758 EXPECT_EQ(viewport_250, skewport_250); | |
759 tiling->ComputeTilePriorityRects(viewport_250, 1.f, 3.5, Occlusion()); | |
760 } | |
761 | |
762 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { | |
763 FakePictureLayerTilingClient client; | |
764 | |
765 gfx::Rect viewport(0, 0, 100, 100); | |
766 gfx::Size layer_bounds(1500, 1500); | |
767 | |
768 client.SetTileSize(gfx::Size(10, 10)); | |
769 LayerTreeSettings settings; | |
770 settings.tiling_interest_area_viewport_multiplier = 10000; | |
771 | |
772 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10. | |
773 // The reason is that each tile has a one pixel border, so tile at (1, 2) | |
774 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at | |
775 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the | |
776 // tiling. | |
777 scoped_refptr<FakePicturePileImpl> pile = | |
778 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
779 scoped_ptr<TestablePictureLayerTiling> tiling = | |
780 TestablePictureLayerTiling::Create(ACTIVE_TREE, 0.25f, pile, &client, | |
781 settings); | |
782 gfx::Rect viewport_in_content_space = | |
783 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | |
784 | |
785 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | |
786 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
787 | |
788 // Compute the soon border. | |
789 float inset = PictureLayerTiling::CalculateSoonBorderDistance( | |
790 viewport_in_content_space, 1.0f / 0.25f); | |
791 gfx::Rect soon_rect_in_content_space = viewport_in_content_space; | |
792 soon_rect_in_content_space.Inset(-inset, -inset); | |
793 | |
794 // Sanity checks. | |
795 for (int i = 0; i < 47; ++i) { | |
796 for (int j = 0; j < 47; ++j) { | |
797 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; | |
798 } | |
799 } | |
800 for (int i = 0; i < 47; ++i) { | |
801 EXPECT_FALSE(tiling->TileAt(i, 47)) << "i: " << i; | |
802 EXPECT_FALSE(tiling->TileAt(47, i)) << "i: " << i; | |
803 } | |
804 | |
805 // No movement in the viewport implies that tiles will either be NOW | |
806 // or EVENTUALLY, with the exception of tiles that are between 0 and 312 | |
807 // pixels away from the viewport, which will be in the SOON bin. | |
808 bool have_now = false; | |
809 bool have_eventually = false; | |
810 bool have_soon = false; | |
811 for (int i = 0; i < 47; ++i) { | |
812 for (int j = 0; j < 47; ++j) { | |
813 Tile* tile = tiling->TileAt(i, j); | |
814 PrioritizedTile prioritized_tile = prioritized_tiles[tile]; | |
815 TilePriority priority = prioritized_tile.priority(); | |
816 | |
817 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j); | |
818 if (viewport_in_content_space.Intersects(tile_rect)) { | |
819 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
820 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
821 have_now = true; | |
822 } else if (soon_rect_in_content_space.Intersects(tile_rect)) { | |
823 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); | |
824 have_soon = true; | |
825 } else { | |
826 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | |
827 EXPECT_GT(priority.distance_to_visible, 0.f); | |
828 have_eventually = true; | |
829 } | |
830 } | |
831 } | |
832 | |
833 EXPECT_TRUE(have_now); | |
834 EXPECT_TRUE(have_soon); | |
835 EXPECT_TRUE(have_eventually); | |
836 | |
837 // Spot check some distances. | |
838 // Tile at 5, 1 should begin at 41x9 in content space (without borders), | |
839 // so the distance to a viewport that ends at 25x25 in content space | |
840 // should be 17 (41 - 25 + 1). In layer space, then that should be | |
841 // 17 / 0.25 = 68 pixels. | |
842 | |
843 // We can verify that the content rect (with borders) is one pixel off | |
844 // 41,9 8x8 on all sides. | |
845 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); | |
846 | |
847 TilePriority priority = prioritized_tiles[tiling->TileAt(5, 1)].priority(); | |
848 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
849 | |
850 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority(); | |
851 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
852 | |
853 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority(); | |
854 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible); | |
855 | |
856 // Move the viewport down 40 pixels. | |
857 viewport = gfx::Rect(0, 40, 100, 100); | |
858 viewport_in_content_space = | |
859 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | |
860 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); | |
861 | |
862 // Compute the soon border. | |
863 inset = PictureLayerTiling::CalculateSoonBorderDistance( | |
864 viewport_in_content_space, 1.0f / 0.25f); | |
865 soon_rect_in_content_space = viewport_in_content_space; | |
866 soon_rect_in_content_space.Inset(-inset, -inset); | |
867 | |
868 EXPECT_EQ(0, skewport.x()); | |
869 EXPECT_EQ(10, skewport.y()); | |
870 EXPECT_EQ(25, skewport.width()); | |
871 EXPECT_EQ(35, skewport.height()); | |
872 | |
873 tiling->ComputeTilePriorityRects(viewport, 1.f, 2.0, Occlusion()); | |
874 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
875 | |
876 have_now = false; | |
877 have_eventually = false; | |
878 have_soon = false; | |
879 | |
880 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | |
881 // some EVENTUALLY tiles. | |
882 for (int i = 0; i < 47; ++i) { | |
883 for (int j = 0; j < 47; ++j) { | |
884 Tile* tile = tiling->TileAt(i, j); | |
885 TilePriority priority = prioritized_tiles[tile].priority(); | |
886 | |
887 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j); | |
888 if (viewport_in_content_space.Intersects(tile_rect)) { | |
889 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i | |
890 << " j: " << j; | |
891 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i | |
892 << " j: " << j; | |
893 have_now = true; | |
894 } else if (skewport.Intersects(tile_rect) || | |
895 soon_rect_in_content_space.Intersects(tile_rect)) { | |
896 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i | |
897 << " j: " << j; | |
898 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | |
899 << " j: " << j; | |
900 have_soon = true; | |
901 } else { | |
902 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) | |
903 << "i: " << i << " j: " << j; | |
904 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | |
905 << " j: " << j; | |
906 have_eventually = true; | |
907 } | |
908 } | |
909 } | |
910 | |
911 EXPECT_TRUE(have_now); | |
912 EXPECT_TRUE(have_soon); | |
913 EXPECT_TRUE(have_eventually); | |
914 | |
915 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority(); | |
916 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
917 | |
918 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority(); | |
919 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | |
920 | |
921 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority(); | |
922 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible); | |
923 | |
924 // Change the underlying layer scale. | |
925 tiling->ComputeTilePriorityRects(viewport, 2.0f, 3.0, Occlusion()); | |
926 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
927 | |
928 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority(); | |
929 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); | |
930 | |
931 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority(); | |
932 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); | |
933 | |
934 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority(); | |
935 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible); | |
936 | |
937 // Test additional scales. | |
938 tiling = TestablePictureLayerTiling::Create(ACTIVE_TREE, 0.2f, pile, &client, | |
939 LayerTreeSettings()); | |
940 tiling->ComputeTilePriorityRects(viewport, 1.0f, 4.0, Occlusion()); | |
941 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
942 | |
943 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority(); | |
944 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); | |
945 | |
946 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority(); | |
947 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible); | |
948 | |
949 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority(); | |
950 EXPECT_FLOAT_EQ(60.f, priority.distance_to_visible); | |
951 | |
952 tiling->ComputeTilePriorityRects(viewport, 0.5f, 5.0, Occlusion()); | |
953 prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
954 | |
955 priority = prioritized_tiles[tiling->TileAt(5, 1)].priority(); | |
956 EXPECT_FLOAT_EQ(55.f, priority.distance_to_visible); | |
957 | |
958 priority = prioritized_tiles[tiling->TileAt(2, 5)].priority(); | |
959 EXPECT_FLOAT_EQ(35.f, priority.distance_to_visible); | |
960 | |
961 priority = prioritized_tiles[tiling->TileAt(3, 4)].priority(); | |
962 EXPECT_FLOAT_EQ(30.f, priority.distance_to_visible); | |
963 } | |
964 | |
965 TEST(PictureLayerTilingTest, ExpandRectEqual) { | |
966 gfx::Rect in(40, 50, 100, 200); | |
967 gfx::Rect bounds(-1000, -1000, 10000, 10000); | |
968 int64 target_area = 100 * 200; | |
969 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
970 in, target_area, bounds, NULL); | |
971 EXPECT_EQ(in.ToString(), out.ToString()); | |
972 } | |
973 | |
974 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | |
975 gfx::Rect in(40, 50, 100, 200); | |
976 gfx::Rect bounds(-1000, -1000, 10000, 10000); | |
977 int64 target_area = 100 * 100; | |
978 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
979 in, target_area, bounds, NULL); | |
980 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | |
981 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | |
982 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); | |
983 | |
984 // |in| represents the visible rect, and |out| represents the eventually rect. | |
985 // If the eventually rect doesn't contain the visible rect, we will start | |
986 // losing tiles. | |
987 EXPECT_TRUE(out.Contains(in)); | |
988 EXPECT_TRUE(bounds.Contains(out)); | |
989 } | |
990 | |
991 TEST(PictureLayerTilingTest, ExpandRectUnbounded) { | |
992 gfx::Rect in(40, 50, 100, 200); | |
993 gfx::Rect bounds(-1000, -1000, 10000, 10000); | |
994 int64 target_area = 200 * 200; | |
995 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
996 in, target_area, bounds, NULL); | |
997 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | |
998 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | |
999 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); | |
1000 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100); | |
1001 EXPECT_TRUE(bounds.Contains(out)); | |
1002 } | |
1003 | |
1004 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) { | |
1005 gfx::Rect in(40, 50, 100, 200); | |
1006 gfx::Rect bounds(50, 60, 40, 30); | |
1007 int64 target_area = 200 * 200; | |
1008 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1009 in, target_area, bounds, NULL); | |
1010 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1011 } | |
1012 | |
1013 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) { | |
1014 gfx::Rect in(40, 50, 100, 200); | |
1015 gfx::Rect bounds = in; | |
1016 int64 target_area = 200 * 200; | |
1017 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1018 in, target_area, bounds, NULL); | |
1019 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1020 } | |
1021 | |
1022 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) { | |
1023 gfx::Rect in(40, 50, 100, 200); | |
1024 gfx::Rect bounds(45, 0, 90, 300); | |
1025 int64 target_area = 200 * 200; | |
1026 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1027 in, target_area, bounds, NULL); | |
1028 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1029 } | |
1030 | |
1031 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) { | |
1032 gfx::Rect in(40, 50, 100, 200); | |
1033 gfx::Rect bounds(40, 0, 100, 300); | |
1034 int64 target_area = 200 * 200; | |
1035 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1036 in, target_area, bounds, NULL); | |
1037 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1038 } | |
1039 | |
1040 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) { | |
1041 gfx::Rect in(40, 50, 100, 200); | |
1042 gfx::Rect bounds(0, 55, 180, 190); | |
1043 int64 target_area = 200 * 200; | |
1044 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1045 in, target_area, bounds, NULL); | |
1046 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1047 } | |
1048 | |
1049 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) { | |
1050 gfx::Rect in(40, 50, 100, 200); | |
1051 gfx::Rect bounds(0, 50, 180, 200); | |
1052 int64 target_area = 200 * 200; | |
1053 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1054 in, target_area, bounds, NULL); | |
1055 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1056 } | |
1057 | |
1058 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) { | |
1059 gfx::Rect in(40, 50, 100, 200); | |
1060 gfx::Rect bounds(20, -1000, 10000, 10000); | |
1061 int64 target_area = 200 * 200; | |
1062 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1063 in, target_area, bounds, NULL); | |
1064 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | |
1065 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); | |
1066 EXPECT_LE(out.width() * out.height(), target_area); | |
1067 EXPECT_GT(out.width() * out.height(), | |
1068 target_area - out.width() - out.height() * 2); | |
1069 EXPECT_TRUE(bounds.Contains(out)); | |
1070 } | |
1071 | |
1072 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { | |
1073 gfx::Rect in(40, 50, 100, 200); | |
1074 gfx::Rect bounds(-1000, -1000, 1000+120, 10000); | |
1075 int64 target_area = 200 * 200; | |
1076 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1077 in, target_area, bounds, NULL); | |
1078 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | |
1079 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); | |
1080 EXPECT_LE(out.width() * out.height(), target_area); | |
1081 EXPECT_GT(out.width() * out.height(), | |
1082 target_area - out.width() - out.height() * 2); | |
1083 EXPECT_TRUE(bounds.Contains(out)); | |
1084 } | |
1085 | |
1086 TEST(PictureLayerTilingTest, ExpandRectBoundedTop) { | |
1087 gfx::Rect in(40, 50, 100, 200); | |
1088 gfx::Rect bounds(-1000, 30, 10000, 10000); | |
1089 int64 target_area = 200 * 200; | |
1090 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1091 in, target_area, bounds, NULL); | |
1092 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | |
1093 EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom()); | |
1094 EXPECT_LE(out.width() * out.height(), target_area); | |
1095 EXPECT_GT(out.width() * out.height(), | |
1096 target_area - out.width() * 2 - out.height()); | |
1097 EXPECT_TRUE(bounds.Contains(out)); | |
1098 } | |
1099 | |
1100 TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) { | |
1101 gfx::Rect in(40, 50, 100, 200); | |
1102 gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220); | |
1103 int64 target_area = 200 * 200; | |
1104 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1105 in, target_area, bounds, NULL); | |
1106 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | |
1107 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); | |
1108 EXPECT_LE(out.width() * out.height(), target_area); | |
1109 EXPECT_GT(out.width() * out.height(), | |
1110 target_area - out.width() * 2 - out.height()); | |
1111 EXPECT_TRUE(bounds.Contains(out)); | |
1112 } | |
1113 | |
1114 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { | |
1115 gfx::Rect in(40, 50, 100, 200); | |
1116 gfx::Rect bounds(0, -4000, 100+40+20, 100000); | |
1117 int64 target_area = 400 * 400; | |
1118 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1119 in, target_area, bounds, NULL); | |
1120 EXPECT_EQ(20, out.right() - in.right()); | |
1121 EXPECT_EQ(40, in.x() - out.x()); | |
1122 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | |
1123 EXPECT_LE(out.width() * out.height(), target_area); | |
1124 EXPECT_GT(out.width() * out.height(), | |
1125 target_area - out.width() * 2); | |
1126 EXPECT_TRUE(bounds.Contains(out)); | |
1127 } | |
1128 | |
1129 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { | |
1130 gfx::Rect in(40, 50, 100, 200); | |
1131 gfx::Rect bounds(-4000, 0, 100000, 200+50+30); | |
1132 int64 target_area = 400 * 400; | |
1133 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1134 in, target_area, bounds, NULL); | |
1135 EXPECT_EQ(30, out.bottom() - in.bottom()); | |
1136 EXPECT_EQ(50, in.y() - out.y()); | |
1137 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | |
1138 EXPECT_LE(out.width() * out.height(), target_area); | |
1139 EXPECT_GT(out.width() * out.height(), | |
1140 target_area - out.height() * 2); | |
1141 EXPECT_TRUE(bounds.Contains(out)); | |
1142 } | |
1143 | |
1144 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { | |
1145 gfx::Rect in(400, 500, 100, 200); | |
1146 gfx::Rect bounds(0, 0, 10, 10); | |
1147 int64 target_area = 400 * 400; | |
1148 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1149 in, target_area, bounds, NULL); | |
1150 EXPECT_TRUE(out.IsEmpty()); | |
1151 } | |
1152 | |
1153 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedFullyCover) { | |
1154 gfx::Rect in(40, 50, 100, 100); | |
1155 gfx::Rect bounds(0, 0, 10, 10); | |
1156 int64 target_area = 400 * 400; | |
1157 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1158 in, target_area, bounds, NULL); | |
1159 EXPECT_EQ(bounds.ToString(), out.ToString()); | |
1160 } | |
1161 | |
1162 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedPartlyCover) { | |
1163 gfx::Rect in(600, 600, 100, 100); | |
1164 gfx::Rect bounds(0, 0, 500, 500); | |
1165 int64 target_area = 400 * 400; | |
1166 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1167 in, target_area, bounds, NULL); | |
1168 EXPECT_EQ(bounds.right(), out.right()); | |
1169 EXPECT_EQ(bounds.bottom(), out.bottom()); | |
1170 EXPECT_LE(out.width() * out.height(), target_area); | |
1171 EXPECT_GT(out.width() * out.height(), | |
1172 target_area - out.width() - out.height()); | |
1173 EXPECT_TRUE(bounds.Contains(out)); | |
1174 } | |
1175 | |
1176 TEST(PictureLayerTilingTest, EmptyStartingRect) { | |
1177 // If a layer has a non-invertible transform, then the starting rect | |
1178 // for the layer would be empty. | |
1179 gfx::Rect in(40, 40, 0, 0); | |
1180 gfx::Rect bounds(0, 0, 10, 10); | |
1181 int64 target_area = 400 * 400; | |
1182 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | |
1183 in, target_area, bounds, NULL); | |
1184 EXPECT_TRUE(out.IsEmpty()); | |
1185 } | |
1186 | |
1187 static void TileExists(bool exists, Tile* tile, | |
1188 const gfx::Rect& geometry_rect) { | |
1189 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | |
1190 } | |
1191 | |
1192 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | |
1193 gfx::Size layer_bounds(1099, 801); | |
1194 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | |
1195 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | |
1196 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1197 | |
1198 tiling_->ComputeTilePriorityRects( | |
1199 gfx::Rect(layer_bounds), // visible content rect | |
1200 1.f, // current contents scale | |
1201 1.0, // current frame time | |
1202 Occlusion()); | |
1203 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | |
1204 | |
1205 // Make the viewport rect empty. All tiles are killed and become zombies. | |
1206 tiling_->ComputeTilePriorityRects(gfx::Rect(), // visible content rect | |
1207 1.f, // current contents scale | |
1208 2.0, // current frame time | |
1209 Occlusion()); | |
1210 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1211 } | |
1212 | |
1213 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | |
1214 gfx::Size layer_bounds(1099, 801); | |
1215 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | |
1216 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | |
1217 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1218 | |
1219 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | |
1220 | |
1221 tiling_->ComputeTilePriorityRects( | |
1222 gfx::Rect(layer_bounds), // visible content rect | |
1223 1.f, // current contents scale | |
1224 1.0, // current frame time | |
1225 Occlusion()); | |
1226 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | |
1227 | |
1228 // If the visible content rect is empty, it should still have live tiles. | |
1229 tiling_->ComputeTilePriorityRects(giant_rect, // visible content rect | |
1230 1.f, // current contents scale | |
1231 2.0, // current frame time | |
1232 Occlusion()); | |
1233 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | |
1234 } | |
1235 | |
1236 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | |
1237 gfx::Size layer_bounds(1099, 801); | |
1238 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | |
1239 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | |
1240 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1241 | |
1242 // This rect does not intersect with the layer, as the layer is outside the | |
1243 // viewport. | |
1244 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | |
1245 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | |
1246 | |
1247 tiling_->ComputeTilePriorityRects(viewport_rect, // visible content rect | |
1248 1.f, // current contents scale | |
1249 1.0, // current frame time | |
1250 Occlusion()); | |
1251 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | |
1252 } | |
1253 | |
1254 static void TilesIntersectingRectExist(const gfx::Rect& rect, | |
1255 bool intersect_exists, | |
1256 Tile* tile, | |
1257 const gfx::Rect& geometry_rect) { | |
1258 bool intersects = rect.Intersects(geometry_rect); | |
1259 bool expected_exists = intersect_exists ? intersects : !intersects; | |
1260 EXPECT_EQ(expected_exists, tile != NULL) | |
1261 << "Rects intersecting " << rect.ToString() << " should exist. " | |
1262 << "Current tile rect is " << geometry_rect.ToString(); | |
1263 } | |
1264 | |
1265 TEST_F(PictureLayerTilingIteratorTest, | |
1266 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | |
1267 gfx::Size layer_bounds(10000, 10000); | |
1268 client_.SetTileSize(gfx::Size(100, 100)); | |
1269 LayerTreeSettings settings; | |
1270 settings.tiling_interest_area_viewport_multiplier = 1; | |
1271 | |
1272 scoped_refptr<FakePicturePileImpl> pile = | |
1273 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); | |
1274 tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, 1.f, pile, | |
1275 &client_, settings); | |
1276 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | |
1277 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1278 | |
1279 gfx::Rect visible_rect(8000, 8000, 50, 50); | |
1280 | |
1281 tiling_->ComputeTilePriorityRects(visible_rect, // visible content rect | |
1282 1.f, // current contents scale | |
1283 1.0, // current frame time | |
1284 Occlusion()); | |
1285 VerifyTiles(1.f, | |
1286 gfx::Rect(layer_bounds), | |
1287 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | |
1288 } | |
1289 | |
1290 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { | |
1291 // The TilePriority of visible tiles should have zero distance_to_visible | |
1292 // and time_to_visible. | |
1293 FakePictureLayerTilingClient client; | |
1294 | |
1295 gfx::Size device_viewport(800, 600); | |
1296 gfx::Size last_layer_bounds(200, 200); | |
1297 gfx::Size current_layer_bounds(200, 200); | |
1298 float current_layer_contents_scale = 1.f; | |
1299 gfx::Transform current_screen_transform; | |
1300 double current_frame_time_in_seconds = 1.0; | |
1301 | |
1302 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1303 current_screen_transform, device_viewport); | |
1304 | |
1305 client.SetTileSize(gfx::Size(100, 100)); | |
1306 | |
1307 scoped_refptr<FakePicturePileImpl> pile = | |
1308 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1309 current_layer_bounds); | |
1310 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1311 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1312 LayerTreeSettings()); | |
1313 | |
1314 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1315 current_layer_contents_scale, | |
1316 current_frame_time_in_seconds, Occlusion()); | |
1317 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1318 | |
1319 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1320 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1321 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1322 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1323 | |
1324 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1325 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1326 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1327 | |
1328 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1329 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1330 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1331 | |
1332 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1333 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1334 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1335 | |
1336 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1337 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1338 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1339 } | |
1340 | |
1341 TEST(ComputeTilePriorityRectsTest, OffscreenTiles) { | |
1342 // The TilePriority of offscreen tiles (without movement) should have nonzero | |
1343 // distance_to_visible and infinite time_to_visible. | |
1344 FakePictureLayerTilingClient client; | |
1345 | |
1346 gfx::Size device_viewport(800, 600); | |
1347 gfx::Size last_layer_bounds(200, 200); | |
1348 gfx::Size current_layer_bounds(200, 200); | |
1349 float current_layer_contents_scale = 1.f; | |
1350 gfx::Transform last_screen_transform; | |
1351 gfx::Transform current_screen_transform; | |
1352 double current_frame_time_in_seconds = 1.0; | |
1353 | |
1354 current_screen_transform.Translate(850, 0); | |
1355 last_screen_transform = current_screen_transform; | |
1356 | |
1357 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1358 current_screen_transform, device_viewport); | |
1359 | |
1360 client.SetTileSize(gfx::Size(100, 100)); | |
1361 | |
1362 scoped_refptr<FakePicturePileImpl> pile = | |
1363 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1364 current_layer_bounds); | |
1365 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1366 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1367 LayerTreeSettings()); | |
1368 | |
1369 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1370 current_layer_contents_scale, | |
1371 current_frame_time_in_seconds, Occlusion()); | |
1372 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1373 | |
1374 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1375 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1376 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1377 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1378 | |
1379 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1380 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1381 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1382 | |
1383 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1384 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1385 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1386 | |
1387 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1388 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1389 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1390 | |
1391 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1392 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1393 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1394 | |
1395 // Furthermore, in this scenario tiles on the right hand side should have a | |
1396 // larger distance to visible. | |
1397 TilePriority left = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1398 TilePriority right = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1399 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | |
1400 | |
1401 left = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1402 right = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1403 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | |
1404 } | |
1405 | |
1406 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenLayer) { | |
1407 // Sanity check that a layer with some tiles visible and others offscreen has | |
1408 // correct TilePriorities for each tile. | |
1409 FakePictureLayerTilingClient client; | |
1410 | |
1411 gfx::Size device_viewport(800, 600); | |
1412 gfx::Size last_layer_bounds(200, 200); | |
1413 gfx::Size current_layer_bounds(200, 200); | |
1414 float current_layer_contents_scale = 1.f; | |
1415 gfx::Transform last_screen_transform; | |
1416 gfx::Transform current_screen_transform; | |
1417 double current_frame_time_in_seconds = 1.0; | |
1418 | |
1419 current_screen_transform.Translate(705, 505); | |
1420 last_screen_transform = current_screen_transform; | |
1421 | |
1422 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1423 current_screen_transform, device_viewport); | |
1424 | |
1425 client.SetTileSize(gfx::Size(100, 100)); | |
1426 | |
1427 scoped_refptr<FakePicturePileImpl> pile = | |
1428 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1429 current_layer_bounds); | |
1430 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1431 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1432 LayerTreeSettings()); | |
1433 | |
1434 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1435 current_layer_contents_scale, | |
1436 current_frame_time_in_seconds, Occlusion()); | |
1437 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1438 | |
1439 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1440 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1441 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1442 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1443 | |
1444 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1445 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1446 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1447 | |
1448 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1449 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1450 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1451 | |
1452 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1453 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1454 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1455 | |
1456 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1457 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1458 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1459 } | |
1460 | |
1461 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenRotatedLayer) { | |
1462 // Each tile of a layer may be affected differently by a transform; Check | |
1463 // that ComputeTilePriorityRects correctly accounts for the transform between | |
1464 // layer space and screen space. | |
1465 FakePictureLayerTilingClient client; | |
1466 | |
1467 gfx::Size device_viewport(800, 600); | |
1468 gfx::Size last_layer_bounds(200, 200); | |
1469 gfx::Size current_layer_bounds(200, 200); | |
1470 float current_layer_contents_scale = 1.f; | |
1471 gfx::Transform last_screen_transform; | |
1472 gfx::Transform current_screen_transform; | |
1473 double current_frame_time_in_seconds = 1.0; | |
1474 | |
1475 // A diagonally rotated layer that is partially off the bottom of the screen. | |
1476 // In this configuration, only the top-left tile would be visible. | |
1477 current_screen_transform.Translate(600, 750); | |
1478 current_screen_transform.RotateAboutZAxis(45); | |
1479 last_screen_transform = current_screen_transform; | |
1480 | |
1481 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1482 current_screen_transform, device_viewport); | |
1483 | |
1484 client.SetTileSize(gfx::Size(100, 100)); | |
1485 | |
1486 scoped_refptr<FakePicturePileImpl> pile = | |
1487 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1488 current_layer_bounds); | |
1489 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1490 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1491 LayerTreeSettings()); | |
1492 | |
1493 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1494 current_layer_contents_scale, | |
1495 current_frame_time_in_seconds, Occlusion()); | |
1496 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1497 | |
1498 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1499 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1500 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1501 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1502 | |
1503 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1504 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1505 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1506 | |
1507 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1508 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1509 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1510 | |
1511 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1512 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1513 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1514 | |
1515 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1516 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1517 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1518 | |
1519 // Furthermore, in this scenario the bottom-right tile should have the larger | |
1520 // distance to visible. | |
1521 TilePriority top_left = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1522 TilePriority top_right = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1523 TilePriority bottom_right = | |
1524 prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1525 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible); | |
1526 | |
1527 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); | |
1528 } | |
1529 | |
1530 TEST(ComputeTilePriorityRectsTest, PerspectiveLayer) { | |
1531 // Perspective transforms need to take a different code path. | |
1532 // This test checks tile priorities of a perspective layer. | |
1533 FakePictureLayerTilingClient client; | |
1534 | |
1535 gfx::Size device_viewport(800, 600); | |
1536 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | |
1537 gfx::Size last_layer_bounds(200, 200); | |
1538 gfx::Size current_layer_bounds(200, 200); | |
1539 float current_layer_contents_scale = 1.f; | |
1540 gfx::Transform last_screen_transform; | |
1541 gfx::Transform current_screen_transform; | |
1542 double current_frame_time_in_seconds = 1.0; | |
1543 | |
1544 // A 3d perspective layer rotated about its Y axis, translated to almost | |
1545 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | |
1546 // the right side, so the top-left tile will technically be closer than the | |
1547 // top-right. | |
1548 | |
1549 // Translate layer to offscreen | |
1550 current_screen_transform.Translate(400.0, 630.0); | |
1551 // Apply perspective about the center of the layer | |
1552 current_screen_transform.Translate(100.0, 100.0); | |
1553 current_screen_transform.ApplyPerspectiveDepth(100.0); | |
1554 current_screen_transform.RotateAboutYAxis(10.0); | |
1555 current_screen_transform.Translate(-100.0, -100.0); | |
1556 last_screen_transform = current_screen_transform; | |
1557 | |
1558 // Sanity check that this transform wouldn't cause w<0 clipping. | |
1559 bool clipped; | |
1560 MathUtil::MapQuad(current_screen_transform, | |
1561 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), | |
1562 &clipped); | |
1563 ASSERT_FALSE(clipped); | |
1564 | |
1565 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1566 current_screen_transform, device_viewport); | |
1567 | |
1568 client.SetTileSize(gfx::Size(100, 100)); | |
1569 | |
1570 scoped_refptr<FakePicturePileImpl> pile = | |
1571 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1572 current_layer_bounds); | |
1573 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1574 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1575 LayerTreeSettings()); | |
1576 | |
1577 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1578 current_layer_contents_scale, | |
1579 current_frame_time_in_seconds, Occlusion()); | |
1580 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1581 | |
1582 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1583 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1584 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1585 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1586 | |
1587 // All tiles will have a positive distance_to_visible | |
1588 // and an infinite time_to_visible. | |
1589 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1590 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); | |
1591 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1592 | |
1593 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1594 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1595 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1596 | |
1597 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1598 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); | |
1599 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1600 | |
1601 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1602 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1603 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1604 | |
1605 // Furthermore, in this scenario the top-left distance_to_visible | |
1606 // will be smallest, followed by top-right. The bottom layers | |
1607 // will of course be further than the top layers. | |
1608 TilePriority top_left = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1609 TilePriority top_right = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1610 TilePriority bottom_left = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1611 TilePriority bottom_right = | |
1612 prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1613 | |
1614 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); | |
1615 | |
1616 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); | |
1617 } | |
1618 | |
1619 TEST(ComputeTilePriorityRectsTest, PerspectiveLayerClippedByW) { | |
1620 // Perspective transforms need to take a different code path. | |
1621 // This test checks tile priorities of a perspective layer. | |
1622 FakePictureLayerTilingClient client; | |
1623 | |
1624 gfx::Size device_viewport(800, 600); | |
1625 gfx::Size last_layer_bounds(200, 200); | |
1626 gfx::Size current_layer_bounds(200, 200); | |
1627 float current_layer_contents_scale = 1.f; | |
1628 gfx::Transform last_screen_transform; | |
1629 gfx::Transform current_screen_transform; | |
1630 double current_frame_time_in_seconds = 1.0; | |
1631 | |
1632 // A 3d perspective layer rotated about its Y axis, translated to almost | |
1633 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | |
1634 // the right side, so the top-left tile will technically be closer than the | |
1635 // top-right. | |
1636 | |
1637 // Translate layer to offscreen | |
1638 current_screen_transform.Translate(400.0, 970.0); | |
1639 // Apply perspective and rotation about the center of the layer | |
1640 current_screen_transform.Translate(100.0, 100.0); | |
1641 current_screen_transform.ApplyPerspectiveDepth(10.0); | |
1642 current_screen_transform.RotateAboutYAxis(10.0); | |
1643 current_screen_transform.Translate(-100.0, -100.0); | |
1644 last_screen_transform = current_screen_transform; | |
1645 | |
1646 // Sanity check that this transform does cause w<0 clipping for the left side | |
1647 // of the layer, but not the right side. | |
1648 bool clipped; | |
1649 MathUtil::MapQuad(current_screen_transform, | |
1650 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), | |
1651 &clipped); | |
1652 ASSERT_TRUE(clipped); | |
1653 | |
1654 MathUtil::MapQuad(current_screen_transform, | |
1655 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | |
1656 &clipped); | |
1657 ASSERT_FALSE(clipped); | |
1658 | |
1659 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1660 current_screen_transform, device_viewport); | |
1661 | |
1662 client.SetTileSize(gfx::Size(100, 100)); | |
1663 | |
1664 scoped_refptr<FakePicturePileImpl> pile = | |
1665 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1666 current_layer_bounds); | |
1667 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1668 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1669 LayerTreeSettings()); | |
1670 | |
1671 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1672 current_layer_contents_scale, | |
1673 current_frame_time_in_seconds, Occlusion()); | |
1674 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1675 | |
1676 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1677 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1678 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1679 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1680 | |
1681 // Left-side tiles will be clipped by the transform, so we have to assume | |
1682 // they are visible just in case. | |
1683 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1684 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1685 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | |
1686 | |
1687 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1688 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1689 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1690 | |
1691 // Right-side tiles will have a positive distance_to_visible | |
1692 // and an infinite time_to_visible. | |
1693 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1694 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); | |
1695 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1696 | |
1697 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1698 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1699 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1700 } | |
1701 | |
1702 TEST(ComputeTilePriorityRectsTest, BasicMotion) { | |
1703 // Test that time_to_visible is computed correctly when | |
1704 // there is some motion. | |
1705 FakePictureLayerTilingClient client; | |
1706 | |
1707 gfx::Size device_viewport(800, 600); | |
1708 gfx::Rect visible_layer_rect(0, 0, 0, 0); | |
1709 gfx::Size last_layer_bounds(200, 200); | |
1710 gfx::Size current_layer_bounds(200, 200); | |
1711 float last_layer_contents_scale = 1.f; | |
1712 float current_layer_contents_scale = 1.f; | |
1713 gfx::Transform last_screen_transform; | |
1714 gfx::Transform current_screen_transform; | |
1715 double last_frame_time_in_seconds = 1.0; | |
1716 double current_frame_time_in_seconds = 2.0; | |
1717 | |
1718 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | |
1719 current_screen_transform.Translate(1800, 0); | |
1720 last_screen_transform.Translate(2800, 0); | |
1721 | |
1722 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1723 current_screen_transform, device_viewport); | |
1724 | |
1725 client.SetTileSize(gfx::Size(100, 100)); | |
1726 LayerTreeSettings settings; | |
1727 settings.tiling_interest_area_viewport_multiplier = 10000; | |
1728 | |
1729 scoped_refptr<FakePicturePileImpl> pile = | |
1730 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1731 current_layer_bounds); | |
1732 scoped_ptr<TestablePictureLayerTiling> tiling = | |
1733 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1734 settings); | |
1735 | |
1736 // previous ("last") frame | |
1737 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1738 last_layer_contents_scale, | |
1739 last_frame_time_in_seconds, Occlusion()); | |
1740 | |
1741 // current frame | |
1742 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1743 current_layer_contents_scale, | |
1744 current_frame_time_in_seconds, Occlusion()); | |
1745 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1746 | |
1747 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1748 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1749 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1750 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1751 | |
1752 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1753 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1754 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1755 | |
1756 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1757 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1758 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1759 | |
1760 // time_to_visible for the right hand side layers needs an extra 0.099 | |
1761 // seconds because this tile is 99 pixels further away. | |
1762 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1763 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1764 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1765 | |
1766 priority = prioritized_tiles[tiling->TileAt(1, 1)].priority(); | |
1767 EXPECT_GT(priority.distance_to_visible, 0.f); | |
1768 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | |
1769 } | |
1770 | |
1771 TEST(ComputeTilePriorityRectsTest, RotationMotion) { | |
1772 // Each tile of a layer may be affected differently by a transform; Check | |
1773 // that ComputeTilePriorityRects correctly accounts for the transform between | |
1774 // layer space and screen space. | |
1775 | |
1776 FakePictureLayerTilingClient client; | |
1777 scoped_ptr<TestablePictureLayerTiling> tiling; | |
1778 | |
1779 gfx::Size device_viewport(800, 600); | |
1780 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. | |
1781 gfx::Size last_layer_bounds(200, 200); | |
1782 gfx::Size current_layer_bounds(200, 200); | |
1783 float last_layer_contents_scale = 1.f; | |
1784 float current_layer_contents_scale = 1.f; | |
1785 gfx::Transform last_screen_transform; | |
1786 gfx::Transform current_screen_transform; | |
1787 double last_frame_time_in_seconds = 1.0; | |
1788 double current_frame_time_in_seconds = 2.0; | |
1789 | |
1790 // Rotation motion is set up specifically so that: | |
1791 // - rotation occurs about the center of the layer | |
1792 // - the top-left tile becomes visible on rotation | |
1793 // - the top-right tile will have an infinite time_to_visible | |
1794 // because it is rotating away from viewport. | |
1795 // - bottom-left layer will have a positive non-zero time_to_visible | |
1796 // because it is rotating toward the viewport. | |
1797 current_screen_transform.Translate(400, 550); | |
1798 current_screen_transform.RotateAboutZAxis(45); | |
1799 | |
1800 last_screen_transform.Translate(400, 550); | |
1801 | |
1802 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | |
1803 current_screen_transform, device_viewport); | |
1804 | |
1805 client.SetTileSize(gfx::Size(100, 100)); | |
1806 | |
1807 scoped_refptr<FakePicturePileImpl> pile = | |
1808 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1809 current_layer_bounds); | |
1810 tiling = TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, &client, | |
1811 LayerTreeSettings()); | |
1812 | |
1813 // previous ("last") frame | |
1814 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1815 last_layer_contents_scale, | |
1816 last_frame_time_in_seconds, Occlusion()); | |
1817 | |
1818 // current frame | |
1819 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | |
1820 current_layer_contents_scale, | |
1821 current_frame_time_in_seconds, Occlusion()); | |
1822 auto prioritized_tiles = tiling->UpdateAndGetAllPrioritizedTilesForTesting(); | |
1823 | |
1824 ASSERT_TRUE(tiling->TileAt(0, 0)); | |
1825 ASSERT_TRUE(tiling->TileAt(0, 1)); | |
1826 ASSERT_TRUE(tiling->TileAt(1, 0)); | |
1827 ASSERT_TRUE(tiling->TileAt(1, 1)); | |
1828 | |
1829 TilePriority priority = prioritized_tiles[tiling->TileAt(0, 0)].priority(); | |
1830 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1831 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1832 | |
1833 priority = prioritized_tiles[tiling->TileAt(0, 1)].priority(); | |
1834 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1835 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1836 | |
1837 priority = prioritized_tiles[tiling->TileAt(1, 0)].priority(); | |
1838 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
1839 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
1840 } | |
1841 | |
1842 TEST(PictureLayerTilingTest, RecycledTilesCleared) { | |
1843 // This test performs the following: | |
1844 // Setup: | |
1845 // - Two tilings, one active one recycled with all tiles shared. | |
1846 // Procedure: | |
1847 // - Viewport moves somewhere far away and active tiling clears tiles. | |
1848 // - Viewport moves back and a new active tiling tile is created. | |
1849 // Result: | |
1850 // - Recycle tiling does _not_ have the tile in the same location (thus it | |
1851 // will be shared next time a pending tiling is created). | |
1852 | |
1853 FakePictureLayerTilingClient active_client; | |
1854 | |
1855 active_client.SetTileSize(gfx::Size(100, 100)); | |
1856 LayerTreeSettings settings; | |
1857 | |
1858 scoped_refptr<FakePicturePileImpl> pile = | |
1859 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1860 gfx::Size(10000, 10000)); | |
1861 scoped_ptr<TestablePictureLayerTiling> active_tiling = | |
1862 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, | |
1863 &active_client, settings); | |
1864 // Create all tiles on this tiling. | |
1865 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, | |
1866 Occlusion()); | |
1867 | |
1868 FakePictureLayerTilingClient recycle_client; | |
1869 recycle_client.SetTileSize(gfx::Size(100, 100)); | |
1870 recycle_client.set_twin_tiling(active_tiling.get()); | |
1871 | |
1872 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1873 gfx::Size(10000, 10000)); | |
1874 scoped_ptr<TestablePictureLayerTiling> recycle_tiling = | |
1875 TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, pile, | |
1876 &recycle_client, settings); | |
1877 | |
1878 // Create all tiles on the second tiling. All tiles should be shared. | |
1879 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, | |
1880 1.0f, Occlusion()); | |
1881 | |
1882 // Set the second tiling as recycled. | |
1883 active_client.set_twin_tiling(NULL); | |
1884 recycle_client.set_twin_tiling(NULL); | |
1885 | |
1886 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | |
1887 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | |
1888 | |
1889 // Move the viewport far away from the (0, 0) tile. | |
1890 active_tiling->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f, | |
1891 2.0, Occlusion()); | |
1892 // Ensure the tile was deleted. | |
1893 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | |
1894 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | |
1895 | |
1896 // Move the viewport back to (0, 0) tile. | |
1897 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 3.0, | |
1898 Occlusion()); | |
1899 | |
1900 // Ensure that we now have a tile here on both active. | |
1901 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | |
1902 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | |
1903 } | |
1904 | |
1905 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { | |
1906 FakePictureLayerTilingClient active_client; | |
1907 active_client.SetTileSize(gfx::Size(100, 100)); | |
1908 | |
1909 scoped_refptr<FakePicturePileImpl> pile = | |
1910 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1911 gfx::Size(100, 100)); | |
1912 scoped_ptr<TestablePictureLayerTiling> active_tiling = | |
1913 TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, pile, | |
1914 &active_client, LayerTreeSettings()); | |
1915 // Create all tiles on this tiling. | |
1916 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, | |
1917 Occlusion()); | |
1918 | |
1919 FakePictureLayerTilingClient recycle_client; | |
1920 recycle_client.SetTileSize(gfx::Size(100, 100)); | |
1921 recycle_client.set_twin_tiling(active_tiling.get()); | |
1922 | |
1923 LayerTreeSettings settings; | |
1924 | |
1925 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1926 gfx::Size(100, 100)); | |
1927 scoped_ptr<TestablePictureLayerTiling> recycle_tiling = | |
1928 TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, pile, | |
1929 &recycle_client, settings); | |
1930 | |
1931 // Create all tiles on the recycle tiling. All tiles should be shared. | |
1932 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, | |
1933 1.0f, Occlusion()); | |
1934 | |
1935 // Set the second tiling as recycled. | |
1936 active_client.set_twin_tiling(NULL); | |
1937 recycle_client.set_twin_tiling(NULL); | |
1938 | |
1939 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | |
1940 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | |
1941 | |
1942 // Reset the active tiling. The recycle tiles should be released too. | |
1943 active_tiling->Reset(); | |
1944 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | |
1945 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | |
1946 } | |
1947 | |
1948 TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { | |
1949 // The tiling has four rows and three columns. | |
1950 Initialize(gfx::Size(150, 100), 1.f, gfx::Size(250, 150)); | |
1951 tiling_->CreateAllTilesForTesting(); | |
1952 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | |
1953 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | |
1954 EXPECT_EQ(4u, tiling_->AllTilesForTesting().size()); | |
1955 | |
1956 client_.SetTileSize(gfx::Size(250, 200)); | |
1957 | |
1958 // Tile size in the tiling should still be 150x100. | |
1959 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | |
1960 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | |
1961 | |
1962 // The layer's size isn't changed, but the tile size was. | |
1963 scoped_refptr<FakePicturePileImpl> pile = | |
1964 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( | |
1965 gfx::Size(250, 150)); | |
1966 tiling_->SetRasterSourceAndResize(pile); | |
1967 | |
1968 // Tile size in the tiling should be resized to 250x200. | |
1969 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | |
1970 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | |
1971 EXPECT_EQ(0u, tiling_->AllTilesForTesting().size()); | |
1972 } | |
1973 | |
1974 } // namespace | |
1975 } // namespace cc | |
OLD | NEW |