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 "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/geometry/quad_f.h"
19 #include "ui/gfx/geometry/rect_conversions.h"
20 #include "ui/gfx/geometry/size_conversions.h"
25 static gfx::Rect
ViewportInLayerSpace(
26 const gfx::Transform
& transform
,
27 const gfx::Size
& device_viewport
) {
29 gfx::Transform inverse
;
30 if (!transform
.GetInverse(&inverse
))
33 gfx::RectF viewport_in_layer_space
= MathUtil::ProjectClippedRect(
34 inverse
, gfx::RectF(gfx::Point(0, 0), device_viewport
));
35 return ToEnclosingRect(viewport_in_layer_space
);
38 class TestablePictureLayerTiling
: public PictureLayerTiling
{
40 using PictureLayerTiling::SetLiveTilesRect
;
41 using PictureLayerTiling::TileAt
;
43 static scoped_ptr
<TestablePictureLayerTiling
> Create(
46 scoped_refptr
<RasterSource
> raster_source
,
47 PictureLayerTilingClient
* client
,
48 const LayerTreeSettings
& settings
) {
49 return make_scoped_ptr(new TestablePictureLayerTiling(
50 tree
, contents_scale
, raster_source
, client
,
51 settings
.tiling_interest_area_viewport_multiplier
,
52 settings
.skewport_target_time_in_seconds
,
53 settings
.skewport_extrapolation_limit_in_content_pixels
));
56 gfx::Rect
live_tiles_rect() const { return live_tiles_rect_
; }
58 using PictureLayerTiling::ComputeSkewport
;
59 using PictureLayerTiling::RemoveTileAt
;
62 TestablePictureLayerTiling(WhichTree tree
,
64 scoped_refptr
<RasterSource
> raster_source
,
65 PictureLayerTilingClient
* client
,
66 float tiling_interest_area_viewport_multiplier
,
67 float skewport_target_time
,
68 int skewport_extrapolation_limit
)
69 : PictureLayerTiling(tree
,
73 tiling_interest_area_viewport_multiplier
,
75 skewport_extrapolation_limit
) {}
78 class PictureLayerTilingIteratorTest
: public testing::Test
{
80 PictureLayerTilingIteratorTest() {}
81 ~PictureLayerTilingIteratorTest() override
{}
83 void Initialize(const gfx::Size
& tile_size
,
85 const gfx::Size
& layer_bounds
) {
86 client_
.SetTileSize(tile_size
);
87 scoped_refptr
<FakePicturePileImpl
> pile
=
88 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
89 tiling_
= TestablePictureLayerTiling::Create(
90 PENDING_TREE
, contents_scale
, pile
, &client_
, LayerTreeSettings());
93 void InitializeActive(const gfx::Size
& tile_size
,
95 const gfx::Size
& layer_bounds
) {
96 client_
.SetTileSize(tile_size
);
97 scoped_refptr
<FakePicturePileImpl
> pile
=
98 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
99 tiling_
= TestablePictureLayerTiling::Create(
100 ACTIVE_TREE
, contents_scale
, pile
, &client_
, LayerTreeSettings());
103 void SetLiveRectAndVerifyTiles(const gfx::Rect
& live_tiles_rect
) {
104 tiling_
->SetLiveTilesRect(live_tiles_rect
);
106 std::vector
<Tile
*> tiles
= tiling_
->AllTilesForTesting();
107 for (std::vector
<Tile
*>::iterator iter
= tiles
.begin();
110 EXPECT_TRUE(live_tiles_rect
.Intersects((*iter
)->content_rect()));
114 void VerifyTilesExactlyCoverRect(
116 const gfx::Rect
& request_rect
,
117 const gfx::Rect
& expect_rect
) {
118 EXPECT_TRUE(request_rect
.Contains(expect_rect
));
120 // Iterators are not valid if this ratio is too large (i.e. the
121 // tiling is too high-res for a low-res destination rect.) This is an
122 // artifact of snapping geometry to integer coordinates and then mapping
123 // back to floating point texture coordinates.
124 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
125 ASSERT_LE(dest_to_contents_scale
, 2.0);
127 Region remaining
= expect_rect
;
128 for (PictureLayerTiling::CoverageIterator
129 iter(tiling_
.get(), rect_scale
, request_rect
);
132 // Geometry cannot overlap previous geometry at all
133 gfx::Rect geometry
= iter
.geometry_rect();
134 EXPECT_TRUE(expect_rect
.Contains(geometry
));
135 EXPECT_TRUE(remaining
.Contains(geometry
));
136 remaining
.Subtract(geometry
);
138 // Sanity check that texture coords are within the texture rect.
139 gfx::RectF texture_rect
= iter
.texture_rect();
140 EXPECT_GE(texture_rect
.x(), 0);
141 EXPECT_GE(texture_rect
.y(), 0);
142 EXPECT_LE(texture_rect
.right(), client_
.TileSize().width());
143 EXPECT_LE(texture_rect
.bottom(), client_
.TileSize().height());
146 // The entire rect must be filled by geometry from the tiling.
147 EXPECT_TRUE(remaining
.IsEmpty());
150 void VerifyTilesExactlyCoverRect(float rect_scale
, const gfx::Rect
& rect
) {
151 VerifyTilesExactlyCoverRect(rect_scale
, rect
, rect
);
156 const gfx::Rect
& rect
,
157 base::Callback
<void(Tile
* tile
,
158 const gfx::Rect
& geometry_rect
)> callback
) {
159 VerifyTiles(tiling_
.get(),
166 PictureLayerTiling
* tiling
,
168 const gfx::Rect
& rect
,
169 base::Callback
<void(Tile
* tile
,
170 const gfx::Rect
& geometry_rect
)> callback
) {
171 Region remaining
= rect
;
172 for (PictureLayerTiling::CoverageIterator
iter(tiling
, rect_scale
, rect
);
175 remaining
.Subtract(iter
.geometry_rect());
176 callback
.Run(*iter
, iter
.geometry_rect());
178 EXPECT_TRUE(remaining
.IsEmpty());
181 void VerifyTilesCoverNonContainedRect(float rect_scale
,
182 const gfx::Rect
& dest_rect
) {
183 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
184 gfx::Rect clamped_rect
= gfx::ScaleToEnclosingRect(
185 gfx::Rect(tiling_
->tiling_size()), 1.f
/ dest_to_contents_scale
);
186 clamped_rect
.Intersect(dest_rect
);
187 VerifyTilesExactlyCoverRect(rect_scale
, dest_rect
, clamped_rect
);
191 FakePictureLayerTilingClient client_
;
192 scoped_ptr
<TestablePictureLayerTiling
> tiling_
;
195 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest
);
198 TEST_F(PictureLayerTilingIteratorTest
, ResizeDeletesTiles
) {
199 // Verifies that a resize with invalidation for newly exposed pixels will
200 // deletes tiles that intersect that invalidation.
201 gfx::Size
tile_size(100, 100);
202 gfx::Size
original_layer_size(10, 10);
203 InitializeActive(tile_size
, 1.f
, original_layer_size
);
204 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
206 // Tiling only has one tile, since its total size is less than one.
207 EXPECT_TRUE(tiling_
->TileAt(0, 0));
209 // Stop creating tiles so that any invalidations are left as holes.
210 gfx::Size
new_layer_size(200, 200);
211 scoped_refptr
<FakePicturePileImpl
> pile
=
212 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size
);
214 Region invalidation
=
215 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
216 tiling_
->SetRasterSourceAndResize(pile
);
217 EXPECT_TRUE(tiling_
->TileAt(0, 0));
218 tiling_
->Invalidate(invalidation
);
219 EXPECT_FALSE(tiling_
->TileAt(0, 0));
222 TEST_F(PictureLayerTilingIteratorTest
, CreateMissingTilesStaysInsideLiveRect
) {
223 // The tiling has three rows and columns.
224 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 250));
225 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
226 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
228 // The live tiles rect is at the very edge of the right-most and
229 // bottom-most tiles. Their border pixels would still be inside the live
230 // tiles rect, but the tiles should not exist just for that.
231 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
232 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 2).y();
234 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
235 EXPECT_FALSE(tiling_
->TileAt(2, 0));
236 EXPECT_FALSE(tiling_
->TileAt(2, 1));
237 EXPECT_FALSE(tiling_
->TileAt(2, 2));
238 EXPECT_FALSE(tiling_
->TileAt(1, 2));
239 EXPECT_FALSE(tiling_
->TileAt(0, 2));
241 // Verify CreateMissingTilesInLiveTilesRect respects this.
242 tiling_
->CreateMissingTilesInLiveTilesRect();
243 EXPECT_FALSE(tiling_
->TileAt(2, 0));
244 EXPECT_FALSE(tiling_
->TileAt(2, 1));
245 EXPECT_FALSE(tiling_
->TileAt(2, 2));
246 EXPECT_FALSE(tiling_
->TileAt(1, 2));
247 EXPECT_FALSE(tiling_
->TileAt(0, 2));
250 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilingOverTileBorders
) {
251 // The tiling has four rows and three columns.
252 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
253 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
254 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
256 // The live tiles rect covers the whole tiling.
257 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
259 // Tiles in the bottom row and right column exist.
260 EXPECT_TRUE(tiling_
->TileAt(2, 0));
261 EXPECT_TRUE(tiling_
->TileAt(2, 1));
262 EXPECT_TRUE(tiling_
->TileAt(2, 2));
263 EXPECT_TRUE(tiling_
->TileAt(2, 3));
264 EXPECT_TRUE(tiling_
->TileAt(1, 3));
265 EXPECT_TRUE(tiling_
->TileAt(0, 3));
267 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
268 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
270 // Shrink the tiling so that the last tile row/column is entirely in the
271 // border pixels of the interior tiles. That row/column is removed.
272 scoped_refptr
<FakePicturePileImpl
> pile
=
273 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
274 gfx::Size(right
+ 1, bottom
+ 1));
275 tiling_
->SetRasterSourceAndResize(pile
);
276 EXPECT_EQ(2, tiling_
->TilingDataForTesting().num_tiles_x());
277 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
279 // The live tiles rect was clamped to the pile size.
280 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
282 // Since the row/column is gone, the tiles should be gone too.
283 EXPECT_FALSE(tiling_
->TileAt(2, 0));
284 EXPECT_FALSE(tiling_
->TileAt(2, 1));
285 EXPECT_FALSE(tiling_
->TileAt(2, 2));
286 EXPECT_FALSE(tiling_
->TileAt(2, 3));
287 EXPECT_FALSE(tiling_
->TileAt(1, 3));
288 EXPECT_FALSE(tiling_
->TileAt(0, 3));
290 // Growing outside the current right/bottom tiles border pixels should create
291 // the tiles again, even though the live rect has not changed size.
292 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
293 gfx::Size(right
+ 2, bottom
+ 2));
294 tiling_
->SetRasterSourceAndResize(pile
);
295 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
296 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
299 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
301 // The last row/column tiles are inside the live tiles rect.
302 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
303 tiling_
->TilingDataForTesting().TileBounds(2, 0)));
304 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
305 tiling_
->TilingDataForTesting().TileBounds(0, 3)));
307 EXPECT_TRUE(tiling_
->TileAt(2, 0));
308 EXPECT_TRUE(tiling_
->TileAt(2, 1));
309 EXPECT_TRUE(tiling_
->TileAt(2, 2));
310 EXPECT_TRUE(tiling_
->TileAt(2, 3));
311 EXPECT_TRUE(tiling_
->TileAt(1, 3));
312 EXPECT_TRUE(tiling_
->TileAt(0, 3));
315 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverTileBorders
) {
316 // The tiling has three rows and columns.
317 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
318 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
319 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
321 // The live tiles rect covers the whole tiling.
322 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
324 // Tiles in the bottom row and right column exist.
325 EXPECT_TRUE(tiling_
->TileAt(2, 0));
326 EXPECT_TRUE(tiling_
->TileAt(2, 1));
327 EXPECT_TRUE(tiling_
->TileAt(2, 2));
328 EXPECT_TRUE(tiling_
->TileAt(2, 3));
329 EXPECT_TRUE(tiling_
->TileAt(1, 3));
330 EXPECT_TRUE(tiling_
->TileAt(0, 3));
332 // Shrink the live tiles rect to the very edge of the right-most and
333 // bottom-most tiles. Their border pixels would still be inside the live
334 // tiles rect, but the tiles should not exist just for that.
335 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 3).x();
336 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
338 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
339 EXPECT_FALSE(tiling_
->TileAt(2, 0));
340 EXPECT_FALSE(tiling_
->TileAt(2, 1));
341 EXPECT_FALSE(tiling_
->TileAt(2, 2));
342 EXPECT_FALSE(tiling_
->TileAt(2, 3));
343 EXPECT_FALSE(tiling_
->TileAt(1, 3));
344 EXPECT_FALSE(tiling_
->TileAt(0, 3));
346 // Including the bottom row and right column again, should create the tiles.
347 SetLiveRectAndVerifyTiles(gfx::Rect(right
+ 1, bottom
+ 1));
348 EXPECT_TRUE(tiling_
->TileAt(2, 0));
349 EXPECT_TRUE(tiling_
->TileAt(2, 1));
350 EXPECT_TRUE(tiling_
->TileAt(2, 2));
351 EXPECT_TRUE(tiling_
->TileAt(2, 3));
352 EXPECT_TRUE(tiling_
->TileAt(1, 2));
353 EXPECT_TRUE(tiling_
->TileAt(0, 2));
355 // Shrink the live tiles rect to the very edge of the left-most and
356 // top-most tiles. Their border pixels would still be inside the live
357 // tiles rect, but the tiles should not exist just for that.
358 int left
= tiling_
->TilingDataForTesting().TileBounds(0, 0).right();
359 int top
= tiling_
->TilingDataForTesting().TileBounds(0, 0).bottom();
361 SetLiveRectAndVerifyTiles(gfx::Rect(left
, top
, 250 - left
, 350 - top
));
362 EXPECT_FALSE(tiling_
->TileAt(0, 3));
363 EXPECT_FALSE(tiling_
->TileAt(0, 2));
364 EXPECT_FALSE(tiling_
->TileAt(0, 1));
365 EXPECT_FALSE(tiling_
->TileAt(0, 0));
366 EXPECT_FALSE(tiling_
->TileAt(1, 0));
367 EXPECT_FALSE(tiling_
->TileAt(2, 0));
369 // Including the top row and left column again, should create the tiles.
370 SetLiveRectAndVerifyTiles(
371 gfx::Rect(left
- 1, top
- 1, 250 - left
, 350 - top
));
372 EXPECT_TRUE(tiling_
->TileAt(0, 3));
373 EXPECT_TRUE(tiling_
->TileAt(0, 2));
374 EXPECT_TRUE(tiling_
->TileAt(0, 1));
375 EXPECT_TRUE(tiling_
->TileAt(0, 0));
376 EXPECT_TRUE(tiling_
->TileAt(1, 0));
377 EXPECT_TRUE(tiling_
->TileAt(2, 0));
380 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverSameTiles
) {
381 // The tiling has four rows and three columns.
382 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
383 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
384 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
386 // The live tiles rect covers the whole tiling.
387 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
390 for (int i
= 0; i
< 3; ++i
) {
391 for (int j
= 0; j
< 4; ++j
)
392 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
395 // Shrink the live tiles rect, but still cover all the tiles.
396 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 349));
398 // All tiles still exist.
399 for (int i
= 0; i
< 3; ++i
) {
400 for (int j
= 0; j
< 4; ++j
)
401 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
404 // Grow the live tiles rect, but still cover all the same tiles.
405 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 350));
407 // All tiles still exist.
408 for (int i
= 0; i
< 3; ++i
) {
409 for (int j
= 0; j
< 4; ++j
)
410 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
414 TEST_F(PictureLayerTilingIteratorTest
, ResizeOverBorderPixelsDeletesTiles
) {
415 // Verifies that a resize with invalidation for newly exposed pixels will
416 // deletes tiles that intersect that invalidation.
417 gfx::Size
tile_size(100, 100);
418 gfx::Size
original_layer_size(99, 99);
419 InitializeActive(tile_size
, 1.f
, original_layer_size
);
420 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
422 // Tiling only has one tile, since its total size is less than one.
423 EXPECT_TRUE(tiling_
->TileAt(0, 0));
425 // Stop creating tiles so that any invalidations are left as holes.
426 scoped_refptr
<FakePicturePileImpl
> pile
=
427 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(
428 gfx::Size(200, 200));
429 tiling_
->SetRasterSourceAndResize(pile
);
431 Region invalidation
=
432 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
433 EXPECT_TRUE(tiling_
->TileAt(0, 0));
434 tiling_
->Invalidate(invalidation
);
435 EXPECT_FALSE(tiling_
->TileAt(0, 0));
437 // The original tile was the same size after resize, but it would include new
439 EXPECT_EQ(gfx::Rect(original_layer_size
),
440 tiling_
->TilingDataForTesting().TileBounds(0, 0));
443 TEST_F(PictureLayerTilingIteratorTest
, LiveTilesExactlyCoverLiveTileRect
) {
444 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
445 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
446 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
447 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
448 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
449 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
450 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
453 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsNoScale
) {
454 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
455 VerifyTilesExactlyCoverRect(1, gfx::Rect());
456 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
457 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
459 // With borders, a size of 3x3 = 1 pixel of content.
460 Initialize(gfx::Size(3, 3), 1.f
, gfx::Size(10, 10));
461 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
462 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
463 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
464 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
467 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsTilingScale
) {
468 Initialize(gfx::Size(200, 100), 2.0f
, gfx::Size(1005, 2010));
469 VerifyTilesExactlyCoverRect(1, gfx::Rect());
470 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
471 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
473 Initialize(gfx::Size(3, 3), 2.0f
, gfx::Size(10, 10));
474 VerifyTilesExactlyCoverRect(1, gfx::Rect());
475 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
476 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
477 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
478 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
480 Initialize(gfx::Size(100, 200), 0.5f
, gfx::Size(1005, 2010));
481 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
482 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
484 Initialize(gfx::Size(150, 250), 0.37f
, gfx::Size(1005, 2010));
485 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
486 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
488 Initialize(gfx::Size(312, 123), 0.01f
, gfx::Size(1005, 2010));
489 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
490 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
493 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsBothScale
) {
494 Initialize(gfx::Size(50, 50), 4.0f
, gfx::Size(800, 600));
495 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect());
496 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(0, 0, 1600, 1200));
497 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(512, 365, 253, 182));
500 gfx::Size
bounds(800, 600);
501 gfx::Rect
full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds
, scale
)));
502 Initialize(gfx::Size(256, 512), 5.2f
, bounds
);
503 VerifyTilesExactlyCoverRect(scale
, full_rect
);
504 VerifyTilesExactlyCoverRect(scale
, gfx::Rect(2014, 1579, 867, 1033));
507 TEST_F(PictureLayerTilingIteratorTest
, IteratorEmptyRect
) {
508 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
511 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1.0f
, empty
);
515 TEST_F(PictureLayerTilingIteratorTest
, NonIntersectingRect
) {
516 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
517 gfx::Rect
non_intersecting(1000, 1000, 50, 50);
518 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1, non_intersecting
);
522 TEST_F(PictureLayerTilingIteratorTest
, LayerEdgeTextureCoordinates
) {
523 Initialize(gfx::Size(300, 300), 1.0f
, gfx::Size(256, 256));
524 // All of these sizes are 256x256, scaled and ceiled.
525 VerifyTilesExactlyCoverRect(1.0f
, gfx::Rect(0, 0, 256, 256));
526 VerifyTilesExactlyCoverRect(0.8f
, gfx::Rect(0, 0, 205, 205));
527 VerifyTilesExactlyCoverRect(1.2f
, gfx::Rect(0, 0, 308, 308));
530 TEST_F(PictureLayerTilingIteratorTest
, NonContainedDestRect
) {
531 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(400, 400));
533 // Too large in all dimensions
534 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, -1000, 2000, 2000));
535 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
536 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
538 // Partially covering content, but too large
539 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, 100, 2000, 100));
540 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, 100, 2000, 100));
541 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, 100, 2000, 100));
544 TEST(PictureLayerTilingTest
, SkewportLimits
) {
545 FakePictureLayerTilingClient client
;
547 gfx::Rect
viewport(0, 0, 100, 100);
548 gfx::Size
layer_bounds(200, 200);
550 client
.SetTileSize(gfx::Size(100, 100));
551 LayerTreeSettings settings
;
552 settings
.skewport_extrapolation_limit_in_content_pixels
= 75;
554 scoped_refptr
<FakePicturePileImpl
> pile
=
555 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
556 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
557 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
560 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
562 // Move viewport down 50 pixels in 0.5 seconds.
563 gfx::Rect down_skewport
=
564 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
566 EXPECT_EQ(0, down_skewport
.x());
567 EXPECT_EQ(50, down_skewport
.y());
568 EXPECT_EQ(100, down_skewport
.width());
569 EXPECT_EQ(175, down_skewport
.height());
570 EXPECT_TRUE(down_skewport
.Contains(gfx::Rect(0, 50, 100, 100)));
572 // Move viewport down 50 and right 10 pixels.
573 gfx::Rect down_right_skewport
=
574 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
576 EXPECT_EQ(10, down_right_skewport
.x());
577 EXPECT_EQ(50, down_right_skewport
.y());
578 EXPECT_EQ(120, down_right_skewport
.width());
579 EXPECT_EQ(175, down_right_skewport
.height());
580 EXPECT_TRUE(down_right_skewport
.Contains(gfx::Rect(10, 50, 100, 100)));
582 // Move viewport left.
583 gfx::Rect left_skewport
=
584 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100));
586 EXPECT_EQ(-125, left_skewport
.x());
587 EXPECT_EQ(0, left_skewport
.y());
588 EXPECT_EQ(175, left_skewport
.width());
589 EXPECT_EQ(100, left_skewport
.height());
590 EXPECT_TRUE(left_skewport
.Contains(gfx::Rect(-50, 0, 100, 100)));
593 gfx::Rect expand_skewport
=
594 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200));
596 // x and y moved by -75 (-50 - 75 = -125).
597 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
598 EXPECT_EQ(-125, expand_skewport
.x());
599 EXPECT_EQ(-125, expand_skewport
.y());
600 EXPECT_EQ(350, expand_skewport
.width());
601 EXPECT_EQ(350, expand_skewport
.height());
602 EXPECT_TRUE(expand_skewport
.Contains(gfx::Rect(-50, -50, 200, 200)));
604 // Expand the viewport past the limit in all directions.
605 gfx::Rect big_expand_skewport
=
606 tiling
->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500));
608 EXPECT_EQ(-575, big_expand_skewport
.x());
609 EXPECT_EQ(-575, big_expand_skewport
.y());
610 EXPECT_EQ(1650, big_expand_skewport
.width());
611 EXPECT_EQ(1650, big_expand_skewport
.height());
612 EXPECT_TRUE(big_expand_skewport
.Contains(gfx::Rect(-500, -500, 1500, 1500)));
614 // Shrink the skewport in all directions.
615 gfx::Rect shrink_viewport
=
616 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 0, 100, 100));
617 EXPECT_EQ(0, shrink_viewport
.x());
618 EXPECT_EQ(0, shrink_viewport
.y());
619 EXPECT_EQ(100, shrink_viewport
.width());
620 EXPECT_EQ(100, shrink_viewport
.height());
622 // Move the skewport really far in one direction.
623 gfx::Rect move_skewport_far
=
624 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 5000, 100, 100));
625 EXPECT_EQ(0, move_skewport_far
.x());
626 EXPECT_EQ(5000, move_skewport_far
.y());
627 EXPECT_EQ(100, move_skewport_far
.width());
628 EXPECT_EQ(175, move_skewport_far
.height());
629 EXPECT_TRUE(move_skewport_far
.Contains(gfx::Rect(0, 5000, 100, 100)));
632 TEST(PictureLayerTilingTest
, ComputeSkewportExtremeCases
) {
633 FakePictureLayerTilingClient client
;
635 gfx::Size
layer_bounds(200, 200);
636 client
.SetTileSize(gfx::Size(100, 100));
637 LayerTreeSettings settings
;
638 scoped_refptr
<FakePicturePileImpl
> pile
=
639 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
640 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
641 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
644 gfx::Rect
viewport1(-1918, 255860, 4010, 2356);
645 gfx::Rect
viewport2(-7088, -91738, 14212, 8350);
646 gfx::Rect
viewport3(-12730024, -158883296, 24607540, 14454512);
648 tiling
->ComputeTilePriorityRects(viewport1
, 1.f
, time
, Occlusion());
650 EXPECT_TRUE(tiling
->ComputeSkewport(time
, viewport2
).Contains(viewport2
));
651 tiling
->ComputeTilePriorityRects(viewport2
, 1.f
, time
, Occlusion());
653 EXPECT_TRUE(tiling
->ComputeSkewport(time
, viewport3
).Contains(viewport3
));
656 TEST(PictureLayerTilingTest
, ComputeSkewport
) {
657 FakePictureLayerTilingClient client
;
659 gfx::Rect
viewport(0, 0, 100, 100);
660 gfx::Size
layer_bounds(200, 200);
662 client
.SetTileSize(gfx::Size(100, 100));
664 scoped_refptr
<FakePicturePileImpl
> pile
=
665 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
666 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
667 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
668 LayerTreeSettings());
670 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
672 // Move viewport down 50 pixels in 0.5 seconds.
673 gfx::Rect down_skewport
=
674 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
676 EXPECT_EQ(0, down_skewport
.x());
677 EXPECT_EQ(50, down_skewport
.y());
678 EXPECT_EQ(100, down_skewport
.width());
679 EXPECT_EQ(200, down_skewport
.height());
682 gfx::Rect shrink_skewport
=
683 tiling
->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50));
685 EXPECT_EQ(25, shrink_skewport
.x());
686 EXPECT_EQ(25, shrink_skewport
.y());
687 EXPECT_EQ(50, shrink_skewport
.width());
688 EXPECT_EQ(50, shrink_skewport
.height());
690 // Move viewport down 50 and right 10 pixels.
691 gfx::Rect down_right_skewport
=
692 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
694 EXPECT_EQ(10, down_right_skewport
.x());
695 EXPECT_EQ(50, down_right_skewport
.y());
696 EXPECT_EQ(120, down_right_skewport
.width());
697 EXPECT_EQ(200, down_right_skewport
.height());
699 // Move viewport left.
700 gfx::Rect left_skewport
=
701 tiling
->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100));
703 EXPECT_EQ(-60, left_skewport
.x());
704 EXPECT_EQ(0, left_skewport
.y());
705 EXPECT_EQ(140, left_skewport
.width());
706 EXPECT_EQ(100, left_skewport
.height());
708 // Expand viewport in 0.2 seconds.
709 gfx::Rect expanded_skewport
=
710 tiling
->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110));
712 EXPECT_EQ(-30, expanded_skewport
.x());
713 EXPECT_EQ(-30, expanded_skewport
.y());
714 EXPECT_EQ(160, expanded_skewport
.width());
715 EXPECT_EQ(160, expanded_skewport
.height());
718 TEST(PictureLayerTilingTest
, SkewportThroughUpdateTilePriorities
) {
719 FakePictureLayerTilingClient client
;
721 gfx::Rect
viewport(0, 0, 100, 100);
722 gfx::Size
layer_bounds(200, 200);
724 client
.SetTileSize(gfx::Size(100, 100));
726 scoped_refptr
<FakePicturePileImpl
> pile
=
727 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
728 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
729 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
730 LayerTreeSettings());
732 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
734 // Move viewport down 50 pixels in 0.5 seconds.
735 gfx::Rect viewport_50
= gfx::Rect(0, 50, 100, 100);
736 gfx::Rect skewport_50
= tiling
->ComputeSkewport(1.5, viewport_50
);
738 EXPECT_EQ(gfx::Rect(0, 50, 100, 200), skewport_50
);
739 tiling
->ComputeTilePriorityRects(viewport_50
, 1.f
, 1.5, Occlusion());
741 gfx::Rect viewport_100
= gfx::Rect(0, 100, 100, 100);
742 gfx::Rect skewport_100
= tiling
->ComputeSkewport(2.0, viewport_100
);
744 EXPECT_EQ(gfx::Rect(0, 100, 100, 200), skewport_100
);
745 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 2.0, Occlusion());
747 // Advance time, but not the viewport.
748 gfx::Rect result
= tiling
->ComputeSkewport(2.5, viewport_100
);
749 // Since the history did advance, we should still get a skewport but a smaller
751 EXPECT_EQ(gfx::Rect(0, 100, 100, 150), result
);
752 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 2.5, Occlusion());
754 // Advance time again.
755 result
= tiling
->ComputeSkewport(3.0, viewport_100
);
756 EXPECT_EQ(viewport_100
, result
);
757 tiling
->ComputeTilePriorityRects(viewport_100
, 1.f
, 3.0, Occlusion());
759 // Ensure we have a skewport.
760 gfx::Rect viewport_150
= gfx::Rect(0, 150, 100, 100);
761 gfx::Rect skewport_150
= tiling
->ComputeSkewport(3.5, viewport_150
);
762 EXPECT_EQ(gfx::Rect(0, 150, 100, 150), skewport_150
);
763 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
765 // Advance the viewport, but not the time.
766 gfx::Rect viewport_200
= gfx::Rect(0, 200, 100, 100);
767 gfx::Rect skewport_200
= tiling
->ComputeSkewport(3.5, viewport_200
);
768 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
770 // Ensure that continued calls with the same value, produce the same skewport.
771 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
772 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
773 tiling
->ComputeTilePriorityRects(viewport_150
, 1.f
, 3.5, Occlusion());
774 EXPECT_EQ(gfx::Rect(0, 200, 100, 300), skewport_200
);
776 tiling
->ComputeTilePriorityRects(viewport_200
, 1.f
, 3.5, Occlusion());
778 // This should never happen, but advance the viewport yet again keeping the
780 gfx::Rect viewport_250
= gfx::Rect(0, 250, 100, 100);
781 gfx::Rect skewport_250
= tiling
->ComputeSkewport(3.5, viewport_250
);
782 EXPECT_EQ(viewport_250
, skewport_250
);
783 tiling
->ComputeTilePriorityRects(viewport_250
, 1.f
, 3.5, Occlusion());
786 TEST(PictureLayerTilingTest
, ViewportDistanceWithScale
) {
787 FakePictureLayerTilingClient client
;
789 gfx::Rect
viewport(0, 0, 100, 100);
790 gfx::Size
layer_bounds(1500, 1500);
792 client
.SetTileSize(gfx::Size(10, 10));
793 LayerTreeSettings settings
;
794 settings
.tiling_interest_area_viewport_multiplier
= 10000;
796 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
797 // The reason is that each tile has a one pixel border, so tile at (1, 2)
798 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
799 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
801 scoped_refptr
<FakePicturePileImpl
> pile
=
802 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
803 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
804 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 0.25f
, pile
, &client
,
806 gfx::Rect viewport_in_content_space
=
807 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
809 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
810 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
812 // Compute the soon border.
813 float inset
= PictureLayerTiling::CalculateSoonBorderDistance(
814 viewport_in_content_space
, 1.0f
/ 0.25f
);
815 gfx::Rect soon_rect_in_content_space
= viewport_in_content_space
;
816 soon_rect_in_content_space
.Inset(-inset
, -inset
);
819 for (int i
= 0; i
< 47; ++i
) {
820 for (int j
= 0; j
< 47; ++j
) {
821 EXPECT_TRUE(tiling
->TileAt(i
, j
)) << "i: " << i
<< " j: " << j
;
824 for (int i
= 0; i
< 47; ++i
) {
825 EXPECT_FALSE(tiling
->TileAt(i
, 47)) << "i: " << i
;
826 EXPECT_FALSE(tiling
->TileAt(47, i
)) << "i: " << i
;
829 // No movement in the viewport implies that tiles will either be NOW
830 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
831 // pixels away from the viewport, which will be in the SOON bin.
832 bool have_now
= false;
833 bool have_eventually
= false;
834 bool have_soon
= false;
835 for (int i
= 0; i
< 47; ++i
) {
836 for (int j
= 0; j
< 47; ++j
) {
837 Tile
* tile
= tiling
->TileAt(i
, j
);
838 PrioritizedTile prioritized_tile
= prioritized_tiles
[tile
];
839 TilePriority priority
= prioritized_tile
.priority();
841 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
842 if (viewport_in_content_space
.Intersects(tile_rect
)) {
843 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
844 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
846 } else if (soon_rect_in_content_space
.Intersects(tile_rect
)) {
847 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
);
850 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
);
851 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
852 have_eventually
= true;
857 EXPECT_TRUE(have_now
);
858 EXPECT_TRUE(have_soon
);
859 EXPECT_TRUE(have_eventually
);
861 // Spot check some distances.
862 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
863 // so the distance to a viewport that ends at 25x25 in content space
864 // should be 17 (41 - 25 + 1). In layer space, then that should be
865 // 17 / 0.25 = 68 pixels.
867 // We can verify that the content rect (with borders) is one pixel off
868 // 41,9 8x8 on all sides.
869 EXPECT_EQ(tiling
->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
871 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
872 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
874 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
875 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
877 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
878 EXPECT_FLOAT_EQ(40.f
, priority
.distance_to_visible
);
880 // Move the viewport down 40 pixels.
881 viewport
= gfx::Rect(0, 40, 100, 100);
882 viewport_in_content_space
=
883 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
884 gfx::Rect skewport
= tiling
->ComputeSkewport(2.0, viewport_in_content_space
);
886 // Compute the soon border.
887 inset
= PictureLayerTiling::CalculateSoonBorderDistance(
888 viewport_in_content_space
, 1.0f
/ 0.25f
);
889 soon_rect_in_content_space
= viewport_in_content_space
;
890 soon_rect_in_content_space
.Inset(-inset
, -inset
);
892 EXPECT_EQ(0, skewport
.x());
893 EXPECT_EQ(10, skewport
.y());
894 EXPECT_EQ(25, skewport
.width());
895 EXPECT_EQ(35, skewport
.height());
897 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 2.0, Occlusion());
898 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
901 have_eventually
= false;
904 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
905 // some EVENTUALLY tiles.
906 for (int i
= 0; i
< 47; ++i
) {
907 for (int j
= 0; j
< 47; ++j
) {
908 Tile
* tile
= tiling
->TileAt(i
, j
);
909 TilePriority priority
= prioritized_tiles
[tile
].priority();
911 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
912 if (viewport_in_content_space
.Intersects(tile_rect
)) {
913 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
) << "i: " << i
915 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
) << "i: " << i
918 } else if (skewport
.Intersects(tile_rect
) ||
919 soon_rect_in_content_space
.Intersects(tile_rect
)) {
920 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
) << "i: " << i
922 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
926 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
)
927 << "i: " << i
<< " j: " << j
;
928 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
930 have_eventually
= true;
935 EXPECT_TRUE(have_now
);
936 EXPECT_TRUE(have_soon
);
937 EXPECT_TRUE(have_eventually
);
939 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
940 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
942 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
943 EXPECT_FLOAT_EQ(28.f
, priority
.distance_to_visible
);
945 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
946 EXPECT_FLOAT_EQ(4.f
, priority
.distance_to_visible
);
948 // Change the underlying layer scale.
949 tiling
->ComputeTilePriorityRects(viewport
, 2.0f
, 3.0, Occlusion());
950 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
952 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
953 EXPECT_FLOAT_EQ(136.f
, priority
.distance_to_visible
);
955 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
956 EXPECT_FLOAT_EQ(56.f
, priority
.distance_to_visible
);
958 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
959 EXPECT_FLOAT_EQ(8.f
, priority
.distance_to_visible
);
961 // Test additional scales.
962 tiling
= TestablePictureLayerTiling::Create(ACTIVE_TREE
, 0.2f
, pile
, &client
,
963 LayerTreeSettings());
964 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 4.0, Occlusion());
965 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
967 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
968 EXPECT_FLOAT_EQ(110.f
, priority
.distance_to_visible
);
970 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
971 EXPECT_FLOAT_EQ(70.f
, priority
.distance_to_visible
);
973 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
974 EXPECT_FLOAT_EQ(60.f
, priority
.distance_to_visible
);
976 tiling
->ComputeTilePriorityRects(viewport
, 0.5f
, 5.0, Occlusion());
977 prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
979 priority
= prioritized_tiles
[tiling
->TileAt(5, 1)].priority();
980 EXPECT_FLOAT_EQ(55.f
, priority
.distance_to_visible
);
982 priority
= prioritized_tiles
[tiling
->TileAt(2, 5)].priority();
983 EXPECT_FLOAT_EQ(35.f
, priority
.distance_to_visible
);
985 priority
= prioritized_tiles
[tiling
->TileAt(3, 4)].priority();
986 EXPECT_FLOAT_EQ(30.f
, priority
.distance_to_visible
);
989 TEST(PictureLayerTilingTest
, ExpandRectEqual
) {
990 gfx::Rect
in(40, 50, 100, 200);
991 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
992 int64 target_area
= 100 * 200;
993 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
994 in
, target_area
, bounds
, NULL
);
995 EXPECT_EQ(in
.ToString(), out
.ToString());
998 TEST(PictureLayerTilingTest
, ExpandRectSmaller
) {
999 gfx::Rect
in(40, 50, 100, 200);
1000 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
1001 int64 target_area
= 100 * 100;
1002 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1003 in
, target_area
, bounds
, NULL
);
1004 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1005 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1006 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
1008 // |in| represents the visible rect, and |out| represents the eventually rect.
1009 // If the eventually rect doesn't contain the visible rect, we will start
1011 EXPECT_TRUE(out
.Contains(in
));
1012 EXPECT_TRUE(bounds
.Contains(out
));
1015 TEST(PictureLayerTilingTest
, ExpandRectUnbounded
) {
1016 gfx::Rect
in(40, 50, 100, 200);
1017 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
1018 int64 target_area
= 200 * 200;
1019 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1020 in
, target_area
, bounds
, NULL
);
1021 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1022 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1023 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
1024 EXPECT_NEAR(200 * 200, out
.width() * out
.height(), 100);
1025 EXPECT_TRUE(bounds
.Contains(out
));
1028 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmaller
) {
1029 gfx::Rect
in(40, 50, 100, 200);
1030 gfx::Rect
bounds(50, 60, 40, 30);
1031 int64 target_area
= 200 * 200;
1032 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1033 in
, target_area
, bounds
, NULL
);
1034 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1037 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqual
) {
1038 gfx::Rect
in(40, 50, 100, 200);
1039 gfx::Rect bounds
= in
;
1040 int64 target_area
= 200 * 200;
1041 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1042 in
, target_area
, bounds
, NULL
);
1043 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1046 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchVertical
) {
1047 gfx::Rect
in(40, 50, 100, 200);
1048 gfx::Rect
bounds(45, 0, 90, 300);
1049 int64 target_area
= 200 * 200;
1050 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1051 in
, target_area
, bounds
, NULL
);
1052 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1055 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchVertical
) {
1056 gfx::Rect
in(40, 50, 100, 200);
1057 gfx::Rect
bounds(40, 0, 100, 300);
1058 int64 target_area
= 200 * 200;
1059 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1060 in
, target_area
, bounds
, NULL
);
1061 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1064 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchHorizontal
) {
1065 gfx::Rect
in(40, 50, 100, 200);
1066 gfx::Rect
bounds(0, 55, 180, 190);
1067 int64 target_area
= 200 * 200;
1068 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1069 in
, target_area
, bounds
, NULL
);
1070 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1073 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchHorizontal
) {
1074 gfx::Rect
in(40, 50, 100, 200);
1075 gfx::Rect
bounds(0, 50, 180, 200);
1076 int64 target_area
= 200 * 200;
1077 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1078 in
, target_area
, bounds
, NULL
);
1079 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1082 TEST(PictureLayerTilingTest
, ExpandRectBoundedLeft
) {
1083 gfx::Rect
in(40, 50, 100, 200);
1084 gfx::Rect
bounds(20, -1000, 10000, 10000);
1085 int64 target_area
= 200 * 200;
1086 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1087 in
, target_area
, bounds
, NULL
);
1088 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1089 EXPECT_EQ(out
.bottom() - in
.bottom(), out
.right() - in
.right());
1090 EXPECT_LE(out
.width() * out
.height(), target_area
);
1091 EXPECT_GT(out
.width() * out
.height(),
1092 target_area
- out
.width() - out
.height() * 2);
1093 EXPECT_TRUE(bounds
.Contains(out
));
1096 TEST(PictureLayerTilingTest
, ExpandRectBoundedRight
) {
1097 gfx::Rect
in(40, 50, 100, 200);
1098 gfx::Rect
bounds(-1000, -1000, 1000+120, 10000);
1099 int64 target_area
= 200 * 200;
1100 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1101 in
, target_area
, bounds
, NULL
);
1102 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1103 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.x() - out
.x());
1104 EXPECT_LE(out
.width() * out
.height(), target_area
);
1105 EXPECT_GT(out
.width() * out
.height(),
1106 target_area
- out
.width() - out
.height() * 2);
1107 EXPECT_TRUE(bounds
.Contains(out
));
1110 TEST(PictureLayerTilingTest
, ExpandRectBoundedTop
) {
1111 gfx::Rect
in(40, 50, 100, 200);
1112 gfx::Rect
bounds(-1000, 30, 10000, 10000);
1113 int64 target_area
= 200 * 200;
1114 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1115 in
, target_area
, bounds
, NULL
);
1116 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1117 EXPECT_EQ(out
.right() - in
.right(), out
.bottom() - in
.bottom());
1118 EXPECT_LE(out
.width() * out
.height(), target_area
);
1119 EXPECT_GT(out
.width() * out
.height(),
1120 target_area
- out
.width() * 2 - out
.height());
1121 EXPECT_TRUE(bounds
.Contains(out
));
1124 TEST(PictureLayerTilingTest
, ExpandRectBoundedBottom
) {
1125 gfx::Rect
in(40, 50, 100, 200);
1126 gfx::Rect
bounds(-1000, -1000, 10000, 1000 + 220);
1127 int64 target_area
= 200 * 200;
1128 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1129 in
, target_area
, bounds
, NULL
);
1130 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1131 EXPECT_EQ(out
.right() - in
.right(), in
.y() - out
.y());
1132 EXPECT_LE(out
.width() * out
.height(), target_area
);
1133 EXPECT_GT(out
.width() * out
.height(),
1134 target_area
- out
.width() * 2 - out
.height());
1135 EXPECT_TRUE(bounds
.Contains(out
));
1138 TEST(PictureLayerTilingTest
, ExpandRectSquishedHorizontally
) {
1139 gfx::Rect
in(40, 50, 100, 200);
1140 gfx::Rect
bounds(0, -4000, 100+40+20, 100000);
1141 int64 target_area
= 400 * 400;
1142 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1143 in
, target_area
, bounds
, NULL
);
1144 EXPECT_EQ(20, out
.right() - in
.right());
1145 EXPECT_EQ(40, in
.x() - out
.x());
1146 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1147 EXPECT_LE(out
.width() * out
.height(), target_area
);
1148 EXPECT_GT(out
.width() * out
.height(),
1149 target_area
- out
.width() * 2);
1150 EXPECT_TRUE(bounds
.Contains(out
));
1153 TEST(PictureLayerTilingTest
, ExpandRectSquishedVertically
) {
1154 gfx::Rect
in(40, 50, 100, 200);
1155 gfx::Rect
bounds(-4000, 0, 100000, 200+50+30);
1156 int64 target_area
= 400 * 400;
1157 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1158 in
, target_area
, bounds
, NULL
);
1159 EXPECT_EQ(30, out
.bottom() - in
.bottom());
1160 EXPECT_EQ(50, in
.y() - out
.y());
1161 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1162 EXPECT_LE(out
.width() * out
.height(), target_area
);
1163 EXPECT_GT(out
.width() * out
.height(),
1164 target_area
- out
.height() * 2);
1165 EXPECT_TRUE(bounds
.Contains(out
));
1168 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsFarAway
) {
1169 gfx::Rect
in(400, 500, 100, 200);
1170 gfx::Rect
bounds(0, 0, 10, 10);
1171 int64 target_area
= 400 * 400;
1172 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1173 in
, target_area
, bounds
, NULL
);
1174 EXPECT_TRUE(out
.IsEmpty());
1177 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedFullyCover
) {
1178 gfx::Rect
in(40, 50, 100, 100);
1179 gfx::Rect
bounds(0, 0, 10, 10);
1180 int64 target_area
= 400 * 400;
1181 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1182 in
, target_area
, bounds
, NULL
);
1183 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1186 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedPartlyCover
) {
1187 gfx::Rect
in(600, 600, 100, 100);
1188 gfx::Rect
bounds(0, 0, 500, 500);
1189 int64 target_area
= 400 * 400;
1190 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1191 in
, target_area
, bounds
, NULL
);
1192 EXPECT_EQ(bounds
.right(), out
.right());
1193 EXPECT_EQ(bounds
.bottom(), out
.bottom());
1194 EXPECT_LE(out
.width() * out
.height(), target_area
);
1195 EXPECT_GT(out
.width() * out
.height(),
1196 target_area
- out
.width() - out
.height());
1197 EXPECT_TRUE(bounds
.Contains(out
));
1200 TEST(PictureLayerTilingTest
, EmptyStartingRect
) {
1201 // If a layer has a non-invertible transform, then the starting rect
1202 // for the layer would be empty.
1203 gfx::Rect
in(40, 40, 0, 0);
1204 gfx::Rect
bounds(0, 0, 10, 10);
1205 int64 target_area
= 400 * 400;
1206 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1207 in
, target_area
, bounds
, NULL
);
1208 EXPECT_TRUE(out
.IsEmpty());
1211 static void TileExists(bool exists
, Tile
* tile
,
1212 const gfx::Rect
& geometry_rect
) {
1213 EXPECT_EQ(exists
, tile
!= NULL
) << geometry_rect
.ToString();
1216 TEST_F(PictureLayerTilingIteratorTest
, TilesExist
) {
1217 gfx::Size
layer_bounds(1099, 801);
1218 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1219 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1220 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1222 tiling_
->ComputeTilePriorityRects(
1223 gfx::Rect(layer_bounds
), // visible content rect
1224 1.f
, // current contents scale
1225 1.0, // current frame time
1227 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1229 // Make the viewport rect empty. All tiles are killed and become zombies.
1230 tiling_
->ComputeTilePriorityRects(gfx::Rect(), // visible content rect
1231 1.f
, // current contents scale
1232 2.0, // current frame time
1234 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1237 TEST_F(PictureLayerTilingIteratorTest
, TilesExistGiantViewport
) {
1238 gfx::Size
layer_bounds(1099, 801);
1239 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1240 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1241 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1243 gfx::Rect
giant_rect(-10000000, -10000000, 1000000000, 1000000000);
1245 tiling_
->ComputeTilePriorityRects(
1246 gfx::Rect(layer_bounds
), // visible content rect
1247 1.f
, // current contents scale
1248 1.0, // current frame time
1250 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1252 // If the visible content rect is empty, it should still have live tiles.
1253 tiling_
->ComputeTilePriorityRects(giant_rect
, // visible content rect
1254 1.f
, // current contents scale
1255 2.0, // current frame time
1257 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1260 TEST_F(PictureLayerTilingIteratorTest
, TilesExistOutsideViewport
) {
1261 gfx::Size
layer_bounds(1099, 801);
1262 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1263 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1264 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1266 // This rect does not intersect with the layer, as the layer is outside the
1268 gfx::Rect
viewport_rect(1100, 0, 1000, 1000);
1269 EXPECT_FALSE(viewport_rect
.Intersects(gfx::Rect(layer_bounds
)));
1271 tiling_
->ComputeTilePriorityRects(viewport_rect
, // visible content rect
1272 1.f
, // current contents scale
1273 1.0, // current frame time
1275 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1278 static void TilesIntersectingRectExist(const gfx::Rect
& rect
,
1279 bool intersect_exists
,
1281 const gfx::Rect
& geometry_rect
) {
1282 bool intersects
= rect
.Intersects(geometry_rect
);
1283 bool expected_exists
= intersect_exists
? intersects
: !intersects
;
1284 EXPECT_EQ(expected_exists
, tile
!= NULL
)
1285 << "Rects intersecting " << rect
.ToString() << " should exist. "
1286 << "Current tile rect is " << geometry_rect
.ToString();
1289 TEST_F(PictureLayerTilingIteratorTest
,
1290 TilesExistLargeViewportAndLayerWithSmallVisibleArea
) {
1291 gfx::Size
layer_bounds(10000, 10000);
1292 client_
.SetTileSize(gfx::Size(100, 100));
1293 LayerTreeSettings settings
;
1294 settings
.tiling_interest_area_viewport_multiplier
= 1;
1296 scoped_refptr
<FakePicturePileImpl
> pile
=
1297 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1298 tiling_
= TestablePictureLayerTiling::Create(PENDING_TREE
, 1.f
, pile
,
1299 &client_
, settings
);
1300 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1301 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1303 gfx::Rect
visible_rect(8000, 8000, 50, 50);
1305 tiling_
->ComputeTilePriorityRects(visible_rect
, // visible content rect
1306 1.f
, // current contents scale
1307 1.0, // current frame time
1310 gfx::Rect(layer_bounds
),
1311 base::Bind(&TilesIntersectingRectExist
, visible_rect
, true));
1314 TEST(ComputeTilePriorityRectsTest
, VisibleTiles
) {
1315 // The TilePriority of visible tiles should have zero distance_to_visible
1316 // and time_to_visible.
1317 FakePictureLayerTilingClient client
;
1319 gfx::Size
device_viewport(800, 600);
1320 gfx::Size
last_layer_bounds(200, 200);
1321 gfx::Size
current_layer_bounds(200, 200);
1322 float current_layer_contents_scale
= 1.f
;
1323 gfx::Transform current_screen_transform
;
1324 double current_frame_time_in_seconds
= 1.0;
1326 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1327 current_screen_transform
, device_viewport
);
1329 client
.SetTileSize(gfx::Size(100, 100));
1331 scoped_refptr
<FakePicturePileImpl
> pile
=
1332 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1333 current_layer_bounds
);
1334 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1335 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1336 LayerTreeSettings());
1338 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1339 current_layer_contents_scale
,
1340 current_frame_time_in_seconds
, Occlusion());
1341 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1343 ASSERT_TRUE(tiling
->TileAt(0, 0));
1344 ASSERT_TRUE(tiling
->TileAt(0, 1));
1345 ASSERT_TRUE(tiling
->TileAt(1, 0));
1346 ASSERT_TRUE(tiling
->TileAt(1, 1));
1348 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1349 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1350 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1352 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1353 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1354 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1356 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1357 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1358 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1360 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1361 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1362 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1365 TEST(ComputeTilePriorityRectsTest
, OffscreenTiles
) {
1366 // The TilePriority of offscreen tiles (without movement) should have nonzero
1367 // distance_to_visible and infinite time_to_visible.
1368 FakePictureLayerTilingClient client
;
1370 gfx::Size
device_viewport(800, 600);
1371 gfx::Size
last_layer_bounds(200, 200);
1372 gfx::Size
current_layer_bounds(200, 200);
1373 float current_layer_contents_scale
= 1.f
;
1374 gfx::Transform last_screen_transform
;
1375 gfx::Transform current_screen_transform
;
1376 double current_frame_time_in_seconds
= 1.0;
1378 current_screen_transform
.Translate(850, 0);
1379 last_screen_transform
= current_screen_transform
;
1381 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1382 current_screen_transform
, device_viewport
);
1384 client
.SetTileSize(gfx::Size(100, 100));
1386 scoped_refptr
<FakePicturePileImpl
> pile
=
1387 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1388 current_layer_bounds
);
1389 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1390 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1391 LayerTreeSettings());
1393 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1394 current_layer_contents_scale
,
1395 current_frame_time_in_seconds
, Occlusion());
1396 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1398 ASSERT_TRUE(tiling
->TileAt(0, 0));
1399 ASSERT_TRUE(tiling
->TileAt(0, 1));
1400 ASSERT_TRUE(tiling
->TileAt(1, 0));
1401 ASSERT_TRUE(tiling
->TileAt(1, 1));
1403 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1404 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1405 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1407 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1408 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1409 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1411 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1412 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1413 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1415 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1416 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1417 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1419 // Furthermore, in this scenario tiles on the right hand side should have a
1420 // larger distance to visible.
1421 TilePriority left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1422 TilePriority right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1423 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1425 left
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1426 right
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1427 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1430 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenLayer
) {
1431 // Sanity check that a layer with some tiles visible and others offscreen has
1432 // correct TilePriorities for each tile.
1433 FakePictureLayerTilingClient client
;
1435 gfx::Size
device_viewport(800, 600);
1436 gfx::Size
last_layer_bounds(200, 200);
1437 gfx::Size
current_layer_bounds(200, 200);
1438 float current_layer_contents_scale
= 1.f
;
1439 gfx::Transform last_screen_transform
;
1440 gfx::Transform current_screen_transform
;
1441 double current_frame_time_in_seconds
= 1.0;
1443 current_screen_transform
.Translate(705, 505);
1444 last_screen_transform
= current_screen_transform
;
1446 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1447 current_screen_transform
, device_viewport
);
1449 client
.SetTileSize(gfx::Size(100, 100));
1451 scoped_refptr
<FakePicturePileImpl
> pile
=
1452 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1453 current_layer_bounds
);
1454 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1455 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1456 LayerTreeSettings());
1458 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1459 current_layer_contents_scale
,
1460 current_frame_time_in_seconds
, Occlusion());
1461 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1463 ASSERT_TRUE(tiling
->TileAt(0, 0));
1464 ASSERT_TRUE(tiling
->TileAt(0, 1));
1465 ASSERT_TRUE(tiling
->TileAt(1, 0));
1466 ASSERT_TRUE(tiling
->TileAt(1, 1));
1468 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1469 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1470 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1472 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1473 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1474 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1476 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1477 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1478 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1480 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1481 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1482 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1485 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenRotatedLayer
) {
1486 // Each tile of a layer may be affected differently by a transform; Check
1487 // that ComputeTilePriorityRects correctly accounts for the transform between
1488 // layer space and screen space.
1489 FakePictureLayerTilingClient client
;
1491 gfx::Size
device_viewport(800, 600);
1492 gfx::Size
last_layer_bounds(200, 200);
1493 gfx::Size
current_layer_bounds(200, 200);
1494 float current_layer_contents_scale
= 1.f
;
1495 gfx::Transform last_screen_transform
;
1496 gfx::Transform current_screen_transform
;
1497 double current_frame_time_in_seconds
= 1.0;
1499 // A diagonally rotated layer that is partially off the bottom of the screen.
1500 // In this configuration, only the top-left tile would be visible.
1501 current_screen_transform
.Translate(600, 750);
1502 current_screen_transform
.RotateAboutZAxis(45);
1503 last_screen_transform
= current_screen_transform
;
1505 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1506 current_screen_transform
, device_viewport
);
1508 client
.SetTileSize(gfx::Size(100, 100));
1510 scoped_refptr
<FakePicturePileImpl
> pile
=
1511 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1512 current_layer_bounds
);
1513 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1514 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1515 LayerTreeSettings());
1517 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1518 current_layer_contents_scale
,
1519 current_frame_time_in_seconds
, Occlusion());
1520 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1522 ASSERT_TRUE(tiling
->TileAt(0, 0));
1523 ASSERT_TRUE(tiling
->TileAt(0, 1));
1524 ASSERT_TRUE(tiling
->TileAt(1, 0));
1525 ASSERT_TRUE(tiling
->TileAt(1, 1));
1527 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1528 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1529 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1531 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1532 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1533 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1535 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1536 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1537 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1539 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1540 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1541 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1543 // Furthermore, in this scenario the bottom-right tile should have the larger
1544 // distance to visible.
1545 TilePriority top_left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1546 TilePriority top_right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1547 TilePriority bottom_right
=
1548 prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1549 EXPECT_GT(top_right
.distance_to_visible
, top_left
.distance_to_visible
);
1551 EXPECT_EQ(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1554 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayer
) {
1555 // Perspective transforms need to take a different code path.
1556 // This test checks tile priorities of a perspective layer.
1557 FakePictureLayerTilingClient client
;
1559 gfx::Size
device_viewport(800, 600);
1560 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscreen.
1561 gfx::Size
last_layer_bounds(200, 200);
1562 gfx::Size
current_layer_bounds(200, 200);
1563 float current_layer_contents_scale
= 1.f
;
1564 gfx::Transform last_screen_transform
;
1565 gfx::Transform current_screen_transform
;
1566 double current_frame_time_in_seconds
= 1.0;
1568 // A 3d perspective layer rotated about its Y axis, translated to almost
1569 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1570 // the right side, so the top-left tile will technically be closer than the
1573 // Translate layer to offscreen
1574 current_screen_transform
.Translate(400.0, 630.0);
1575 // Apply perspective about the center of the layer
1576 current_screen_transform
.Translate(100.0, 100.0);
1577 current_screen_transform
.ApplyPerspectiveDepth(100.0);
1578 current_screen_transform
.RotateAboutYAxis(10.0);
1579 current_screen_transform
.Translate(-100.0, -100.0);
1580 last_screen_transform
= current_screen_transform
;
1582 // Sanity check that this transform wouldn't cause w<0 clipping.
1584 MathUtil::MapQuad(current_screen_transform
,
1585 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1587 ASSERT_FALSE(clipped
);
1589 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1590 current_screen_transform
, device_viewport
);
1592 client
.SetTileSize(gfx::Size(100, 100));
1594 scoped_refptr
<FakePicturePileImpl
> pile
=
1595 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1596 current_layer_bounds
);
1597 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1598 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1599 LayerTreeSettings());
1601 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1602 current_layer_contents_scale
,
1603 current_frame_time_in_seconds
, Occlusion());
1604 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1606 ASSERT_TRUE(tiling
->TileAt(0, 0));
1607 ASSERT_TRUE(tiling
->TileAt(0, 1));
1608 ASSERT_TRUE(tiling
->TileAt(1, 0));
1609 ASSERT_TRUE(tiling
->TileAt(1, 1));
1611 // All tiles will have a positive distance_to_visible
1612 // and an infinite time_to_visible.
1613 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1614 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1615 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1617 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1618 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1619 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1621 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1622 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1623 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1625 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1626 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1627 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1629 // Furthermore, in this scenario the top-left distance_to_visible
1630 // will be smallest, followed by top-right. The bottom layers
1631 // will of course be further than the top layers.
1632 TilePriority top_left
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1633 TilePriority top_right
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1634 TilePriority bottom_left
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1635 TilePriority bottom_right
=
1636 prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1638 EXPECT_GT(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1640 EXPECT_GT(bottom_left
.distance_to_visible
, top_left
.distance_to_visible
);
1643 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayerClippedByW
) {
1644 // Perspective transforms need to take a different code path.
1645 // This test checks tile priorities of a perspective layer.
1646 FakePictureLayerTilingClient client
;
1648 gfx::Size
device_viewport(800, 600);
1649 gfx::Size
last_layer_bounds(200, 200);
1650 gfx::Size
current_layer_bounds(200, 200);
1651 float current_layer_contents_scale
= 1.f
;
1652 gfx::Transform last_screen_transform
;
1653 gfx::Transform current_screen_transform
;
1654 double current_frame_time_in_seconds
= 1.0;
1656 // A 3d perspective layer rotated about its Y axis, translated to almost
1657 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1658 // the right side, so the top-left tile will technically be closer than the
1661 // Translate layer to offscreen
1662 current_screen_transform
.Translate(400.0, 970.0);
1663 // Apply perspective and rotation about the center of the layer
1664 current_screen_transform
.Translate(100.0, 100.0);
1665 current_screen_transform
.ApplyPerspectiveDepth(10.0);
1666 current_screen_transform
.RotateAboutYAxis(10.0);
1667 current_screen_transform
.Translate(-100.0, -100.0);
1668 last_screen_transform
= current_screen_transform
;
1670 // Sanity check that this transform does cause w<0 clipping for the left side
1671 // of the layer, but not the right side.
1673 MathUtil::MapQuad(current_screen_transform
,
1674 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1676 ASSERT_TRUE(clipped
);
1678 MathUtil::MapQuad(current_screen_transform
,
1679 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1681 ASSERT_FALSE(clipped
);
1683 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1684 current_screen_transform
, device_viewport
);
1686 client
.SetTileSize(gfx::Size(100, 100));
1688 scoped_refptr
<FakePicturePileImpl
> pile
=
1689 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1690 current_layer_bounds
);
1691 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1692 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1693 LayerTreeSettings());
1695 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1696 current_layer_contents_scale
,
1697 current_frame_time_in_seconds
, Occlusion());
1698 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1700 ASSERT_TRUE(tiling
->TileAt(0, 0));
1701 ASSERT_TRUE(tiling
->TileAt(0, 1));
1702 ASSERT_TRUE(tiling
->TileAt(1, 0));
1703 ASSERT_TRUE(tiling
->TileAt(1, 1));
1705 // Left-side tiles will be clipped by the transform, so we have to assume
1706 // they are visible just in case.
1707 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1708 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1709 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1711 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1712 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1713 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1715 // Right-side tiles will have a positive distance_to_visible
1716 // and an infinite time_to_visible.
1717 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1718 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1719 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1721 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1722 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1723 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1726 TEST(ComputeTilePriorityRectsTest
, BasicMotion
) {
1727 // Test that time_to_visible is computed correctly when
1728 // there is some motion.
1729 FakePictureLayerTilingClient client
;
1731 gfx::Size
device_viewport(800, 600);
1732 gfx::Rect
visible_layer_rect(0, 0, 0, 0);
1733 gfx::Size
last_layer_bounds(200, 200);
1734 gfx::Size
current_layer_bounds(200, 200);
1735 float last_layer_contents_scale
= 1.f
;
1736 float current_layer_contents_scale
= 1.f
;
1737 gfx::Transform last_screen_transform
;
1738 gfx::Transform current_screen_transform
;
1739 double last_frame_time_in_seconds
= 1.0;
1740 double current_frame_time_in_seconds
= 2.0;
1742 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1743 current_screen_transform
.Translate(1800, 0);
1744 last_screen_transform
.Translate(2800, 0);
1746 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1747 current_screen_transform
, device_viewport
);
1749 client
.SetTileSize(gfx::Size(100, 100));
1750 LayerTreeSettings settings
;
1751 settings
.tiling_interest_area_viewport_multiplier
= 10000;
1753 scoped_refptr
<FakePicturePileImpl
> pile
=
1754 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1755 current_layer_bounds
);
1756 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1757 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1760 // previous ("last") frame
1761 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1762 last_layer_contents_scale
,
1763 last_frame_time_in_seconds
, Occlusion());
1766 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1767 current_layer_contents_scale
,
1768 current_frame_time_in_seconds
, Occlusion());
1769 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1771 ASSERT_TRUE(tiling
->TileAt(0, 0));
1772 ASSERT_TRUE(tiling
->TileAt(0, 1));
1773 ASSERT_TRUE(tiling
->TileAt(1, 0));
1774 ASSERT_TRUE(tiling
->TileAt(1, 1));
1776 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1777 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1778 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1780 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1781 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1782 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1784 // time_to_visible for the right hand side layers needs an extra 0.099
1785 // seconds because this tile is 99 pixels further away.
1786 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1787 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1788 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1790 priority
= prioritized_tiles
[tiling
->TileAt(1, 1)].priority();
1791 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1792 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1795 TEST(ComputeTilePriorityRectsTest
, RotationMotion
) {
1796 // Each tile of a layer may be affected differently by a transform; Check
1797 // that ComputeTilePriorityRects correctly accounts for the transform between
1798 // layer space and screen space.
1800 FakePictureLayerTilingClient client
;
1801 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1803 gfx::Size
device_viewport(800, 600);
1804 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscren.
1805 gfx::Size
last_layer_bounds(200, 200);
1806 gfx::Size
current_layer_bounds(200, 200);
1807 float last_layer_contents_scale
= 1.f
;
1808 float current_layer_contents_scale
= 1.f
;
1809 gfx::Transform last_screen_transform
;
1810 gfx::Transform current_screen_transform
;
1811 double last_frame_time_in_seconds
= 1.0;
1812 double current_frame_time_in_seconds
= 2.0;
1814 // Rotation motion is set up specifically so that:
1815 // - rotation occurs about the center of the layer
1816 // - the top-left tile becomes visible on rotation
1817 // - the top-right tile will have an infinite time_to_visible
1818 // because it is rotating away from viewport.
1819 // - bottom-left layer will have a positive non-zero time_to_visible
1820 // because it is rotating toward the viewport.
1821 current_screen_transform
.Translate(400, 550);
1822 current_screen_transform
.RotateAboutZAxis(45);
1824 last_screen_transform
.Translate(400, 550);
1826 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1827 current_screen_transform
, device_viewport
);
1829 client
.SetTileSize(gfx::Size(100, 100));
1831 scoped_refptr
<FakePicturePileImpl
> pile
=
1832 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1833 current_layer_bounds
);
1834 tiling
= TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
, &client
,
1835 LayerTreeSettings());
1837 // previous ("last") frame
1838 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1839 last_layer_contents_scale
,
1840 last_frame_time_in_seconds
, Occlusion());
1843 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1844 current_layer_contents_scale
,
1845 current_frame_time_in_seconds
, Occlusion());
1846 auto prioritized_tiles
= tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
1848 ASSERT_TRUE(tiling
->TileAt(0, 0));
1849 ASSERT_TRUE(tiling
->TileAt(0, 1));
1850 ASSERT_TRUE(tiling
->TileAt(1, 0));
1851 ASSERT_TRUE(tiling
->TileAt(1, 1));
1853 TilePriority priority
= prioritized_tiles
[tiling
->TileAt(0, 0)].priority();
1854 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1855 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1857 priority
= prioritized_tiles
[tiling
->TileAt(0, 1)].priority();
1858 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1859 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1861 priority
= prioritized_tiles
[tiling
->TileAt(1, 0)].priority();
1862 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1863 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1866 TEST(PictureLayerTilingTest
, RecycledTilesCleared
) {
1867 // This test performs the following:
1869 // - Two tilings, one active one recycled with all tiles shared.
1871 // - Viewport moves somewhere far away and active tiling clears tiles.
1872 // - Viewport moves back and a new active tiling tile is created.
1874 // - Recycle tiling does _not_ have the tile in the same location (thus it
1875 // will be shared next time a pending tiling is created).
1877 FakePictureLayerTilingClient active_client
;
1879 active_client
.SetTileSize(gfx::Size(100, 100));
1880 LayerTreeSettings settings
;
1882 scoped_refptr
<FakePicturePileImpl
> pile
=
1883 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1884 gfx::Size(10000, 10000));
1885 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1886 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
,
1887 &active_client
, settings
);
1888 // Create all tiles on this tiling.
1889 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1892 FakePictureLayerTilingClient recycle_client
;
1893 recycle_client
.SetTileSize(gfx::Size(100, 100));
1894 recycle_client
.set_twin_tiling(active_tiling
.get());
1896 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1897 gfx::Size(10000, 10000));
1898 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1899 TestablePictureLayerTiling::Create(PENDING_TREE
, 1.0f
, pile
,
1900 &recycle_client
, settings
);
1902 // Create all tiles on the second tiling. All tiles should be shared.
1903 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1906 // Set the second tiling as recycled.
1907 active_client
.set_twin_tiling(NULL
);
1908 recycle_client
.set_twin_tiling(NULL
);
1910 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1911 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1913 // Move the viewport far away from the (0, 0) tile.
1914 active_tiling
->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f
,
1916 // Ensure the tile was deleted.
1917 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1918 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1920 // Move the viewport back to (0, 0) tile.
1921 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 3.0,
1924 // Ensure that we now have a tile here on both active.
1925 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1926 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1929 TEST(PictureLayerTilingTest
, RecycledTilesClearedOnReset
) {
1930 FakePictureLayerTilingClient active_client
;
1931 active_client
.SetTileSize(gfx::Size(100, 100));
1933 scoped_refptr
<FakePicturePileImpl
> pile
=
1934 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1935 gfx::Size(100, 100));
1936 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1937 TestablePictureLayerTiling::Create(ACTIVE_TREE
, 1.0f
, pile
,
1938 &active_client
, LayerTreeSettings());
1939 // Create all tiles on this tiling.
1940 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1943 FakePictureLayerTilingClient recycle_client
;
1944 recycle_client
.SetTileSize(gfx::Size(100, 100));
1945 recycle_client
.set_twin_tiling(active_tiling
.get());
1947 LayerTreeSettings settings
;
1949 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1950 gfx::Size(100, 100));
1951 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1952 TestablePictureLayerTiling::Create(PENDING_TREE
, 1.0f
, pile
,
1953 &recycle_client
, settings
);
1955 // Create all tiles on the recycle tiling. All tiles should be shared.
1956 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1959 // Set the second tiling as recycled.
1960 active_client
.set_twin_tiling(NULL
);
1961 recycle_client
.set_twin_tiling(NULL
);
1963 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1964 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1966 // Reset the active tiling. The recycle tiles should be released too.
1967 active_tiling
->Reset();
1968 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1969 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1972 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilesAndUpdateToCurrent
) {
1973 // The tiling has four rows and three columns.
1974 Initialize(gfx::Size(150, 100), 1.f
, gfx::Size(250, 150));
1975 tiling_
->CreateAllTilesForTesting();
1976 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1977 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1978 EXPECT_EQ(4u, tiling_
->AllTilesForTesting().size());
1980 client_
.SetTileSize(gfx::Size(250, 200));
1982 // Tile size in the tiling should still be 150x100.
1983 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1984 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1986 // The layer's size isn't changed, but the tile size was.
1987 scoped_refptr
<FakePicturePileImpl
> pile
=
1988 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1989 gfx::Size(250, 150));
1990 tiling_
->SetRasterSourceAndResize(pile
);
1992 // Tile size in the tiling should be resized to 250x200.
1993 EXPECT_EQ(250, tiling_
->TilingDataForTesting().max_texture_size().width());
1994 EXPECT_EQ(200, tiling_
->TilingDataForTesting().max_texture_size().height());
1995 EXPECT_EQ(0u, tiling_
->AllTilesForTesting().size());