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