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.
8 #include "cc/base/math_util.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/fake_picture_layer_tiling_client.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/tiles/picture_layer_tiling.h"
16 #include "cc/tiles/picture_layer_tiling_set.h"
17 #include "cc/trees/layer_tree_settings.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"
26 static gfx::Rect
ViewportInLayerSpace(
27 const gfx::Transform
& transform
,
28 const gfx::Size
& device_viewport
) {
30 gfx::Transform inverse
;
31 if (!transform
.GetInverse(&inverse
))
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
);
39 class TestablePictureLayerTiling
: public PictureLayerTiling
{
41 using PictureLayerTiling::SetLiveTilesRect
;
42 using PictureLayerTiling::TileAt
;
44 static scoped_ptr
<TestablePictureLayerTiling
> Create(
47 scoped_refptr
<RasterSource
> raster_source
,
48 PictureLayerTilingClient
* client
,
49 const LayerTreeSettings
& settings
) {
50 return make_scoped_ptr(new TestablePictureLayerTiling(
51 tree
, contents_scale
, raster_source
, client
,
52 settings
.tiling_interest_area_padding
,
53 settings
.skewport_target_time_in_seconds
,
54 settings
.skewport_extrapolation_limit_in_content_pixels
));
57 gfx::Rect
live_tiles_rect() const { return live_tiles_rect_
; }
59 using PictureLayerTiling::ComputeSkewport
;
60 using PictureLayerTiling::RemoveTileAt
;
63 TestablePictureLayerTiling(WhichTree tree
,
65 scoped_refptr
<RasterSource
> raster_source
,
66 PictureLayerTilingClient
* client
,
67 size_t tiling_interest_area_padding
,
68 float skewport_target_time
,
69 int skewport_extrapolation_limit
)
70 : PictureLayerTiling(tree
,
74 tiling_interest_area_padding
,
76 skewport_extrapolation_limit
) {}
79 class PictureLayerTilingIteratorTest
: public testing::Test
{
81 PictureLayerTilingIteratorTest() {}
82 ~PictureLayerTilingIteratorTest() override
{}
84 void Initialize(const gfx::Size
& tile_size
,
86 const gfx::Size
& layer_bounds
) {
87 client_
.SetTileSize(tile_size
);
88 scoped_refptr
<FakePicturePileImpl
> pile
=
89 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
90 tiling_
= TestablePictureLayerTiling::Create(
91 PENDING_TREE
, contents_scale
, pile
, &client_
, LayerTreeSettings());
92 tiling_
->set_resolution(HIGH_RESOLUTION
);
95 void InitializeActive(const gfx::Size
& tile_size
,
97 const gfx::Size
& layer_bounds
) {
98 client_
.SetTileSize(tile_size
);
99 scoped_refptr
<FakePicturePileImpl
> pile
=
100 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
101 tiling_
= TestablePictureLayerTiling::Create(
102 ACTIVE_TREE
, contents_scale
, pile
, &client_
, LayerTreeSettings());
103 tiling_
->set_resolution(HIGH_RESOLUTION
);
106 void SetLiveRectAndVerifyTiles(const gfx::Rect
& live_tiles_rect
) {
107 tiling_
->SetLiveTilesRect(live_tiles_rect
);
109 std::vector
<Tile
*> tiles
= tiling_
->AllTilesForTesting();
110 for (std::vector
<Tile
*>::iterator iter
= tiles
.begin();
113 EXPECT_TRUE(live_tiles_rect
.Intersects((*iter
)->content_rect()));
117 void VerifyTilesExactlyCoverRect(
119 const gfx::Rect
& request_rect
,
120 const gfx::Rect
& expect_rect
) {
121 EXPECT_TRUE(request_rect
.Contains(expect_rect
));
123 // Iterators are not valid if this ratio is too large (i.e. the
124 // tiling is too high-res for a low-res destination rect.) This is an
125 // artifact of snapping geometry to integer coordinates and then mapping
126 // back to floating point texture coordinates.
127 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
128 ASSERT_LE(dest_to_contents_scale
, 2.0);
130 Region remaining
= expect_rect
;
131 for (PictureLayerTiling::CoverageIterator
132 iter(tiling_
.get(), rect_scale
, request_rect
);
135 // Geometry cannot overlap previous geometry at all
136 gfx::Rect geometry
= iter
.geometry_rect();
137 EXPECT_TRUE(expect_rect
.Contains(geometry
));
138 EXPECT_TRUE(remaining
.Contains(geometry
));
139 remaining
.Subtract(geometry
);
141 // Sanity check that texture coords are within the texture rect.
142 gfx::RectF texture_rect
= iter
.texture_rect();
143 EXPECT_GE(texture_rect
.x(), 0);
144 EXPECT_GE(texture_rect
.y(), 0);
145 EXPECT_LE(texture_rect
.right(), client_
.TileSize().width());
146 EXPECT_LE(texture_rect
.bottom(), client_
.TileSize().height());
149 // The entire rect must be filled by geometry from the tiling.
150 EXPECT_TRUE(remaining
.IsEmpty());
153 void VerifyTilesExactlyCoverRect(float rect_scale
, const gfx::Rect
& rect
) {
154 VerifyTilesExactlyCoverRect(rect_scale
, rect
, rect
);
159 const gfx::Rect
& rect
,
160 base::Callback
<void(Tile
* tile
,
161 const gfx::Rect
& geometry_rect
)> callback
) {
162 VerifyTiles(tiling_
.get(),
169 PictureLayerTiling
* tiling
,
171 const gfx::Rect
& rect
,
172 base::Callback
<void(Tile
* tile
,
173 const gfx::Rect
& geometry_rect
)> callback
) {
174 Region remaining
= rect
;
175 for (PictureLayerTiling::CoverageIterator
iter(tiling
, rect_scale
, rect
);
178 remaining
.Subtract(iter
.geometry_rect());
179 callback
.Run(*iter
, iter
.geometry_rect());
181 EXPECT_TRUE(remaining
.IsEmpty());
184 void VerifyTilesCoverNonContainedRect(float rect_scale
,
185 const gfx::Rect
& dest_rect
) {
186 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
187 gfx::Rect clamped_rect
= gfx::ScaleToEnclosingRect(
188 gfx::Rect(tiling_
->tiling_size()), 1.f
/ dest_to_contents_scale
);
189 clamped_rect
.Intersect(dest_rect
);
190 VerifyTilesExactlyCoverRect(rect_scale
, dest_rect
, clamped_rect
);
194 FakePictureLayerTilingClient client_
;
195 scoped_ptr
<TestablePictureLayerTiling
> tiling_
;
198 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest
);
201 TEST_F(PictureLayerTilingIteratorTest
, ResizeDeletesTiles
) {
202 // Verifies that a resize with invalidation for newly exposed pixels will
203 // deletes tiles that intersect that invalidation.
204 gfx::Size
tile_size(100, 100);
205 gfx::Size
original_layer_size(10, 10);
206 InitializeActive(tile_size
, 1.f
, original_layer_size
);
207 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
209 // Tiling only has one tile, since its total size is less than one.
210 EXPECT_TRUE(tiling_
->TileAt(0, 0));
212 // Stop creating tiles so that any invalidations are left as holes.
213 gfx::Size
new_layer_size(200, 200);
214 scoped_refptr
<FakePicturePileImpl
> pile
=
215 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size
);
217 Region invalidation
=
218 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
219 tiling_
->SetRasterSourceAndResize(pile
);
220 EXPECT_TRUE(tiling_
->TileAt(0, 0));
221 tiling_
->Invalidate(invalidation
);
222 EXPECT_FALSE(tiling_
->TileAt(0, 0));
225 TEST_F(PictureLayerTilingIteratorTest
, CreateMissingTilesStaysInsideLiveRect
) {
226 // The tiling has three rows and columns.
227 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 250));
228 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
229 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
231 // The live tiles rect is at the very edge of the right-most and
232 // bottom-most tiles. Their border pixels would still be inside the live
233 // tiles rect, but the tiles should not exist just for that.
234 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
235 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 2).y();
237 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
238 EXPECT_FALSE(tiling_
->TileAt(2, 0));
239 EXPECT_FALSE(tiling_
->TileAt(2, 1));
240 EXPECT_FALSE(tiling_
->TileAt(2, 2));
241 EXPECT_FALSE(tiling_
->TileAt(1, 2));
242 EXPECT_FALSE(tiling_
->TileAt(0, 2));
244 // Verify CreateMissingTilesInLiveTilesRect respects this.
245 tiling_
->CreateMissingTilesInLiveTilesRect();
246 EXPECT_FALSE(tiling_
->TileAt(2, 0));
247 EXPECT_FALSE(tiling_
->TileAt(2, 1));
248 EXPECT_FALSE(tiling_
->TileAt(2, 2));
249 EXPECT_FALSE(tiling_
->TileAt(1, 2));
250 EXPECT_FALSE(tiling_
->TileAt(0, 2));
253 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilingOverTileBorders
) {
254 // The tiling has four rows and three columns.
255 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
256 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
257 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
259 // The live tiles rect covers the whole tiling.
260 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
262 // Tiles in the bottom row and right column exist.
263 EXPECT_TRUE(tiling_
->TileAt(2, 0));
264 EXPECT_TRUE(tiling_
->TileAt(2, 1));
265 EXPECT_TRUE(tiling_
->TileAt(2, 2));
266 EXPECT_TRUE(tiling_
->TileAt(2, 3));
267 EXPECT_TRUE(tiling_
->TileAt(1, 3));
268 EXPECT_TRUE(tiling_
->TileAt(0, 3));
270 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
271 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
273 // Shrink the tiling so that the last tile row/column is entirely in the
274 // border pixels of the interior tiles. That row/column is removed.
275 scoped_refptr
<FakePicturePileImpl
> pile
=
276 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
277 gfx::Size(right
+ 1, bottom
+ 1));
278 tiling_
->SetRasterSourceAndResize(pile
);
279 EXPECT_EQ(2, tiling_
->TilingDataForTesting().num_tiles_x());
280 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
282 // The live tiles rect was clamped to the pile size.
283 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
285 // Since the row/column is gone, the tiles should be gone too.
286 EXPECT_FALSE(tiling_
->TileAt(2, 0));
287 EXPECT_FALSE(tiling_
->TileAt(2, 1));
288 EXPECT_FALSE(tiling_
->TileAt(2, 2));
289 EXPECT_FALSE(tiling_
->TileAt(2, 3));
290 EXPECT_FALSE(tiling_
->TileAt(1, 3));
291 EXPECT_FALSE(tiling_
->TileAt(0, 3));
293 // Growing outside the current right/bottom tiles border pixels should create
294 // the tiles again, even though the live rect has not changed size.
295 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
296 gfx::Size(right
+ 2, bottom
+ 2));
297 tiling_
->SetRasterSourceAndResize(pile
);
298 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
299 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
302 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
304 // The last row/column tiles are inside the live tiles rect.
305 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
306 tiling_
->TilingDataForTesting().TileBounds(2, 0)));
307 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
308 tiling_
->TilingDataForTesting().TileBounds(0, 3)));
310 EXPECT_TRUE(tiling_
->TileAt(2, 0));
311 EXPECT_TRUE(tiling_
->TileAt(2, 1));
312 EXPECT_TRUE(tiling_
->TileAt(2, 2));
313 EXPECT_TRUE(tiling_
->TileAt(2, 3));
314 EXPECT_TRUE(tiling_
->TileAt(1, 3));
315 EXPECT_TRUE(tiling_
->TileAt(0, 3));
318 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverTileBorders
) {
319 // The tiling has three rows and columns.
320 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
321 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
322 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
324 // The live tiles rect covers the whole tiling.
325 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
327 // Tiles in the bottom row and right column exist.
328 EXPECT_TRUE(tiling_
->TileAt(2, 0));
329 EXPECT_TRUE(tiling_
->TileAt(2, 1));
330 EXPECT_TRUE(tiling_
->TileAt(2, 2));
331 EXPECT_TRUE(tiling_
->TileAt(2, 3));
332 EXPECT_TRUE(tiling_
->TileAt(1, 3));
333 EXPECT_TRUE(tiling_
->TileAt(0, 3));
335 // Shrink the live tiles rect to the very edge of the right-most and
336 // bottom-most tiles. Their border pixels would still be inside the live
337 // tiles rect, but the tiles should not exist just for that.
338 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 3).x();
339 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
341 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
342 EXPECT_FALSE(tiling_
->TileAt(2, 0));
343 EXPECT_FALSE(tiling_
->TileAt(2, 1));
344 EXPECT_FALSE(tiling_
->TileAt(2, 2));
345 EXPECT_FALSE(tiling_
->TileAt(2, 3));
346 EXPECT_FALSE(tiling_
->TileAt(1, 3));
347 EXPECT_FALSE(tiling_
->TileAt(0, 3));
349 // Including the bottom row and right column again, should create the tiles.
350 SetLiveRectAndVerifyTiles(gfx::Rect(right
+ 1, bottom
+ 1));
351 EXPECT_TRUE(tiling_
->TileAt(2, 0));
352 EXPECT_TRUE(tiling_
->TileAt(2, 1));
353 EXPECT_TRUE(tiling_
->TileAt(2, 2));
354 EXPECT_TRUE(tiling_
->TileAt(2, 3));
355 EXPECT_TRUE(tiling_
->TileAt(1, 2));
356 EXPECT_TRUE(tiling_
->TileAt(0, 2));
358 // Shrink the live tiles rect to the very edge of the left-most and
359 // top-most tiles. Their border pixels would still be inside the live
360 // tiles rect, but the tiles should not exist just for that.
361 int left
= tiling_
->TilingDataForTesting().TileBounds(0, 0).right();
362 int top
= tiling_
->TilingDataForTesting().TileBounds(0, 0).bottom();
364 SetLiveRectAndVerifyTiles(gfx::Rect(left
, top
, 250 - left
, 350 - top
));
365 EXPECT_FALSE(tiling_
->TileAt(0, 3));
366 EXPECT_FALSE(tiling_
->TileAt(0, 2));
367 EXPECT_FALSE(tiling_
->TileAt(0, 1));
368 EXPECT_FALSE(tiling_
->TileAt(0, 0));
369 EXPECT_FALSE(tiling_
->TileAt(1, 0));
370 EXPECT_FALSE(tiling_
->TileAt(2, 0));
372 // Including the top row and left column again, should create the tiles.
373 SetLiveRectAndVerifyTiles(
374 gfx::Rect(left
- 1, top
- 1, 250 - left
, 350 - top
));
375 EXPECT_TRUE(tiling_
->TileAt(0, 3));
376 EXPECT_TRUE(tiling_
->TileAt(0, 2));
377 EXPECT_TRUE(tiling_
->TileAt(0, 1));
378 EXPECT_TRUE(tiling_
->TileAt(0, 0));
379 EXPECT_TRUE(tiling_
->TileAt(1, 0));
380 EXPECT_TRUE(tiling_
->TileAt(2, 0));
383 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverSameTiles
) {
384 // The tiling has four rows and three columns.
385 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
386 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
387 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
389 // The live tiles rect covers the whole tiling.
390 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
393 for (int i
= 0; i
< 3; ++i
) {
394 for (int j
= 0; j
< 4; ++j
)
395 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
398 // Shrink the live tiles rect, but still cover all the tiles.
399 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 349));
401 // All tiles still exist.
402 for (int i
= 0; i
< 3; ++i
) {
403 for (int j
= 0; j
< 4; ++j
)
404 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
407 // Grow the live tiles rect, but still cover all the same tiles.
408 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 350));
410 // All tiles still exist.
411 for (int i
= 0; i
< 3; ++i
) {
412 for (int j
= 0; j
< 4; ++j
)
413 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
417 TEST_F(PictureLayerTilingIteratorTest
, ResizeOverBorderPixelsDeletesTiles
) {
418 // Verifies that a resize with invalidation for newly exposed pixels will
419 // deletes tiles that intersect that invalidation.
420 gfx::Size
tile_size(100, 100);
421 gfx::Size
original_layer_size(99, 99);
422 InitializeActive(tile_size
, 1.f
, original_layer_size
);
423 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
425 // Tiling only has one tile, since its total size is less than one.
426 EXPECT_TRUE(tiling_
->TileAt(0, 0));
428 // Stop creating tiles so that any invalidations are left as holes.
429 scoped_refptr
<FakePicturePileImpl
> pile
=
430 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(
431 gfx::Size(200, 200));
432 tiling_
->SetRasterSourceAndResize(pile
);
434 Region invalidation
=
435 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
436 EXPECT_TRUE(tiling_
->TileAt(0, 0));
437 tiling_
->Invalidate(invalidation
);
438 EXPECT_FALSE(tiling_
->TileAt(0, 0));
440 // The original tile was the same size after resize, but it would include new
442 EXPECT_EQ(gfx::Rect(original_layer_size
),
443 tiling_
->TilingDataForTesting().TileBounds(0, 0));
446 TEST_F(PictureLayerTilingIteratorTest
, LiveTilesExactlyCoverLiveTileRect
) {
447 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
448 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
449 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
450 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
451 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
452 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
453 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
456 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsNoScale
) {
457 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
458 VerifyTilesExactlyCoverRect(1, gfx::Rect());
459 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
460 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
462 // With borders, a size of 3x3 = 1 pixel of content.
463 Initialize(gfx::Size(3, 3), 1.f
, gfx::Size(10, 10));
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));
470 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsTilingScale
) {
471 Initialize(gfx::Size(200, 100), 2.0f
, gfx::Size(1005, 2010));
472 VerifyTilesExactlyCoverRect(1, gfx::Rect());
473 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
474 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
476 Initialize(gfx::Size(3, 3), 2.0f
, gfx::Size(10, 10));
477 VerifyTilesExactlyCoverRect(1, gfx::Rect());
478 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
479 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
480 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
481 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
483 Initialize(gfx::Size(100, 200), 0.5f
, gfx::Size(1005, 2010));
484 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
485 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
487 Initialize(gfx::Size(150, 250), 0.37f
, gfx::Size(1005, 2010));
488 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
489 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
491 Initialize(gfx::Size(312, 123), 0.01f
, gfx::Size(1005, 2010));
492 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
493 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
496 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsBothScale
) {
497 Initialize(gfx::Size(50, 50), 4.0f
, gfx::Size(800, 600));
498 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect());
499 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(0, 0, 1600, 1200));
500 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(512, 365, 253, 182));
503 gfx::Size
bounds(800, 600);
504 gfx::Rect
full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds
, scale
)));
505 Initialize(gfx::Size(256, 512), 5.2f
, bounds
);
506 VerifyTilesExactlyCoverRect(scale
, full_rect
);
507 VerifyTilesExactlyCoverRect(scale
, gfx::Rect(2014, 1579, 867, 1033));
510 TEST_F(PictureLayerTilingIteratorTest
, IteratorEmptyRect
) {
511 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
514 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1.0f
, empty
);
518 TEST_F(PictureLayerTilingIteratorTest
, NonIntersectingRect
) {
519 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
520 gfx::Rect
non_intersecting(1000, 1000, 50, 50);
521 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1, non_intersecting
);
525 TEST_F(PictureLayerTilingIteratorTest
, LayerEdgeTextureCoordinates
) {
526 Initialize(gfx::Size(300, 300), 1.0f
, gfx::Size(256, 256));
527 // All of these sizes are 256x256, scaled and ceiled.
528 VerifyTilesExactlyCoverRect(1.0f
, gfx::Rect(0, 0, 256, 256));
529 VerifyTilesExactlyCoverRect(0.8f
, gfx::Rect(0, 0, 205, 205));
530 VerifyTilesExactlyCoverRect(1.2f
, gfx::Rect(0, 0, 308, 308));
533 TEST_F(PictureLayerTilingIteratorTest
, NonContainedDestRect
) {
534 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(400, 400));
536 // Too large in all dimensions
537 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, -1000, 2000, 2000));
538 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
539 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
541 // Partially covering content, but too large
542 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, 100, 2000, 100));
543 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, 100, 2000, 100));
544 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, 100, 2000, 100));
547 TEST(PictureLayerTilingTest
, SkewportLimits
) {
548 FakePictureLayerTilingClient client
;
550 gfx::Rect
viewport(0, 0, 100, 100);
551 gfx::Size
layer_bounds(200, 200);
553 client
.SetTileSize(gfx::Size(100, 100));
554 LayerTreeSettings settings
;
555 settings
.skewport_extrapolation_limit_in_content_pixels
= 75;
557 scoped_refptr
<FakePicturePileImpl
> pile
=
558 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
559 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
560 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
563 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
565 // Move viewport down 50 pixels in 0.5 seconds.
566 gfx::Rect down_skewport
=
567 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
569 EXPECT_EQ(0, down_skewport
.x());
570 EXPECT_EQ(50, down_skewport
.y());
571 EXPECT_EQ(100, down_skewport
.width());
572 EXPECT_EQ(175, down_skewport
.height());
573 EXPECT_TRUE(down_skewport
.Contains(gfx::Rect(0, 50, 100, 100)));
575 // Move viewport down 50 and right 10 pixels.
576 gfx::Rect down_right_skewport
=
577 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
579 EXPECT_EQ(10, down_right_skewport
.x());
580 EXPECT_EQ(50, down_right_skewport
.y());
581 EXPECT_EQ(120, down_right_skewport
.width());
582 EXPECT_EQ(175, down_right_skewport
.height());
583 EXPECT_TRUE(down_right_skewport
.Contains(gfx::Rect(10, 50, 100, 100)));
585 // Move viewport left.
586 gfx::Rect left_skewport
=
587 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100));
589 EXPECT_EQ(-125, left_skewport
.x());
590 EXPECT_EQ(0, left_skewport
.y());
591 EXPECT_EQ(175, left_skewport
.width());
592 EXPECT_EQ(100, left_skewport
.height());
593 EXPECT_TRUE(left_skewport
.Contains(gfx::Rect(-50, 0, 100, 100)));
596 gfx::Rect expand_skewport
=
597 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200));
599 // x and y moved by -75 (-50 - 75 = -125).
600 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
601 EXPECT_EQ(-125, expand_skewport
.x());
602 EXPECT_EQ(-125, expand_skewport
.y());
603 EXPECT_EQ(350, expand_skewport
.width());
604 EXPECT_EQ(350, expand_skewport
.height());
605 EXPECT_TRUE(expand_skewport
.Contains(gfx::Rect(-50, -50, 200, 200)));
607 // Expand the viewport past the limit in all directions.
608 gfx::Rect big_expand_skewport
=
609 tiling
->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500));
611 EXPECT_EQ(-575, big_expand_skewport
.x());
612 EXPECT_EQ(-575, big_expand_skewport
.y());
613 EXPECT_EQ(1650, big_expand_skewport
.width());
614 EXPECT_EQ(1650, big_expand_skewport
.height());
615 EXPECT_TRUE(big_expand_skewport
.Contains(gfx::Rect(-500, -500, 1500, 1500)));
617 // Shrink the skewport in all directions.
618 gfx::Rect shrink_viewport
=
619 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 0, 100, 100));
620 EXPECT_EQ(0, shrink_viewport
.x());
621 EXPECT_EQ(0, shrink_viewport
.y());
622 EXPECT_EQ(100, shrink_viewport
.width());
623 EXPECT_EQ(100, shrink_viewport
.height());
625 // Move the skewport really far in one direction.
626 gfx::Rect move_skewport_far
=
627 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 5000, 100, 100));
628 EXPECT_EQ(0, move_skewport_far
.x());
629 EXPECT_EQ(5000, move_skewport_far
.y());
630 EXPECT_EQ(100, move_skewport_far
.width());
631 EXPECT_EQ(175, move_skewport_far
.height());
632 EXPECT_TRUE(move_skewport_far
.Contains(gfx::Rect(0, 5000, 100, 100)));
635 TEST(PictureLayerTilingTest
, ComputeSkewportExtremeCases
) {
636 FakePictureLayerTilingClient client
;
638 gfx::Size
layer_bounds(200, 200);
639 client
.SetTileSize(gfx::Size(100, 100));
640 LayerTreeSettings settings
;
641 scoped_refptr
<FakePicturePileImpl
> pile
=
642 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
643 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
644 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
647 gfx::Rect
viewport1(-1918, 255860, 4010, 2356);
648 gfx::Rect
viewport2(-7088, -91738, 14212, 8350);
649 gfx::Rect
viewport3(-12730024, -158883296, 24607540, 14454512);
651 tiling
->ComputeTilePriorityRects(viewport1
, 1.f
, time
, Occlusion());
653 EXPECT_TRUE(tiling
->ComputeSkewport(time
, viewport2
).Contains(viewport2
));
654 tiling
->ComputeTilePriorityRects(viewport2
, 1.f
, time
, Occlusion());
656 EXPECT_TRUE(tiling
->ComputeSkewport(time
, viewport3
).Contains(viewport3
));
659 TEST(PictureLayerTilingTest
, ComputeSkewport
) {
660 FakePictureLayerTilingClient client
;
662 gfx::Rect
viewport(0, 0, 100, 100);
663 gfx::Size
layer_bounds(200, 200);
665 client
.SetTileSize(gfx::Size(100, 100));
667 scoped_refptr
<FakePicturePileImpl
> pile
=
668 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
669 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
670 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
671 LayerTreeSettings());
673 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
675 // Move viewport down 50 pixels in 0.5 seconds.
676 gfx::Rect down_skewport
=
677 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
679 EXPECT_EQ(0, down_skewport
.x());
680 EXPECT_EQ(50, down_skewport
.y());
681 EXPECT_EQ(100, down_skewport
.width());
682 EXPECT_EQ(200, down_skewport
.height());
685 gfx::Rect shrink_skewport
=
686 tiling
->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50));
688 EXPECT_EQ(25, shrink_skewport
.x());
689 EXPECT_EQ(25, shrink_skewport
.y());
690 EXPECT_EQ(50, shrink_skewport
.width());
691 EXPECT_EQ(50, shrink_skewport
.height());
693 // Move viewport down 50 and right 10 pixels.
694 gfx::Rect down_right_skewport
=
695 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
697 EXPECT_EQ(10, down_right_skewport
.x());
698 EXPECT_EQ(50, down_right_skewport
.y());
699 EXPECT_EQ(120, down_right_skewport
.width());
700 EXPECT_EQ(200, down_right_skewport
.height());
702 // Move viewport left.
703 gfx::Rect left_skewport
=
704 tiling
->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100));
706 EXPECT_EQ(-60, left_skewport
.x());
707 EXPECT_EQ(0, left_skewport
.y());
708 EXPECT_EQ(140, left_skewport
.width());
709 EXPECT_EQ(100, left_skewport
.height());
711 // Expand viewport in 0.2 seconds.
712 gfx::Rect expanded_skewport
=
713 tiling
->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110));
715 EXPECT_EQ(-30, expanded_skewport
.x());
716 EXPECT_EQ(-30, expanded_skewport
.y());
717 EXPECT_EQ(160, expanded_skewport
.width());
718 EXPECT_EQ(160, expanded_skewport
.height());
721 TEST(PictureLayerTilingTest
, SkewportThroughUpdateTilePriorities
) {
722 FakePictureLayerTilingClient client
;
724 gfx::Rect
viewport(0, 0, 100, 100);
725 gfx::Size
layer_bounds(200, 200);
727 client
.SetTileSize(gfx::Size(100, 100));
729 scoped_refptr
<FakePicturePileImpl
> pile
=
730 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
731 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
732 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
733 LayerTreeSettings());
735 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
737 // Move viewport down 50 pixels in 0.5 seconds.
738 gfx::Rect viewport_50
= gfx::Rect(0, 50, 100, 100);
739 gfx::Rect skewport_50
= tiling
->ComputeSkewport(1.5, viewport_50
);
741 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50
);
742 tiling
->ComputeTilePriorityRects(viewport_50
, 1.f
, 1.5, Occlusion());
744 gfx::Rect viewport_100
= gfx::Rect(0, 100, 100, 100);
745 gfx::Rect skewport_100
= tiling
->ComputeSkewport(2.0, viewport_100
);
747 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100
);
748 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 2.0, Occlusion());
750 // Advance time, but not the viewport.
751 gfx::Rect result
= tiling
->ComputeSkewport(2.5, viewport_100
);
752 // Since the history did advance, we should still get a skewport but a smaller
754 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result
);
755 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 2.5, Occlusion());
757 // Advance time again.
758 result
= tiling
->ComputeSkewport(3.0, viewport_100
);
759 EXPECT_EQ(viewport_100
, result
);
760 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 3.0, Occlusion());
762 // Ensure we have a skewport.
763 gfx::Rect viewport_150
= gfx::Rect(0, 150, 100, 100);
764 gfx::Rect skewport_150
= tiling
->ComputeSkewport(3.5, viewport_150
);
765 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150
);
766 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
768 // Advance the viewport, but not the time.
769 gfx::Rect viewport_200
= gfx::Rect(0, 200, 100, 100);
770 gfx::Rect skewport_200
= tiling
->ComputeSkewport(3.5, viewport_200
);
771 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
773 // Ensure that continued calls with the same value, produce the same skewport.
774 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
775 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
776 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
777 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
779 tiling
->ComputeTilePriorityRects(viewport_200
, 1.f
, 3.5, Occlusion());
781 // This should never happen, but advance the viewport yet again keeping the
783 gfx::Rect viewport_250
= gfx::Rect(0, 250, 100, 100);
784 gfx::Rect skewport_250
= tiling
->ComputeSkewport(3.5, viewport_250
);
785 EXPECT_EQ(viewport_250
, skewport_250
);
786 tiling
->ComputeTilePriorityRects(viewport_250
, 1.f
, 3.5, Occlusion());
789 TEST(PictureLayerTilingTest
, ViewportDistanceWithScale
) {
790 FakePictureLayerTilingClient client
;
792 gfx::Rect
viewport(0, 0, 100, 100);
793 gfx::Size
layer_bounds(1500, 1500);
795 client
.SetTileSize(gfx::Size(10, 10));
796 LayerTreeSettings settings
;
798 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
799 // The reason is that each tile has a one pixel border, so tile at (1, 2)
800 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
801 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
803 scoped_refptr
<FakePicturePileImpl
> pile
=
804 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
805 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
806 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 0.25f
, pile
, &client
,
808 tiling
->set_resolution(HIGH_RESOLUTION
);
809 gfx::Rect viewport_in_content_space
=
810 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
812 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
813 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
815 // Compute the soon border.
816 float inset
= PictureLayerTiling::CalculateSoonBorderDistance(
817 viewport_in_content_space
, 1.0f
/ 0.25f
);
818 gfx::Rect soon_rect_in_content_space
= viewport_in_content_space
;
819 soon_rect_in_content_space
.Inset(-inset
, -inset
);
822 for (int i
= 0; i
< 47; ++i
) {
823 for (int j
= 0; j
< 47; ++j
) {
824 EXPECT_TRUE(tiling
->TileAt(i
, j
)) << "i: " << i
<< " j: " << j
;
827 for (int i
= 0; i
< 47; ++i
) {
828 EXPECT_FALSE(tiling
->TileAt(i
, 47)) << "i: " << i
;
829 EXPECT_FALSE(tiling
->TileAt(47, i
)) << "i: " << i
;
832 // No movement in the viewport implies that tiles will either be NOW
833 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
834 // pixels away from the viewport, which will be in the SOON bin.
835 bool have_now
= false;
836 bool have_eventually
= false;
837 bool have_soon
= false;
838 for (int i
= 0; i
< 47; ++i
) {
839 for (int j
= 0; j
< 47; ++j
) {
840 Tile
* tile
= tiling
->TileAt(i
, j
);
841 PrioritizedTile prioritized_tile
= prioritized_tiles
[tile
];
842 TilePriority priority
= prioritized_tile
.priority();
844 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
845 if (viewport_in_content_space
.Intersects(tile_rect
)) {
846 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
847 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
849 } else if (soon_rect_in_content_space
.Intersects(tile_rect
)) {
850 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
);
853 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
);
854 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
855 have_eventually
= true;
860 EXPECT_TRUE(have_now
);
861 EXPECT_TRUE(have_soon
);
862 EXPECT_TRUE(have_eventually
);
864 // Spot check some distances.
865 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
866 // so the distance to a viewport that ends at 25x25 in content space
867 // should be 17 (41 - 25 + 1). In layer space, then that should be
868 // 17 / 0.25 = 68 pixels.
870 // We can verify that the content rect (with borders) is one pixel off
871 // 41,9 8x8 on all sides.
872 EXPECT_EQ(tiling
->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
874 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
875 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
877 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
878 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
880 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
881 EXPECT_FLOAT_EQ(40.f
, priority
.distance_to_visible
);
883 // Move the viewport down 40 pixels.
884 viewport
= gfx::Rect(0, 40, 100, 100);
885 viewport_in_content_space
=
886 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
887 gfx::Rect skewport
= tiling
->ComputeSkewport(2.0, viewport_in_content_space
);
889 // Compute the soon border.
890 inset
= PictureLayerTiling::CalculateSoonBorderDistance(
891 viewport_in_content_space
, 1.0f
/ 0.25f
);
892 soon_rect_in_content_space
= viewport_in_content_space
;
893 soon_rect_in_content_space
.Inset(-inset
, -inset
);
895 EXPECT_EQ(0, skewport
.x());
896 EXPECT_EQ(10, skewport
.y());
897 EXPECT_EQ(25, skewport
.width());
898 EXPECT_EQ(35, skewport
.height());
900 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 2.0, Occlusion());
901 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
904 have_eventually
= false;
907 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
908 // some EVENTUALLY tiles.
909 for (int i
= 0; i
< 47; ++i
) {
910 for (int j
= 0; j
< 47; ++j
) {
911 Tile
* tile
= tiling
->TileAt(i
, j
);
912 TilePriority priority
= prioritized_tiles
[tile
].priority();
914 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
915 if (viewport_in_content_space
.Intersects(tile_rect
)) {
916 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
) << "i: " << i
918 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
) << "i: " << i
921 } else if (skewport
.Intersects(tile_rect
) ||
922 soon_rect_in_content_space
.Intersects(tile_rect
)) {
923 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
) << "i: " << i
925 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
929 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
)
930 << "i: " << i
<< " j: " << j
;
931 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
933 have_eventually
= true;
938 EXPECT_TRUE(have_now
);
939 EXPECT_TRUE(have_soon
);
940 EXPECT_TRUE(have_eventually
);
942 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
943 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
945 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
946 EXPECT_FLOAT_EQ(28.f
, priority
.distance_to_visible
);
948 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
949 EXPECT_FLOAT_EQ(4.f
, priority
.distance_to_visible
);
951 // Change the underlying layer scale.
952 tiling
->ComputeTilePriorityRects(viewport
, 2.0f
, 3.0, Occlusion());
953 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
955 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
956 EXPECT_FLOAT_EQ(136.f
, priority
.distance_to_visible
);
958 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
959 EXPECT_FLOAT_EQ(56.f
, priority
.distance_to_visible
);
961 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
962 EXPECT_FLOAT_EQ(8.f
, priority
.distance_to_visible
);
964 // Test additional scales.
965 tiling
= TestablePictureLayerTiling::Create(ACTIVE_TREE
, 0.2f
, pile
, &client
,
966 LayerTreeSettings());
967 tiling
->set_resolution(HIGH_RESOLUTION
);
968 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 4.0, Occlusion());
969 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
971 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
972 EXPECT_FLOAT_EQ(110.f
, priority
.distance_to_visible
);
974 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
975 EXPECT_FLOAT_EQ(70.f
, priority
.distance_to_visible
);
977 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
978 EXPECT_FLOAT_EQ(60.f
, priority
.distance_to_visible
);
980 tiling
->ComputeTilePriorityRects(viewport
, 0.5f
, 5.0, Occlusion());
981 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
983 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
984 EXPECT_FLOAT_EQ(55.f
, priority
.distance_to_visible
);
986 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
987 EXPECT_FLOAT_EQ(35.f
, priority
.distance_to_visible
);
989 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
990 EXPECT_FLOAT_EQ(30.f
, priority
.distance_to_visible
);
993 static void TileExists(bool exists
, Tile
* tile
,
994 const gfx::Rect
& geometry_rect
) {
995 EXPECT_EQ(exists
, tile
!= NULL
) << geometry_rect
.ToString();
998 TEST_F(PictureLayerTilingIteratorTest
, TilesExist
) {
999 gfx::Size
layer_bounds(1099, 801);
1000 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1001 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1002 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1004 tiling_
->ComputeTilePriorityRects(
1005 gfx::Rect(layer_bounds
), // visible content rect
1006 1.f
, // current contents scale
1007 1.0, // current frame time
1009 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1011 // Make the viewport rect empty. All tiles are killed and become zombies.
1012 tiling_
->ComputeTilePriorityRects(gfx::Rect(), // visible content rect
1013 1.f
, // current contents scale
1014 2.0, // current frame time
1016 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1019 TEST_F(PictureLayerTilingIteratorTest
, TilesExistGiantViewport
) {
1020 gfx::Size
layer_bounds(1099, 801);
1021 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1022 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1023 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1025 gfx::Rect
giant_rect(-10000000, -10000000, 1000000000, 1000000000);
1027 tiling_
->ComputeTilePriorityRects(
1028 gfx::Rect(layer_bounds
), // visible content rect
1029 1.f
, // current contents scale
1030 1.0, // current frame time
1032 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1034 // If the visible content rect is empty, it should still have live tiles.
1035 tiling_
->ComputeTilePriorityRects(giant_rect
, // visible content rect
1036 1.f
, // current contents scale
1037 2.0, // current frame time
1039 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1042 TEST_F(PictureLayerTilingIteratorTest
, TilesExistOutsideViewport
) {
1043 gfx::Size
layer_bounds(1099, 801);
1044 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1045 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1046 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1048 // This rect does not intersect with the layer, as the layer is outside the
1050 gfx::Rect
viewport_rect(1100, 0, 1000, 1000);
1051 EXPECT_FALSE(viewport_rect
.Intersects(gfx::Rect(layer_bounds
)));
1053 tiling_
->ComputeTilePriorityRects(viewport_rect
, // visible content rect
1054 1.f
, // current contents scale
1055 1.0, // current frame time
1057 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1060 static void TilesIntersectingRectExist(const gfx::Rect
& rect
,
1061 bool intersect_exists
,
1063 const gfx::Rect
& geometry_rect
) {
1064 bool intersects
= rect
.Intersects(geometry_rect
);
1065 bool expected_exists
= intersect_exists
? intersects
: !intersects
;
1066 EXPECT_EQ(expected_exists
, tile
!= NULL
)
1067 << "Rects intersecting " << rect
.ToString() << " should exist. "
1068 << "Current tile rect is " << geometry_rect
.ToString();
1071 TEST_F(PictureLayerTilingIteratorTest
,
1072 TilesExistLargeViewportAndLayerWithSmallVisibleArea
) {
1073 gfx::Size
layer_bounds(10000, 10000);
1074 client_
.SetTileSize(gfx::Size(100, 100));
1075 LayerTreeSettings settings
;
1076 settings
.tiling_interest_area_padding
= 1;
1078 scoped_refptr
<FakePicturePileImpl
> pile
=
1079 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1080 tiling_
= TestablePictureLayerTiling::Create(PENDING_TREE
, 1.f
, pile
,
1081 &client_
, settings
);
1082 tiling_
->set_resolution(HIGH_RESOLUTION
);
1083 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1084 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1086 gfx::Rect
visible_rect(8000, 8000, 50, 50);
1088 tiling_
->ComputeTilePriorityRects(visible_rect
, // visible content rect
1089 1.f
, // current contents scale
1090 1.0, // current frame time
1093 gfx::Rect(layer_bounds
),
1094 base::Bind(&TilesIntersectingRectExist
, visible_rect
, true));
1097 TEST(ComputeTilePriorityRectsTest
, VisibleTiles
) {
1098 // The TilePriority of visible tiles should have zero distance_to_visible
1099 // and time_to_visible.
1100 FakePictureLayerTilingClient client
;
1102 gfx::Size
device_viewport(800, 600);
1103 gfx::Size
last_layer_bounds(200, 200);
1104 gfx::Size
current_layer_bounds(200, 200);
1105 float current_layer_contents_scale
= 1.f
;
1106 gfx::Transform current_screen_transform
;
1107 double current_frame_time_in_seconds
= 1.0;
1109 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1110 current_screen_transform
, device_viewport
);
1112 client
.SetTileSize(gfx::Size(100, 100));
1114 scoped_refptr
<FakePicturePileImpl
> pile
=
1115 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1116 current_layer_bounds
);
1117 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1118 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1119 LayerTreeSettings());
1120 tiling
->set_resolution(HIGH_RESOLUTION
);
1122 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1123 current_layer_contents_scale
,
1124 current_frame_time_in_seconds
, Occlusion());
1125 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1127 ASSERT_TRUE(tiling
->TileAt(0, 0));
1128 ASSERT_TRUE(tiling
->TileAt(0, 1));
1129 ASSERT_TRUE(tiling
->TileAt(1, 0));
1130 ASSERT_TRUE(tiling
->TileAt(1, 1));
1132 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1133 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1134 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1136 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1137 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1138 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1140 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1141 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1142 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1144 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1145 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1146 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1149 TEST(ComputeTilePriorityRectsTest
, OffscreenTiles
) {
1150 // The TilePriority of offscreen tiles (without movement) should have nonzero
1151 // distance_to_visible and infinite time_to_visible.
1152 FakePictureLayerTilingClient client
;
1154 gfx::Size
device_viewport(800, 600);
1155 gfx::Size
last_layer_bounds(200, 200);
1156 gfx::Size
current_layer_bounds(200, 200);
1157 float current_layer_contents_scale
= 1.f
;
1158 gfx::Transform last_screen_transform
;
1159 gfx::Transform current_screen_transform
;
1160 double current_frame_time_in_seconds
= 1.0;
1162 current_screen_transform
.Translate(850, 0);
1163 last_screen_transform
= current_screen_transform
;
1165 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1166 current_screen_transform
, device_viewport
);
1168 client
.SetTileSize(gfx::Size(100, 100));
1170 scoped_refptr
<FakePicturePileImpl
> pile
=
1171 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1172 current_layer_bounds
);
1173 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1174 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1175 LayerTreeSettings());
1176 tiling
->set_resolution(HIGH_RESOLUTION
);
1178 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1179 current_layer_contents_scale
,
1180 current_frame_time_in_seconds
, Occlusion());
1181 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1183 ASSERT_TRUE(tiling
->TileAt(0, 0));
1184 ASSERT_TRUE(tiling
->TileAt(0, 1));
1185 ASSERT_TRUE(tiling
->TileAt(1, 0));
1186 ASSERT_TRUE(tiling
->TileAt(1, 1));
1188 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1189 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1190 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1192 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1193 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1194 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1196 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1197 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1198 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1200 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1201 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1202 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1204 // Furthermore, in this scenario tiles on the right hand side should have a
1205 // larger distance to visible.
1206 TilePriority left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1207 TilePriority right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1208 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1210 left
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1211 right
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1212 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1215 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenLayer
) {
1216 // Sanity check that a layer with some tiles visible and others offscreen has
1217 // correct TilePriorities for each tile.
1218 FakePictureLayerTilingClient client
;
1220 gfx::Size
device_viewport(800, 600);
1221 gfx::Size
last_layer_bounds(200, 200);
1222 gfx::Size
current_layer_bounds(200, 200);
1223 float current_layer_contents_scale
= 1.f
;
1224 gfx::Transform last_screen_transform
;
1225 gfx::Transform current_screen_transform
;
1226 double current_frame_time_in_seconds
= 1.0;
1228 current_screen_transform
.Translate(705, 505);
1229 last_screen_transform
= current_screen_transform
;
1231 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1232 current_screen_transform
, device_viewport
);
1234 client
.SetTileSize(gfx::Size(100, 100));
1236 scoped_refptr
<FakePicturePileImpl
> pile
=
1237 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1238 current_layer_bounds
);
1239 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1240 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1241 LayerTreeSettings());
1242 tiling
->set_resolution(HIGH_RESOLUTION
);
1244 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1245 current_layer_contents_scale
,
1246 current_frame_time_in_seconds
, Occlusion());
1247 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1249 ASSERT_TRUE(tiling
->TileAt(0, 0));
1250 ASSERT_TRUE(tiling
->TileAt(0, 1));
1251 ASSERT_TRUE(tiling
->TileAt(1, 0));
1252 ASSERT_TRUE(tiling
->TileAt(1, 1));
1254 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1255 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1256 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1258 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1259 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1260 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1262 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1263 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1264 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1266 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1267 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1268 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1271 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenRotatedLayer
) {
1272 // Each tile of a layer may be affected differently by a transform; Check
1273 // that ComputeTilePriorityRects correctly accounts for the transform between
1274 // layer space and screen space.
1275 FakePictureLayerTilingClient client
;
1277 gfx::Size
device_viewport(800, 600);
1278 gfx::Size
last_layer_bounds(200, 200);
1279 gfx::Size
current_layer_bounds(200, 200);
1280 float current_layer_contents_scale
= 1.f
;
1281 gfx::Transform last_screen_transform
;
1282 gfx::Transform current_screen_transform
;
1283 double current_frame_time_in_seconds
= 1.0;
1285 // A diagonally rotated layer that is partially off the bottom of the screen.
1286 // In this configuration, only the top-left tile would be visible.
1287 current_screen_transform
.Translate(600, 750);
1288 current_screen_transform
.RotateAboutZAxis(45);
1289 last_screen_transform
= current_screen_transform
;
1291 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1292 current_screen_transform
, device_viewport
);
1294 client
.SetTileSize(gfx::Size(100, 100));
1296 scoped_refptr
<FakePicturePileImpl
> pile
=
1297 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1298 current_layer_bounds
);
1299 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1300 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1301 LayerTreeSettings());
1302 tiling
->set_resolution(HIGH_RESOLUTION
);
1304 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1305 current_layer_contents_scale
,
1306 current_frame_time_in_seconds
, Occlusion());
1307 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1309 ASSERT_TRUE(tiling
->TileAt(0, 0));
1310 ASSERT_TRUE(tiling
->TileAt(0, 1));
1311 ASSERT_TRUE(tiling
->TileAt(1, 0));
1312 ASSERT_TRUE(tiling
->TileAt(1, 1));
1314 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1315 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1316 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1318 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1319 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1320 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1322 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1323 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1324 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1326 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1327 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1328 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1330 // Furthermore, in this scenario the bottom-right tile should have the larger
1331 // distance to visible.
1332 TilePriority top_left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1333 TilePriority top_right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1334 TilePriority bottom_right
=
1335 prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1336 EXPECT_GT(top_right
.distance_to_visible
, top_left
.distance_to_visible
);
1338 EXPECT_EQ(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1341 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayer
) {
1342 // Perspective transforms need to take a different code path.
1343 // This test checks tile priorities of a perspective layer.
1344 FakePictureLayerTilingClient client
;
1346 gfx::Size
device_viewport(800, 600);
1347 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscreen.
1348 gfx::Size
last_layer_bounds(200, 200);
1349 gfx::Size
current_layer_bounds(200, 200);
1350 float current_layer_contents_scale
= 1.f
;
1351 gfx::Transform last_screen_transform
;
1352 gfx::Transform current_screen_transform
;
1353 double current_frame_time_in_seconds
= 1.0;
1355 // A 3d perspective layer rotated about its Y axis, translated to almost
1356 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1357 // the right side, so the top-left tile will technically be closer than the
1360 // Translate layer to offscreen
1361 current_screen_transform
.Translate(400.0, 630.0);
1362 // Apply perspective about the center of the layer
1363 current_screen_transform
.Translate(100.0, 100.0);
1364 current_screen_transform
.ApplyPerspectiveDepth(100.0);
1365 current_screen_transform
.RotateAboutYAxis(10.0);
1366 current_screen_transform
.Translate(-100.0, -100.0);
1367 last_screen_transform
= current_screen_transform
;
1369 // Sanity check that this transform wouldn't cause w<0 clipping.
1371 MathUtil::MapQuad(current_screen_transform
,
1372 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1374 ASSERT_FALSE(clipped
);
1376 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1377 current_screen_transform
, device_viewport
);
1379 client
.SetTileSize(gfx::Size(100, 100));
1381 scoped_refptr
<FakePicturePileImpl
> pile
=
1382 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1383 current_layer_bounds
);
1384 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1385 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1386 LayerTreeSettings());
1387 tiling
->set_resolution(HIGH_RESOLUTION
);
1389 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1390 current_layer_contents_scale
,
1391 current_frame_time_in_seconds
, Occlusion());
1392 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1394 ASSERT_TRUE(tiling
->TileAt(0, 0));
1395 ASSERT_TRUE(tiling
->TileAt(0, 1));
1396 ASSERT_TRUE(tiling
->TileAt(1, 0));
1397 ASSERT_TRUE(tiling
->TileAt(1, 1));
1399 // All tiles will have a positive distance_to_visible
1400 // and an infinite time_to_visible.
1401 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1402 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1403 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1405 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1406 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1407 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1409 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1410 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1411 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1413 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1414 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1415 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1417 // Furthermore, in this scenario the top-left distance_to_visible
1418 // will be smallest, followed by top-right. The bottom layers
1419 // will of course be further than the top layers.
1420 TilePriority top_left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1421 TilePriority top_right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1422 TilePriority bottom_left
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1423 TilePriority bottom_right
=
1424 prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1426 EXPECT_GT(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1428 EXPECT_GT(bottom_left
.distance_to_visible
, top_left
.distance_to_visible
);
1431 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayerClippedByW
) {
1432 // Perspective transforms need to take a different code path.
1433 // This test checks tile priorities of a perspective layer.
1434 FakePictureLayerTilingClient client
;
1436 gfx::Size
device_viewport(800, 600);
1437 gfx::Size
last_layer_bounds(200, 200);
1438 gfx::Size
current_layer_bounds(200, 200);
1439 float current_layer_contents_scale
= 1.f
;
1440 gfx::Transform last_screen_transform
;
1441 gfx::Transform current_screen_transform
;
1442 double current_frame_time_in_seconds
= 1.0;
1444 // A 3d perspective layer rotated about its Y axis, translated to almost
1445 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1446 // the right side, so the top-left tile will technically be closer than the
1449 // Translate layer to offscreen
1450 current_screen_transform
.Translate(400.0, 970.0);
1451 // Apply perspective and rotation about the center of the layer
1452 current_screen_transform
.Translate(100.0, 100.0);
1453 current_screen_transform
.ApplyPerspectiveDepth(10.0);
1454 current_screen_transform
.RotateAboutYAxis(10.0);
1455 current_screen_transform
.Translate(-100.0, -100.0);
1456 last_screen_transform
= current_screen_transform
;
1458 // Sanity check that this transform does cause w<0 clipping for the left side
1459 // of the layer, but not the right side.
1461 MathUtil::MapQuad(current_screen_transform
,
1462 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1464 ASSERT_TRUE(clipped
);
1466 MathUtil::MapQuad(current_screen_transform
,
1467 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1469 ASSERT_FALSE(clipped
);
1471 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1472 current_screen_transform
, device_viewport
);
1474 client
.SetTileSize(gfx::Size(100, 100));
1476 scoped_refptr
<FakePicturePileImpl
> pile
=
1477 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1478 current_layer_bounds
);
1479 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1480 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1481 LayerTreeSettings());
1482 tiling
->set_resolution(HIGH_RESOLUTION
);
1484 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1485 current_layer_contents_scale
,
1486 current_frame_time_in_seconds
, Occlusion());
1487 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1489 ASSERT_TRUE(tiling
->TileAt(0, 0));
1490 ASSERT_TRUE(tiling
->TileAt(0, 1));
1491 ASSERT_TRUE(tiling
->TileAt(1, 0));
1492 ASSERT_TRUE(tiling
->TileAt(1, 1));
1494 // Left-side tiles will be clipped by the transform, so we have to assume
1495 // they are visible just in case.
1496 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1497 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1498 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1500 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1501 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1502 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1504 // Right-side tiles will have a positive distance_to_visible
1505 // and an infinite time_to_visible.
1506 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1507 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1508 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1510 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1511 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1512 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1515 TEST(ComputeTilePriorityRectsTest
, BasicMotion
) {
1516 // Test that time_to_visible is computed correctly when
1517 // there is some motion.
1518 FakePictureLayerTilingClient client
;
1520 gfx::Size
device_viewport(800, 600);
1521 gfx::Rect
visible_layer_rect(0, 0, 0, 0);
1522 gfx::Size
last_layer_bounds(200, 200);
1523 gfx::Size
current_layer_bounds(200, 200);
1524 float last_layer_contents_scale
= 1.f
;
1525 float current_layer_contents_scale
= 1.f
;
1526 gfx::Transform last_screen_transform
;
1527 gfx::Transform current_screen_transform
;
1528 double last_frame_time_in_seconds
= 1.0;
1529 double current_frame_time_in_seconds
= 2.0;
1531 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1532 current_screen_transform
.Translate(1800, 0);
1533 last_screen_transform
.Translate(2800, 0);
1535 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1536 current_screen_transform
, device_viewport
);
1538 client
.SetTileSize(gfx::Size(100, 100));
1539 LayerTreeSettings settings
;
1541 scoped_refptr
<FakePicturePileImpl
> pile
=
1542 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1543 current_layer_bounds
);
1544 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1545 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1547 tiling
->set_resolution(HIGH_RESOLUTION
);
1549 // previous ("last") frame
1550 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1551 last_layer_contents_scale
,
1552 last_frame_time_in_seconds
, Occlusion());
1555 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1556 current_layer_contents_scale
,
1557 current_frame_time_in_seconds
, Occlusion());
1558 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1560 ASSERT_TRUE(tiling
->TileAt(0, 0));
1561 ASSERT_TRUE(tiling
->TileAt(0, 1));
1562 ASSERT_TRUE(tiling
->TileAt(1, 0));
1563 ASSERT_TRUE(tiling
->TileAt(1, 1));
1565 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1566 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1567 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1569 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1570 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1571 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1573 // time_to_visible for the right hand side layers needs an extra 0.099
1574 // seconds because this tile is 99 pixels further away.
1575 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1576 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1577 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1579 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1580 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1581 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1584 TEST(ComputeTilePriorityRectsTest
, RotationMotion
) {
1585 // Each tile of a layer may be affected differently by a transform; Check
1586 // that ComputeTilePriorityRects correctly accounts for the transform between
1587 // layer space and screen space.
1589 FakePictureLayerTilingClient client
;
1590 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1592 gfx::Size
device_viewport(800, 600);
1593 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscren.
1594 gfx::Size
last_layer_bounds(200, 200);
1595 gfx::Size
current_layer_bounds(200, 200);
1596 float last_layer_contents_scale
= 1.f
;
1597 float current_layer_contents_scale
= 1.f
;
1598 gfx::Transform last_screen_transform
;
1599 gfx::Transform current_screen_transform
;
1600 double last_frame_time_in_seconds
= 1.0;
1601 double current_frame_time_in_seconds
= 2.0;
1603 // Rotation motion is set up specifically so that:
1604 // - rotation occurs about the center of the layer
1605 // - the top-left tile becomes visible on rotation
1606 // - the top-right tile will have an infinite time_to_visible
1607 // because it is rotating away from viewport.
1608 // - bottom-left layer will have a positive non-zero time_to_visible
1609 // because it is rotating toward the viewport.
1610 current_screen_transform
.Translate(400, 550);
1611 current_screen_transform
.RotateAboutZAxis(45);
1613 last_screen_transform
.Translate(400, 550);
1615 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1616 current_screen_transform
, device_viewport
);
1618 client
.SetTileSize(gfx::Size(100, 100));
1620 scoped_refptr
<FakePicturePileImpl
> pile
=
1621 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1622 current_layer_bounds
);
1623 tiling
= TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1624 LayerTreeSettings());
1625 tiling
->set_resolution(HIGH_RESOLUTION
);
1627 // previous ("last") frame
1628 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1629 last_layer_contents_scale
,
1630 last_frame_time_in_seconds
, Occlusion());
1633 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1634 current_layer_contents_scale
,
1635 current_frame_time_in_seconds
, Occlusion());
1636 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1638 ASSERT_TRUE(tiling
->TileAt(0, 0));
1639 ASSERT_TRUE(tiling
->TileAt(0, 1));
1640 ASSERT_TRUE(tiling
->TileAt(1, 0));
1641 ASSERT_TRUE(tiling
->TileAt(1, 1));
1643 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1644 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1645 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1647 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1648 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1649 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1651 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1652 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1653 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1656 TEST(PictureLayerTilingTest
, RecycledTilesCleared
) {
1657 // This test performs the following:
1659 // - Two tilings, one active one recycled with all tiles shared.
1661 // - Viewport moves somewhere far away and active tiling clears tiles.
1662 // - Viewport moves back and a new active tiling tile is created.
1664 // - Recycle tiling does _not_ have the tile in the same location (thus it
1665 // will be shared next time a pending tiling is created).
1667 FakePictureLayerTilingClient active_client
;
1669 active_client
.SetTileSize(gfx::Size(100, 100));
1670 LayerTreeSettings settings
;
1672 scoped_refptr
<FakePicturePileImpl
> pile
=
1673 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1674 gfx::Size(10000, 10000));
1675 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1676 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
,
1677 &active_client
, settings
);
1678 active_tiling
->set_resolution(HIGH_RESOLUTION
);
1679 // Create all tiles on this tiling.
1680 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1683 FakePictureLayerTilingClient recycle_client
;
1684 recycle_client
.SetTileSize(gfx::Size(100, 100));
1685 recycle_client
.set_twin_tiling(active_tiling
.get());
1687 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1688 gfx::Size(10000, 10000));
1689 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1690 TestablePictureLayerTiling::Create(PENDING_TREE
, 1.0f
, pile
,
1691 &recycle_client
, settings
);
1692 recycle_tiling
->set_resolution(HIGH_RESOLUTION
);
1694 // Create all tiles on the second tiling. All tiles should be shared.
1695 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1698 // Set the second tiling as recycled.
1699 active_client
.set_twin_tiling(NULL
);
1700 recycle_client
.set_twin_tiling(NULL
);
1702 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1703 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1705 // Move the viewport far away from the (0, 0) tile.
1706 active_tiling
->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f
,
1708 // Ensure the tile was deleted.
1709 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1710 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1712 // Move the viewport back to (0, 0) tile.
1713 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 3.0,
1716 // Ensure that we now have a tile here on both active.
1717 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1718 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1721 TEST(PictureLayerTilingTest
, RecycledTilesClearedOnReset
) {
1722 FakePictureLayerTilingClient active_client
;
1723 active_client
.SetTileSize(gfx::Size(100, 100));
1725 scoped_refptr
<FakePicturePileImpl
> pile
=
1726 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1727 gfx::Size(100, 100));
1728 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1729 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
,
1730 &active_client
, LayerTreeSettings());
1731 active_tiling
->set_resolution(HIGH_RESOLUTION
);
1732 // Create all tiles on this tiling.
1733 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1736 FakePictureLayerTilingClient recycle_client
;
1737 recycle_client
.SetTileSize(gfx::Size(100, 100));
1738 recycle_client
.set_twin_tiling(active_tiling
.get());
1740 LayerTreeSettings settings
;
1742 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1743 gfx::Size(100, 100));
1744 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1745 TestablePictureLayerTiling::Create(PENDING_TREE
, 1.0f
, pile
,
1746 &recycle_client
, settings
);
1747 recycle_tiling
->set_resolution(HIGH_RESOLUTION
);
1749 // Create all tiles on the recycle tiling. All tiles should be shared.
1750 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1753 // Set the second tiling as recycled.
1754 active_client
.set_twin_tiling(NULL
);
1755 recycle_client
.set_twin_tiling(NULL
);
1757 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1758 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1760 // Reset the active tiling. The recycle tiles should be released too.
1761 active_tiling
->Reset();
1762 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1763 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1766 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilesAndUpdateToCurrent
) {
1767 // The tiling has four rows and three columns.
1768 Initialize(gfx::Size(150, 100), 1.f
, gfx::Size(250, 150));
1769 tiling_
->CreateAllTilesForTesting();
1770 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1771 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1772 EXPECT_EQ(4u, tiling_
->AllTilesForTesting().size());
1774 client_
.SetTileSize(gfx::Size(250, 200));
1776 // Tile size in the tiling should still be 150x100.
1777 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1778 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1780 // The layer's size isn't changed, but the tile size was.
1781 scoped_refptr
<FakePicturePileImpl
> pile
=
1782 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1783 gfx::Size(250, 150));
1784 tiling_
->SetRasterSourceAndResize(pile
);
1786 // Tile size in the tiling should be resized to 250x200.
1787 EXPECT_EQ(250, tiling_
->TilingDataForTesting().max_texture_size().width());
1788 EXPECT_EQ(200, tiling_
->TilingDataForTesting().max_texture_size().height());
1789 EXPECT_EQ(0u, tiling_
->AllTilesForTesting().size());
1792 // This test runs into floating point issues because of big numbers.
1793 TEST_F(PictureLayerTilingIteratorTest
, GiantRect
) {
1794 gfx::Size
tile_size(256, 256);
1795 gfx::Size
layer_size(33554432, 33554432);
1796 bool filled
= false;
1797 float contents_scale
= 1.f
;
1799 client_
.SetTileSize(tile_size
);
1800 scoped_refptr
<FakePicturePileImpl
> pile
= FakePicturePileImpl::CreatePile(
1801 tile_size
, layer_size
, gfx::Rect(), filled
);
1802 tiling_
= TestablePictureLayerTiling::Create(
1803 PENDING_TREE
, contents_scale
, pile
, &client_
, LayerTreeSettings());
1805 gfx::Rect
content_rect(25554432, 25554432, 950, 860);
1806 VerifyTilesExactlyCoverRect(contents_scale
, content_rect
);