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 gfx::Rect soon_rect
= viewport
;
695 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
696 gfx::Rect soon_rect_in_content_space
=
697 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect
, 0.25f
));
700 for (int i
= 0; i
< 47; ++i
) {
701 for (int j
= 0; j
< 47; ++j
) {
702 EXPECT_TRUE(tiling
->TileAt(i
, j
)) << "i: " << i
<< " j: " << j
;
705 for (int i
= 0; i
< 47; ++i
) {
706 EXPECT_FALSE(tiling
->TileAt(i
, 47)) << "i: " << i
;
707 EXPECT_FALSE(tiling
->TileAt(47, i
)) << "i: " << i
;
710 // No movement in the viewport implies that tiles will either be NOW
711 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
712 // pixels away from the viewport, which will be in the SOON bin.
713 bool have_now
= false;
714 bool have_eventually
= false;
715 bool have_soon
= false;
716 for (int i
= 0; i
< 47; ++i
) {
717 for (int j
= 0; j
< 47; ++j
) {
718 Tile
* tile
= tiling
->TileAt(i
, j
);
719 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
721 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
722 if (viewport_in_content_space
.Intersects(tile_rect
)) {
723 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
724 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
726 } else if (soon_rect_in_content_space
.Intersects(tile_rect
)) {
727 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
);
730 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
);
731 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
732 have_eventually
= true;
737 EXPECT_TRUE(have_now
);
738 EXPECT_TRUE(have_soon
);
739 EXPECT_TRUE(have_eventually
);
741 // Spot check some distances.
742 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
743 // so the distance to a viewport that ends at 25x25 in content space
744 // should be 17 (41 - 25 + 1). In layer space, then that should be
745 // 17 / 0.25 = 68 pixels.
747 // We can verify that the content rect (with borders) is one pixel off
748 // 41,9 8x8 on all sides.
749 EXPECT_EQ(tiling
->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
751 TilePriority priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
752 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
754 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
755 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
757 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
758 EXPECT_FLOAT_EQ(40.f
, priority
.distance_to_visible
);
760 // Move the viewport down 40 pixels.
761 viewport
= gfx::Rect(0, 40, 100, 100);
762 viewport_in_content_space
=
763 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
764 gfx::Rect skewport
= tiling
->ComputeSkewport(2.0, viewport_in_content_space
);
766 soon_rect
= viewport
;
767 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
768 soon_rect_in_content_space
=
769 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect
, 0.25f
));
771 EXPECT_EQ(0, skewport
.x());
772 EXPECT_EQ(10, skewport
.y());
773 EXPECT_EQ(25, skewport
.width());
774 EXPECT_EQ(35, skewport
.height());
776 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 2.0, Occlusion());
777 tiling
->UpdateAllTilePrioritiesForTesting();
780 have_eventually
= false;
783 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
784 // some EVENTUALLY tiles.
785 for (int i
= 0; i
< 47; ++i
) {
786 for (int j
= 0; j
< 47; ++j
) {
787 Tile
* tile
= tiling
->TileAt(i
, j
);
788 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
790 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
791 if (viewport_in_content_space
.Intersects(tile_rect
)) {
792 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
) << "i: " << i
794 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
) << "i: " << i
797 } else if (skewport
.Intersects(tile_rect
) ||
798 soon_rect_in_content_space
.Intersects(tile_rect
)) {
799 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
) << "i: " << i
801 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
805 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
)
806 << "i: " << i
<< " j: " << j
;
807 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
809 have_eventually
= true;
814 EXPECT_TRUE(have_now
);
815 EXPECT_TRUE(have_soon
);
816 EXPECT_TRUE(have_eventually
);
818 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
819 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
821 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
822 EXPECT_FLOAT_EQ(28.f
, priority
.distance_to_visible
);
824 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
825 EXPECT_FLOAT_EQ(4.f
, priority
.distance_to_visible
);
827 // Change the underlying layer scale.
828 tiling
->ComputeTilePriorityRects(viewport
, 2.0f
, 3.0, Occlusion());
829 tiling
->UpdateAllTilePrioritiesForTesting();
831 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
832 EXPECT_FLOAT_EQ(136.f
, priority
.distance_to_visible
);
834 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
835 EXPECT_FLOAT_EQ(56.f
, priority
.distance_to_visible
);
837 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
838 EXPECT_FLOAT_EQ(8.f
, priority
.distance_to_visible
);
840 // Test additional scales.
841 tiling
= TestablePictureLayerTiling::Create(0.2f
, pile
, &client
,
842 LayerTreeSettings());
843 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 4.0, Occlusion());
844 tiling
->UpdateAllTilePrioritiesForTesting();
846 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
847 EXPECT_FLOAT_EQ(110.f
, priority
.distance_to_visible
);
849 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
850 EXPECT_FLOAT_EQ(70.f
, priority
.distance_to_visible
);
852 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
853 EXPECT_FLOAT_EQ(60.f
, priority
.distance_to_visible
);
855 tiling
->ComputeTilePriorityRects(viewport
, 0.5f
, 5.0, Occlusion());
856 tiling
->UpdateAllTilePrioritiesForTesting();
858 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
859 EXPECT_FLOAT_EQ(55.f
, priority
.distance_to_visible
);
861 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
862 EXPECT_FLOAT_EQ(35.f
, priority
.distance_to_visible
);
864 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
865 EXPECT_FLOAT_EQ(30.f
, priority
.distance_to_visible
);
868 TEST(PictureLayerTilingTest
, ExpandRectEqual
) {
869 gfx::Rect
in(40, 50, 100, 200);
870 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
871 int64 target_area
= 100 * 200;
872 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
873 in
, target_area
, bounds
, NULL
);
874 EXPECT_EQ(in
.ToString(), out
.ToString());
877 TEST(PictureLayerTilingTest
, ExpandRectSmaller
) {
878 gfx::Rect
in(40, 50, 100, 200);
879 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
880 int64 target_area
= 100 * 100;
881 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
882 in
, target_area
, bounds
, NULL
);
883 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
884 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
885 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
887 // |in| represents the visible rect, and |out| represents the eventually rect.
888 // If the eventually rect doesn't contain the visible rect, we will start
890 EXPECT_TRUE(out
.Contains(in
));
891 EXPECT_TRUE(bounds
.Contains(out
));
894 TEST(PictureLayerTilingTest
, ExpandRectUnbounded
) {
895 gfx::Rect
in(40, 50, 100, 200);
896 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
897 int64 target_area
= 200 * 200;
898 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
899 in
, target_area
, bounds
, NULL
);
900 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
901 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
902 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
903 EXPECT_NEAR(200 * 200, out
.width() * out
.height(), 100);
904 EXPECT_TRUE(bounds
.Contains(out
));
907 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmaller
) {
908 gfx::Rect
in(40, 50, 100, 200);
909 gfx::Rect
bounds(50, 60, 40, 30);
910 int64 target_area
= 200 * 200;
911 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
912 in
, target_area
, bounds
, NULL
);
913 EXPECT_EQ(bounds
.ToString(), out
.ToString());
916 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqual
) {
917 gfx::Rect
in(40, 50, 100, 200);
918 gfx::Rect bounds
= in
;
919 int64 target_area
= 200 * 200;
920 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
921 in
, target_area
, bounds
, NULL
);
922 EXPECT_EQ(bounds
.ToString(), out
.ToString());
925 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchVertical
) {
926 gfx::Rect
in(40, 50, 100, 200);
927 gfx::Rect
bounds(45, 0, 90, 300);
928 int64 target_area
= 200 * 200;
929 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
930 in
, target_area
, bounds
, NULL
);
931 EXPECT_EQ(bounds
.ToString(), out
.ToString());
934 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchVertical
) {
935 gfx::Rect
in(40, 50, 100, 200);
936 gfx::Rect
bounds(40, 0, 100, 300);
937 int64 target_area
= 200 * 200;
938 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
939 in
, target_area
, bounds
, NULL
);
940 EXPECT_EQ(bounds
.ToString(), out
.ToString());
943 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchHorizontal
) {
944 gfx::Rect
in(40, 50, 100, 200);
945 gfx::Rect
bounds(0, 55, 180, 190);
946 int64 target_area
= 200 * 200;
947 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
948 in
, target_area
, bounds
, NULL
);
949 EXPECT_EQ(bounds
.ToString(), out
.ToString());
952 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchHorizontal
) {
953 gfx::Rect
in(40, 50, 100, 200);
954 gfx::Rect
bounds(0, 50, 180, 200);
955 int64 target_area
= 200 * 200;
956 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
957 in
, target_area
, bounds
, NULL
);
958 EXPECT_EQ(bounds
.ToString(), out
.ToString());
961 TEST(PictureLayerTilingTest
, ExpandRectBoundedLeft
) {
962 gfx::Rect
in(40, 50, 100, 200);
963 gfx::Rect
bounds(20, -1000, 10000, 10000);
964 int64 target_area
= 200 * 200;
965 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
966 in
, target_area
, bounds
, NULL
);
967 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
968 EXPECT_EQ(out
.bottom() - in
.bottom(), out
.right() - in
.right());
969 EXPECT_LE(out
.width() * out
.height(), target_area
);
970 EXPECT_GT(out
.width() * out
.height(),
971 target_area
- out
.width() - out
.height() * 2);
972 EXPECT_TRUE(bounds
.Contains(out
));
975 TEST(PictureLayerTilingTest
, ExpandRectBoundedRight
) {
976 gfx::Rect
in(40, 50, 100, 200);
977 gfx::Rect
bounds(-1000, -1000, 1000+120, 10000);
978 int64 target_area
= 200 * 200;
979 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
980 in
, target_area
, bounds
, NULL
);
981 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
982 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.x() - out
.x());
983 EXPECT_LE(out
.width() * out
.height(), target_area
);
984 EXPECT_GT(out
.width() * out
.height(),
985 target_area
- out
.width() - out
.height() * 2);
986 EXPECT_TRUE(bounds
.Contains(out
));
989 TEST(PictureLayerTilingTest
, ExpandRectBoundedTop
) {
990 gfx::Rect
in(40, 50, 100, 200);
991 gfx::Rect
bounds(-1000, 30, 10000, 10000);
992 int64 target_area
= 200 * 200;
993 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
994 in
, target_area
, bounds
, NULL
);
995 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
996 EXPECT_EQ(out
.right() - in
.right(), out
.bottom() - in
.bottom());
997 EXPECT_LE(out
.width() * out
.height(), target_area
);
998 EXPECT_GT(out
.width() * out
.height(),
999 target_area
- out
.width() * 2 - out
.height());
1000 EXPECT_TRUE(bounds
.Contains(out
));
1003 TEST(PictureLayerTilingTest
, ExpandRectBoundedBottom
) {
1004 gfx::Rect
in(40, 50, 100, 200);
1005 gfx::Rect
bounds(-1000, -1000, 10000, 1000 + 220);
1006 int64 target_area
= 200 * 200;
1007 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1008 in
, target_area
, bounds
, NULL
);
1009 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1010 EXPECT_EQ(out
.right() - in
.right(), in
.y() - out
.y());
1011 EXPECT_LE(out
.width() * out
.height(), target_area
);
1012 EXPECT_GT(out
.width() * out
.height(),
1013 target_area
- out
.width() * 2 - out
.height());
1014 EXPECT_TRUE(bounds
.Contains(out
));
1017 TEST(PictureLayerTilingTest
, ExpandRectSquishedHorizontally
) {
1018 gfx::Rect
in(40, 50, 100, 200);
1019 gfx::Rect
bounds(0, -4000, 100+40+20, 100000);
1020 int64 target_area
= 400 * 400;
1021 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1022 in
, target_area
, bounds
, NULL
);
1023 EXPECT_EQ(20, out
.right() - in
.right());
1024 EXPECT_EQ(40, in
.x() - out
.x());
1025 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1026 EXPECT_LE(out
.width() * out
.height(), target_area
);
1027 EXPECT_GT(out
.width() * out
.height(),
1028 target_area
- out
.width() * 2);
1029 EXPECT_TRUE(bounds
.Contains(out
));
1032 TEST(PictureLayerTilingTest
, ExpandRectSquishedVertically
) {
1033 gfx::Rect
in(40, 50, 100, 200);
1034 gfx::Rect
bounds(-4000, 0, 100000, 200+50+30);
1035 int64 target_area
= 400 * 400;
1036 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1037 in
, target_area
, bounds
, NULL
);
1038 EXPECT_EQ(30, out
.bottom() - in
.bottom());
1039 EXPECT_EQ(50, in
.y() - out
.y());
1040 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1041 EXPECT_LE(out
.width() * out
.height(), target_area
);
1042 EXPECT_GT(out
.width() * out
.height(),
1043 target_area
- out
.height() * 2);
1044 EXPECT_TRUE(bounds
.Contains(out
));
1047 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsFarAway
) {
1048 gfx::Rect
in(400, 500, 100, 200);
1049 gfx::Rect
bounds(0, 0, 10, 10);
1050 int64 target_area
= 400 * 400;
1051 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1052 in
, target_area
, bounds
, NULL
);
1053 EXPECT_TRUE(out
.IsEmpty());
1056 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedFullyCover
) {
1057 gfx::Rect
in(40, 50, 100, 100);
1058 gfx::Rect
bounds(0, 0, 10, 10);
1059 int64 target_area
= 400 * 400;
1060 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1061 in
, target_area
, bounds
, NULL
);
1062 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1065 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedPartlyCover
) {
1066 gfx::Rect
in(600, 600, 100, 100);
1067 gfx::Rect
bounds(0, 0, 500, 500);
1068 int64 target_area
= 400 * 400;
1069 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1070 in
, target_area
, bounds
, NULL
);
1071 EXPECT_EQ(bounds
.right(), out
.right());
1072 EXPECT_EQ(bounds
.bottom(), out
.bottom());
1073 EXPECT_LE(out
.width() * out
.height(), target_area
);
1074 EXPECT_GT(out
.width() * out
.height(),
1075 target_area
- out
.width() - out
.height());
1076 EXPECT_TRUE(bounds
.Contains(out
));
1079 TEST(PictureLayerTilingTest
, EmptyStartingRect
) {
1080 // If a layer has a non-invertible transform, then the starting rect
1081 // for the layer would be empty.
1082 gfx::Rect
in(40, 40, 0, 0);
1083 gfx::Rect
bounds(0, 0, 10, 10);
1084 int64 target_area
= 400 * 400;
1085 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1086 in
, target_area
, bounds
, NULL
);
1087 EXPECT_TRUE(out
.IsEmpty());
1090 static void TileExists(bool exists
, Tile
* tile
,
1091 const gfx::Rect
& geometry_rect
) {
1092 EXPECT_EQ(exists
, tile
!= NULL
) << geometry_rect
.ToString();
1095 TEST_F(PictureLayerTilingIteratorTest
, TilesExist
) {
1096 gfx::Size
layer_bounds(1099, 801);
1097 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1098 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1099 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1101 client_
.set_tree(ACTIVE_TREE
);
1102 tiling_
->ComputeTilePriorityRects(
1103 gfx::Rect(layer_bounds
), // visible content rect
1104 1.f
, // current contents scale
1105 1.0, // current frame time
1107 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1109 // Make the viewport rect empty. All tiles are killed and become zombies.
1110 tiling_
->ComputeTilePriorityRects(gfx::Rect(), // visible content rect
1111 1.f
, // current contents scale
1112 2.0, // current frame time
1114 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1117 TEST_F(PictureLayerTilingIteratorTest
, TilesExistGiantViewport
) {
1118 gfx::Size
layer_bounds(1099, 801);
1119 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1120 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1121 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1123 gfx::Rect
giant_rect(-10000000, -10000000, 1000000000, 1000000000);
1125 client_
.set_tree(ACTIVE_TREE
);
1126 tiling_
->ComputeTilePriorityRects(
1127 gfx::Rect(layer_bounds
), // visible content rect
1128 1.f
, // current contents scale
1129 1.0, // current frame time
1131 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1133 // If the visible content rect is empty, it should still have live tiles.
1134 tiling_
->ComputeTilePriorityRects(giant_rect
, // visible content rect
1135 1.f
, // current contents scale
1136 2.0, // current frame time
1138 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1141 TEST_F(PictureLayerTilingIteratorTest
, TilesExistOutsideViewport
) {
1142 gfx::Size
layer_bounds(1099, 801);
1143 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1144 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1145 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1147 // This rect does not intersect with the layer, as the layer is outside the
1149 gfx::Rect
viewport_rect(1100, 0, 1000, 1000);
1150 EXPECT_FALSE(viewport_rect
.Intersects(gfx::Rect(layer_bounds
)));
1152 client_
.set_tree(ACTIVE_TREE
);
1153 tiling_
->ComputeTilePriorityRects(viewport_rect
, // visible content rect
1154 1.f
, // current contents scale
1155 1.0, // current frame time
1157 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1160 static void TilesIntersectingRectExist(const gfx::Rect
& rect
,
1161 bool intersect_exists
,
1163 const gfx::Rect
& geometry_rect
) {
1164 bool intersects
= rect
.Intersects(geometry_rect
);
1165 bool expected_exists
= intersect_exists
? intersects
: !intersects
;
1166 EXPECT_EQ(expected_exists
, tile
!= NULL
)
1167 << "Rects intersecting " << rect
.ToString() << " should exist. "
1168 << "Current tile rect is " << geometry_rect
.ToString();
1171 TEST_F(PictureLayerTilingIteratorTest
,
1172 TilesExistLargeViewportAndLayerWithSmallVisibleArea
) {
1173 gfx::Size
layer_bounds(10000, 10000);
1174 client_
.SetTileSize(gfx::Size(100, 100));
1175 client_
.set_tree(PENDING_TREE
);
1176 LayerTreeSettings settings
;
1177 settings
.max_tiles_for_interest_area
= 1;
1179 scoped_refptr
<FakePicturePileImpl
> pile
=
1180 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1181 tiling_
= TestablePictureLayerTiling::Create(1.f
, pile
, &client_
, settings
);
1182 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1183 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1185 gfx::Rect
visible_rect(8000, 8000, 50, 50);
1187 client_
.set_tree(ACTIVE_TREE
);
1188 tiling_
->ComputeTilePriorityRects(visible_rect
, // visible content rect
1189 1.f
, // current contents scale
1190 1.0, // current frame time
1193 gfx::Rect(layer_bounds
),
1194 base::Bind(&TilesIntersectingRectExist
, visible_rect
, true));
1197 TEST(ComputeTilePriorityRectsTest
, VisibleTiles
) {
1198 // The TilePriority of visible tiles should have zero distance_to_visible
1199 // and time_to_visible.
1200 FakePictureLayerTilingClient client
;
1202 gfx::Size
device_viewport(800, 600);
1203 gfx::Size
last_layer_bounds(200, 200);
1204 gfx::Size
current_layer_bounds(200, 200);
1205 float current_layer_contents_scale
= 1.f
;
1206 gfx::Transform current_screen_transform
;
1207 double current_frame_time_in_seconds
= 1.0;
1209 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1210 current_screen_transform
, device_viewport
);
1212 client
.SetTileSize(gfx::Size(100, 100));
1213 client
.set_tree(ACTIVE_TREE
);
1215 scoped_refptr
<FakePicturePileImpl
> pile
=
1216 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1217 current_layer_bounds
);
1218 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1219 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1220 LayerTreeSettings());
1222 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1223 current_layer_contents_scale
,
1224 current_frame_time_in_seconds
, Occlusion());
1225 tiling
->UpdateAllTilePrioritiesForTesting();
1227 ASSERT_TRUE(tiling
->TileAt(0, 0));
1228 ASSERT_TRUE(tiling
->TileAt(0, 1));
1229 ASSERT_TRUE(tiling
->TileAt(1, 0));
1230 ASSERT_TRUE(tiling
->TileAt(1, 1));
1232 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1233 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1234 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1236 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1237 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1238 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1240 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1241 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1242 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1244 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1245 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1246 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1249 TEST(ComputeTilePriorityRectsTest
, OffscreenTiles
) {
1250 // The TilePriority of offscreen tiles (without movement) should have nonzero
1251 // distance_to_visible and infinite time_to_visible.
1252 FakePictureLayerTilingClient client
;
1254 gfx::Size
device_viewport(800, 600);
1255 gfx::Size
last_layer_bounds(200, 200);
1256 gfx::Size
current_layer_bounds(200, 200);
1257 float current_layer_contents_scale
= 1.f
;
1258 gfx::Transform last_screen_transform
;
1259 gfx::Transform current_screen_transform
;
1260 double current_frame_time_in_seconds
= 1.0;
1262 current_screen_transform
.Translate(850, 0);
1263 last_screen_transform
= current_screen_transform
;
1265 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1266 current_screen_transform
, device_viewport
);
1268 client
.SetTileSize(gfx::Size(100, 100));
1269 client
.set_tree(ACTIVE_TREE
);
1271 scoped_refptr
<FakePicturePileImpl
> pile
=
1272 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1273 current_layer_bounds
);
1274 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1275 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1276 LayerTreeSettings());
1278 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1279 current_layer_contents_scale
,
1280 current_frame_time_in_seconds
, Occlusion());
1281 tiling
->UpdateAllTilePrioritiesForTesting();
1283 ASSERT_TRUE(tiling
->TileAt(0, 0));
1284 ASSERT_TRUE(tiling
->TileAt(0, 1));
1285 ASSERT_TRUE(tiling
->TileAt(1, 0));
1286 ASSERT_TRUE(tiling
->TileAt(1, 1));
1288 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1289 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1290 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1292 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1293 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1294 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1296 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1297 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1298 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1300 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1301 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1302 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1304 // Furthermore, in this scenario tiles on the right hand side should have a
1305 // larger distance to visible.
1306 TilePriority left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1307 TilePriority right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1308 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1310 left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1311 right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1312 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1315 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenLayer
) {
1316 // Sanity check that a layer with some tiles visible and others offscreen has
1317 // correct TilePriorities for each tile.
1318 FakePictureLayerTilingClient client
;
1320 gfx::Size
device_viewport(800, 600);
1321 gfx::Size
last_layer_bounds(200, 200);
1322 gfx::Size
current_layer_bounds(200, 200);
1323 float current_layer_contents_scale
= 1.f
;
1324 gfx::Transform last_screen_transform
;
1325 gfx::Transform current_screen_transform
;
1326 double current_frame_time_in_seconds
= 1.0;
1328 current_screen_transform
.Translate(705, 505);
1329 last_screen_transform
= current_screen_transform
;
1331 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1332 current_screen_transform
, device_viewport
);
1334 client
.SetTileSize(gfx::Size(100, 100));
1335 client
.set_tree(ACTIVE_TREE
);
1337 scoped_refptr
<FakePicturePileImpl
> pile
=
1338 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1339 current_layer_bounds
);
1340 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1341 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1342 LayerTreeSettings());
1344 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1345 current_layer_contents_scale
,
1346 current_frame_time_in_seconds
, Occlusion());
1347 tiling
->UpdateAllTilePrioritiesForTesting();
1349 ASSERT_TRUE(tiling
->TileAt(0, 0));
1350 ASSERT_TRUE(tiling
->TileAt(0, 1));
1351 ASSERT_TRUE(tiling
->TileAt(1, 0));
1352 ASSERT_TRUE(tiling
->TileAt(1, 1));
1354 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1355 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1356 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1358 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1359 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1360 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1362 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1363 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1364 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1366 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1367 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1368 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1371 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenRotatedLayer
) {
1372 // Each tile of a layer may be affected differently by a transform; Check
1373 // that ComputeTilePriorityRects correctly accounts for the transform between
1374 // layer space and screen space.
1375 FakePictureLayerTilingClient client
;
1377 gfx::Size
device_viewport(800, 600);
1378 gfx::Size
last_layer_bounds(200, 200);
1379 gfx::Size
current_layer_bounds(200, 200);
1380 float current_layer_contents_scale
= 1.f
;
1381 gfx::Transform last_screen_transform
;
1382 gfx::Transform current_screen_transform
;
1383 double current_frame_time_in_seconds
= 1.0;
1385 // A diagonally rotated layer that is partially off the bottom of the screen.
1386 // In this configuration, only the top-left tile would be visible.
1387 current_screen_transform
.Translate(600, 750);
1388 current_screen_transform
.RotateAboutZAxis(45);
1389 last_screen_transform
= current_screen_transform
;
1391 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1392 current_screen_transform
, device_viewport
);
1394 client
.SetTileSize(gfx::Size(100, 100));
1395 client
.set_tree(ACTIVE_TREE
);
1397 scoped_refptr
<FakePicturePileImpl
> pile
=
1398 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1399 current_layer_bounds
);
1400 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1401 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1402 LayerTreeSettings());
1404 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1405 current_layer_contents_scale
,
1406 current_frame_time_in_seconds
, Occlusion());
1407 tiling
->UpdateAllTilePrioritiesForTesting();
1409 ASSERT_TRUE(tiling
->TileAt(0, 0));
1410 ASSERT_TRUE(tiling
->TileAt(0, 1));
1411 ASSERT_TRUE(tiling
->TileAt(1, 0));
1412 ASSERT_TRUE(tiling
->TileAt(1, 1));
1414 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1415 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1416 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1418 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1419 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1420 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1422 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1423 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1424 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1426 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1427 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1428 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1430 // Furthermore, in this scenario the bottom-right tile should have the larger
1431 // distance to visible.
1432 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1433 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1434 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1435 EXPECT_GT(top_right
.distance_to_visible
, top_left
.distance_to_visible
);
1437 EXPECT_EQ(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1440 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayer
) {
1441 // Perspective transforms need to take a different code path.
1442 // This test checks tile priorities of a perspective layer.
1443 FakePictureLayerTilingClient client
;
1445 gfx::Size
device_viewport(800, 600);
1446 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscreen.
1447 gfx::Size
last_layer_bounds(200, 200);
1448 gfx::Size
current_layer_bounds(200, 200);
1449 float current_layer_contents_scale
= 1.f
;
1450 gfx::Transform last_screen_transform
;
1451 gfx::Transform current_screen_transform
;
1452 double current_frame_time_in_seconds
= 1.0;
1454 // A 3d perspective layer rotated about its Y axis, translated to almost
1455 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1456 // the right side, so the top-left tile will technically be closer than the
1459 // Translate layer to offscreen
1460 current_screen_transform
.Translate(400.0, 630.0);
1461 // Apply perspective about the center of the layer
1462 current_screen_transform
.Translate(100.0, 100.0);
1463 current_screen_transform
.ApplyPerspectiveDepth(100.0);
1464 current_screen_transform
.RotateAboutYAxis(10.0);
1465 current_screen_transform
.Translate(-100.0, -100.0);
1466 last_screen_transform
= current_screen_transform
;
1468 // Sanity check that this transform wouldn't cause w<0 clipping.
1470 MathUtil::MapQuad(current_screen_transform
,
1471 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1473 ASSERT_FALSE(clipped
);
1475 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1476 current_screen_transform
, device_viewport
);
1478 client
.SetTileSize(gfx::Size(100, 100));
1479 client
.set_tree(ACTIVE_TREE
);
1481 scoped_refptr
<FakePicturePileImpl
> pile
=
1482 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1483 current_layer_bounds
);
1484 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1485 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1486 LayerTreeSettings());
1488 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1489 current_layer_contents_scale
,
1490 current_frame_time_in_seconds
, Occlusion());
1491 tiling
->UpdateAllTilePrioritiesForTesting();
1493 ASSERT_TRUE(tiling
->TileAt(0, 0));
1494 ASSERT_TRUE(tiling
->TileAt(0, 1));
1495 ASSERT_TRUE(tiling
->TileAt(1, 0));
1496 ASSERT_TRUE(tiling
->TileAt(1, 1));
1498 // All tiles will have a positive distance_to_visible
1499 // and an infinite time_to_visible.
1500 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1501 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1502 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1504 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1505 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1506 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1508 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1509 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1510 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1512 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1513 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1514 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1516 // Furthermore, in this scenario the top-left distance_to_visible
1517 // will be smallest, followed by top-right. The bottom layers
1518 // will of course be further than the top layers.
1519 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1520 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1521 TilePriority bottom_left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1522 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1524 EXPECT_GT(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1526 EXPECT_GT(bottom_left
.distance_to_visible
, top_left
.distance_to_visible
);
1529 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayerClippedByW
) {
1530 // Perspective transforms need to take a different code path.
1531 // This test checks tile priorities of a perspective layer.
1532 FakePictureLayerTilingClient client
;
1534 gfx::Size
device_viewport(800, 600);
1535 gfx::Size
last_layer_bounds(200, 200);
1536 gfx::Size
current_layer_bounds(200, 200);
1537 float current_layer_contents_scale
= 1.f
;
1538 gfx::Transform last_screen_transform
;
1539 gfx::Transform current_screen_transform
;
1540 double current_frame_time_in_seconds
= 1.0;
1542 // A 3d perspective layer rotated about its Y axis, translated to almost
1543 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1544 // the right side, so the top-left tile will technically be closer than the
1547 // Translate layer to offscreen
1548 current_screen_transform
.Translate(400.0, 970.0);
1549 // Apply perspective and rotation about the center of the layer
1550 current_screen_transform
.Translate(100.0, 100.0);
1551 current_screen_transform
.ApplyPerspectiveDepth(10.0);
1552 current_screen_transform
.RotateAboutYAxis(10.0);
1553 current_screen_transform
.Translate(-100.0, -100.0);
1554 last_screen_transform
= current_screen_transform
;
1556 // Sanity check that this transform does cause w<0 clipping for the left side
1557 // of the layer, but not the right side.
1559 MathUtil::MapQuad(current_screen_transform
,
1560 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1562 ASSERT_TRUE(clipped
);
1564 MathUtil::MapQuad(current_screen_transform
,
1565 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1567 ASSERT_FALSE(clipped
);
1569 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1570 current_screen_transform
, device_viewport
);
1572 client
.SetTileSize(gfx::Size(100, 100));
1573 client
.set_tree(ACTIVE_TREE
);
1575 scoped_refptr
<FakePicturePileImpl
> pile
=
1576 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1577 current_layer_bounds
);
1578 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1579 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1580 LayerTreeSettings());
1582 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1583 current_layer_contents_scale
,
1584 current_frame_time_in_seconds
, Occlusion());
1585 tiling
->UpdateAllTilePrioritiesForTesting();
1587 ASSERT_TRUE(tiling
->TileAt(0, 0));
1588 ASSERT_TRUE(tiling
->TileAt(0, 1));
1589 ASSERT_TRUE(tiling
->TileAt(1, 0));
1590 ASSERT_TRUE(tiling
->TileAt(1, 1));
1592 // Left-side tiles will be clipped by the transform, so we have to assume
1593 // they are visible just in case.
1594 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1595 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1596 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1598 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1599 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1600 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1602 // Right-side tiles will have a positive distance_to_visible
1603 // and an infinite time_to_visible.
1604 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1605 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1606 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1608 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1609 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1610 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1613 TEST(ComputeTilePriorityRectsTest
, BasicMotion
) {
1614 // Test that time_to_visible is computed correctly when
1615 // there is some motion.
1616 FakePictureLayerTilingClient client
;
1618 gfx::Size
device_viewport(800, 600);
1619 gfx::Rect
visible_layer_rect(0, 0, 0, 0);
1620 gfx::Size
last_layer_bounds(200, 200);
1621 gfx::Size
current_layer_bounds(200, 200);
1622 float last_layer_contents_scale
= 1.f
;
1623 float current_layer_contents_scale
= 1.f
;
1624 gfx::Transform last_screen_transform
;
1625 gfx::Transform current_screen_transform
;
1626 double last_frame_time_in_seconds
= 1.0;
1627 double current_frame_time_in_seconds
= 2.0;
1629 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1630 current_screen_transform
.Translate(1800, 0);
1631 last_screen_transform
.Translate(2800, 0);
1633 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1634 current_screen_transform
, device_viewport
);
1636 client
.SetTileSize(gfx::Size(100, 100));
1637 client
.set_tree(ACTIVE_TREE
);
1638 LayerTreeSettings settings
;
1639 settings
.max_tiles_for_interest_area
= 10000;
1641 scoped_refptr
<FakePicturePileImpl
> pile
=
1642 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1643 current_layer_bounds
);
1644 scoped_ptr
<TestablePictureLayerTiling
> tiling
=
1645 TestablePictureLayerTiling::Create(1.0f
, pile
, &client
, settings
);
1647 // previous ("last") frame
1648 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1649 last_layer_contents_scale
,
1650 last_frame_time_in_seconds
, Occlusion());
1653 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1654 current_layer_contents_scale
,
1655 current_frame_time_in_seconds
, Occlusion());
1656 tiling
->UpdateAllTilePrioritiesForTesting();
1658 ASSERT_TRUE(tiling
->TileAt(0, 0));
1659 ASSERT_TRUE(tiling
->TileAt(0, 1));
1660 ASSERT_TRUE(tiling
->TileAt(1, 0));
1661 ASSERT_TRUE(tiling
->TileAt(1, 1));
1663 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1664 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1665 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1667 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1668 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1669 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1671 // time_to_visible for the right hand side layers needs an extra 0.099
1672 // seconds because this tile is 99 pixels further away.
1673 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1674 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1675 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1677 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1678 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1679 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1682 TEST(ComputeTilePriorityRectsTest
, RotationMotion
) {
1683 // Each tile of a layer may be affected differently by a transform; Check
1684 // that ComputeTilePriorityRects correctly accounts for the transform between
1685 // layer space and screen space.
1687 FakePictureLayerTilingClient client
;
1688 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1690 gfx::Size
device_viewport(800, 600);
1691 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscren.
1692 gfx::Size
last_layer_bounds(200, 200);
1693 gfx::Size
current_layer_bounds(200, 200);
1694 float last_layer_contents_scale
= 1.f
;
1695 float current_layer_contents_scale
= 1.f
;
1696 gfx::Transform last_screen_transform
;
1697 gfx::Transform current_screen_transform
;
1698 double last_frame_time_in_seconds
= 1.0;
1699 double current_frame_time_in_seconds
= 2.0;
1701 // Rotation motion is set up specifically so that:
1702 // - rotation occurs about the center of the layer
1703 // - the top-left tile becomes visible on rotation
1704 // - the top-right tile will have an infinite time_to_visible
1705 // because it is rotating away from viewport.
1706 // - bottom-left layer will have a positive non-zero time_to_visible
1707 // because it is rotating toward the viewport.
1708 current_screen_transform
.Translate(400, 550);
1709 current_screen_transform
.RotateAboutZAxis(45);
1711 last_screen_transform
.Translate(400, 550);
1713 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1714 current_screen_transform
, device_viewport
);
1716 client
.SetTileSize(gfx::Size(100, 100));
1717 client
.set_tree(ACTIVE_TREE
);
1719 scoped_refptr
<FakePicturePileImpl
> pile
=
1720 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1721 current_layer_bounds
);
1722 tiling
= TestablePictureLayerTiling::Create(1.0f
, pile
, &client
,
1723 LayerTreeSettings());
1725 // previous ("last") frame
1726 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1727 last_layer_contents_scale
,
1728 last_frame_time_in_seconds
, Occlusion());
1731 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1732 current_layer_contents_scale
,
1733 current_frame_time_in_seconds
, Occlusion());
1734 tiling
->UpdateAllTilePrioritiesForTesting();
1736 ASSERT_TRUE(tiling
->TileAt(0, 0));
1737 ASSERT_TRUE(tiling
->TileAt(0, 1));
1738 ASSERT_TRUE(tiling
->TileAt(1, 0));
1739 ASSERT_TRUE(tiling
->TileAt(1, 1));
1741 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1742 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1743 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1745 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1746 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1747 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1749 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1750 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1751 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1754 TEST(PictureLayerTilingTest
, RecycledTilesCleared
) {
1755 // This test performs the following:
1757 // - Two tilings, one active one recycled with all tiles shared.
1759 // - Viewport moves somewhere far away and active tiling clears tiles.
1760 // - Viewport moves back and a new active tiling tile is created.
1762 // - Recycle tiling does _not_ have the tile in the same location (thus it
1763 // will be shared next time a pending tiling is created).
1765 FakePictureLayerTilingClient active_client
;
1767 active_client
.SetTileSize(gfx::Size(100, 100));
1768 active_client
.set_tree(ACTIVE_TREE
);
1769 LayerTreeSettings settings
;
1770 settings
.max_tiles_for_interest_area
= 10;
1772 scoped_refptr
<FakePicturePileImpl
> pile
=
1773 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1774 gfx::Size(10000, 10000));
1775 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1776 TestablePictureLayerTiling::Create(1.0f
, pile
, &active_client
, settings
);
1777 // Create all tiles on this tiling.
1778 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1781 FakePictureLayerTilingClient recycle_client
;
1782 recycle_client
.SetTileSize(gfx::Size(100, 100));
1783 recycle_client
.set_tree(PENDING_TREE
);
1784 recycle_client
.set_twin_tiling(active_tiling
.get());
1786 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1787 gfx::Size(10000, 10000));
1788 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1789 TestablePictureLayerTiling::Create(1.0f
, pile
, &recycle_client
, settings
);
1791 // Create all tiles on the second tiling. All tiles should be shared.
1792 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1795 // Set the second tiling as recycled.
1796 active_client
.set_twin_tiling(NULL
);
1797 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
1798 recycle_client
.set_twin_tiling(NULL
);
1800 // Verify that tiles exist and are shared.
1801 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1802 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1803 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
1805 // Move the viewport far away from the (0, 0) tile.
1806 active_tiling
->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f
,
1808 // Ensure the tile was deleted on both tilings.
1809 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1810 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1812 // Move the viewport back to (0, 0) tile.
1813 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 3.0,
1816 // Ensure that we now have a tile here on both tilings again.
1817 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1818 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1821 TEST(PictureLayerTilingTest
, RecycledTilesClearedOnReset
) {
1822 FakePictureLayerTilingClient active_client
;
1823 active_client
.SetTileSize(gfx::Size(100, 100));
1824 active_client
.set_tree(ACTIVE_TREE
);
1826 scoped_refptr
<FakePicturePileImpl
> pile
=
1827 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1828 gfx::Size(100, 100));
1829 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
=
1830 TestablePictureLayerTiling::Create(1.0f
, pile
, &active_client
,
1831 LayerTreeSettings());
1832 // Create all tiles on this tiling.
1833 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1836 FakePictureLayerTilingClient recycle_client
;
1837 recycle_client
.SetTileSize(gfx::Size(100, 100));
1838 recycle_client
.set_tree(PENDING_TREE
);
1839 recycle_client
.set_twin_tiling(active_tiling
.get());
1841 LayerTreeSettings settings
;
1842 settings
.max_tiles_for_interest_area
= 10;
1844 pile
= FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1845 gfx::Size(100, 100));
1846 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
=
1847 TestablePictureLayerTiling::Create(1.0f
, pile
, &recycle_client
, settings
);
1849 // Create all tiles on the recycle tiling. All tiles should be shared.
1850 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1853 // Set the second tiling as recycled.
1854 active_client
.set_twin_tiling(NULL
);
1855 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
1856 recycle_client
.set_twin_tiling(NULL
);
1858 // Verify that tiles exist and are shared.
1859 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
1860 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
1861 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
1863 // Reset the active tiling. The recycle tiles should be released too.
1864 active_tiling
->Reset();
1865 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
1866 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
1869 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilesAndUpdateToCurrent
) {
1870 // The tiling has four rows and three columns.
1871 Initialize(gfx::Size(150, 100), 1.f
, gfx::Size(250, 150));
1872 tiling_
->CreateAllTilesForTesting();
1873 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1874 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1875 EXPECT_EQ(4u, tiling_
->AllRefTilesForTesting().size());
1877 client_
.SetTileSize(gfx::Size(250, 200));
1878 client_
.set_tree(PENDING_TREE
);
1880 // Tile size in the tiling should still be 150x100.
1881 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
1882 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
1884 // The layer's size isn't changed, but the tile size was.
1885 scoped_refptr
<FakePicturePileImpl
> pile
=
1886 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1887 gfx::Size(250, 150));
1888 tiling_
->SetRasterSourceAndResize(pile
);
1890 // Tile size in the tiling should be resized to 250x200.
1891 EXPECT_EQ(250, tiling_
->TilingDataForTesting().max_texture_size().width());
1892 EXPECT_EQ(200, tiling_
->TilingDataForTesting().max_texture_size().height());
1893 EXPECT_EQ(0u, tiling_
->AllRefTilesForTesting().size());