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.
5 #include "cc/resources/picture_layer_tiling.h"
10 #include "cc/base/math_util.h"
11 #include "cc/resources/picture_layer_tiling_set.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_output_surface_client.h"
14 #include "cc/test/fake_picture_layer_tiling_client.h"
15 #include "cc/test/fake_picture_pile_impl.h"
16 #include "cc/test/test_context_provider.h"
17 #include "cc/test/test_shared_bitmap_manager.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/geometry/quad_f.h"
20 #include "ui/gfx/geometry/rect_conversions.h"
21 #include "ui/gfx/geometry/size_conversions.h"
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(
46 scoped_refptr
<RasterSource
> raster_source
,
47 PictureLayerTilingClient
* client
,
48 const LayerTreeSettings
& settings
) {
49 return make_scoped_ptr(new TestablePictureLayerTiling(
50 contents_scale
, raster_source
, client
,
51 settings
.max_tiles_for_interest_area
,
52 settings
.skewport_target_time_in_seconds
,
53 settings
.skewport_extrapolation_limit_in_content_pixels
));
56 gfx::Rect
live_tiles_rect() const { return live_tiles_rect_
; }
58 using PictureLayerTiling::ComputeSkewport
;
59 using PictureLayerTiling::RemoveTileAt
;
62 TestablePictureLayerTiling(float contents_scale
,
63 scoped_refptr
<RasterSource
> raster_source
,
64 PictureLayerTilingClient
* client
,
65 size_t max_tiles_for_interest_area
,
66 float skewport_target_time
,
67 int skewport_extrapolation_limit
)
68 : PictureLayerTiling(contents_scale
,
71 max_tiles_for_interest_area
,
73 skewport_extrapolation_limit
) {}
76 class PictureLayerTilingIteratorTest
: public testing::Test
{
78 PictureLayerTilingIteratorTest() {}
79 ~PictureLayerTilingIteratorTest() override
{}
81 void Initialize(const gfx::Size
& tile_size
,
83 const gfx::Size
& layer_bounds
) {
84 client_
.SetTileSize(tile_size
);
85 client_
.set_tree(PENDING_TREE
);
86 scoped_refptr
<FakePicturePileImpl
> pile
=
87 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
88 tiling_
= TestablePictureLayerTiling::Create(contents_scale
, pile
, &client_
,
92 void SetLiveRectAndVerifyTiles(const gfx::Rect
& live_tiles_rect
) {
93 tiling_
->SetLiveTilesRect(live_tiles_rect
);
95 std::vector
<Tile
*> tiles
= tiling_
->AllTilesForTesting();
96 for (std::vector
<Tile
*>::iterator iter
= tiles
.begin();
99 EXPECT_TRUE(live_tiles_rect
.Intersects((*iter
)->content_rect()));
103 void VerifyTilesExactlyCoverRect(
105 const gfx::Rect
& request_rect
,
106 const gfx::Rect
& expect_rect
) {
107 EXPECT_TRUE(request_rect
.Contains(expect_rect
));
109 // Iterators are not valid if this ratio is too large (i.e. the
110 // tiling is too high-res for a low-res destination rect.) This is an
111 // artifact of snapping geometry to integer coordinates and then mapping
112 // back to floating point texture coordinates.
113 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
114 ASSERT_LE(dest_to_contents_scale
, 2.0);
116 Region remaining
= expect_rect
;
117 for (PictureLayerTiling::CoverageIterator
118 iter(tiling_
.get(), rect_scale
, request_rect
);
121 // Geometry cannot overlap previous geometry at all
122 gfx::Rect geometry
= iter
.geometry_rect();
123 EXPECT_TRUE(expect_rect
.Contains(geometry
));
124 EXPECT_TRUE(remaining
.Contains(geometry
));
125 remaining
.Subtract(geometry
);
127 // Sanity check that texture coords are within the texture rect.
128 gfx::RectF texture_rect
= iter
.texture_rect();
129 EXPECT_GE(texture_rect
.x(), 0);
130 EXPECT_GE(texture_rect
.y(), 0);
131 EXPECT_LE(texture_rect
.right(), client_
.TileSize().width());
132 EXPECT_LE(texture_rect
.bottom(), client_
.TileSize().height());
135 // The entire rect must be filled by geometry from the tiling.
136 EXPECT_TRUE(remaining
.IsEmpty());
139 void VerifyTilesExactlyCoverRect(float rect_scale
, const gfx::Rect
& rect
) {
140 VerifyTilesExactlyCoverRect(rect_scale
, rect
, rect
);
145 const gfx::Rect
& rect
,
146 base::Callback
<void(Tile
* tile
,
147 const gfx::Rect
& geometry_rect
)> callback
) {
148 VerifyTiles(tiling_
.get(),
155 PictureLayerTiling
* tiling
,
157 const gfx::Rect
& rect
,
158 base::Callback
<void(Tile
* tile
,
159 const gfx::Rect
& geometry_rect
)> callback
) {
160 Region remaining
= rect
;
161 for (PictureLayerTiling::CoverageIterator
iter(tiling
, rect_scale
, rect
);
164 remaining
.Subtract(iter
.geometry_rect());
165 callback
.Run(*iter
, iter
.geometry_rect());
167 EXPECT_TRUE(remaining
.IsEmpty());
170 void VerifyTilesCoverNonContainedRect(float rect_scale
,
171 const gfx::Rect
& dest_rect
) {
172 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
173 gfx::Rect clamped_rect
= gfx::ScaleToEnclosingRect(
174 gfx::Rect(tiling_
->tiling_size()), 1.f
/ dest_to_contents_scale
);
175 clamped_rect
.Intersect(dest_rect
);
176 VerifyTilesExactlyCoverRect(rect_scale
, dest_rect
, clamped_rect
);
180 FakePictureLayerTilingClient client_
;
181 scoped_ptr
<TestablePictureLayerTiling
> tiling_
;
184 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest
);
187 TEST_F(PictureLayerTilingIteratorTest
, ResizeDeletesTiles
) {
188 // Verifies that a resize with invalidation for newly exposed pixels will
189 // deletes tiles that intersect that invalidation.
190 gfx::Size
tile_size(100, 100);
191 gfx::Size
original_layer_size(10, 10);
192 Initialize(tile_size
, 1.f
, original_layer_size
);
193 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
195 // Tiling only has one tile, since its total size is less than one.
196 EXPECT_TRUE(tiling_
->TileAt(0, 0));
198 // Stop creating tiles so that any invalidations are left as holes.
199 gfx::Size
new_layer_size(200, 200);
200 scoped_refptr
<FakePicturePileImpl
> pile
=
201 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size
);
203 Region invalidation
=
204 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
205 tiling_
->SetRasterSourceAndResize(pile
);
206 EXPECT_TRUE(tiling_
->TileAt(0, 0));
207 tiling_
->Invalidate(invalidation
);
208 EXPECT_FALSE(tiling_
->TileAt(0, 0));
211 TEST_F(PictureLayerTilingIteratorTest
, CreateMissingTilesStaysInsideLiveRect
) {
212 // The tiling has three rows and columns.
213 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 250));
214 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
215 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
217 // The live tiles rect is at the very edge of the right-most and
218 // bottom-most tiles. Their border pixels would still be inside the live
219 // tiles rect, but the tiles should not exist just for that.
220 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
221 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 2).y();
223 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
224 EXPECT_FALSE(tiling_
->TileAt(2, 0));
225 EXPECT_FALSE(tiling_
->TileAt(2, 1));
226 EXPECT_FALSE(tiling_
->TileAt(2, 2));
227 EXPECT_FALSE(tiling_
->TileAt(1, 2));
228 EXPECT_FALSE(tiling_
->TileAt(0, 2));
230 // Verify CreateMissingTilesInLiveTilesRect respects this.
231 tiling_
->CreateMissingTilesInLiveTilesRect();
232 EXPECT_FALSE(tiling_
->TileAt(2, 0));
233 EXPECT_FALSE(tiling_
->TileAt(2, 1));
234 EXPECT_FALSE(tiling_
->TileAt(2, 2));
235 EXPECT_FALSE(tiling_
->TileAt(1, 2));
236 EXPECT_FALSE(tiling_
->TileAt(0, 2));
239 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilingOverTileBorders
) {
240 // The tiling has four rows and three columns.
241 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
242 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
243 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
245 // The live tiles rect covers the whole tiling.
246 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
248 // Tiles in the bottom row and right column exist.
249 EXPECT_TRUE(tiling_
->TileAt(2, 0));
250 EXPECT_TRUE(tiling_
->TileAt(2, 1));
251 EXPECT_TRUE(tiling_
->TileAt(2, 2));
252 EXPECT_TRUE(tiling_
->TileAt(2, 3));
253 EXPECT_TRUE(tiling_
->TileAt(1, 3));
254 EXPECT_TRUE(tiling_
->TileAt(0, 3));
256 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
257 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
259 // Shrink the tiling so that the last tile row/column is entirely in the
260 // border pixels of the interior tiles. That row/column is removed.
261 scoped_refptr
<FakePicturePileImpl
> pile
=
262 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
263 gfx::Size(right
+ 1, bottom
+ 1));
264 tiling_
->SetRasterSourceAndResize(pile
);
265 EXPECT_EQ(2, tiling_
->TilingDataForTesting().num_tiles_x());
266 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
268 // The live tiles rect was clamped to the pile size.
269 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
271 // Since the row/column is gone, the tiles should be gone too.
272 EXPECT_FALSE(tiling_
->TileAt(2, 0));
273 EXPECT_FALSE(tiling_
->TileAt(2, 1));
274 EXPECT_FALSE(tiling_
->TileAt(2, 2));
275 EXPECT_FALSE(tiling_
->TileAt(2, 3));
276 EXPECT_FALSE(tiling_
->TileAt(1, 3));
277 EXPECT_FALSE(tiling_
->TileAt(0, 3));
279 // Growing outside the current right/bottom tiles border pixels should create
280 // the tiles again, even though the live rect has not changed size.
281 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
282 gfx::Size(right
+ 2, bottom
+ 2));
283 tiling_
->SetRasterSourceAndResize(pile
);
284 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
285 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
288 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
290 // The last row/column tiles are inside the live tiles rect.
291 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
292 tiling_
->TilingDataForTesting().TileBounds(2, 0)));
293 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
294 tiling_
->TilingDataForTesting().TileBounds(0, 3)));
296 EXPECT_TRUE(tiling_
->TileAt(2, 0));
297 EXPECT_TRUE(tiling_
->TileAt(2, 1));
298 EXPECT_TRUE(tiling_
->TileAt(2, 2));
299 EXPECT_TRUE(tiling_
->TileAt(2, 3));
300 EXPECT_TRUE(tiling_
->TileAt(1, 3));
301 EXPECT_TRUE(tiling_
->TileAt(0, 3));
304 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverTileBorders
) {
305 // The tiling has three rows and columns.
306 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
307 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
308 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
310 // The live tiles rect covers the whole tiling.
311 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
313 // Tiles in the bottom row and right column exist.
314 EXPECT_TRUE(tiling_
->TileAt(2, 0));
315 EXPECT_TRUE(tiling_
->TileAt(2, 1));
316 EXPECT_TRUE(tiling_
->TileAt(2, 2));
317 EXPECT_TRUE(tiling_
->TileAt(2, 3));
318 EXPECT_TRUE(tiling_
->TileAt(1, 3));
319 EXPECT_TRUE(tiling_
->TileAt(0, 3));
321 // Shrink the live tiles rect to the very edge of the right-most and
322 // bottom-most tiles. Their border pixels would still be inside the live
323 // tiles rect, but the tiles should not exist just for that.
324 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 3).x();
325 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
327 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
328 EXPECT_FALSE(tiling_
->TileAt(2, 0));
329 EXPECT_FALSE(tiling_
->TileAt(2, 1));
330 EXPECT_FALSE(tiling_
->TileAt(2, 2));
331 EXPECT_FALSE(tiling_
->TileAt(2, 3));
332 EXPECT_FALSE(tiling_
->TileAt(1, 3));
333 EXPECT_FALSE(tiling_
->TileAt(0, 3));
335 // Including the bottom row and right column again, should create the tiles.
336 SetLiveRectAndVerifyTiles(gfx::Rect(right
+ 1, bottom
+ 1));
337 EXPECT_TRUE(tiling_
->TileAt(2, 0));
338 EXPECT_TRUE(tiling_
->TileAt(2, 1));
339 EXPECT_TRUE(tiling_
->TileAt(2, 2));
340 EXPECT_TRUE(tiling_
->TileAt(2, 3));
341 EXPECT_TRUE(tiling_
->TileAt(1, 2));
342 EXPECT_TRUE(tiling_
->TileAt(0, 2));
344 // Shrink the live tiles rect to the very edge of the left-most and
345 // top-most tiles. Their border pixels would still be inside the live
346 // tiles rect, but the tiles should not exist just for that.
347 int left
= tiling_
->TilingDataForTesting().TileBounds(0, 0).right();
348 int top
= tiling_
->TilingDataForTesting().TileBounds(0, 0).bottom();
350 SetLiveRectAndVerifyTiles(gfx::Rect(left
, top
, 250 - left
, 350 - top
));
351 EXPECT_FALSE(tiling_
->TileAt(0, 3));
352 EXPECT_FALSE(tiling_
->TileAt(0, 2));
353 EXPECT_FALSE(tiling_
->TileAt(0, 1));
354 EXPECT_FALSE(tiling_
->TileAt(0, 0));
355 EXPECT_FALSE(tiling_
->TileAt(1, 0));
356 EXPECT_FALSE(tiling_
->TileAt(2, 0));
358 // Including the top row and left column again, should create the tiles.
359 SetLiveRectAndVerifyTiles(
360 gfx::Rect(left
- 1, top
- 1, 250 - left
, 350 - top
));
361 EXPECT_TRUE(tiling_
->TileAt(0, 3));
362 EXPECT_TRUE(tiling_
->TileAt(0, 2));
363 EXPECT_TRUE(tiling_
->TileAt(0, 1));
364 EXPECT_TRUE(tiling_
->TileAt(0, 0));
365 EXPECT_TRUE(tiling_
->TileAt(1, 0));
366 EXPECT_TRUE(tiling_
->TileAt(2, 0));
369 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverSameTiles
) {
370 // The tiling has four rows and three columns.
371 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
372 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
373 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
375 // The live tiles rect covers the whole tiling.
376 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
379 for (int i
= 0; i
< 3; ++i
) {
380 for (int j
= 0; j
< 4; ++j
)
381 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
384 // Shrink the live tiles rect, but still cover all the tiles.
385 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 349));
387 // All tiles still exist.
388 for (int i
= 0; i
< 3; ++i
) {
389 for (int j
= 0; j
< 4; ++j
)
390 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
393 // Grow the live tiles rect, but still cover all the same tiles.
394 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 350));
396 // All tiles still exist.
397 for (int i
= 0; i
< 3; ++i
) {
398 for (int j
= 0; j
< 4; ++j
)
399 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
403 TEST_F(PictureLayerTilingIteratorTest
, ResizeOverBorderPixelsDeletesTiles
) {
404 // Verifies that a resize with invalidation for newly exposed pixels will
405 // deletes tiles that intersect that invalidation.
406 gfx::Size
tile_size(100, 100);
407 gfx::Size
original_layer_size(99, 99);
408 Initialize(tile_size
, 1.f
, original_layer_size
);
409 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
411 // Tiling only has one tile, since its total size is less than one.
412 EXPECT_TRUE(tiling_
->TileAt(0, 0));
414 // Stop creating tiles so that any invalidations are left as holes.
415 scoped_refptr
<FakePicturePileImpl
> pile
=
416 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(
417 gfx::Size(200, 200));
418 tiling_
->SetRasterSourceAndResize(pile
);
420 Region invalidation
=
421 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
422 EXPECT_TRUE(tiling_
->TileAt(0, 0));
423 tiling_
->Invalidate(invalidation
);
424 EXPECT_FALSE(tiling_
->TileAt(0, 0));
426 // The original tile was the same size after resize, but it would include new
428 EXPECT_EQ(gfx::Rect(original_layer_size
),
429 tiling_
->TilingDataForTesting().TileBounds(0, 0));
432 TEST_F(PictureLayerTilingIteratorTest
, LiveTilesExactlyCoverLiveTileRect
) {
433 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
434 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
435 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
436 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
437 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
438 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
439 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
442 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsNoScale
) {
443 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
444 VerifyTilesExactlyCoverRect(1, gfx::Rect());
445 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
446 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
448 // With borders, a size of 3x3 = 1 pixel of content.
449 Initialize(gfx::Size(3, 3), 1.f
, gfx::Size(10, 10));
450 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
451 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
452 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
453 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
456 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsTilingScale
) {
457 Initialize(gfx::Size(200, 100), 2.0f
, gfx::Size(1005, 2010));
458 VerifyTilesExactlyCoverRect(1, gfx::Rect());
459 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
460 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
462 Initialize(gfx::Size(3, 3), 2.0f
, gfx::Size(10, 10));
463 VerifyTilesExactlyCoverRect(1, gfx::Rect());
464 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
465 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
466 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
467 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
469 Initialize(gfx::Size(100, 200), 0.5f
, gfx::Size(1005, 2010));
470 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
471 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
473 Initialize(gfx::Size(150, 250), 0.37f
, gfx::Size(1005, 2010));
474 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
475 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
477 Initialize(gfx::Size(312, 123), 0.01f
, gfx::Size(1005, 2010));
478 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
479 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
482 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsBothScale
) {
483 Initialize(gfx::Size(50, 50), 4.0f
, gfx::Size(800, 600));
484 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect());
485 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(0, 0, 1600, 1200));
486 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(512, 365, 253, 182));
489 gfx::Size
bounds(800, 600);
490 gfx::Rect
full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds
, scale
)));
491 Initialize(gfx::Size(256, 512), 5.2f
, bounds
);
492 VerifyTilesExactlyCoverRect(scale
, full_rect
);
493 VerifyTilesExactlyCoverRect(scale
, gfx::Rect(2014, 1579, 867, 1033));
496 TEST_F(PictureLayerTilingIteratorTest
, IteratorEmptyRect
) {
497 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
500 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1.0f
, empty
);
504 TEST_F(PictureLayerTilingIteratorTest
, NonIntersectingRect
) {
505 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
506 gfx::Rect
non_intersecting(1000, 1000, 50, 50);
507 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1, non_intersecting
);
511 TEST_F(PictureLayerTilingIteratorTest
, LayerEdgeTextureCoordinates
) {
512 Initialize(gfx::Size(300, 300), 1.0f
, gfx::Size(256, 256));
513 // All of these sizes are 256x256, scaled and ceiled.
514 VerifyTilesExactlyCoverRect(1.0f
, gfx::Rect(0, 0, 256, 256));
515 VerifyTilesExactlyCoverRect(0.8f
, gfx::Rect(0, 0, 205, 205));
516 VerifyTilesExactlyCoverRect(1.2f
, gfx::Rect(0, 0, 308, 308));
519 TEST_F(PictureLayerTilingIteratorTest
, NonContainedDestRect
) {
520 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(400, 400));
522 // Too large in all dimensions
523 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, -1000, 2000, 2000));
524 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
525 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
527 // Partially covering content, but too large
528 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, 100, 2000, 100));
529 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, 100, 2000, 100));
530 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, 100, 2000, 100));
533 TEST(PictureLayerTilingTest
, SkewportLimits
) {
534 FakePictureLayerTilingClient client
;
535 client
.set_tree(ACTIVE_TREE
);
537 gfx::Rect
viewport(0, 0, 100, 100);
538 gfx::Size
layer_bounds(200, 200);
540 client
.SetTileSize(gfx::Size(100, 100));
541 LayerTreeSettings settings
;
542 settings
.max_tiles_for_interest_area
= 10000;
543 settings
.skewport_extrapolation_limit_in_content_pixels
= 75;
545 scoped_refptr
<FakePicturePileImpl
> pile
=
546 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
547 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
548 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
, settings
);
550 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
552 // Move viewport down 50 pixels in 0.5 seconds.
553 gfx::Rect down_skewport
=
554 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
556 EXPECT_EQ(0, down_skewport
.x());
557 EXPECT_EQ(50, down_skewport
.y());
558 EXPECT_EQ(100, down_skewport
.width());
559 EXPECT_EQ(175, down_skewport
.height());
560 EXPECT_TRUE(down_skewport
.Contains(gfx::Rect(0, 50, 100, 100)));
562 // Move viewport down 50 and right 10 pixels.
563 gfx::Rect down_right_skewport
=
564 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
566 EXPECT_EQ(10, down_right_skewport
.x());
567 EXPECT_EQ(50, down_right_skewport
.y());
568 EXPECT_EQ(120, down_right_skewport
.width());
569 EXPECT_EQ(175, down_right_skewport
.height());
570 EXPECT_TRUE(down_right_skewport
.Contains(gfx::Rect(10, 50, 100, 100)));
572 // Move viewport left.
573 gfx::Rect left_skewport
=
574 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100));
576 EXPECT_EQ(-125, left_skewport
.x());
577 EXPECT_EQ(0, left_skewport
.y());
578 EXPECT_EQ(175, left_skewport
.width());
579 EXPECT_EQ(100, left_skewport
.height());
580 EXPECT_TRUE(left_skewport
.Contains(gfx::Rect(-50, 0, 100, 100)));
583 gfx::Rect expand_skewport
=
584 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200));
586 // x and y moved by -75 (-50 - 75 = -125).
587 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
588 EXPECT_EQ(-125, expand_skewport
.x());
589 EXPECT_EQ(-125, expand_skewport
.y());
590 EXPECT_EQ(350, expand_skewport
.width());
591 EXPECT_EQ(350, expand_skewport
.height());
592 EXPECT_TRUE(expand_skewport
.Contains(gfx::Rect(-50, -50, 200, 200)));
594 // Expand the viewport past the limit.
595 gfx::Rect big_expand_skewport
=
596 tiling
->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500));
598 EXPECT_EQ(-575, big_expand_skewport
.x());
599 EXPECT_EQ(-575, big_expand_skewport
.y());
600 EXPECT_EQ(1650, big_expand_skewport
.width());
601 EXPECT_EQ(1650, big_expand_skewport
.height());
602 EXPECT_TRUE(big_expand_skewport
.Contains(gfx::Rect(-500, -500, 1500, 1500)));
605 TEST(PictureLayerTilingTest
, ComputeSkewport
) {
606 FakePictureLayerTilingClient client
;
608 gfx::Rect
viewport(0, 0, 100, 100);
609 gfx::Size
layer_bounds(200, 200);
611 client
.SetTileSize(gfx::Size(100, 100));
612 client
.set_tree(ACTIVE_TREE
);
614 scoped_refptr
<FakePicturePileImpl
> pile
=
615 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
616 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
617 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
618 LayerTreeSettings());
620 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
622 // Move viewport down 50 pixels in 0.5 seconds.
623 gfx::Rect down_skewport
=
624 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
626 EXPECT_EQ(0, down_skewport
.x());
627 EXPECT_EQ(50, down_skewport
.y());
628 EXPECT_EQ(100, down_skewport
.width());
629 EXPECT_EQ(200, down_skewport
.height());
632 gfx::Rect shrink_skewport
=
633 tiling
->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50));
635 EXPECT_EQ(25, shrink_skewport
.x());
636 EXPECT_EQ(25, shrink_skewport
.y());
637 EXPECT_EQ(50, shrink_skewport
.width());
638 EXPECT_EQ(50, shrink_skewport
.height());
640 // Move viewport down 50 and right 10 pixels.
641 gfx::Rect down_right_skewport
=
642 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
644 EXPECT_EQ(10, down_right_skewport
.x());
645 EXPECT_EQ(50, down_right_skewport
.y());
646 EXPECT_EQ(120, down_right_skewport
.width());
647 EXPECT_EQ(200, down_right_skewport
.height());
649 // Move viewport left.
650 gfx::Rect left_skewport
=
651 tiling
->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100));
653 EXPECT_EQ(-60, left_skewport
.x());
654 EXPECT_EQ(0, left_skewport
.y());
655 EXPECT_EQ(140, left_skewport
.width());
656 EXPECT_EQ(100, left_skewport
.height());
658 // Expand viewport in 0.2 seconds.
659 gfx::Rect expanded_skewport
=
660 tiling
->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110));
662 EXPECT_EQ(-30, expanded_skewport
.x());
663 EXPECT_EQ(-30, expanded_skewport
.y());
664 EXPECT_EQ(160, expanded_skewport
.width());
665 EXPECT_EQ(160, expanded_skewport
.height());
668 TEST(PictureLayerTilingTest
, ViewportDistanceWithScale
) {
669 FakePictureLayerTilingClient client
;
671 gfx::Rect
viewport(0, 0, 100, 100);
672 gfx::Size
layer_bounds(1500, 1500);
674 client
.SetTileSize(gfx::Size(10, 10));
675 client
.set_tree(ACTIVE_TREE
);
676 LayerTreeSettings settings
;
677 settings
.max_tiles_for_interest_area
= 10000;
679 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
680 // The reason is that each tile has a one pixel border, so tile at (1, 2)
681 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
682 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
684 scoped_refptr
<FakePicturePileImpl
> pile
=
685 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
686 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
687 TestablePictureLayerTiling::Create(0.25f
, pile
, &client
, settings
);
688 gfx::Rect viewport_in_content_space
=
689 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
691 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
692 tiling
->UpdateAllTilePrioritiesForTesting();
694 // Compute the soon border.
695 float inset
= PictureLayerTiling::CalculateSoonBorderDistance(
696 viewport_in_content_space
, 1.0f
/ 0.25f
);
697 gfx::Rect soon_rect_in_content_space
= viewport_in_content_space
;
698 soon_rect_in_content_space
.Inset(-inset
, -inset
);
701 for (int i
= 0; i
< 47; ++i
) {
702 for (int j
= 0; j
< 47; ++j
) {
703 EXPECT_TRUE(tiling
->TileAt(i
, j
)) << "i: " << i
<< " j: " << j
;
706 for (int i
= 0; i
< 47; ++i
) {
707 EXPECT_FALSE(tiling
->TileAt(i
, 47)) << "i: " << i
;
708 EXPECT_FALSE(tiling
->TileAt(47, i
)) << "i: " << i
;
711 // No movement in the viewport implies that tiles will either be NOW
712 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
713 // pixels away from the viewport, which will be in the SOON bin.
714 bool have_now
= false;
715 bool have_eventually
= false;
716 bool have_soon
= false;
717 for (int i
= 0; i
< 47; ++i
) {
718 for (int j
= 0; j
< 47; ++j
) {
719 Tile
* tile
= tiling
->TileAt(i
, j
);
720 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
722 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
723 if (viewport_in_content_space
.Intersects(tile_rect
)) {
724 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
725 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
727 } else if (soon_rect_in_content_space
.Intersects(tile_rect
)) {
728 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
);
731 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
);
732 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
733 have_eventually
= true;
738 EXPECT_TRUE(have_now
);
739 EXPECT_TRUE(have_soon
);
740 EXPECT_TRUE(have_eventually
);
742 // Spot check some distances.
743 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
744 // so the distance to a viewport that ends at 25x25 in content space
745 // should be 17 (41 - 25 + 1). In layer space, then that should be
746 // 17 / 0.25 = 68 pixels.
748 // We can verify that the content rect (with borders) is one pixel off
749 // 41,9 8x8 on all sides.
750 EXPECT_EQ(tiling
->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
752 TilePriority priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
753 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
755 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
756 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
758 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
759 EXPECT_FLOAT_EQ(40.f
, priority
.distance_to_visible
);
761 // Move the viewport down 40 pixels.
762 viewport
= gfx::Rect(0, 40, 100, 100);
763 viewport_in_content_space
=
764 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
765 gfx::Rect skewport
= tiling
->ComputeSkewport(2.0, viewport_in_content_space
);
767 // Compute the soon border.
768 inset
= PictureLayerTiling::CalculateSoonBorderDistance(
769 viewport_in_content_space
, 1.0f
/ 0.25f
);
770 soon_rect_in_content_space
= viewport_in_content_space
;
771 soon_rect_in_content_space
.Inset(-inset
, -inset
);
773 EXPECT_EQ(0, skewport
.x());
774 EXPECT_EQ(10, skewport
.y());
775 EXPECT_EQ(25, skewport
.width());
776 EXPECT_EQ(35, skewport
.height());
778 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 2.0, Occlusion());
779 tiling
->UpdateAllTilePrioritiesForTesting();
782 have_eventually
= false;
785 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
786 // some EVENTUALLY tiles.
787 for (int i
= 0; i
< 47; ++i
) {
788 for (int j
= 0; j
< 47; ++j
) {
789 Tile
* tile
= tiling
->TileAt(i
, j
);
790 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
792 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
793 if (viewport_in_content_space
.Intersects(tile_rect
)) {
794 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
) << "i: " << i
796 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
) << "i: " << i
799 } else if (skewport
.Intersects(tile_rect
) ||
800 soon_rect_in_content_space
.Intersects(tile_rect
)) {
801 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
) << "i: " << i
803 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
807 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
)
808 << "i: " << i
<< " j: " << j
;
809 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
811 have_eventually
= true;
816 EXPECT_TRUE(have_now
);
817 EXPECT_TRUE(have_soon
);
818 EXPECT_TRUE(have_eventually
);
820 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
821 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
823 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
824 EXPECT_FLOAT_EQ(28.f
, priority
.distance_to_visible
);
826 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
827 EXPECT_FLOAT_EQ(4.f
, priority
.distance_to_visible
);
829 // Change the underlying layer scale.
830 tiling
->ComputeTilePriorityRects(viewport
, 2.0f
, 3.0, Occlusion());
831 tiling
->UpdateAllTilePrioritiesForTesting();
833 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
834 EXPECT_FLOAT_EQ(136.f
, priority
.distance_to_visible
);
836 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
837 EXPECT_FLOAT_EQ(56.f
, priority
.distance_to_visible
);
839 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
840 EXPECT_FLOAT_EQ(8.f
, priority
.distance_to_visible
);
842 // Test additional scales.
843 tiling
= TestablePictureLayerTiling::Create(0.2f
, pile
, &client
,
844 LayerTreeSettings());
845 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 4.0, Occlusion());
846 tiling
->UpdateAllTilePrioritiesForTesting();
848 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
849 EXPECT_FLOAT_EQ(110.f
, priority
.distance_to_visible
);
851 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
852 EXPECT_FLOAT_EQ(70.f
, priority
.distance_to_visible
);
854 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
855 EXPECT_FLOAT_EQ(60.f
, priority
.distance_to_visible
);
857 tiling
->ComputeTilePriorityRects(viewport
, 0.5f
, 5.0, Occlusion());
858 tiling
->UpdateAllTilePrioritiesForTesting();
860 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
861 EXPECT_FLOAT_EQ(55.f
, priority
.distance_to_visible
);
863 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
864 EXPECT_FLOAT_EQ(35.f
, priority
.distance_to_visible
);
866 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
867 EXPECT_FLOAT_EQ(30.f
, priority
.distance_to_visible
);
870 TEST(PictureLayerTilingTest
, ExpandRectEqual
) {
871 gfx::Rect
in(40, 50, 100, 200);
872 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
873 int64 target_area
= 100 * 200;
874 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
875 in
, target_area
, bounds
, NULL
);
876 EXPECT_EQ(in
.ToString(), out
.ToString());
879 TEST(PictureLayerTilingTest
, ExpandRectSmaller
) {
880 gfx::Rect
in(40, 50, 100, 200);
881 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
882 int64 target_area
= 100 * 100;
883 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
884 in
, target_area
, bounds
, NULL
);
885 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
886 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
887 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
889 // |in| represents the visible rect, and |out| represents the eventually rect.
890 // If the eventually rect doesn't contain the visible rect, we will start
892 EXPECT_TRUE(out
.Contains(in
));
893 EXPECT_TRUE(bounds
.Contains(out
));
896 TEST(PictureLayerTilingTest
, ExpandRectUnbounded
) {
897 gfx::Rect
in(40, 50, 100, 200);
898 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
899 int64 target_area
= 200 * 200;
900 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
901 in
, target_area
, bounds
, NULL
);
902 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
903 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
904 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
905 EXPECT_NEAR(200 * 200, out
.width() * out
.height(), 100);
906 EXPECT_TRUE(bounds
.Contains(out
));
909 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmaller
) {
910 gfx::Rect
in(40, 50, 100, 200);
911 gfx::Rect
bounds(50, 60, 40, 30);
912 int64 target_area
= 200 * 200;
913 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
914 in
, target_area
, bounds
, NULL
);
915 EXPECT_EQ(bounds
.ToString(), out
.ToString());
918 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqual
) {
919 gfx::Rect
in(40, 50, 100, 200);
920 gfx::Rect bounds
= in
;
921 int64 target_area
= 200 * 200;
922 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
923 in
, target_area
, bounds
, NULL
);
924 EXPECT_EQ(bounds
.ToString(), out
.ToString());
927 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchVertical
) {
928 gfx::Rect
in(40, 50, 100, 200);
929 gfx::Rect
bounds(45, 0, 90, 300);
930 int64 target_area
= 200 * 200;
931 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
932 in
, target_area
, bounds
, NULL
);
933 EXPECT_EQ(bounds
.ToString(), out
.ToString());
936 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchVertical
) {
937 gfx::Rect
in(40, 50, 100, 200);
938 gfx::Rect
bounds(40, 0, 100, 300);
939 int64 target_area
= 200 * 200;
940 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
941 in
, target_area
, bounds
, NULL
);
942 EXPECT_EQ(bounds
.ToString(), out
.ToString());
945 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchHorizontal
) {
946 gfx::Rect
in(40, 50, 100, 200);
947 gfx::Rect
bounds(0, 55, 180, 190);
948 int64 target_area
= 200 * 200;
949 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
950 in
, target_area
, bounds
, NULL
);
951 EXPECT_EQ(bounds
.ToString(), out
.ToString());
954 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchHorizontal
) {
955 gfx::Rect
in(40, 50, 100, 200);
956 gfx::Rect
bounds(0, 50, 180, 200);
957 int64 target_area
= 200 * 200;
958 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
959 in
, target_area
, bounds
, NULL
);
960 EXPECT_EQ(bounds
.ToString(), out
.ToString());
963 TEST(PictureLayerTilingTest
, ExpandRectBoundedLeft
) {
964 gfx::Rect
in(40, 50, 100, 200);
965 gfx::Rect
bounds(20, -1000, 10000, 10000);
966 int64 target_area
= 200 * 200;
967 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
968 in
, target_area
, bounds
, NULL
);
969 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
970 EXPECT_EQ(out
.bottom() - in
.bottom(), out
.right() - in
.right());
971 EXPECT_LE(out
.width() * out
.height(), target_area
);
972 EXPECT_GT(out
.width() * out
.height(),
973 target_area
- out
.width() - out
.height() * 2);
974 EXPECT_TRUE(bounds
.Contains(out
));
977 TEST(PictureLayerTilingTest
, ExpandRectBoundedRight
) {
978 gfx::Rect
in(40, 50, 100, 200);
979 gfx::Rect
bounds(-1000, -1000, 1000+120, 10000);
980 int64 target_area
= 200 * 200;
981 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
982 in
, target_area
, bounds
, NULL
);
983 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
984 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.x() - out
.x());
985 EXPECT_LE(out
.width() * out
.height(), target_area
);
986 EXPECT_GT(out
.width() * out
.height(),
987 target_area
- out
.width() - out
.height() * 2);
988 EXPECT_TRUE(bounds
.Contains(out
));
991 TEST(PictureLayerTilingTest
, ExpandRectBoundedTop
) {
992 gfx::Rect
in(40, 50, 100, 200);
993 gfx::Rect
bounds(-1000, 30, 10000, 10000);
994 int64 target_area
= 200 * 200;
995 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
996 in
, target_area
, bounds
, NULL
);
997 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
998 EXPECT_EQ(out
.right() - in
.right(), out
.bottom() - in
.bottom());
999 EXPECT_LE(out
.width() * out
.height(), target_area
);
1000 EXPECT_GT(out
.width() * out
.height(),
1001 target_area
- out
.width() * 2 - out
.height());
1002 EXPECT_TRUE(bounds
.Contains(out
));
1005 TEST(PictureLayerTilingTest
, ExpandRectBoundedBottom
) {
1006 gfx::Rect
in(40, 50, 100, 200);
1007 gfx::Rect
bounds(-1000, -1000, 10000, 1000 + 220);
1008 int64 target_area
= 200 * 200;
1009 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1010 in
, target_area
, bounds
, NULL
);
1011 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1012 EXPECT_EQ(out
.right() - in
.right(), in
.y() - out
.y());
1013 EXPECT_LE(out
.width() * out
.height(), target_area
);
1014 EXPECT_GT(out
.width() * out
.height(),
1015 target_area
- out
.width() * 2 - out
.height());
1016 EXPECT_TRUE(bounds
.Contains(out
));
1019 TEST(PictureLayerTilingTest
, ExpandRectSquishedHorizontally
) {
1020 gfx::Rect
in(40, 50, 100, 200);
1021 gfx::Rect
bounds(0, -4000, 100+40+20, 100000);
1022 int64 target_area
= 400 * 400;
1023 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1024 in
, target_area
, bounds
, NULL
);
1025 EXPECT_EQ(20, out
.right() - in
.right());
1026 EXPECT_EQ(40, in
.x() - out
.x());
1027 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1028 EXPECT_LE(out
.width() * out
.height(), target_area
);
1029 EXPECT_GT(out
.width() * out
.height(),
1030 target_area
- out
.width() * 2);
1031 EXPECT_TRUE(bounds
.Contains(out
));
1034 TEST(PictureLayerTilingTest
, ExpandRectSquishedVertically
) {
1035 gfx::Rect
in(40, 50, 100, 200);
1036 gfx::Rect
bounds(-4000, 0, 100000, 200+50+30);
1037 int64 target_area
= 400 * 400;
1038 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1039 in
, target_area
, bounds
, NULL
);
1040 EXPECT_EQ(30, out
.bottom() - in
.bottom());
1041 EXPECT_EQ(50, in
.y() - out
.y());
1042 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1043 EXPECT_LE(out
.width() * out
.height(), target_area
);
1044 EXPECT_GT(out
.width() * out
.height(),
1045 target_area
- out
.height() * 2);
1046 EXPECT_TRUE(bounds
.Contains(out
));
1049 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsFarAway
) {
1050 gfx::Rect
in(400, 500, 100, 200);
1051 gfx::Rect
bounds(0, 0, 10, 10);
1052 int64 target_area
= 400 * 400;
1053 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1054 in
, target_area
, bounds
, NULL
);
1055 EXPECT_TRUE(out
.IsEmpty());
1058 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedFullyCover
) {
1059 gfx::Rect
in(40, 50, 100, 100);
1060 gfx::Rect
bounds(0, 0, 10, 10);
1061 int64 target_area
= 400 * 400;
1062 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1063 in
, target_area
, bounds
, NULL
);
1064 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1067 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedPartlyCover
) {
1068 gfx::Rect
in(600, 600, 100, 100);
1069 gfx::Rect
bounds(0, 0, 500, 500);
1070 int64 target_area
= 400 * 400;
1071 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1072 in
, target_area
, bounds
, NULL
);
1073 EXPECT_EQ(bounds
.right(), out
.right());
1074 EXPECT_EQ(bounds
.bottom(), out
.bottom());
1075 EXPECT_LE(out
.width() * out
.height(), target_area
);
1076 EXPECT_GT(out
.width() * out
.height(),
1077 target_area
- out
.width() - out
.height());
1078 EXPECT_TRUE(bounds
.Contains(out
));
1081 TEST(PictureLayerTilingTest
, EmptyStartingRect
) {
1082 // If a layer has a non-invertible transform, then the starting rect
1083 // for the layer would be empty.
1084 gfx::Rect
in(40, 40, 0, 0);
1085 gfx::Rect
bounds(0, 0, 10, 10);
1086 int64 target_area
= 400 * 400;
1087 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1088 in
, target_area
, bounds
, NULL
);
1089 EXPECT_TRUE(out
.IsEmpty());
1092 static void TileExists(bool exists
, Tile
* tile
,
1093 const gfx::Rect
& geometry_rect
) {
1094 EXPECT_EQ(exists
, tile
!= NULL
) << geometry_rect
.ToString();
1097 TEST_F(PictureLayerTilingIteratorTest
, TilesExist
) {
1098 gfx::Size
layer_bounds(1099, 801);
1099 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1100 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1101 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1103 client_
.set_tree(ACTIVE_TREE
);
1104 tiling_
->ComputeTilePriorityRects(
1105 gfx::Rect(layer_bounds
), // visible content rect
1106 1.f
, // current contents scale
1107 1.0, // current frame time
1109 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1111 // Make the viewport rect empty. All tiles are killed and become zombies.
1112 tiling_
->ComputeTilePriorityRects(gfx::Rect(), // visible content rect
1113 1.f
, // current contents scale
1114 2.0, // current frame time
1116 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1119 TEST_F(PictureLayerTilingIteratorTest
, TilesExistGiantViewport
) {
1120 gfx::Size
layer_bounds(1099, 801);
1121 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1122 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1123 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1125 gfx::Rect
giant_rect(-10000000, -10000000, 1000000000, 1000000000);
1127 client_
.set_tree(ACTIVE_TREE
);
1128 tiling_
->ComputeTilePriorityRects(
1129 gfx::Rect(layer_bounds
), // visible content rect
1130 1.f
, // current contents scale
1131 1.0, // current frame time
1133 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1135 // If the visible content rect is empty, it should still have live tiles.
1136 tiling_
->ComputeTilePriorityRects(giant_rect
, // visible content rect
1137 1.f
, // current contents scale
1138 2.0, // current frame time
1140 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1143 TEST_F(PictureLayerTilingIteratorTest
, TilesExistOutsideViewport
) {
1144 gfx::Size
layer_bounds(1099, 801);
1145 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1146 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1147 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1149 // This rect does not intersect with the layer, as the layer is outside the
1151 gfx::Rect
viewport_rect(1100, 0, 1000, 1000);
1152 EXPECT_FALSE(viewport_rect
.Intersects(gfx::Rect(layer_bounds
)));
1154 client_
.set_tree(ACTIVE_TREE
);
1155 tiling_
->ComputeTilePriorityRects(viewport_rect
, // visible content rect
1156 1.f
, // current contents scale
1157 1.0, // current frame time
1159 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1162 static void TilesIntersectingRectExist(const gfx::Rect
& rect
,
1163 bool intersect_exists
,
1165 const gfx::Rect
& geometry_rect
) {
1166 bool intersects
= rect
.Intersects(geometry_rect
);
1167 bool expected_exists
= intersect_exists
? intersects
: !intersects
;
1168 EXPECT_EQ(expected_exists
, tile
!= NULL
)
1169 << "Rects intersecting " << rect
.ToString() << " should exist. "
1170 << "Current tile rect is " << geometry_rect
.ToString();
1173 TEST_F(PictureLayerTilingIteratorTest
,
1174 TilesExistLargeViewportAndLayerWithSmallVisibleArea
) {
1175 gfx::Size
layer_bounds(10000, 10000);
1176 client_
.SetTileSize(gfx::Size(100, 100));
1177 client_
.set_tree(PENDING_TREE
);
1178 LayerTreeSettings settings
;
1179 settings
.max_tiles_for_interest_area
= 1;
1181 scoped_refptr
<FakePicturePileImpl
> pile
=
1182 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1183 tiling_
= TestablePictureLayerTiling::Create(1.f
, pile
, &client_
, settings
);
1184 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1185 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1187 gfx::Rect
visible_rect(8000, 8000, 50, 50);
1189 client_
.set_tree(ACTIVE_TREE
);
1190 tiling_
->ComputeTilePriorityRects(visible_rect
, // visible content rect
1191 1.f
, // current contents scale
1192 1.0, // current frame time
1195 gfx::Rect(layer_bounds
),
1196 base::Bind(&TilesIntersectingRectExist
, visible_rect
, true));
1199 TEST(ComputeTilePriorityRectsTest
, VisibleTiles
) {
1200 // The TilePriority of visible tiles should have zero distance_to_visible
1201 // and time_to_visible.
1202 FakePictureLayerTilingClient client
;
1204 gfx::Size
device_viewport(800, 600);
1205 gfx::Size
last_layer_bounds(200, 200);
1206 gfx::Size
current_layer_bounds(200, 200);
1207 float current_layer_contents_scale
= 1.f
;
1208 gfx::Transform current_screen_transform
;
1209 double current_frame_time_in_seconds
= 1.0;
1211 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1212 current_screen_transform
, device_viewport
);
1214 client
.SetTileSize(gfx::Size(100, 100));
1215 client
.set_tree(ACTIVE_TREE
);
1217 scoped_refptr
<FakePicturePileImpl
> pile
=
1218 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1219 current_layer_bounds
);
1220 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1221 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1222 LayerTreeSettings());
1224 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1225 current_layer_contents_scale
,
1226 current_frame_time_in_seconds
, Occlusion());
1227 tiling
->UpdateAllTilePrioritiesForTesting();
1229 ASSERT_TRUE(tiling
->TileAt(0, 0));
1230 ASSERT_TRUE(tiling
->TileAt(0, 1));
1231 ASSERT_TRUE(tiling
->TileAt(1, 0));
1232 ASSERT_TRUE(tiling
->TileAt(1, 1));
1234 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1235 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1236 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1238 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1239 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1240 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1242 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1243 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1244 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1246 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1247 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1248 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1251 TEST(ComputeTilePriorityRectsTest
, OffscreenTiles
) {
1252 // The TilePriority of offscreen tiles (without movement) should have nonzero
1253 // distance_to_visible and infinite time_to_visible.
1254 FakePictureLayerTilingClient client
;
1256 gfx::Size
device_viewport(800, 600);
1257 gfx::Size
last_layer_bounds(200, 200);
1258 gfx::Size
current_layer_bounds(200, 200);
1259 float current_layer_contents_scale
= 1.f
;
1260 gfx::Transform last_screen_transform
;
1261 gfx::Transform current_screen_transform
;
1262 double current_frame_time_in_seconds
= 1.0;
1264 current_screen_transform
.Translate(850, 0);
1265 last_screen_transform
= current_screen_transform
;
1267 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1268 current_screen_transform
, device_viewport
);
1270 client
.SetTileSize(gfx::Size(100, 100));
1271 client
.set_tree(ACTIVE_TREE
);
1273 scoped_refptr
<FakePicturePileImpl
> pile
=
1274 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1275 current_layer_bounds
);
1276 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1277 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1278 LayerTreeSettings());
1280 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1281 current_layer_contents_scale
,
1282 current_frame_time_in_seconds
, Occlusion());
1283 tiling
->UpdateAllTilePrioritiesForTesting();
1285 ASSERT_TRUE(tiling
->TileAt(0, 0));
1286 ASSERT_TRUE(tiling
->TileAt(0, 1));
1287 ASSERT_TRUE(tiling
->TileAt(1, 0));
1288 ASSERT_TRUE(tiling
->TileAt(1, 1));
1290 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1291 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1292 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1294 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1295 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1296 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1298 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1299 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1300 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1302 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1303 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1304 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1306 // Furthermore, in this scenario tiles on the right hand side should have a
1307 // larger distance to visible.
1308 TilePriority left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1309 TilePriority right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1310 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1312 left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1313 right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1314 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1317 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenLayer
) {
1318 // Sanity check that a layer with some tiles visible and others offscreen has
1319 // correct TilePriorities for each tile.
1320 FakePictureLayerTilingClient client
;
1322 gfx::Size
device_viewport(800, 600);
1323 gfx::Size
last_layer_bounds(200, 200);
1324 gfx::Size
current_layer_bounds(200, 200);
1325 float current_layer_contents_scale
= 1.f
;
1326 gfx::Transform last_screen_transform
;
1327 gfx::Transform current_screen_transform
;
1328 double current_frame_time_in_seconds
= 1.0;
1330 current_screen_transform
.Translate(705, 505);
1331 last_screen_transform
= current_screen_transform
;
1333 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1334 current_screen_transform
, device_viewport
);
1336 client
.SetTileSize(gfx::Size(100, 100));
1337 client
.set_tree(ACTIVE_TREE
);
1339 scoped_refptr
<FakePicturePileImpl
> pile
=
1340 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1341 current_layer_bounds
);
1342 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1343 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1344 LayerTreeSettings());
1346 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1347 current_layer_contents_scale
,
1348 current_frame_time_in_seconds
, Occlusion());
1349 tiling
->UpdateAllTilePrioritiesForTesting();
1351 ASSERT_TRUE(tiling
->TileAt(0, 0));
1352 ASSERT_TRUE(tiling
->TileAt(0, 1));
1353 ASSERT_TRUE(tiling
->TileAt(1, 0));
1354 ASSERT_TRUE(tiling
->TileAt(1, 1));
1356 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1357 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1358 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1360 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1361 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1362 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1364 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1365 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1366 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1368 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1369 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1370 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1373 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenRotatedLayer
) {
1374 // Each tile of a layer may be affected differently by a transform; Check
1375 // that ComputeTilePriorityRects correctly accounts for the transform between
1376 // layer space and screen space.
1377 FakePictureLayerTilingClient client
;
1379 gfx::Size
device_viewport(800, 600);
1380 gfx::Size
last_layer_bounds(200, 200);
1381 gfx::Size
current_layer_bounds(200, 200);
1382 float current_layer_contents_scale
= 1.f
;
1383 gfx::Transform last_screen_transform
;
1384 gfx::Transform current_screen_transform
;
1385 double current_frame_time_in_seconds
= 1.0;
1387 // A diagonally rotated layer that is partially off the bottom of the screen.
1388 // In this configuration, only the top-left tile would be visible.
1389 current_screen_transform
.Translate(600, 750);
1390 current_screen_transform
.RotateAboutZAxis(45);
1391 last_screen_transform
= current_screen_transform
;
1393 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1394 current_screen_transform
, device_viewport
);
1396 client
.SetTileSize(gfx::Size(100, 100));
1397 client
.set_tree(ACTIVE_TREE
);
1399 scoped_refptr
<FakePicturePileImpl
> pile
=
1400 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1401 current_layer_bounds
);
1402 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1403 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1404 LayerTreeSettings());
1406 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1407 current_layer_contents_scale
,
1408 current_frame_time_in_seconds
, Occlusion());
1409 tiling
->UpdateAllTilePrioritiesForTesting();
1411 ASSERT_TRUE(tiling
->TileAt(0, 0));
1412 ASSERT_TRUE(tiling
->TileAt(0, 1));
1413 ASSERT_TRUE(tiling
->TileAt(1, 0));
1414 ASSERT_TRUE(tiling
->TileAt(1, 1));
1416 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1417 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1418 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1420 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1421 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1422 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1424 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1425 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1426 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1428 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1429 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1430 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1432 // Furthermore, in this scenario the bottom-right tile should have the larger
1433 // distance to visible.
1434 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1435 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1436 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1437 EXPECT_GT(top_right
.distance_to_visible
, top_left
.distance_to_visible
);
1439 EXPECT_EQ(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1442 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayer
) {
1443 // Perspective transforms need to take a different code path.
1444 // This test checks tile priorities of a perspective layer.
1445 FakePictureLayerTilingClient client
;
1447 gfx::Size
device_viewport(800, 600);
1448 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscreen.
1449 gfx::Size
last_layer_bounds(200, 200);
1450 gfx::Size
current_layer_bounds(200, 200);
1451 float current_layer_contents_scale
= 1.f
;
1452 gfx::Transform last_screen_transform
;
1453 gfx::Transform current_screen_transform
;
1454 double current_frame_time_in_seconds
= 1.0;
1456 // A 3d perspective layer rotated about its Y axis, translated to almost
1457 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1458 // the right side, so the top-left tile will technically be closer than the
1461 // Translate layer to offscreen
1462 current_screen_transform
.Translate(400.0, 630.0);
1463 // Apply perspective about the center of the layer
1464 current_screen_transform
.Translate(100.0, 100.0);
1465 current_screen_transform
.ApplyPerspectiveDepth(100.0);
1466 current_screen_transform
.RotateAboutYAxis(10.0);
1467 current_screen_transform
.Translate(-100.0, -100.0);
1468 last_screen_transform
= current_screen_transform
;
1470 // Sanity check that this transform wouldn't cause w<0 clipping.
1472 MathUtil::MapQuad(current_screen_transform
,
1473 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1475 ASSERT_FALSE(clipped
);
1477 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1478 current_screen_transform
, device_viewport
);
1480 client
.SetTileSize(gfx::Size(100, 100));
1481 client
.set_tree(ACTIVE_TREE
);
1483 scoped_refptr
<FakePicturePileImpl
> pile
=
1484 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1485 current_layer_bounds
);
1486 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1487 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1488 LayerTreeSettings());
1490 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1491 current_layer_contents_scale
,
1492 current_frame_time_in_seconds
, Occlusion());
1493 tiling
->UpdateAllTilePrioritiesForTesting();
1495 ASSERT_TRUE(tiling
->TileAt(0, 0));
1496 ASSERT_TRUE(tiling
->TileAt(0, 1));
1497 ASSERT_TRUE(tiling
->TileAt(1, 0));
1498 ASSERT_TRUE(tiling
->TileAt(1, 1));
1500 // All tiles will have a positive distance_to_visible
1501 // and an infinite time_to_visible.
1502 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1503 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1504 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1506 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1507 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1508 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1510 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1511 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1512 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1514 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1515 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1516 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1518 // Furthermore, in this scenario the top-left distance_to_visible
1519 // will be smallest, followed by top-right. The bottom layers
1520 // will of course be further than the top layers.
1521 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1522 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1523 TilePriority bottom_left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1524 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1526 EXPECT_GT(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1528 EXPECT_GT(bottom_left
.distance_to_visible
, top_left
.distance_to_visible
);
1531 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayerClippedByW
) {
1532 // Perspective transforms need to take a different code path.
1533 // This test checks tile priorities of a perspective layer.
1534 FakePictureLayerTilingClient client
;
1536 gfx::Size
device_viewport(800, 600);
1537 gfx::Size
last_layer_bounds(200, 200);
1538 gfx::Size
current_layer_bounds(200, 200);
1539 float current_layer_contents_scale
= 1.f
;
1540 gfx::Transform last_screen_transform
;
1541 gfx::Transform current_screen_transform
;
1542 double current_frame_time_in_seconds
= 1.0;
1544 // A 3d perspective layer rotated about its Y axis, translated to almost
1545 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1546 // the right side, so the top-left tile will technically be closer than the
1549 // Translate layer to offscreen
1550 current_screen_transform
.Translate(400.0, 970.0);
1551 // Apply perspective and rotation about the center of the layer
1552 current_screen_transform
.Translate(100.0, 100.0);
1553 current_screen_transform
.ApplyPerspectiveDepth(10.0);
1554 current_screen_transform
.RotateAboutYAxis(10.0);
1555 current_screen_transform
.Translate(-100.0, -100.0);
1556 last_screen_transform
= current_screen_transform
;
1558 // Sanity check that this transform does cause w<0 clipping for the left side
1559 // of the layer, but not the right side.
1561 MathUtil::MapQuad(current_screen_transform
,
1562 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1564 ASSERT_TRUE(clipped
);
1566 MathUtil::MapQuad(current_screen_transform
,
1567 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1569 ASSERT_FALSE(clipped
);
1571 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1572 current_screen_transform
, device_viewport
);
1574 client
.SetTileSize(gfx::Size(100, 100));
1575 client
.set_tree(ACTIVE_TREE
);
1577 scoped_refptr
<FakePicturePileImpl
> pile
=
1578 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1579 current_layer_bounds
);
1580 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1581 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1582 LayerTreeSettings());
1584 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1585 current_layer_contents_scale
,
1586 current_frame_time_in_seconds
, Occlusion());
1587 tiling
->UpdateAllTilePrioritiesForTesting();
1589 ASSERT_TRUE(tiling
->TileAt(0, 0));
1590 ASSERT_TRUE(tiling
->TileAt(0, 1));
1591 ASSERT_TRUE(tiling
->TileAt(1, 0));
1592 ASSERT_TRUE(tiling
->TileAt(1, 1));
1594 // Left-side tiles will be clipped by the transform, so we have to assume
1595 // they are visible just in case.
1596 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1597 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1598 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1600 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1601 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1602 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1604 // Right-side tiles will have a positive distance_to_visible
1605 // and an infinite time_to_visible.
1606 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1607 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1608 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1610 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1611 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1612 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1615 TEST(ComputeTilePriorityRectsTest
, BasicMotion
) {
1616 // Test that time_to_visible is computed correctly when
1617 // there is some motion.
1618 FakePictureLayerTilingClient client
;
1620 gfx::Size
device_viewport(800, 600);
1621 gfx::Rect
visible_layer_rect(0, 0, 0, 0);
1622 gfx::Size
last_layer_bounds(200, 200);
1623 gfx::Size
current_layer_bounds(200, 200);
1624 float last_layer_contents_scale
= 1.f
;
1625 float current_layer_contents_scale
= 1.f
;
1626 gfx::Transform last_screen_transform
;
1627 gfx::Transform current_screen_transform
;
1628 double last_frame_time_in_seconds
= 1.0;
1629 double current_frame_time_in_seconds
= 2.0;
1631 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1632 current_screen_transform
.Translate(1800, 0);
1633 last_screen_transform
.Translate(2800, 0);
1635 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1636 current_screen_transform
, device_viewport
);
1638 client
.SetTileSize(gfx::Size(100, 100));
1639 client
.set_tree(ACTIVE_TREE
);
1640 LayerTreeSettings settings
;
1641 settings
.max_tiles_for_interest_area
= 10000;
1643 scoped_refptr
<FakePicturePileImpl
> pile
=
1644 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1645 current_layer_bounds
);
1646 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1647 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
, settings
);
1649 // previous ("last") frame
1650 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1651 last_layer_contents_scale
,
1652 last_frame_time_in_seconds
, Occlusion());
1655 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1656 current_layer_contents_scale
,
1657 current_frame_time_in_seconds
, Occlusion());
1658 tiling
->UpdateAllTilePrioritiesForTesting();
1660 ASSERT_TRUE(tiling
->TileAt(0, 0));
1661 ASSERT_TRUE(tiling
->TileAt(0, 1));
1662 ASSERT_TRUE(tiling
->TileAt(1, 0));
1663 ASSERT_TRUE(tiling
->TileAt(1, 1));
1665 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1666 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1667 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1669 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1670 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1671 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1673 // time_to_visible for the right hand side layers needs an extra 0.099
1674 // seconds because this tile is 99 pixels further away.
1675 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1676 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1677 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1679 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1680 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1681 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1684 TEST(ComputeTilePriorityRectsTest
, RotationMotion
) {
1685 // Each tile of a layer may be affected differently by a transform; Check
1686 // that ComputeTilePriorityRects correctly accounts for the transform between
1687 // layer space and screen space.
1689 FakePictureLayerTilingClient client
;
1690 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1692 gfx::Size
device_viewport(800, 600);
1693 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscren.
1694 gfx::Size
last_layer_bounds(200, 200);
1695 gfx::Size
current_layer_bounds(200, 200);
1696 float last_layer_contents_scale
= 1.f
;
1697 float current_layer_contents_scale
= 1.f
;
1698 gfx::Transform last_screen_transform
;
1699 gfx::Transform current_screen_transform
;
1700 double last_frame_time_in_seconds
= 1.0;
1701 double current_frame_time_in_seconds
= 2.0;
1703 // Rotation motion is set up specifically so that:
1704 // - rotation occurs about the center of the layer
1705 // - the top-left tile becomes visible on rotation
1706 // - the top-right tile will have an infinite time_to_visible
1707 // because it is rotating away from viewport.
1708 // - bottom-left layer will have a positive non-zero time_to_visible
1709 // because it is rotating toward the viewport.
1710 current_screen_transform
.Translate(400, 550);
1711 current_screen_transform
.RotateAboutZAxis(45);
1713 last_screen_transform
.Translate(400, 550);
1715 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1716 current_screen_transform
, device_viewport
);
1718 client
.SetTileSize(gfx::Size(100, 100));
1719 client
.set_tree(ACTIVE_TREE
);
1721 scoped_refptr
<FakePicturePileImpl
> pile
=
1722 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1723 current_layer_bounds
);
1724 tiling
= TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1725 LayerTreeSettings());
1727 // previous ("last") frame
1728 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1729 last_layer_contents_scale
,
1730 last_frame_time_in_seconds
, Occlusion());
1733 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1734 current_layer_contents_scale
,
1735 current_frame_time_in_seconds
, Occlusion());
1736 tiling
->UpdateAllTilePrioritiesForTesting();
1738 ASSERT_TRUE(tiling
->TileAt(0, 0));
1739 ASSERT_TRUE(tiling
->TileAt(0, 1));
1740 ASSERT_TRUE(tiling
->TileAt(1, 0));
1741 ASSERT_TRUE(tiling
->TileAt(1, 1));
1743 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1744 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1745 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1747 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1748 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1749 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1751 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1752 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1753 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1756 TEST(PictureLayerTilingTest
, RecycledTilesCleared
) {
1757 // This test performs the following:
1759 // - Two tilings, one active one recycled with all tiles shared.
1761 // - Viewport moves somewhere far away and active tiling clears tiles.
1762 // - Viewport moves back and a new active tiling tile is created.
1764 // - Recycle tiling does _not_ have the tile in the same location (thus it
1765 // will be shared next time a pending tiling is created).
1767 FakePictureLayerTilingClient active_client
;
1769 active_client
.SetTileSize(gfx::Size(100, 100));
1770 active_client
.set_tree(ACTIVE_TREE
);
1771 LayerTreeSettings settings
;
1772 settings
.max_tiles_for_interest_area
= 10;
1774 scoped_refptr
<FakePicturePileImpl
> pile
=
1775 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1776 gfx::Size(10000, 10000));
1777 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1778 TestablePictureLayerTiling::Create(1.0f
, pile
, &active_client
, settings
);
1779 // Create all tiles on this tiling.
1780 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1783 FakePictureLayerTilingClient recycle_client
;
1784 recycle_client
.SetTileSize(gfx::Size(100, 100));
1785 recycle_client
.set_tree(PENDING_TREE
);
1786 recycle_client
.set_twin_tiling(active_tiling
.get());
1788 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1789 gfx::Size(10000, 10000));
1790 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1791 TestablePictureLayerTiling::Create(1.0f
, pile
, &recycle_client
, settings
);
1793 // Create all tiles on the second tiling. All tiles should be shared.
1794 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1797 // Set the second tiling as recycled.
1798 active_client
.set_twin_tiling(NULL
);
1799 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
1800 recycle_client
.set_twin_tiling(NULL
);
1802 // Verify that tiles exist and are shared.
1803 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1804 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1805 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
1807 // Move the viewport far away from the (0, 0) tile.
1808 active_tiling
->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f
,
1810 // Ensure the tile was deleted on both tilings.
1811 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1812 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1814 // Move the viewport back to (0, 0) tile.
1815 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 3.0,
1818 // Ensure that we now have a tile here on both tilings again.
1819 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1820 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1823 TEST(PictureLayerTilingTest
, RecycledTilesClearedOnReset
) {
1824 FakePictureLayerTilingClient active_client
;
1825 active_client
.SetTileSize(gfx::Size(100, 100));
1826 active_client
.set_tree(ACTIVE_TREE
);
1828 scoped_refptr
<FakePicturePileImpl
> pile
=
1829 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1830 gfx::Size(100, 100));
1831 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1832 TestablePictureLayerTiling::Create(1.0f
, pile
, &active_client
,
1833 LayerTreeSettings());
1834 // Create all tiles on this tiling.
1835 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1838 FakePictureLayerTilingClient recycle_client
;
1839 recycle_client
.SetTileSize(gfx::Size(100, 100));
1840 recycle_client
.set_tree(PENDING_TREE
);
1841 recycle_client
.set_twin_tiling(active_tiling
.get());
1843 LayerTreeSettings settings
;
1844 settings
.max_tiles_for_interest_area
= 10;
1846 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1847 gfx::Size(100, 100));
1848 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1849 TestablePictureLayerTiling::Create(1.0f
, pile
, &recycle_client
, settings
);
1851 // Create all tiles on the recycle tiling. All tiles should be shared.
1852 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1855 // Set the second tiling as recycled.
1856 active_client
.set_twin_tiling(NULL
);
1857 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
1858 recycle_client
.set_twin_tiling(NULL
);
1860 // Verify that tiles exist and are shared.
1861 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1862 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1863 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
1865 // Reset the active tiling. The recycle tiles should be released too.
1866 active_tiling
->Reset();
1867 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1868 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1871 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilesAndUpdateToCurrent
) {
1872 // The tiling has four rows and three columns.
1873 Initialize(gfx::Size(150, 100), 1.f
, gfx::Size(250, 150));
1874 tiling_
->CreateAllTilesForTesting();
1875 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1876 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1877 EXPECT_EQ(4u, tiling_
->AllRefTilesForTesting().size());
1879 client_
.SetTileSize(gfx::Size(250, 200));
1880 client_
.set_tree(PENDING_TREE
);
1882 // Tile size in the tiling should still be 150x100.
1883 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1884 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1886 // The layer's size isn't changed, but the tile size was.
1887 scoped_refptr
<FakePicturePileImpl
> pile
=
1888 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1889 gfx::Size(250, 150));
1890 tiling_
->SetRasterSourceAndResize(pile
);
1892 // Tile size in the tiling should be resized to 250x200.
1893 EXPECT_EQ(250, tiling_
->TilingDataForTesting().max_texture_size().width());
1894 EXPECT_EQ(200, tiling_
->TilingDataForTesting().max_texture_size().height());
1895 EXPECT_EQ(0u, tiling_
->AllRefTilesForTesting().size());