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/test_context_provider.h"
16 #include "cc/test/test_shared_bitmap_manager.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/geometry/quad_f.h"
19 #include "ui/gfx/geometry/rect_conversions.h"
20 #include "ui/gfx/geometry/size_conversions.h"
25 static gfx::Rect
ViewportInLayerSpace(
26 const gfx::Transform
& transform
,
27 const gfx::Size
& device_viewport
) {
29 gfx::Transform inverse
;
30 if (!transform
.GetInverse(&inverse
))
33 gfx::RectF viewport_in_layer_space
= MathUtil::ProjectClippedRect(
34 inverse
, gfx::RectF(gfx::Point(0, 0), device_viewport
));
35 return ToEnclosingRect(viewport_in_layer_space
);
38 static void UpdateAllTilePriorities(PictureLayerTilingSet
* set
,
39 const gfx::Rect
& visible_layer_rect
,
40 float layer_contents_scale
,
41 double current_frame_time_in_seconds
) {
42 for (size_t i
= 0; i
< set
->num_tilings(); ++i
) {
44 ->ComputeTilePriorityRects(visible_layer_rect
, layer_contents_scale
,
45 current_frame_time_in_seconds
, Occlusion());
49 class TestablePictureLayerTiling
: public PictureLayerTiling
{
51 using PictureLayerTiling::SetLiveTilesRect
;
52 using PictureLayerTiling::TileAt
;
54 static scoped_ptr
<TestablePictureLayerTiling
> Create(
56 const gfx::Size
& layer_bounds
,
57 PictureLayerTilingClient
* client
,
58 const LayerTreeSettings
& settings
) {
59 return make_scoped_ptr(new TestablePictureLayerTiling(
60 contents_scale
, layer_bounds
, client
,
61 settings
.max_tiles_for_interest_area
,
62 settings
.skewport_target_time_in_seconds
,
63 settings
.skewport_extrapolation_limit_in_content_pixels
));
66 gfx::Rect
live_tiles_rect() const { return live_tiles_rect_
; }
68 using PictureLayerTiling::ComputeSkewport
;
69 using PictureLayerTiling::RemoveTileAt
;
72 TestablePictureLayerTiling(float contents_scale
,
73 const gfx::Size
& layer_bounds
,
74 PictureLayerTilingClient
* client
,
75 size_t max_tiles_for_interest_area
,
76 float skewport_target_time
,
77 int skewport_extrapolation_limit
)
78 : PictureLayerTiling(contents_scale
,
81 max_tiles_for_interest_area
,
83 skewport_extrapolation_limit
) {}
86 class PictureLayerTilingIteratorTest
: public testing::Test
{
88 PictureLayerTilingIteratorTest() {}
89 virtual ~PictureLayerTilingIteratorTest() {}
91 void Initialize(const gfx::Size
& tile_size
,
93 const gfx::Size
& layer_bounds
) {
94 client_
.SetTileSize(tile_size
);
95 client_
.set_tree(PENDING_TREE
);
96 tiling_
= TestablePictureLayerTiling::Create(contents_scale
, layer_bounds
,
97 &client_
, LayerTreeSettings());
100 void SetLiveRectAndVerifyTiles(const gfx::Rect
& live_tiles_rect
) {
101 tiling_
->SetLiveTilesRect(live_tiles_rect
);
103 std::vector
<Tile
*> tiles
= tiling_
->AllTilesForTesting();
104 for (std::vector
<Tile
*>::iterator iter
= tiles
.begin();
107 EXPECT_TRUE(live_tiles_rect
.Intersects((*iter
)->content_rect()));
111 void VerifyTilesExactlyCoverRect(
113 const gfx::Rect
& request_rect
,
114 const gfx::Rect
& expect_rect
) {
115 EXPECT_TRUE(request_rect
.Contains(expect_rect
));
117 // Iterators are not valid if this ratio is too large (i.e. the
118 // tiling is too high-res for a low-res destination rect.) This is an
119 // artifact of snapping geometry to integer coordinates and then mapping
120 // back to floating point texture coordinates.
121 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
122 ASSERT_LE(dest_to_contents_scale
, 2.0);
124 Region remaining
= expect_rect
;
125 for (PictureLayerTiling::CoverageIterator
126 iter(tiling_
.get(), rect_scale
, request_rect
);
129 // Geometry cannot overlap previous geometry at all
130 gfx::Rect geometry
= iter
.geometry_rect();
131 EXPECT_TRUE(expect_rect
.Contains(geometry
));
132 EXPECT_TRUE(remaining
.Contains(geometry
));
133 remaining
.Subtract(geometry
);
135 // Sanity check that texture coords are within the texture rect.
136 gfx::RectF texture_rect
= iter
.texture_rect();
137 EXPECT_GE(texture_rect
.x(), 0);
138 EXPECT_GE(texture_rect
.y(), 0);
139 EXPECT_LE(texture_rect
.right(), client_
.TileSize().width());
140 EXPECT_LE(texture_rect
.bottom(), client_
.TileSize().height());
142 EXPECT_EQ(iter
.texture_size(), client_
.TileSize());
145 // The entire rect must be filled by geometry from the tiling.
146 EXPECT_TRUE(remaining
.IsEmpty());
149 void VerifyTilesExactlyCoverRect(float rect_scale
, const gfx::Rect
& rect
) {
150 VerifyTilesExactlyCoverRect(rect_scale
, rect
, rect
);
155 const gfx::Rect
& rect
,
156 base::Callback
<void(Tile
* tile
,
157 const gfx::Rect
& geometry_rect
)> callback
) {
158 VerifyTiles(tiling_
.get(),
165 PictureLayerTiling
* tiling
,
167 const gfx::Rect
& rect
,
168 base::Callback
<void(Tile
* tile
,
169 const gfx::Rect
& geometry_rect
)> callback
) {
170 Region remaining
= rect
;
171 for (PictureLayerTiling::CoverageIterator
iter(tiling
, rect_scale
, rect
);
174 remaining
.Subtract(iter
.geometry_rect());
175 callback
.Run(*iter
, iter
.geometry_rect());
177 EXPECT_TRUE(remaining
.IsEmpty());
180 void VerifyTilesCoverNonContainedRect(float rect_scale
,
181 const gfx::Rect
& dest_rect
) {
182 float dest_to_contents_scale
= tiling_
->contents_scale() / rect_scale
;
183 gfx::Rect clamped_rect
= gfx::ScaleToEnclosingRect(
184 gfx::Rect(tiling_
->tiling_size()), 1.f
/ dest_to_contents_scale
);
185 clamped_rect
.Intersect(dest_rect
);
186 VerifyTilesExactlyCoverRect(rect_scale
, dest_rect
, clamped_rect
);
190 FakePictureLayerTilingClient client_
;
191 scoped_ptr
<TestablePictureLayerTiling
> tiling_
;
194 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest
);
197 TEST_F(PictureLayerTilingIteratorTest
, ResizeDeletesTiles
) {
198 // Verifies that a resize with invalidation for newly exposed pixels will
199 // deletes tiles that intersect that invalidation.
200 gfx::Size
tile_size(100, 100);
201 gfx::Size
original_layer_size(10, 10);
202 Initialize(tile_size
, 1.f
, original_layer_size
);
203 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
205 // Tiling only has one tile, since its total size is less than one.
206 EXPECT_TRUE(tiling_
->TileAt(0, 0));
208 // Stop creating tiles so that any invalidations are left as holes.
209 client_
.set_allow_create_tile(false);
211 Region invalidation
=
212 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
213 tiling_
->Resize(gfx::Size(200, 200));
214 EXPECT_TRUE(tiling_
->TileAt(0, 0));
215 tiling_
->Invalidate(invalidation
);
216 EXPECT_FALSE(tiling_
->TileAt(0, 0));
219 TEST_F(PictureLayerTilingIteratorTest
, CreateMissingTilesStaysInsideLiveRect
) {
220 // The tiling has three rows and columns.
221 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 250));
222 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
223 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
225 // The live tiles rect is at the very edge of the right-most and
226 // bottom-most tiles. Their border pixels would still be inside the live
227 // tiles rect, but the tiles should not exist just for that.
228 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
229 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 2).y();
231 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
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));
238 // Verify CreateMissingTilesInLiveTilesRect respects this.
239 tiling_
->CreateMissingTilesInLiveTilesRect();
240 EXPECT_FALSE(tiling_
->TileAt(2, 0));
241 EXPECT_FALSE(tiling_
->TileAt(2, 1));
242 EXPECT_FALSE(tiling_
->TileAt(2, 2));
243 EXPECT_FALSE(tiling_
->TileAt(1, 2));
244 EXPECT_FALSE(tiling_
->TileAt(0, 2));
247 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilingOverTileBorders
) {
248 // The tiling has four rows and three columns.
249 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
250 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
251 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
253 // The live tiles rect covers the whole tiling.
254 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
256 // Tiles in the bottom row and right column exist.
257 EXPECT_TRUE(tiling_
->TileAt(2, 0));
258 EXPECT_TRUE(tiling_
->TileAt(2, 1));
259 EXPECT_TRUE(tiling_
->TileAt(2, 2));
260 EXPECT_TRUE(tiling_
->TileAt(2, 3));
261 EXPECT_TRUE(tiling_
->TileAt(1, 3));
262 EXPECT_TRUE(tiling_
->TileAt(0, 3));
264 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 2).x();
265 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
267 // Shrink the tiling so that the last tile row/column is entirely in the
268 // border pixels of the interior tiles. That row/column is removed.
269 tiling_
->Resize(gfx::Size(right
+ 1, bottom
+ 1));
270 EXPECT_EQ(2, tiling_
->TilingDataForTesting().num_tiles_x());
271 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_y());
273 // The live tiles rect was clamped to the pile size.
274 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
276 // Since the row/column is gone, the tiles should be gone too.
277 EXPECT_FALSE(tiling_
->TileAt(2, 0));
278 EXPECT_FALSE(tiling_
->TileAt(2, 1));
279 EXPECT_FALSE(tiling_
->TileAt(2, 2));
280 EXPECT_FALSE(tiling_
->TileAt(2, 3));
281 EXPECT_FALSE(tiling_
->TileAt(1, 3));
282 EXPECT_FALSE(tiling_
->TileAt(0, 3));
284 // Growing outside the current right/bottom tiles border pixels should create
285 // the tiles again, even though the live rect has not changed size.
286 tiling_
->Resize(gfx::Size(right
+ 2, bottom
+ 2));
287 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
288 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
291 EXPECT_EQ(gfx::Rect(right
+ 1, bottom
+ 1), tiling_
->live_tiles_rect());
293 // The last row/column tiles are inside the live tiles rect.
294 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
295 tiling_
->TilingDataForTesting().TileBounds(2, 0)));
296 EXPECT_TRUE(gfx::Rect(right
+ 1, bottom
+ 1).Intersects(
297 tiling_
->TilingDataForTesting().TileBounds(0, 3)));
299 EXPECT_TRUE(tiling_
->TileAt(2, 0));
300 EXPECT_TRUE(tiling_
->TileAt(2, 1));
301 EXPECT_TRUE(tiling_
->TileAt(2, 2));
302 EXPECT_TRUE(tiling_
->TileAt(2, 3));
303 EXPECT_TRUE(tiling_
->TileAt(1, 3));
304 EXPECT_TRUE(tiling_
->TileAt(0, 3));
307 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverTileBorders
) {
308 // The tiling has three rows and columns.
309 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
310 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
311 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
313 // The live tiles rect covers the whole tiling.
314 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
316 // Tiles in the bottom row and right column exist.
317 EXPECT_TRUE(tiling_
->TileAt(2, 0));
318 EXPECT_TRUE(tiling_
->TileAt(2, 1));
319 EXPECT_TRUE(tiling_
->TileAt(2, 2));
320 EXPECT_TRUE(tiling_
->TileAt(2, 3));
321 EXPECT_TRUE(tiling_
->TileAt(1, 3));
322 EXPECT_TRUE(tiling_
->TileAt(0, 3));
324 // Shrink the live tiles rect to the very edge of the right-most and
325 // bottom-most tiles. Their border pixels would still be inside the live
326 // tiles rect, but the tiles should not exist just for that.
327 int right
= tiling_
->TilingDataForTesting().TileBounds(2, 3).x();
328 int bottom
= tiling_
->TilingDataForTesting().TileBounds(2, 3).y();
330 SetLiveRectAndVerifyTiles(gfx::Rect(right
, bottom
));
331 EXPECT_FALSE(tiling_
->TileAt(2, 0));
332 EXPECT_FALSE(tiling_
->TileAt(2, 1));
333 EXPECT_FALSE(tiling_
->TileAt(2, 2));
334 EXPECT_FALSE(tiling_
->TileAt(2, 3));
335 EXPECT_FALSE(tiling_
->TileAt(1, 3));
336 EXPECT_FALSE(tiling_
->TileAt(0, 3));
338 // Including the bottom row and right column again, should create the tiles.
339 SetLiveRectAndVerifyTiles(gfx::Rect(right
+ 1, bottom
+ 1));
340 EXPECT_TRUE(tiling_
->TileAt(2, 0));
341 EXPECT_TRUE(tiling_
->TileAt(2, 1));
342 EXPECT_TRUE(tiling_
->TileAt(2, 2));
343 EXPECT_TRUE(tiling_
->TileAt(2, 3));
344 EXPECT_TRUE(tiling_
->TileAt(1, 2));
345 EXPECT_TRUE(tiling_
->TileAt(0, 2));
347 // Shrink the live tiles rect to the very edge of the left-most and
348 // top-most tiles. Their border pixels would still be inside the live
349 // tiles rect, but the tiles should not exist just for that.
350 int left
= tiling_
->TilingDataForTesting().TileBounds(0, 0).right();
351 int top
= tiling_
->TilingDataForTesting().TileBounds(0, 0).bottom();
353 SetLiveRectAndVerifyTiles(gfx::Rect(left
, top
, 250 - left
, 350 - top
));
354 EXPECT_FALSE(tiling_
->TileAt(0, 3));
355 EXPECT_FALSE(tiling_
->TileAt(0, 2));
356 EXPECT_FALSE(tiling_
->TileAt(0, 1));
357 EXPECT_FALSE(tiling_
->TileAt(0, 0));
358 EXPECT_FALSE(tiling_
->TileAt(1, 0));
359 EXPECT_FALSE(tiling_
->TileAt(2, 0));
361 // Including the top row and left column again, should create the tiles.
362 SetLiveRectAndVerifyTiles(
363 gfx::Rect(left
- 1, top
- 1, 250 - left
, 350 - top
));
364 EXPECT_TRUE(tiling_
->TileAt(0, 3));
365 EXPECT_TRUE(tiling_
->TileAt(0, 2));
366 EXPECT_TRUE(tiling_
->TileAt(0, 1));
367 EXPECT_TRUE(tiling_
->TileAt(0, 0));
368 EXPECT_TRUE(tiling_
->TileAt(1, 0));
369 EXPECT_TRUE(tiling_
->TileAt(2, 0));
372 TEST_F(PictureLayerTilingIteratorTest
, ResizeLiveTileRectOverSameTiles
) {
373 // The tiling has four rows and three columns.
374 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(250, 350));
375 EXPECT_EQ(3, tiling_
->TilingDataForTesting().num_tiles_x());
376 EXPECT_EQ(4, tiling_
->TilingDataForTesting().num_tiles_y());
378 // The live tiles rect covers the whole tiling.
379 SetLiveRectAndVerifyTiles(gfx::Rect(250, 350));
382 for (int i
= 0; i
< 3; ++i
) {
383 for (int j
= 0; j
< 4; ++j
)
384 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
387 // Shrink the live tiles rect, but still cover all the tiles.
388 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 349));
390 // All tiles still exist.
391 for (int i
= 0; i
< 3; ++i
) {
392 for (int j
= 0; j
< 4; ++j
)
393 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
396 // Grow the live tiles rect, but still cover all the same tiles.
397 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 350));
399 // All tiles still exist.
400 for (int i
= 0; i
< 3; ++i
) {
401 for (int j
= 0; j
< 4; ++j
)
402 EXPECT_TRUE(tiling_
->TileAt(i
, j
)) << i
<< "," << j
;
406 TEST_F(PictureLayerTilingIteratorTest
, ResizeOverBorderPixelsDeletesTiles
) {
407 // Verifies that a resize with invalidation for newly exposed pixels will
408 // deletes tiles that intersect that invalidation.
409 gfx::Size
tile_size(100, 100);
410 gfx::Size
original_layer_size(99, 99);
411 Initialize(tile_size
, 1.f
, original_layer_size
);
412 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size
));
414 // Tiling only has one tile, since its total size is less than one.
415 EXPECT_TRUE(tiling_
->TileAt(0, 0));
417 // Stop creating tiles so that any invalidations are left as holes.
418 client_
.set_allow_create_tile(false);
420 Region invalidation
=
421 SubtractRegions(gfx::Rect(tile_size
), gfx::Rect(original_layer_size
));
422 tiling_
->Resize(gfx::Size(200, 200));
423 EXPECT_TRUE(tiling_
->TileAt(0, 0));
424 tiling_
->Invalidate(invalidation
);
425 EXPECT_FALSE(tiling_
->TileAt(0, 0));
427 // The original tile was the same size after resize, but it would include new
429 EXPECT_EQ(gfx::Rect(original_layer_size
),
430 tiling_
->TilingDataForTesting().TileBounds(0, 0));
433 TEST_F(PictureLayerTilingIteratorTest
, LiveTilesExactlyCoverLiveTileRect
) {
434 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
435 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
436 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
437 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
438 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
439 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
440 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
443 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsNoScale
) {
444 Initialize(gfx::Size(100, 100), 1.f
, gfx::Size(1099, 801));
445 VerifyTilesExactlyCoverRect(1, gfx::Rect());
446 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
447 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
449 // With borders, a size of 3x3 = 1 pixel of content.
450 Initialize(gfx::Size(3, 3), 1.f
, gfx::Size(10, 10));
451 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
452 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
453 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
454 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
457 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsTilingScale
) {
458 Initialize(gfx::Size(200, 100), 2.0f
, gfx::Size(1005, 2010));
459 VerifyTilesExactlyCoverRect(1, gfx::Rect());
460 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
461 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
463 Initialize(gfx::Size(3, 3), 2.0f
, gfx::Size(10, 10));
464 VerifyTilesExactlyCoverRect(1, gfx::Rect());
465 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
466 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
467 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
468 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
470 Initialize(gfx::Size(100, 200), 0.5f
, gfx::Size(1005, 2010));
471 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
472 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
474 Initialize(gfx::Size(150, 250), 0.37f
, gfx::Size(1005, 2010));
475 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
476 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
478 Initialize(gfx::Size(312, 123), 0.01f
, gfx::Size(1005, 2010));
479 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
480 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
483 TEST_F(PictureLayerTilingIteratorTest
, IteratorCoversLayerBoundsBothScale
) {
484 Initialize(gfx::Size(50, 50), 4.0f
, gfx::Size(800, 600));
485 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect());
486 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(0, 0, 1600, 1200));
487 VerifyTilesExactlyCoverRect(2.0f
, gfx::Rect(512, 365, 253, 182));
490 gfx::Size
bounds(800, 600);
491 gfx::Rect
full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds
, scale
)));
492 Initialize(gfx::Size(256, 512), 5.2f
, bounds
);
493 VerifyTilesExactlyCoverRect(scale
, full_rect
);
494 VerifyTilesExactlyCoverRect(scale
, gfx::Rect(2014, 1579, 867, 1033));
497 TEST_F(PictureLayerTilingIteratorTest
, IteratorEmptyRect
) {
498 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
501 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1.0f
, empty
);
505 TEST_F(PictureLayerTilingIteratorTest
, NonIntersectingRect
) {
506 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(800, 600));
507 gfx::Rect
non_intersecting(1000, 1000, 50, 50);
508 PictureLayerTiling::CoverageIterator
iter(tiling_
.get(), 1, non_intersecting
);
512 TEST_F(PictureLayerTilingIteratorTest
, LayerEdgeTextureCoordinates
) {
513 Initialize(gfx::Size(300, 300), 1.0f
, gfx::Size(256, 256));
514 // All of these sizes are 256x256, scaled and ceiled.
515 VerifyTilesExactlyCoverRect(1.0f
, gfx::Rect(0, 0, 256, 256));
516 VerifyTilesExactlyCoverRect(0.8f
, gfx::Rect(0, 0, 205, 205));
517 VerifyTilesExactlyCoverRect(1.2f
, gfx::Rect(0, 0, 308, 308));
520 TEST_F(PictureLayerTilingIteratorTest
, NonContainedDestRect
) {
521 Initialize(gfx::Size(100, 100), 1.0f
, gfx::Size(400, 400));
523 // Too large in all dimensions
524 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, -1000, 2000, 2000));
525 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
526 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, -1000, 2000, 2000));
528 // Partially covering content, but too large
529 VerifyTilesCoverNonContainedRect(1.0f
, gfx::Rect(-1000, 100, 2000, 100));
530 VerifyTilesCoverNonContainedRect(1.5f
, gfx::Rect(-1000, 100, 2000, 100));
531 VerifyTilesCoverNonContainedRect(0.5f
, gfx::Rect(-1000, 100, 2000, 100));
534 TEST(PictureLayerTilingTest
, SkewportLimits
) {
535 FakePictureLayerTilingClient client
;
536 client
.set_tree(ACTIVE_TREE
);
537 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
539 gfx::Rect
viewport(0, 0, 100, 100);
540 gfx::Size
layer_bounds(200, 200);
542 client
.SetTileSize(gfx::Size(100, 100));
543 LayerTreeSettings settings
;
544 settings
.max_tiles_for_interest_area
= 10000;
545 settings
.skewport_extrapolation_limit_in_content_pixels
= 75;
547 TestablePictureLayerTiling::Create(1.0f
, layer_bounds
, &client
, settings
);
549 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
551 // Move viewport down 50 pixels in 0.5 seconds.
552 gfx::Rect down_skewport
=
553 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
555 EXPECT_EQ(0, down_skewport
.x());
556 EXPECT_EQ(50, down_skewport
.y());
557 EXPECT_EQ(100, down_skewport
.width());
558 EXPECT_EQ(175, down_skewport
.height());
559 EXPECT_TRUE(down_skewport
.Contains(gfx::Rect(0, 50, 100, 100)));
561 // Move viewport down 50 and right 10 pixels.
562 gfx::Rect down_right_skewport
=
563 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
565 EXPECT_EQ(10, down_right_skewport
.x());
566 EXPECT_EQ(50, down_right_skewport
.y());
567 EXPECT_EQ(120, down_right_skewport
.width());
568 EXPECT_EQ(175, down_right_skewport
.height());
569 EXPECT_TRUE(down_right_skewport
.Contains(gfx::Rect(10, 50, 100, 100)));
571 // Move viewport left.
572 gfx::Rect left_skewport
=
573 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100));
575 EXPECT_EQ(-125, left_skewport
.x());
576 EXPECT_EQ(0, left_skewport
.y());
577 EXPECT_EQ(175, left_skewport
.width());
578 EXPECT_EQ(100, left_skewport
.height());
579 EXPECT_TRUE(left_skewport
.Contains(gfx::Rect(-50, 0, 100, 100)));
582 gfx::Rect expand_skewport
=
583 tiling
->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200));
585 // x and y moved by -75 (-50 - 75 = -125).
586 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
587 EXPECT_EQ(-125, expand_skewport
.x());
588 EXPECT_EQ(-125, expand_skewport
.y());
589 EXPECT_EQ(350, expand_skewport
.width());
590 EXPECT_EQ(350, expand_skewport
.height());
591 EXPECT_TRUE(expand_skewport
.Contains(gfx::Rect(-50, -50, 200, 200)));
593 // Expand the viewport past the limit.
594 gfx::Rect big_expand_skewport
=
595 tiling
->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500));
597 EXPECT_EQ(-575, big_expand_skewport
.x());
598 EXPECT_EQ(-575, big_expand_skewport
.y());
599 EXPECT_EQ(1650, big_expand_skewport
.width());
600 EXPECT_EQ(1650, big_expand_skewport
.height());
601 EXPECT_TRUE(big_expand_skewport
.Contains(gfx::Rect(-500, -500, 1500, 1500)));
604 TEST(PictureLayerTilingTest
, ComputeSkewport
) {
605 FakePictureLayerTilingClient client
;
606 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
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
);
613 tiling
= TestablePictureLayerTiling::Create(1.0f
, layer_bounds
, &client
,
614 LayerTreeSettings());
616 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
618 // Move viewport down 50 pixels in 0.5 seconds.
619 gfx::Rect down_skewport
=
620 tiling
->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
622 EXPECT_EQ(0, down_skewport
.x());
623 EXPECT_EQ(50, down_skewport
.y());
624 EXPECT_EQ(100, down_skewport
.width());
625 EXPECT_EQ(200, down_skewport
.height());
628 gfx::Rect shrink_skewport
=
629 tiling
->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50));
631 EXPECT_EQ(25, shrink_skewport
.x());
632 EXPECT_EQ(25, shrink_skewport
.y());
633 EXPECT_EQ(50, shrink_skewport
.width());
634 EXPECT_EQ(50, shrink_skewport
.height());
636 // Move viewport down 50 and right 10 pixels.
637 gfx::Rect down_right_skewport
=
638 tiling
->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
640 EXPECT_EQ(10, down_right_skewport
.x());
641 EXPECT_EQ(50, down_right_skewport
.y());
642 EXPECT_EQ(120, down_right_skewport
.width());
643 EXPECT_EQ(200, down_right_skewport
.height());
645 // Move viewport left.
646 gfx::Rect left_skewport
=
647 tiling
->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100));
649 EXPECT_EQ(-60, left_skewport
.x());
650 EXPECT_EQ(0, left_skewport
.y());
651 EXPECT_EQ(140, left_skewport
.width());
652 EXPECT_EQ(100, left_skewport
.height());
654 // Expand viewport in 0.2 seconds.
655 gfx::Rect expanded_skewport
=
656 tiling
->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110));
658 EXPECT_EQ(-30, expanded_skewport
.x());
659 EXPECT_EQ(-30, expanded_skewport
.y());
660 EXPECT_EQ(160, expanded_skewport
.width());
661 EXPECT_EQ(160, expanded_skewport
.height());
664 TEST(PictureLayerTilingTest
, ViewportDistanceWithScale
) {
665 FakePictureLayerTilingClient client
;
666 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
668 gfx::Rect
viewport(0, 0, 100, 100);
669 gfx::Size
layer_bounds(1500, 1500);
671 client
.SetTileSize(gfx::Size(10, 10));
672 client
.set_tree(ACTIVE_TREE
);
673 LayerTreeSettings settings
;
674 settings
.max_tiles_for_interest_area
= 10000;
676 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10.
677 // The reason is that each tile has a one pixel border, so tile at (1, 2)
678 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at
679 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the
681 tiling
= TestablePictureLayerTiling::Create(0.25f
, layer_bounds
, &client
,
683 gfx::Rect viewport_in_content_space
=
684 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
686 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 1.0, Occlusion());
687 tiling
->UpdateAllTilePrioritiesForTesting();
689 gfx::Rect soon_rect
= viewport
;
690 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
691 gfx::Rect soon_rect_in_content_space
=
692 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect
, 0.25f
));
695 for (int i
= 0; i
< 47; ++i
) {
696 for (int j
= 0; j
< 47; ++j
) {
697 EXPECT_TRUE(tiling
->TileAt(i
, j
)) << "i: " << i
<< " j: " << j
;
700 for (int i
= 0; i
< 47; ++i
) {
701 EXPECT_FALSE(tiling
->TileAt(i
, 47)) << "i: " << i
;
702 EXPECT_FALSE(tiling
->TileAt(47, i
)) << "i: " << i
;
705 // No movement in the viewport implies that tiles will either be NOW
706 // or EVENTUALLY, with the exception of tiles that are between 0 and 312
707 // pixels away from the viewport, which will be in the SOON bin.
708 bool have_now
= false;
709 bool have_eventually
= false;
710 bool have_soon
= false;
711 for (int i
= 0; i
< 47; ++i
) {
712 for (int j
= 0; j
< 47; ++j
) {
713 Tile
* tile
= tiling
->TileAt(i
, j
);
714 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
716 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
717 if (viewport_in_content_space
.Intersects(tile_rect
)) {
718 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
719 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
721 } else if (soon_rect_in_content_space
.Intersects(tile_rect
)) {
722 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
);
725 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
);
726 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
727 have_eventually
= true;
732 EXPECT_TRUE(have_now
);
733 EXPECT_TRUE(have_soon
);
734 EXPECT_TRUE(have_eventually
);
736 // Spot check some distances.
737 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
738 // so the distance to a viewport that ends at 25x25 in content space
739 // should be 17 (41 - 25 + 1). In layer space, then that should be
740 // 17 / 0.25 = 68 pixels.
742 // We can verify that the content rect (with borders) is one pixel off
743 // 41,9 8x8 on all sides.
744 EXPECT_EQ(tiling
->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
746 TilePriority priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
747 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
749 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
750 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
752 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
753 EXPECT_FLOAT_EQ(40.f
, priority
.distance_to_visible
);
755 // Move the viewport down 40 pixels.
756 viewport
= gfx::Rect(0, 40, 100, 100);
757 viewport_in_content_space
=
758 gfx::ToEnclosedRect(gfx::ScaleRect(viewport
, 0.25f
));
759 gfx::Rect skewport
= tiling
->ComputeSkewport(2.0, viewport_in_content_space
);
761 soon_rect
= viewport
;
762 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
763 soon_rect_in_content_space
=
764 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect
, 0.25f
));
766 EXPECT_EQ(0, skewport
.x());
767 EXPECT_EQ(10, skewport
.y());
768 EXPECT_EQ(25, skewport
.width());
769 EXPECT_EQ(35, skewport
.height());
771 tiling
->ComputeTilePriorityRects(viewport
, 1.f
, 2.0, Occlusion());
772 tiling
->UpdateAllTilePrioritiesForTesting();
775 have_eventually
= false;
778 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
779 // some EVENTUALLY tiles.
780 for (int i
= 0; i
< 47; ++i
) {
781 for (int j
= 0; j
< 47; ++j
) {
782 Tile
* tile
= tiling
->TileAt(i
, j
);
783 TilePriority priority
= tile
->priority(ACTIVE_TREE
);
785 gfx::Rect tile_rect
= tiling
->TilingDataForTesting().TileBounds(i
, j
);
786 if (viewport_in_content_space
.Intersects(tile_rect
)) {
787 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
) << "i: " << i
789 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
) << "i: " << i
792 } else if (skewport
.Intersects(tile_rect
) ||
793 soon_rect_in_content_space
.Intersects(tile_rect
)) {
794 EXPECT_EQ(TilePriority::SOON
, priority
.priority_bin
) << "i: " << i
796 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
800 EXPECT_EQ(TilePriority::EVENTUALLY
, priority
.priority_bin
)
801 << "i: " << i
<< " j: " << j
;
802 EXPECT_GT(priority
.distance_to_visible
, 0.f
) << "i: " << i
804 have_eventually
= true;
809 EXPECT_TRUE(have_now
);
810 EXPECT_TRUE(have_soon
);
811 EXPECT_TRUE(have_eventually
);
813 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
814 EXPECT_FLOAT_EQ(68.f
, priority
.distance_to_visible
);
816 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
817 EXPECT_FLOAT_EQ(28.f
, priority
.distance_to_visible
);
819 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
820 EXPECT_FLOAT_EQ(4.f
, priority
.distance_to_visible
);
822 // Change the underlying layer scale.
823 tiling
->ComputeTilePriorityRects(viewport
, 2.0f
, 3.0, Occlusion());
824 tiling
->UpdateAllTilePrioritiesForTesting();
826 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
827 EXPECT_FLOAT_EQ(136.f
, priority
.distance_to_visible
);
829 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
830 EXPECT_FLOAT_EQ(56.f
, priority
.distance_to_visible
);
832 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
833 EXPECT_FLOAT_EQ(8.f
, priority
.distance_to_visible
);
835 // Test additional scales.
836 tiling
= TestablePictureLayerTiling::Create(0.2f
, layer_bounds
, &client
,
837 LayerTreeSettings());
838 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 4.0, Occlusion());
839 tiling
->UpdateAllTilePrioritiesForTesting();
841 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
842 EXPECT_FLOAT_EQ(110.f
, priority
.distance_to_visible
);
844 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
845 EXPECT_FLOAT_EQ(70.f
, priority
.distance_to_visible
);
847 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
848 EXPECT_FLOAT_EQ(60.f
, priority
.distance_to_visible
);
850 tiling
->ComputeTilePriorityRects(viewport
, 0.5f
, 5.0, Occlusion());
851 tiling
->UpdateAllTilePrioritiesForTesting();
853 priority
= tiling
->TileAt(5, 1)->priority(ACTIVE_TREE
);
854 EXPECT_FLOAT_EQ(55.f
, priority
.distance_to_visible
);
856 priority
= tiling
->TileAt(2, 5)->priority(ACTIVE_TREE
);
857 EXPECT_FLOAT_EQ(35.f
, priority
.distance_to_visible
);
859 priority
= tiling
->TileAt(3, 4)->priority(ACTIVE_TREE
);
860 EXPECT_FLOAT_EQ(30.f
, priority
.distance_to_visible
);
863 TEST(PictureLayerTilingTest
, ExpandRectEqual
) {
864 gfx::Rect
in(40, 50, 100, 200);
865 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
866 int64 target_area
= 100 * 200;
867 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
868 in
, target_area
, bounds
, NULL
);
869 EXPECT_EQ(in
.ToString(), out
.ToString());
872 TEST(PictureLayerTilingTest
, ExpandRectSmaller
) {
873 gfx::Rect
in(40, 50, 100, 200);
874 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
875 int64 target_area
= 100 * 100;
876 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
877 in
, target_area
, bounds
, NULL
);
878 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
879 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
880 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
882 // |in| represents the visible rect, and |out| represents the eventually rect.
883 // If the eventually rect doesn't contain the visible rect, we will start
885 EXPECT_TRUE(out
.Contains(in
));
886 EXPECT_TRUE(bounds
.Contains(out
));
889 TEST(PictureLayerTilingTest
, ExpandRectUnbounded
) {
890 gfx::Rect
in(40, 50, 100, 200);
891 gfx::Rect
bounds(-1000, -1000, 10000, 10000);
892 int64 target_area
= 200 * 200;
893 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
894 in
, target_area
, bounds
, NULL
);
895 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
896 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
897 EXPECT_EQ(out
.width() - in
.width(), out
.height() - in
.height());
898 EXPECT_NEAR(200 * 200, out
.width() * out
.height(), 100);
899 EXPECT_TRUE(bounds
.Contains(out
));
902 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmaller
) {
903 gfx::Rect
in(40, 50, 100, 200);
904 gfx::Rect
bounds(50, 60, 40, 30);
905 int64 target_area
= 200 * 200;
906 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
907 in
, target_area
, bounds
, NULL
);
908 EXPECT_EQ(bounds
.ToString(), out
.ToString());
911 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqual
) {
912 gfx::Rect
in(40, 50, 100, 200);
913 gfx::Rect bounds
= in
;
914 int64 target_area
= 200 * 200;
915 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
916 in
, target_area
, bounds
, NULL
);
917 EXPECT_EQ(bounds
.ToString(), out
.ToString());
920 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchVertical
) {
921 gfx::Rect
in(40, 50, 100, 200);
922 gfx::Rect
bounds(45, 0, 90, 300);
923 int64 target_area
= 200 * 200;
924 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
925 in
, target_area
, bounds
, NULL
);
926 EXPECT_EQ(bounds
.ToString(), out
.ToString());
929 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchVertical
) {
930 gfx::Rect
in(40, 50, 100, 200);
931 gfx::Rect
bounds(40, 0, 100, 300);
932 int64 target_area
= 200 * 200;
933 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
934 in
, target_area
, bounds
, NULL
);
935 EXPECT_EQ(bounds
.ToString(), out
.ToString());
938 TEST(PictureLayerTilingTest
, ExpandRectBoundedSmallerStretchHorizontal
) {
939 gfx::Rect
in(40, 50, 100, 200);
940 gfx::Rect
bounds(0, 55, 180, 190);
941 int64 target_area
= 200 * 200;
942 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
943 in
, target_area
, bounds
, NULL
);
944 EXPECT_EQ(bounds
.ToString(), out
.ToString());
947 TEST(PictureLayerTilingTest
, ExpandRectBoundedEqualStretchHorizontal
) {
948 gfx::Rect
in(40, 50, 100, 200);
949 gfx::Rect
bounds(0, 50, 180, 200);
950 int64 target_area
= 200 * 200;
951 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
952 in
, target_area
, bounds
, NULL
);
953 EXPECT_EQ(bounds
.ToString(), out
.ToString());
956 TEST(PictureLayerTilingTest
, ExpandRectBoundedLeft
) {
957 gfx::Rect
in(40, 50, 100, 200);
958 gfx::Rect
bounds(20, -1000, 10000, 10000);
959 int64 target_area
= 200 * 200;
960 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
961 in
, target_area
, bounds
, NULL
);
962 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
963 EXPECT_EQ(out
.bottom() - in
.bottom(), out
.right() - in
.right());
964 EXPECT_LE(out
.width() * out
.height(), target_area
);
965 EXPECT_GT(out
.width() * out
.height(),
966 target_area
- out
.width() - out
.height() * 2);
967 EXPECT_TRUE(bounds
.Contains(out
));
970 TEST(PictureLayerTilingTest
, ExpandRectBoundedRight
) {
971 gfx::Rect
in(40, 50, 100, 200);
972 gfx::Rect
bounds(-1000, -1000, 1000+120, 10000);
973 int64 target_area
= 200 * 200;
974 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
975 in
, target_area
, bounds
, NULL
);
976 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
977 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.x() - out
.x());
978 EXPECT_LE(out
.width() * out
.height(), target_area
);
979 EXPECT_GT(out
.width() * out
.height(),
980 target_area
- out
.width() - out
.height() * 2);
981 EXPECT_TRUE(bounds
.Contains(out
));
984 TEST(PictureLayerTilingTest
, ExpandRectBoundedTop
) {
985 gfx::Rect
in(40, 50, 100, 200);
986 gfx::Rect
bounds(-1000, 30, 10000, 10000);
987 int64 target_area
= 200 * 200;
988 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
989 in
, target_area
, bounds
, NULL
);
990 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
991 EXPECT_EQ(out
.right() - in
.right(), out
.bottom() - in
.bottom());
992 EXPECT_LE(out
.width() * out
.height(), target_area
);
993 EXPECT_GT(out
.width() * out
.height(),
994 target_area
- out
.width() * 2 - out
.height());
995 EXPECT_TRUE(bounds
.Contains(out
));
998 TEST(PictureLayerTilingTest
, ExpandRectBoundedBottom
) {
999 gfx::Rect
in(40, 50, 100, 200);
1000 gfx::Rect
bounds(-1000, -1000, 10000, 1000 + 220);
1001 int64 target_area
= 200 * 200;
1002 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1003 in
, target_area
, bounds
, NULL
);
1004 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1005 EXPECT_EQ(out
.right() - in
.right(), in
.y() - out
.y());
1006 EXPECT_LE(out
.width() * out
.height(), target_area
);
1007 EXPECT_GT(out
.width() * out
.height(),
1008 target_area
- out
.width() * 2 - out
.height());
1009 EXPECT_TRUE(bounds
.Contains(out
));
1012 TEST(PictureLayerTilingTest
, ExpandRectSquishedHorizontally
) {
1013 gfx::Rect
in(40, 50, 100, 200);
1014 gfx::Rect
bounds(0, -4000, 100+40+20, 100000);
1015 int64 target_area
= 400 * 400;
1016 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1017 in
, target_area
, bounds
, NULL
);
1018 EXPECT_EQ(20, out
.right() - in
.right());
1019 EXPECT_EQ(40, in
.x() - out
.x());
1020 EXPECT_EQ(out
.bottom() - in
.bottom(), in
.y() - out
.y());
1021 EXPECT_LE(out
.width() * out
.height(), target_area
);
1022 EXPECT_GT(out
.width() * out
.height(),
1023 target_area
- out
.width() * 2);
1024 EXPECT_TRUE(bounds
.Contains(out
));
1027 TEST(PictureLayerTilingTest
, ExpandRectSquishedVertically
) {
1028 gfx::Rect
in(40, 50, 100, 200);
1029 gfx::Rect
bounds(-4000, 0, 100000, 200+50+30);
1030 int64 target_area
= 400 * 400;
1031 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1032 in
, target_area
, bounds
, NULL
);
1033 EXPECT_EQ(30, out
.bottom() - in
.bottom());
1034 EXPECT_EQ(50, in
.y() - out
.y());
1035 EXPECT_EQ(out
.right() - in
.right(), in
.x() - out
.x());
1036 EXPECT_LE(out
.width() * out
.height(), target_area
);
1037 EXPECT_GT(out
.width() * out
.height(),
1038 target_area
- out
.height() * 2);
1039 EXPECT_TRUE(bounds
.Contains(out
));
1042 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsFarAway
) {
1043 gfx::Rect
in(400, 500, 100, 200);
1044 gfx::Rect
bounds(0, 0, 10, 10);
1045 int64 target_area
= 400 * 400;
1046 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1047 in
, target_area
, bounds
, NULL
);
1048 EXPECT_TRUE(out
.IsEmpty());
1051 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedFullyCover
) {
1052 gfx::Rect
in(40, 50, 100, 100);
1053 gfx::Rect
bounds(0, 0, 10, 10);
1054 int64 target_area
= 400 * 400;
1055 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1056 in
, target_area
, bounds
, NULL
);
1057 EXPECT_EQ(bounds
.ToString(), out
.ToString());
1060 TEST(PictureLayerTilingTest
, ExpandRectOutOfBoundsExpandedPartlyCover
) {
1061 gfx::Rect
in(600, 600, 100, 100);
1062 gfx::Rect
bounds(0, 0, 500, 500);
1063 int64 target_area
= 400 * 400;
1064 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1065 in
, target_area
, bounds
, NULL
);
1066 EXPECT_EQ(bounds
.right(), out
.right());
1067 EXPECT_EQ(bounds
.bottom(), out
.bottom());
1068 EXPECT_LE(out
.width() * out
.height(), target_area
);
1069 EXPECT_GT(out
.width() * out
.height(),
1070 target_area
- out
.width() - out
.height());
1071 EXPECT_TRUE(bounds
.Contains(out
));
1074 TEST(PictureLayerTilingTest
, EmptyStartingRect
) {
1075 // If a layer has a non-invertible transform, then the starting rect
1076 // for the layer would be empty.
1077 gfx::Rect
in(40, 40, 0, 0);
1078 gfx::Rect
bounds(0, 0, 10, 10);
1079 int64 target_area
= 400 * 400;
1080 gfx::Rect out
= PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
1081 in
, target_area
, bounds
, NULL
);
1082 EXPECT_TRUE(out
.IsEmpty());
1085 TEST(PictureLayerTilingTest
, TilingRasterTileIteratorStaticViewport
) {
1086 FakePictureLayerTilingClient client
;
1087 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1089 gfx::Rect
viewport(50, 50, 100, 100);
1090 gfx::Size
layer_bounds(800, 800);
1092 gfx::Rect soon_rect
= viewport
;
1093 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
1095 client
.SetTileSize(gfx::Size(30, 30));
1096 client
.set_tree(ACTIVE_TREE
);
1097 LayerTreeSettings settings
;
1098 settings
.max_tiles_for_interest_area
= 10000;
1101 TestablePictureLayerTiling::Create(1.0f
, layer_bounds
, &client
, settings
);
1102 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0, Occlusion());
1103 tiling
->UpdateAllTilePrioritiesForTesting();
1105 PictureLayerTiling::TilingRasterTileIterator empty_iterator
;
1106 EXPECT_FALSE(empty_iterator
);
1108 std::vector
<Tile
*> all_tiles
= tiling
->AllTilesForTesting();
1111 EXPECT_EQ(841u, all_tiles
.size());
1113 // The explanation of each iteration is as follows:
1114 // 1. First iteration tests that we can get all of the tiles correctly.
1115 // 2. Second iteration ensures that we can get all of the tiles again (first
1116 // iteration didn't change any tiles), as well set all tiles to be ready to
1118 // 3. Third iteration ensures that no tiles are returned, since they were all
1119 // marked as ready to draw.
1120 for (int i
= 0; i
< 3; ++i
) {
1121 PictureLayerTiling::TilingRasterTileIterator
it(tiling
.get());
1123 // There are 3 bins in TilePriority.
1124 bool have_tiles
[3] = {};
1126 // On the third iteration, we should get no tiles since everything was
1127 // marked as ready to draw.
1134 std::set
<Tile
*> unique_tiles
;
1135 unique_tiles
.insert(*it
);
1136 Tile
* last_tile
= *it
;
1137 have_tiles
[last_tile
->priority(ACTIVE_TREE
).priority_bin
] = true;
1139 // On the second iteration, mark everything as ready to draw (solid color).
1141 ManagedTileState::DrawInfo
& draw_info
= last_tile
->draw_info();
1142 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1145 int eventually_bin_order_correct_count
= 0;
1146 int eventually_bin_order_incorrect_count
= 0;
1148 Tile
* new_tile
= *it
;
1150 unique_tiles
.insert(new_tile
);
1152 TilePriority last_priority
= last_tile
->priority(ACTIVE_TREE
);
1153 TilePriority new_priority
= new_tile
->priority(ACTIVE_TREE
);
1154 EXPECT_LE(last_priority
.priority_bin
, new_priority
.priority_bin
);
1155 if (last_priority
.priority_bin
== new_priority
.priority_bin
) {
1156 if (last_priority
.priority_bin
== TilePriority::EVENTUALLY
) {
1157 bool order_correct
= last_priority
.distance_to_visible
<=
1158 new_priority
.distance_to_visible
;
1159 eventually_bin_order_correct_count
+= order_correct
;
1160 eventually_bin_order_incorrect_count
+= !order_correct
;
1161 } else if (!soon_rect
.Intersects(new_tile
->content_rect()) &&
1162 !soon_rect
.Intersects(last_tile
->content_rect())) {
1163 EXPECT_LE(last_priority
.distance_to_visible
,
1164 new_priority
.distance_to_visible
);
1165 EXPECT_EQ(TilePriority::NOW
, new_priority
.priority_bin
);
1166 } else if (new_priority
.distance_to_visible
> 0.f
) {
1167 EXPECT_EQ(TilePriority::SOON
, new_priority
.priority_bin
);
1170 have_tiles
[new_priority
.priority_bin
] = true;
1172 last_tile
= new_tile
;
1174 // On the second iteration, mark everything as ready to draw (solid
1177 ManagedTileState::DrawInfo
& draw_info
= last_tile
->draw_info();
1178 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1182 EXPECT_GT(eventually_bin_order_correct_count
,
1183 eventually_bin_order_incorrect_count
);
1185 // We should have now and eventually tiles, as well as soon tiles from
1186 // the border region.
1187 EXPECT_TRUE(have_tiles
[TilePriority::NOW
]);
1188 EXPECT_TRUE(have_tiles
[TilePriority::SOON
]);
1189 EXPECT_TRUE(have_tiles
[TilePriority::EVENTUALLY
]);
1191 EXPECT_EQ(unique_tiles
.size(), all_tiles
.size());
1195 TEST(PictureLayerTilingTest
, TilingRasterTileIteratorMovingViewport
) {
1196 FakePictureLayerTilingClient client
;
1197 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1199 gfx::Rect
viewport(50, 0, 100, 100);
1200 gfx::Rect
moved_viewport(50, 0, 100, 500);
1201 gfx::Size
layer_bounds(1000, 1000);
1203 client
.SetTileSize(gfx::Size(30, 30));
1204 client
.set_tree(ACTIVE_TREE
);
1205 LayerTreeSettings settings
;
1206 settings
.max_tiles_for_interest_area
= 10000;
1209 TestablePictureLayerTiling::Create(1.f
, layer_bounds
, &client
, settings
);
1210 tiling
->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0, Occlusion());
1211 tiling
->ComputeTilePriorityRects(moved_viewport
, 1.0f
, 2.0, Occlusion());
1212 tiling
->UpdateAllTilePrioritiesForTesting();
1214 gfx::Rect soon_rect
= moved_viewport
;
1215 soon_rect
.Inset(-312.f
, -312.f
, -312.f
, -312.f
);
1217 // There are 3 bins in TilePriority.
1218 bool have_tiles
[3] = {};
1219 Tile
* last_tile
= NULL
;
1220 int eventually_bin_order_correct_count
= 0;
1221 int eventually_bin_order_incorrect_count
= 0;
1222 for (PictureLayerTiling::TilingRasterTileIterator
it(tiling
.get()); it
;
1227 Tile
* new_tile
= *it
;
1229 TilePriority last_priority
= last_tile
->priority(ACTIVE_TREE
);
1230 TilePriority new_priority
= new_tile
->priority(ACTIVE_TREE
);
1232 have_tiles
[new_priority
.priority_bin
] = true;
1234 EXPECT_LE(last_priority
.priority_bin
, new_priority
.priority_bin
);
1235 if (last_priority
.priority_bin
== new_priority
.priority_bin
) {
1236 if (last_priority
.priority_bin
== TilePriority::EVENTUALLY
) {
1237 bool order_correct
= last_priority
.distance_to_visible
<=
1238 new_priority
.distance_to_visible
;
1239 eventually_bin_order_correct_count
+= order_correct
;
1240 eventually_bin_order_incorrect_count
+= !order_correct
;
1241 } else if (!soon_rect
.Intersects(new_tile
->content_rect()) &&
1242 !soon_rect
.Intersects(last_tile
->content_rect())) {
1243 EXPECT_LE(last_priority
.distance_to_visible
,
1244 new_priority
.distance_to_visible
);
1245 } else if (new_priority
.distance_to_visible
> 0.f
) {
1246 EXPECT_EQ(TilePriority::SOON
, new_priority
.priority_bin
);
1249 last_tile
= new_tile
;
1252 EXPECT_GT(eventually_bin_order_correct_count
,
1253 eventually_bin_order_incorrect_count
);
1255 EXPECT_TRUE(have_tiles
[TilePriority::NOW
]);
1256 EXPECT_TRUE(have_tiles
[TilePriority::SOON
]);
1257 EXPECT_TRUE(have_tiles
[TilePriority::EVENTUALLY
]);
1260 static void TileExists(bool exists
, Tile
* tile
,
1261 const gfx::Rect
& geometry_rect
) {
1262 EXPECT_EQ(exists
, tile
!= NULL
) << geometry_rect
.ToString();
1265 TEST_F(PictureLayerTilingIteratorTest
, TilesExist
) {
1266 gfx::Size
layer_bounds(1099, 801);
1267 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1268 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1269 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1271 client_
.set_tree(ACTIVE_TREE
);
1272 tiling_
->ComputeTilePriorityRects(
1273 gfx::Rect(layer_bounds
), // visible content rect
1274 1.f
, // current contents scale
1275 1.0, // current frame time
1277 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1279 // Make the viewport rect empty. All tiles are killed and become zombies.
1280 tiling_
->ComputeTilePriorityRects(gfx::Rect(), // visible content rect
1281 1.f
, // current contents scale
1282 2.0, // current frame time
1284 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1287 TEST_F(PictureLayerTilingIteratorTest
, TilesExistGiantViewport
) {
1288 gfx::Size
layer_bounds(1099, 801);
1289 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1290 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1291 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1293 gfx::Rect
giant_rect(-10000000, -10000000, 1000000000, 1000000000);
1295 client_
.set_tree(ACTIVE_TREE
);
1296 tiling_
->ComputeTilePriorityRects(
1297 gfx::Rect(layer_bounds
), // visible content rect
1298 1.f
, // current contents scale
1299 1.0, // current frame time
1301 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1303 // If the visible content rect is empty, it should still have live tiles.
1304 tiling_
->ComputeTilePriorityRects(giant_rect
, // visible content rect
1305 1.f
, // current contents scale
1306 2.0, // current frame time
1308 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1311 TEST_F(PictureLayerTilingIteratorTest
, TilesExistOutsideViewport
) {
1312 gfx::Size
layer_bounds(1099, 801);
1313 Initialize(gfx::Size(100, 100), 1.f
, layer_bounds
);
1314 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1315 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1317 // This rect does not intersect with the layer, as the layer is outside the
1319 gfx::Rect
viewport_rect(1100, 0, 1000, 1000);
1320 EXPECT_FALSE(viewport_rect
.Intersects(gfx::Rect(layer_bounds
)));
1322 client_
.set_tree(ACTIVE_TREE
);
1323 tiling_
->ComputeTilePriorityRects(viewport_rect
, // visible content rect
1324 1.f
, // current contents scale
1325 1.0, // current frame time
1327 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, true));
1330 static void TilesIntersectingRectExist(const gfx::Rect
& rect
,
1331 bool intersect_exists
,
1333 const gfx::Rect
& geometry_rect
) {
1334 bool intersects
= rect
.Intersects(geometry_rect
);
1335 bool expected_exists
= intersect_exists
? intersects
: !intersects
;
1336 EXPECT_EQ(expected_exists
, tile
!= NULL
)
1337 << "Rects intersecting " << rect
.ToString() << " should exist. "
1338 << "Current tile rect is " << geometry_rect
.ToString();
1341 TEST_F(PictureLayerTilingIteratorTest
,
1342 TilesExistLargeViewportAndLayerWithSmallVisibleArea
) {
1343 gfx::Size
layer_bounds(10000, 10000);
1344 client_
.SetTileSize(gfx::Size(100, 100));
1345 client_
.set_tree(PENDING_TREE
);
1346 LayerTreeSettings settings
;
1347 settings
.max_tiles_for_interest_area
= 1;
1350 TestablePictureLayerTiling::Create(1.f
, layer_bounds
, &client_
, settings
);
1351 VerifyTilesExactlyCoverRect(1.f
, gfx::Rect(layer_bounds
));
1352 VerifyTiles(1.f
, gfx::Rect(layer_bounds
), base::Bind(&TileExists
, false));
1354 gfx::Rect
visible_rect(8000, 8000, 50, 50);
1356 client_
.set_tree(ACTIVE_TREE
);
1357 tiling_
->ComputeTilePriorityRects(visible_rect
, // visible content rect
1358 1.f
, // current contents scale
1359 1.0, // current frame time
1362 gfx::Rect(layer_bounds
),
1363 base::Bind(&TilesIntersectingRectExist
, visible_rect
, true));
1366 TEST_F(PictureLayerTilingIteratorTest
, AddTilingsToMatchScale
) {
1367 gfx::Size
layer_bounds(1099, 801);
1368 gfx::Size
tile_size(100, 100);
1370 client_
.SetTileSize(tile_size
);
1371 client_
.set_tree(PENDING_TREE
);
1373 LayerTreeSettings defaults
;
1374 auto active_set
= PictureLayerTilingSet::Create(
1375 &client_
, 10000, defaults
.skewport_target_time_in_seconds
,
1376 defaults
.skewport_extrapolation_limit_in_content_pixels
);
1378 active_set
->AddTiling(1.f
, layer_bounds
);
1380 VerifyTiles(active_set
->tiling_at(0), 1.f
, gfx::Rect(layer_bounds
),
1381 base::Bind(&TileExists
, false));
1383 UpdateAllTilePriorities(active_set
.get(),
1384 gfx::Rect(layer_bounds
), // visible content rect
1385 1.f
, // current contents scale
1386 1.0); // current frame time
1388 // The active tiling has tiles now.
1389 VerifyTiles(active_set
->tiling_at(0), 1.f
, gfx::Rect(layer_bounds
),
1390 base::Bind(&TileExists
, true));
1392 // Add the same tilings to the pending set.
1393 auto pending_set
= PictureLayerTilingSet::Create(
1394 &client_
, 10000, defaults
.skewport_target_time_in_seconds
,
1395 defaults
.skewport_extrapolation_limit_in_content_pixels
);
1396 Region invalidation
;
1397 pending_set
->SyncTilingsForTesting(*active_set
, layer_bounds
, invalidation
,
1398 0.f
, client_
.raster_source());
1400 // The pending tiling starts with no tiles.
1401 VerifyTiles(pending_set
->tiling_at(0), 1.f
, gfx::Rect(layer_bounds
),
1402 base::Bind(&TileExists
, false));
1404 // ComputeTilePriorityRects on the pending tiling at the same frame time. The
1405 // pending tiling should get tiles.
1406 UpdateAllTilePriorities(pending_set
.get(),
1407 gfx::Rect(layer_bounds
), // visible content rect
1408 1.f
, // current contents scale
1409 1.0); // current frame time
1411 VerifyTiles(pending_set
->tiling_at(0), 1.f
, gfx::Rect(layer_bounds
),
1412 base::Bind(&TileExists
, true));
1415 TEST(ComputeTilePriorityRectsTest
, VisibleTiles
) {
1416 // The TilePriority of visible tiles should have zero distance_to_visible
1417 // and time_to_visible.
1419 FakePictureLayerTilingClient client
;
1420 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1422 gfx::Size
device_viewport(800, 600);
1423 gfx::Size
last_layer_bounds(200, 200);
1424 gfx::Size
current_layer_bounds(200, 200);
1425 float current_layer_contents_scale
= 1.f
;
1426 gfx::Transform current_screen_transform
;
1427 double current_frame_time_in_seconds
= 1.0;
1429 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1430 current_screen_transform
, device_viewport
);
1432 client
.SetTileSize(gfx::Size(100, 100));
1433 client
.set_tree(ACTIVE_TREE
);
1434 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1435 current_layer_bounds
, &client
,
1436 LayerTreeSettings());
1438 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1439 current_layer_contents_scale
,
1440 current_frame_time_in_seconds
, Occlusion());
1441 tiling
->UpdateAllTilePrioritiesForTesting();
1443 ASSERT_TRUE(tiling
->TileAt(0, 0));
1444 ASSERT_TRUE(tiling
->TileAt(0, 1));
1445 ASSERT_TRUE(tiling
->TileAt(1, 0));
1446 ASSERT_TRUE(tiling
->TileAt(1, 1));
1448 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1449 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1450 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1452 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1453 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1454 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1456 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1457 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1458 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1460 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1461 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1462 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1465 TEST(ComputeTilePriorityRectsTest
, OffscreenTiles
) {
1466 // The TilePriority of offscreen tiles (without movement) should have nonzero
1467 // distance_to_visible and infinite time_to_visible.
1469 FakePictureLayerTilingClient client
;
1470 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1472 gfx::Size
device_viewport(800, 600);
1473 gfx::Size
last_layer_bounds(200, 200);
1474 gfx::Size
current_layer_bounds(200, 200);
1475 float current_layer_contents_scale
= 1.f
;
1476 gfx::Transform last_screen_transform
;
1477 gfx::Transform current_screen_transform
;
1478 double current_frame_time_in_seconds
= 1.0;
1480 current_screen_transform
.Translate(850, 0);
1481 last_screen_transform
= current_screen_transform
;
1483 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1484 current_screen_transform
, device_viewport
);
1486 client
.SetTileSize(gfx::Size(100, 100));
1487 client
.set_tree(ACTIVE_TREE
);
1488 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1489 current_layer_bounds
, &client
,
1490 LayerTreeSettings());
1492 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1493 current_layer_contents_scale
,
1494 current_frame_time_in_seconds
, Occlusion());
1495 tiling
->UpdateAllTilePrioritiesForTesting();
1497 ASSERT_TRUE(tiling
->TileAt(0, 0));
1498 ASSERT_TRUE(tiling
->TileAt(0, 1));
1499 ASSERT_TRUE(tiling
->TileAt(1, 0));
1500 ASSERT_TRUE(tiling
->TileAt(1, 1));
1502 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1503 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1504 EXPECT_NE(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_GT(priority
.distance_to_visible
, 0.f
);
1512 EXPECT_NE(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 tiles on the right hand side should have a
1519 // larger distance to visible.
1520 TilePriority left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1521 TilePriority right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1522 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1524 left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1525 right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1526 EXPECT_GT(right
.distance_to_visible
, left
.distance_to_visible
);
1529 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenLayer
) {
1530 // Sanity check that a layer with some tiles visible and others offscreen has
1531 // correct TilePriorities for each tile.
1533 FakePictureLayerTilingClient client
;
1534 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
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 current_screen_transform
.Translate(705, 505);
1545 last_screen_transform
= current_screen_transform
;
1547 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1548 current_screen_transform
, device_viewport
);
1550 client
.SetTileSize(gfx::Size(100, 100));
1551 client
.set_tree(ACTIVE_TREE
);
1552 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1553 current_layer_bounds
, &client
,
1554 LayerTreeSettings());
1556 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1557 current_layer_contents_scale
,
1558 current_frame_time_in_seconds
, Occlusion());
1559 tiling
->UpdateAllTilePrioritiesForTesting();
1561 ASSERT_TRUE(tiling
->TileAt(0, 0));
1562 ASSERT_TRUE(tiling
->TileAt(0, 1));
1563 ASSERT_TRUE(tiling
->TileAt(1, 0));
1564 ASSERT_TRUE(tiling
->TileAt(1, 1));
1566 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1567 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1568 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1570 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1571 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1572 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1574 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1575 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1576 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1578 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1579 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1580 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1583 TEST(ComputeTilePriorityRectsTest
, PartiallyOffscreenRotatedLayer
) {
1584 // Each tile of a layer may be affected differently by a transform; Check
1585 // that ComputeTilePriorityRects correctly accounts for the transform between
1586 // layer space and screen space.
1588 FakePictureLayerTilingClient client
;
1589 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1591 gfx::Size
device_viewport(800, 600);
1592 gfx::Size
last_layer_bounds(200, 200);
1593 gfx::Size
current_layer_bounds(200, 200);
1594 float current_layer_contents_scale
= 1.f
;
1595 gfx::Transform last_screen_transform
;
1596 gfx::Transform current_screen_transform
;
1597 double current_frame_time_in_seconds
= 1.0;
1599 // A diagonally rotated layer that is partially off the bottom of the screen.
1600 // In this configuration, only the top-left tile would be visible.
1601 current_screen_transform
.Translate(600, 750);
1602 current_screen_transform
.RotateAboutZAxis(45);
1603 last_screen_transform
= current_screen_transform
;
1605 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1606 current_screen_transform
, device_viewport
);
1608 client
.SetTileSize(gfx::Size(100, 100));
1609 client
.set_tree(ACTIVE_TREE
);
1610 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1611 current_layer_bounds
, &client
,
1612 LayerTreeSettings());
1614 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1615 current_layer_contents_scale
,
1616 current_frame_time_in_seconds
, Occlusion());
1617 tiling
->UpdateAllTilePrioritiesForTesting();
1619 ASSERT_TRUE(tiling
->TileAt(0, 0));
1620 ASSERT_TRUE(tiling
->TileAt(0, 1));
1621 ASSERT_TRUE(tiling
->TileAt(1, 0));
1622 ASSERT_TRUE(tiling
->TileAt(1, 1));
1624 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1625 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1626 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1628 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1629 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1630 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1632 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1633 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1634 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1636 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1637 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1638 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1640 // Furthermore, in this scenario the bottom-right tile should have the larger
1641 // distance to visible.
1642 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1643 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1644 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1645 EXPECT_GT(top_right
.distance_to_visible
, top_left
.distance_to_visible
);
1647 EXPECT_EQ(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1650 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayer
) {
1651 // Perspective transforms need to take a different code path.
1652 // This test checks tile priorities of a perspective layer.
1654 FakePictureLayerTilingClient client
;
1655 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1657 gfx::Size
device_viewport(800, 600);
1658 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscreen.
1659 gfx::Size
last_layer_bounds(200, 200);
1660 gfx::Size
current_layer_bounds(200, 200);
1661 float current_layer_contents_scale
= 1.f
;
1662 gfx::Transform last_screen_transform
;
1663 gfx::Transform current_screen_transform
;
1664 double current_frame_time_in_seconds
= 1.0;
1666 // A 3d perspective layer rotated about its Y axis, translated to almost
1667 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1668 // the right side, so the top-left tile will technically be closer than the
1671 // Translate layer to offscreen
1672 current_screen_transform
.Translate(400.0, 630.0);
1673 // Apply perspective about the center of the layer
1674 current_screen_transform
.Translate(100.0, 100.0);
1675 current_screen_transform
.ApplyPerspectiveDepth(100.0);
1676 current_screen_transform
.RotateAboutYAxis(10.0);
1677 current_screen_transform
.Translate(-100.0, -100.0);
1678 last_screen_transform
= current_screen_transform
;
1680 // Sanity check that this transform wouldn't cause w<0 clipping.
1682 MathUtil::MapQuad(current_screen_transform
,
1683 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1685 ASSERT_FALSE(clipped
);
1687 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1688 current_screen_transform
, device_viewport
);
1690 client
.SetTileSize(gfx::Size(100, 100));
1691 client
.set_tree(ACTIVE_TREE
);
1692 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1693 current_layer_bounds
, &client
,
1694 LayerTreeSettings());
1696 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1697 current_layer_contents_scale
,
1698 current_frame_time_in_seconds
, Occlusion());
1699 tiling
->UpdateAllTilePrioritiesForTesting();
1701 ASSERT_TRUE(tiling
->TileAt(0, 0));
1702 ASSERT_TRUE(tiling
->TileAt(0, 1));
1703 ASSERT_TRUE(tiling
->TileAt(1, 0));
1704 ASSERT_TRUE(tiling
->TileAt(1, 1));
1706 // All tiles will have a positive distance_to_visible
1707 // and an infinite time_to_visible.
1708 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1709 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1710 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1712 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1713 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1714 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1716 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1717 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1718 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1720 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1721 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1722 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1724 // Furthermore, in this scenario the top-left distance_to_visible
1725 // will be smallest, followed by top-right. The bottom layers
1726 // will of course be further than the top layers.
1727 TilePriority top_left
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1728 TilePriority top_right
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1729 TilePriority bottom_left
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1730 TilePriority bottom_right
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1732 EXPECT_GT(bottom_right
.distance_to_visible
, top_right
.distance_to_visible
);
1734 EXPECT_GT(bottom_left
.distance_to_visible
, top_left
.distance_to_visible
);
1737 TEST(ComputeTilePriorityRectsTest
, PerspectiveLayerClippedByW
) {
1738 // Perspective transforms need to take a different code path.
1739 // This test checks tile priorities of a perspective layer.
1741 FakePictureLayerTilingClient client
;
1742 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1744 gfx::Size
device_viewport(800, 600);
1745 gfx::Size
last_layer_bounds(200, 200);
1746 gfx::Size
current_layer_bounds(200, 200);
1747 float current_layer_contents_scale
= 1.f
;
1748 gfx::Transform last_screen_transform
;
1749 gfx::Transform current_screen_transform
;
1750 double current_frame_time_in_seconds
= 1.0;
1752 // A 3d perspective layer rotated about its Y axis, translated to almost
1753 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1754 // the right side, so the top-left tile will technically be closer than the
1757 // Translate layer to offscreen
1758 current_screen_transform
.Translate(400.0, 970.0);
1759 // Apply perspective and rotation about the center of the layer
1760 current_screen_transform
.Translate(100.0, 100.0);
1761 current_screen_transform
.ApplyPerspectiveDepth(10.0);
1762 current_screen_transform
.RotateAboutYAxis(10.0);
1763 current_screen_transform
.Translate(-100.0, -100.0);
1764 last_screen_transform
= current_screen_transform
;
1766 // Sanity check that this transform does cause w<0 clipping for the left side
1767 // of the layer, but not the right side.
1769 MathUtil::MapQuad(current_screen_transform
,
1770 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1772 ASSERT_TRUE(clipped
);
1774 MathUtil::MapQuad(current_screen_transform
,
1775 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1777 ASSERT_FALSE(clipped
);
1779 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1780 current_screen_transform
, device_viewport
);
1782 client
.SetTileSize(gfx::Size(100, 100));
1783 client
.set_tree(ACTIVE_TREE
);
1784 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1785 current_layer_bounds
, &client
,
1786 LayerTreeSettings());
1788 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1789 current_layer_contents_scale
,
1790 current_frame_time_in_seconds
, Occlusion());
1791 tiling
->UpdateAllTilePrioritiesForTesting();
1793 ASSERT_TRUE(tiling
->TileAt(0, 0));
1794 ASSERT_TRUE(tiling
->TileAt(0, 1));
1795 ASSERT_TRUE(tiling
->TileAt(1, 0));
1796 ASSERT_TRUE(tiling
->TileAt(1, 1));
1798 // Left-side tiles will be clipped by the transform, so we have to assume
1799 // they are visible just in case.
1800 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1801 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1802 EXPECT_FLOAT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1804 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1805 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1806 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1808 // Right-side tiles will have a positive distance_to_visible
1809 // and an infinite time_to_visible.
1810 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1811 EXPECT_FLOAT_EQ(priority
.distance_to_visible
, 0.f
);
1812 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1814 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1815 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1816 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1819 TEST(ComputeTilePriorityRectsTest
, BasicMotion
) {
1820 // Test that time_to_visible is computed correctly when
1821 // there is some motion.
1823 FakePictureLayerTilingClient client
;
1824 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1826 gfx::Size
device_viewport(800, 600);
1827 gfx::Rect
visible_layer_rect(0, 0, 0, 0);
1828 gfx::Size
last_layer_bounds(200, 200);
1829 gfx::Size
current_layer_bounds(200, 200);
1830 float last_layer_contents_scale
= 1.f
;
1831 float current_layer_contents_scale
= 1.f
;
1832 gfx::Transform last_screen_transform
;
1833 gfx::Transform current_screen_transform
;
1834 double last_frame_time_in_seconds
= 1.0;
1835 double current_frame_time_in_seconds
= 2.0;
1837 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1838 current_screen_transform
.Translate(1800, 0);
1839 last_screen_transform
.Translate(2800, 0);
1841 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1842 current_screen_transform
, device_viewport
);
1844 client
.SetTileSize(gfx::Size(100, 100));
1845 client
.set_tree(ACTIVE_TREE
);
1846 LayerTreeSettings settings
;
1847 settings
.max_tiles_for_interest_area
= 10000;
1848 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1849 current_layer_bounds
, &client
,
1852 // previous ("last") frame
1853 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1854 last_layer_contents_scale
,
1855 last_frame_time_in_seconds
, Occlusion());
1858 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1859 current_layer_contents_scale
,
1860 current_frame_time_in_seconds
, Occlusion());
1861 tiling
->UpdateAllTilePrioritiesForTesting();
1863 ASSERT_TRUE(tiling
->TileAt(0, 0));
1864 ASSERT_TRUE(tiling
->TileAt(0, 1));
1865 ASSERT_TRUE(tiling
->TileAt(1, 0));
1866 ASSERT_TRUE(tiling
->TileAt(1, 1));
1868 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1869 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1870 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1872 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1873 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1874 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1876 // time_to_visible for the right hand side layers needs an extra 0.099
1877 // seconds because this tile is 99 pixels further away.
1878 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1879 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1880 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1882 priority
= tiling
->TileAt(1, 1)->priority(ACTIVE_TREE
);
1883 EXPECT_GT(priority
.distance_to_visible
, 0.f
);
1884 EXPECT_NE(TilePriority::NOW
, priority
.priority_bin
);
1887 TEST(ComputeTilePriorityRectsTest
, RotationMotion
) {
1888 // Each tile of a layer may be affected differently by a transform; Check
1889 // that ComputeTilePriorityRects correctly accounts for the transform between
1890 // layer space and screen space.
1892 FakePictureLayerTilingClient client
;
1893 scoped_ptr
<TestablePictureLayerTiling
> tiling
;
1895 gfx::Size
device_viewport(800, 600);
1896 gfx::Rect
visible_layer_rect(0, 0, 0, 0); // offscren.
1897 gfx::Size
last_layer_bounds(200, 200);
1898 gfx::Size
current_layer_bounds(200, 200);
1899 float last_layer_contents_scale
= 1.f
;
1900 float current_layer_contents_scale
= 1.f
;
1901 gfx::Transform last_screen_transform
;
1902 gfx::Transform current_screen_transform
;
1903 double last_frame_time_in_seconds
= 1.0;
1904 double current_frame_time_in_seconds
= 2.0;
1906 // Rotation motion is set up specifically so that:
1907 // - rotation occurs about the center of the layer
1908 // - the top-left tile becomes visible on rotation
1909 // - the top-right tile will have an infinite time_to_visible
1910 // because it is rotating away from viewport.
1911 // - bottom-left layer will have a positive non-zero time_to_visible
1912 // because it is rotating toward the viewport.
1913 current_screen_transform
.Translate(400, 550);
1914 current_screen_transform
.RotateAboutZAxis(45);
1916 last_screen_transform
.Translate(400, 550);
1918 gfx::Rect viewport_in_layer_space
= ViewportInLayerSpace(
1919 current_screen_transform
, device_viewport
);
1921 client
.SetTileSize(gfx::Size(100, 100));
1922 client
.set_tree(ACTIVE_TREE
);
1923 tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1924 current_layer_bounds
, &client
,
1925 LayerTreeSettings());
1927 // previous ("last") frame
1928 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1929 last_layer_contents_scale
,
1930 last_frame_time_in_seconds
, Occlusion());
1933 tiling
->ComputeTilePriorityRects(viewport_in_layer_space
,
1934 current_layer_contents_scale
,
1935 current_frame_time_in_seconds
, Occlusion());
1936 tiling
->UpdateAllTilePrioritiesForTesting();
1938 ASSERT_TRUE(tiling
->TileAt(0, 0));
1939 ASSERT_TRUE(tiling
->TileAt(0, 1));
1940 ASSERT_TRUE(tiling
->TileAt(1, 0));
1941 ASSERT_TRUE(tiling
->TileAt(1, 1));
1943 TilePriority priority
= tiling
->TileAt(0, 0)->priority(ACTIVE_TREE
);
1944 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1945 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1947 priority
= tiling
->TileAt(0, 1)->priority(ACTIVE_TREE
);
1948 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1949 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1951 priority
= tiling
->TileAt(1, 0)->priority(ACTIVE_TREE
);
1952 EXPECT_FLOAT_EQ(0.f
, priority
.distance_to_visible
);
1953 EXPECT_EQ(TilePriority::NOW
, priority
.priority_bin
);
1956 TEST(PictureLayerTilingTest
, RecycledTilesCleared
) {
1957 // This test performs the following:
1959 // - Two tilings, one active one recycled with all tiles shared.
1961 // - Viewport moves somewhere far away and active tiling clears tiles.
1962 // - Viewport moves back and a new active tiling tile is created.
1964 // - Recycle tiling does _not_ have the tile in the same location (thus it
1965 // will be shared next time a pending tiling is created).
1967 FakePictureLayerTilingClient active_client
;
1968 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
;
1970 active_client
.SetTileSize(gfx::Size(100, 100));
1971 active_client
.set_tree(ACTIVE_TREE
);
1972 LayerTreeSettings settings
;
1973 settings
.max_tiles_for_interest_area
= 10;
1974 active_tiling
= TestablePictureLayerTiling::Create(1.0f
, // contents_scale
1975 gfx::Size(10000, 10000),
1976 &active_client
, settings
);
1977 // Create all tiles on this tiling.
1978 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
1981 FakePictureLayerTilingClient recycle_client
;
1982 recycle_client
.SetTileSize(gfx::Size(100, 100));
1983 recycle_client
.set_tree(PENDING_TREE
);
1984 recycle_client
.set_twin_tiling(active_tiling
.get());
1986 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
;
1987 recycle_tiling
= TestablePictureLayerTiling::Create(
1988 1.0f
, // contents_scale
1989 gfx::Size(10000, 10000), &recycle_client
, settings
);
1991 // Create all tiles on the second tiling. All tiles should be shared.
1992 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
1995 // Set the second tiling as recycled.
1996 active_client
.set_twin_tiling(NULL
);
1997 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
1998 recycle_client
.set_twin_tiling(NULL
);
2000 // Verify that tiles exist and are shared.
2001 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2002 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
2003 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
2005 // Move the viewport far away from the (0, 0) tile.
2006 active_tiling
->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f
,
2008 // Ensure the tile was deleted on both tilings.
2009 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
2010 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
2012 // Move the viewport back to (0, 0) tile.
2013 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 3.0,
2016 // Ensure that we now have a tile here on both tilings again.
2017 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2018 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
2021 TEST(PictureLayerTilingTest
, RecycledTilesClearedOnReset
) {
2022 FakePictureLayerTilingClient active_client
;
2023 scoped_ptr
<TestablePictureLayerTiling
> active_tiling
;
2025 active_client
.SetTileSize(gfx::Size(100, 100));
2026 active_client
.set_tree(ACTIVE_TREE
);
2027 active_tiling
= TestablePictureLayerTiling::Create(
2028 1.0f
, // contents_scale
2029 gfx::Size(100, 100), &active_client
, LayerTreeSettings());
2030 // Create all tiles on this tiling.
2031 active_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
, 1.0f
,
2034 FakePictureLayerTilingClient recycle_client
;
2035 recycle_client
.SetTileSize(gfx::Size(100, 100));
2036 recycle_client
.set_tree(PENDING_TREE
);
2037 recycle_client
.set_twin_tiling(active_tiling
.get());
2039 LayerTreeSettings settings
;
2040 settings
.max_tiles_for_interest_area
= 10;
2041 scoped_ptr
<TestablePictureLayerTiling
> recycle_tiling
;
2042 recycle_tiling
= TestablePictureLayerTiling::Create(
2043 1.0f
, // contents_scale
2044 gfx::Size(100, 100), &recycle_client
, settings
);
2046 // Create all tiles on the recycle tiling. All tiles should be shared.
2047 recycle_tiling
->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f
,
2050 // Set the second tiling as recycled.
2051 active_client
.set_twin_tiling(NULL
);
2052 active_client
.set_recycled_twin_tiling(recycle_tiling
.get());
2053 recycle_client
.set_twin_tiling(NULL
);
2055 // Verify that tiles exist and are shared.
2056 EXPECT_TRUE(active_tiling
->TileAt(0, 0));
2057 EXPECT_TRUE(recycle_tiling
->TileAt(0, 0));
2058 EXPECT_EQ(active_tiling
->TileAt(0, 0), recycle_tiling
->TileAt(0, 0));
2060 // Reset the active tiling. The recycle tiles should be released too.
2061 active_tiling
->Reset();
2062 EXPECT_FALSE(active_tiling
->TileAt(0, 0));
2063 EXPECT_FALSE(recycle_tiling
->TileAt(0, 0));
2066 TEST_F(PictureLayerTilingIteratorTest
, ResizeTilesAndUpdateToCurrent
) {
2067 // The tiling has four rows and three columns.
2068 Initialize(gfx::Size(150, 100), 1.f
, gfx::Size(250, 150));
2069 tiling_
->CreateAllTilesForTesting();
2070 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
2071 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
2072 EXPECT_EQ(4u, tiling_
->AllRefTilesForTesting().size());
2074 client_
.SetTileSize(gfx::Size(250, 200));
2075 client_
.set_tree(PENDING_TREE
);
2077 // Tile size in the tiling should still be 150x100.
2078 EXPECT_EQ(150, tiling_
->TilingDataForTesting().max_texture_size().width());
2079 EXPECT_EQ(100, tiling_
->TilingDataForTesting().max_texture_size().height());
2081 tiling_
->Resize(gfx::Size(250, 150));
2083 // Tile size in the tiling should be resized to 250x200.
2084 EXPECT_EQ(250, tiling_
->TilingDataForTesting().max_texture_size().width());
2085 EXPECT_EQ(200, tiling_
->TilingDataForTesting().max_texture_size().height());
2086 EXPECT_EQ(0u, tiling_
->AllRefTilesForTesting().size());