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 "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/rect_conversions.h"
18 #include "ui/gfx/size_conversions.h"
23 static gfx::Rect ViewportInLayerSpace(
24 const gfx::Transform& transform,
25 const gfx::Size& device_viewport) {
27 gfx::Transform inverse;
28 if (!transform.GetInverse(&inverse))
31 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect(
32 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport));
33 return ToEnclosingRect(viewport_in_layer_space);
36 class TestablePictureLayerTiling : public PictureLayerTiling {
38 using PictureLayerTiling::SetLiveTilesRect;
39 using PictureLayerTiling::TileAt;
41 static scoped_ptr<TestablePictureLayerTiling> Create(
43 const gfx::Size& layer_bounds,
44 PictureLayerTilingClient* client) {
45 return make_scoped_ptr(new TestablePictureLayerTiling(
51 using PictureLayerTiling::ComputeSkewport;
54 TestablePictureLayerTiling(float contents_scale,
55 const gfx::Size& layer_bounds,
56 PictureLayerTilingClient* client)
57 : PictureLayerTiling(contents_scale, layer_bounds, client) { }
60 class PictureLayerTilingIteratorTest : public testing::Test {
62 PictureLayerTilingIteratorTest() {}
63 virtual ~PictureLayerTilingIteratorTest() {}
65 void Initialize(const gfx::Size& tile_size,
67 const gfx::Size& layer_bounds) {
68 client_.SetTileSize(tile_size);
69 tiling_ = TestablePictureLayerTiling::Create(contents_scale,
74 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) {
75 tiling_->SetLiveTilesRect(live_tiles_rect);
77 std::vector<Tile*> tiles = tiling_->AllTilesForTesting();
78 for (std::vector<Tile*>::iterator iter = tiles.begin();
81 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect()));
85 void VerifyTilesExactlyCoverRect(
87 const gfx::Rect& request_rect,
88 const gfx::Rect& expect_rect) {
89 EXPECT_TRUE(request_rect.Contains(expect_rect));
91 // Iterators are not valid if this ratio is too large (i.e. the
92 // tiling is too high-res for a low-res destination rect.) This is an
93 // artifact of snapping geometry to integer coordinates and then mapping
94 // back to floating point texture coordinates.
95 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale;
96 ASSERT_LE(dest_to_contents_scale, 2.0);
98 Region remaining = expect_rect;
99 for (PictureLayerTiling::CoverageIterator
100 iter(tiling_.get(), rect_scale, request_rect);
103 // Geometry cannot overlap previous geometry at all
104 gfx::Rect geometry = iter.geometry_rect();
105 EXPECT_TRUE(expect_rect.Contains(geometry));
106 EXPECT_TRUE(remaining.Contains(geometry));
107 remaining.Subtract(geometry);
109 // Sanity check that texture coords are within the texture rect.
110 gfx::RectF texture_rect = iter.texture_rect();
111 EXPECT_GE(texture_rect.x(), 0);
112 EXPECT_GE(texture_rect.y(), 0);
113 EXPECT_LE(texture_rect.right(), client_.TileSize().width());
114 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height());
116 EXPECT_EQ(iter.texture_size(), client_.TileSize());
119 // The entire rect must be filled by geometry from the tiling.
120 EXPECT_TRUE(remaining.IsEmpty());
123 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) {
124 VerifyTilesExactlyCoverRect(rect_scale, rect, rect);
129 const gfx::Rect& rect,
130 base::Callback<void(Tile* tile,
131 const gfx::Rect& geometry_rect)> callback) {
132 VerifyTiles(tiling_.get(),
139 PictureLayerTiling* tiling,
141 const gfx::Rect& rect,
142 base::Callback<void(Tile* tile,
143 const gfx::Rect& geometry_rect)> callback) {
144 Region remaining = rect;
145 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect);
148 remaining.Subtract(iter.geometry_rect());
149 callback.Run(*iter, iter.geometry_rect());
151 EXPECT_TRUE(remaining.IsEmpty());
154 void VerifyTilesCoverNonContainedRect(float rect_scale,
155 const gfx::Rect& dest_rect) {
156 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale;
157 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect(
158 tiling_->ContentRect(), 1.f / dest_to_contents_scale);
159 clamped_rect.Intersect(dest_rect);
160 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect);
163 void set_max_tiles_for_interest_area(size_t area) {
164 client_.set_max_tiles_for_interest_area(area);
168 FakePictureLayerTilingClient client_;
169 scoped_ptr<TestablePictureLayerTiling> tiling_;
172 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest);
175 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) {
176 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801));
177 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100));
178 SetLiveRectAndVerifyTiles(gfx::Rect(101, 99));
179 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
180 SetLiveRectAndVerifyTiles(gfx::Rect(1, 801));
181 SetLiveRectAndVerifyTiles(gfx::Rect(1099, 1));
182 SetLiveRectAndVerifyTiles(gfx::Rect(201, 800));
185 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsNoScale) {
186 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801));
187 VerifyTilesExactlyCoverRect(1, gfx::Rect());
188 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1099, 801));
189 VerifyTilesExactlyCoverRect(1, gfx::Rect(52, 83, 789, 412));
191 // With borders, a size of 3x3 = 1 pixel of content.
192 Initialize(gfx::Size(3, 3), 1, gfx::Size(10, 10));
193 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
194 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
195 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
196 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
199 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsTilingScale) {
200 Initialize(gfx::Size(200, 100), 2.0f, gfx::Size(1005, 2010));
201 VerifyTilesExactlyCoverRect(1, gfx::Rect());
202 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
203 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
205 Initialize(gfx::Size(3, 3), 2.0f, gfx::Size(10, 10));
206 VerifyTilesExactlyCoverRect(1, gfx::Rect());
207 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1, 1));
208 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 2, 2));
209 VerifyTilesExactlyCoverRect(1, gfx::Rect(1, 1, 2, 2));
210 VerifyTilesExactlyCoverRect(1, gfx::Rect(3, 2, 5, 2));
212 Initialize(gfx::Size(100, 200), 0.5f, gfx::Size(1005, 2010));
213 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
214 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
216 Initialize(gfx::Size(150, 250), 0.37f, gfx::Size(1005, 2010));
217 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
218 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
220 Initialize(gfx::Size(312, 123), 0.01f, gfx::Size(1005, 2010));
221 VerifyTilesExactlyCoverRect(1, gfx::Rect(0, 0, 1005, 2010));
222 VerifyTilesExactlyCoverRect(1, gfx::Rect(50, 112, 512, 381));
225 TEST_F(PictureLayerTilingIteratorTest, IteratorCoversLayerBoundsBothScale) {
226 Initialize(gfx::Size(50, 50), 4.0f, gfx::Size(800, 600));
227 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect());
228 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(0, 0, 1600, 1200));
229 VerifyTilesExactlyCoverRect(2.0f, gfx::Rect(512, 365, 253, 182));
232 gfx::Size bounds(800, 600);
233 gfx::Rect full_rect(gfx::ToCeiledSize(gfx::ScaleSize(bounds, scale)));
234 Initialize(gfx::Size(256, 512), 5.2f, bounds);
235 VerifyTilesExactlyCoverRect(scale, full_rect);
236 VerifyTilesExactlyCoverRect(scale, gfx::Rect(2014, 1579, 867, 1033));
239 TEST_F(PictureLayerTilingIteratorTest, IteratorEmptyRect) {
240 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600));
243 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.0f, empty);
247 TEST_F(PictureLayerTilingIteratorTest, NonIntersectingRect) {
248 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(800, 600));
249 gfx::Rect non_intersecting(1000, 1000, 50, 50);
250 PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1, non_intersecting);
254 TEST_F(PictureLayerTilingIteratorTest, LayerEdgeTextureCoordinates) {
255 Initialize(gfx::Size(300, 300), 1.0f, gfx::Size(256, 256));
256 // All of these sizes are 256x256, scaled and ceiled.
257 VerifyTilesExactlyCoverRect(1.0f, gfx::Rect(0, 0, 256, 256));
258 VerifyTilesExactlyCoverRect(0.8f, gfx::Rect(0, 0, 205, 205));
259 VerifyTilesExactlyCoverRect(1.2f, gfx::Rect(0, 0, 308, 308));
262 TEST_F(PictureLayerTilingIteratorTest, NonContainedDestRect) {
263 Initialize(gfx::Size(100, 100), 1.0f, gfx::Size(400, 400));
265 // Too large in all dimensions
266 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000));
267 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000));
268 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000));
270 // Partially covering content, but too large
271 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100));
272 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100));
273 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100));
276 TEST(PictureLayerTilingTest, SkewportLimits) {
277 FakePictureLayerTilingClient client;
278 client.set_skewport_extrapolation_limit_in_content_pixels(75);
279 scoped_ptr<TestablePictureLayerTiling> tiling;
281 gfx::Rect viewport(0, 0, 100, 100);
282 gfx::Size layer_bounds(200, 200);
284 client.SetTileSize(gfx::Size(100, 100));
285 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client);
287 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0);
289 // Move viewport down 50 pixels in 0.5 seconds.
290 gfx::Rect down_skewport =
291 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
293 EXPECT_EQ(0, down_skewport.x());
294 EXPECT_EQ(50, down_skewport.y());
295 EXPECT_EQ(100, down_skewport.width());
296 EXPECT_EQ(175, down_skewport.height());
297 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100)));
299 // Move viewport down 50 and right 10 pixels.
300 gfx::Rect down_right_skewport =
301 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
303 EXPECT_EQ(10, down_right_skewport.x());
304 EXPECT_EQ(50, down_right_skewport.y());
305 EXPECT_EQ(120, down_right_skewport.width());
306 EXPECT_EQ(175, down_right_skewport.height());
307 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100)));
309 // Move viewport left.
310 gfx::Rect left_skewport =
311 tiling->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100));
313 EXPECT_EQ(-125, left_skewport.x());
314 EXPECT_EQ(0, left_skewport.y());
315 EXPECT_EQ(175, left_skewport.width());
316 EXPECT_EQ(100, left_skewport.height());
317 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100)));
320 gfx::Rect expand_skewport =
321 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200));
323 // x and y moved by -75 (-50 - 75 = -125).
324 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75].
325 EXPECT_EQ(-125, expand_skewport.x());
326 EXPECT_EQ(-125, expand_skewport.y());
327 EXPECT_EQ(350, expand_skewport.width());
328 EXPECT_EQ(350, expand_skewport.height());
329 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200)));
331 // Expand the viewport past the limit.
332 gfx::Rect big_expand_skewport =
333 tiling->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500));
335 EXPECT_EQ(-575, big_expand_skewport.x());
336 EXPECT_EQ(-575, big_expand_skewport.y());
337 EXPECT_EQ(1650, big_expand_skewport.width());
338 EXPECT_EQ(1650, big_expand_skewport.height());
339 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500)));
342 TEST(PictureLayerTilingTest, ComputeSkewport) {
343 FakePictureLayerTilingClient client;
344 scoped_ptr<TestablePictureLayerTiling> tiling;
346 gfx::Rect viewport(0, 0, 100, 100);
347 gfx::Size layer_bounds(200, 200);
349 client.SetTileSize(gfx::Size(100, 100));
350 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client);
352 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0);
354 // Move viewport down 50 pixels in 0.5 seconds.
355 gfx::Rect down_skewport =
356 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100));
358 EXPECT_EQ(0, down_skewport.x());
359 EXPECT_EQ(50, down_skewport.y());
360 EXPECT_EQ(100, down_skewport.width());
361 EXPECT_EQ(200, down_skewport.height());
364 gfx::Rect shrink_skewport =
365 tiling->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50));
367 EXPECT_EQ(25, shrink_skewport.x());
368 EXPECT_EQ(25, shrink_skewport.y());
369 EXPECT_EQ(50, shrink_skewport.width());
370 EXPECT_EQ(50, shrink_skewport.height());
372 // Move viewport down 50 and right 10 pixels.
373 gfx::Rect down_right_skewport =
374 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100));
376 EXPECT_EQ(10, down_right_skewport.x());
377 EXPECT_EQ(50, down_right_skewport.y());
378 EXPECT_EQ(120, down_right_skewport.width());
379 EXPECT_EQ(200, down_right_skewport.height());
381 // Move viewport left.
382 gfx::Rect left_skewport =
383 tiling->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100));
385 EXPECT_EQ(-60, left_skewport.x());
386 EXPECT_EQ(0, left_skewport.y());
387 EXPECT_EQ(140, left_skewport.width());
388 EXPECT_EQ(100, left_skewport.height());
390 // Expand viewport in 0.2 seconds.
391 gfx::Rect expanded_skewport =
392 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110));
394 EXPECT_EQ(-30, expanded_skewport.x());
395 EXPECT_EQ(-30, expanded_skewport.y());
396 EXPECT_EQ(160, expanded_skewport.width());
397 EXPECT_EQ(160, expanded_skewport.height());
400 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) {
401 FakePictureLayerTilingClient client;
402 scoped_ptr<TestablePictureLayerTiling> tiling;
404 gfx::Rect viewport(0, 0, 100, 100);
405 gfx::Size layer_bounds(200, 200);
407 client.SetTileSize(gfx::Size(10, 10));
409 // Tiling at 0.25 scale: this should create 36 tiles (6x6) of size 10x10.
410 // The reason is that each tile has a one pixel border, so tile at (1, 2)
411 // for instance begins at (8, 16) pixels. So tile at (5, 5) will begin at
412 // (40, 40) and extend right to the end of 200 * 0.25 = 50 edge of the
414 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client);
415 gfx::Rect viewport_in_content_space =
416 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f));
418 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0);
421 for (int i = 0; i < 6; ++i) {
422 for (int j = 0; j < 6; ++j) {
423 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j;
426 for (int i = 0; i < 7; ++i) {
427 EXPECT_FALSE(tiling->TileAt(i, 6)) << "i: " << i;
428 EXPECT_FALSE(tiling->TileAt(6, i)) << "i: " << i;
431 // No movement in the viewport implies that tiles will either be NOW
433 bool have_now = false;
434 bool have_eventually = false;
435 for (int i = 0; i < 6; ++i) {
436 for (int j = 0; j < 6; ++j) {
437 Tile* tile = tiling->TileAt(i, j);
438 TilePriority priority = tile->priority(ACTIVE_TREE);
440 if (viewport_in_content_space.Intersects(tile->content_rect())) {
441 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
442 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
445 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin);
446 EXPECT_GT(priority.distance_to_visible, 0.f);
447 have_eventually = true;
452 EXPECT_TRUE(have_now);
453 EXPECT_TRUE(have_eventually);
455 // Spot check some distances.
456 // Tile at 5, 1 should begin at 41x9 in content space (without borders),
457 // so the distance to a viewport that ends at 25x25 in content space
458 // should be 17 (41 - 25 + 1). In layer space, then that should be
459 // 17 / 0.25 = 68 pixels.
461 // We can verify that the content rect (with borders) is one pixel off
462 // 41,9 8x8 on all sides.
463 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10");
465 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE);
466 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
468 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE);
469 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
471 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE);
472 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible);
474 // Move the viewport down 40 pixels.
475 viewport = gfx::Rect(0, 40, 100, 100);
476 viewport_in_content_space =
477 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f));
478 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space);
480 EXPECT_EQ(0, skewport.x());
481 EXPECT_EQ(10, skewport.y());
482 EXPECT_EQ(25, skewport.width());
483 EXPECT_EQ(35, skewport.height());
485 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 2.0);
488 have_eventually = false;
489 bool have_soon = false;
491 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and
492 // some EVENTUALLY tiles.
493 for (int i = 0; i < 6; ++i) {
494 for (int j = 0; j < 6; ++j) {
495 Tile* tile = tiling->TileAt(i, j);
496 TilePriority priority = tile->priority(ACTIVE_TREE);
498 if (viewport_in_content_space.Intersects(tile->content_rect())) {
499 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i
501 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i
504 } else if (skewport.Intersects(tile->content_rect())) {
505 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i
507 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
511 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin)
512 << "i: " << i << " j: " << j;
513 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i
515 have_eventually = true;
520 EXPECT_TRUE(have_now);
521 EXPECT_TRUE(have_soon);
522 EXPECT_TRUE(have_eventually);
524 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE);
525 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible);
527 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE);
528 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible);
530 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE);
531 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
533 // Change the underlying layer scale.
534 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 2.0f, 3.0);
536 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE);
537 EXPECT_FLOAT_EQ(34.f, priority.distance_to_visible);
539 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE);
540 EXPECT_FLOAT_EQ(14.f, priority.distance_to_visible);
542 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE);
543 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
546 TEST(PictureLayerTilingTest, ExpandRectEqual) {
547 gfx::Rect in(40, 50, 100, 200);
548 gfx::Rect bounds(-1000, -1000, 10000, 10000);
549 int64 target_area = 100 * 200;
550 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
551 in, target_area, bounds, NULL);
552 EXPECT_EQ(in.ToString(), out.ToString());
555 TEST(PictureLayerTilingTest, ExpandRectSmaller) {
556 gfx::Rect in(40, 50, 100, 200);
557 gfx::Rect bounds(-1000, -1000, 10000, 10000);
558 int64 target_area = 100 * 100;
559 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
560 in, target_area, bounds, NULL);
561 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
562 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
563 EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
564 EXPECT_NEAR(100 * 100, out.width() * out.height(), 50);
565 EXPECT_TRUE(bounds.Contains(out));
568 TEST(PictureLayerTilingTest, ExpandRectUnbounded) {
569 gfx::Rect in(40, 50, 100, 200);
570 gfx::Rect bounds(-1000, -1000, 10000, 10000);
571 int64 target_area = 200 * 200;
572 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
573 in, target_area, bounds, NULL);
574 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
575 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
576 EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
577 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100);
578 EXPECT_TRUE(bounds.Contains(out));
581 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) {
582 gfx::Rect in(40, 50, 100, 200);
583 gfx::Rect bounds(50, 60, 40, 30);
584 int64 target_area = 200 * 200;
585 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
586 in, target_area, bounds, NULL);
587 EXPECT_EQ(bounds.ToString(), out.ToString());
590 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) {
591 gfx::Rect in(40, 50, 100, 200);
592 gfx::Rect bounds = in;
593 int64 target_area = 200 * 200;
594 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
595 in, target_area, bounds, NULL);
596 EXPECT_EQ(bounds.ToString(), out.ToString());
599 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) {
600 gfx::Rect in(40, 50, 100, 200);
601 gfx::Rect bounds(45, 0, 90, 300);
602 int64 target_area = 200 * 200;
603 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
604 in, target_area, bounds, NULL);
605 EXPECT_EQ(bounds.ToString(), out.ToString());
608 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) {
609 gfx::Rect in(40, 50, 100, 200);
610 gfx::Rect bounds(40, 0, 100, 300);
611 int64 target_area = 200 * 200;
612 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
613 in, target_area, bounds, NULL);
614 EXPECT_EQ(bounds.ToString(), out.ToString());
617 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) {
618 gfx::Rect in(40, 50, 100, 200);
619 gfx::Rect bounds(0, 55, 180, 190);
620 int64 target_area = 200 * 200;
621 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
622 in, target_area, bounds, NULL);
623 EXPECT_EQ(bounds.ToString(), out.ToString());
626 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) {
627 gfx::Rect in(40, 50, 100, 200);
628 gfx::Rect bounds(0, 50, 180, 200);
629 int64 target_area = 200 * 200;
630 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
631 in, target_area, bounds, NULL);
632 EXPECT_EQ(bounds.ToString(), out.ToString());
635 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) {
636 gfx::Rect in(40, 50, 100, 200);
637 gfx::Rect bounds(20, -1000, 10000, 10000);
638 int64 target_area = 200 * 200;
639 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
640 in, target_area, bounds, NULL);
641 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
642 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right());
643 EXPECT_LE(out.width() * out.height(), target_area);
644 EXPECT_GT(out.width() * out.height(),
645 target_area - out.width() - out.height() * 2);
646 EXPECT_TRUE(bounds.Contains(out));
649 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) {
650 gfx::Rect in(40, 50, 100, 200);
651 gfx::Rect bounds(-1000, -1000, 1000+120, 10000);
652 int64 target_area = 200 * 200;
653 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
654 in, target_area, bounds, NULL);
655 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
656 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x());
657 EXPECT_LE(out.width() * out.height(), target_area);
658 EXPECT_GT(out.width() * out.height(),
659 target_area - out.width() - out.height() * 2);
660 EXPECT_TRUE(bounds.Contains(out));
663 TEST(PictureLayerTilingTest, ExpandRectBoundedTop) {
664 gfx::Rect in(40, 50, 100, 200);
665 gfx::Rect bounds(-1000, 30, 10000, 10000);
666 int64 target_area = 200 * 200;
667 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
668 in, target_area, bounds, NULL);
669 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
670 EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom());
671 EXPECT_LE(out.width() * out.height(), target_area);
672 EXPECT_GT(out.width() * out.height(),
673 target_area - out.width() * 2 - out.height());
674 EXPECT_TRUE(bounds.Contains(out));
677 TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) {
678 gfx::Rect in(40, 50, 100, 200);
679 gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220);
680 int64 target_area = 200 * 200;
681 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
682 in, target_area, bounds, NULL);
683 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
684 EXPECT_EQ(out.right() - in.right(), in.y() - out.y());
685 EXPECT_LE(out.width() * out.height(), target_area);
686 EXPECT_GT(out.width() * out.height(),
687 target_area - out.width() * 2 - out.height());
688 EXPECT_TRUE(bounds.Contains(out));
691 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) {
692 gfx::Rect in(40, 50, 100, 200);
693 gfx::Rect bounds(0, -4000, 100+40+20, 100000);
694 int64 target_area = 400 * 400;
695 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
696 in, target_area, bounds, NULL);
697 EXPECT_EQ(20, out.right() - in.right());
698 EXPECT_EQ(40, in.x() - out.x());
699 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
700 EXPECT_LE(out.width() * out.height(), target_area);
701 EXPECT_GT(out.width() * out.height(),
702 target_area - out.width() * 2);
703 EXPECT_TRUE(bounds.Contains(out));
706 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) {
707 gfx::Rect in(40, 50, 100, 200);
708 gfx::Rect bounds(-4000, 0, 100000, 200+50+30);
709 int64 target_area = 400 * 400;
710 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
711 in, target_area, bounds, NULL);
712 EXPECT_EQ(30, out.bottom() - in.bottom());
713 EXPECT_EQ(50, in.y() - out.y());
714 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
715 EXPECT_LE(out.width() * out.height(), target_area);
716 EXPECT_GT(out.width() * out.height(),
717 target_area - out.height() * 2);
718 EXPECT_TRUE(bounds.Contains(out));
721 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) {
722 gfx::Rect in(400, 500, 100, 200);
723 gfx::Rect bounds(0, 0, 10, 10);
724 int64 target_area = 400 * 400;
725 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
726 in, target_area, bounds, NULL);
727 EXPECT_TRUE(out.IsEmpty());
730 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedFullyCover) {
731 gfx::Rect in(40, 50, 100, 100);
732 gfx::Rect bounds(0, 0, 10, 10);
733 int64 target_area = 400 * 400;
734 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
735 in, target_area, bounds, NULL);
736 EXPECT_EQ(bounds.ToString(), out.ToString());
739 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsExpandedPartlyCover) {
740 gfx::Rect in(600, 600, 100, 100);
741 gfx::Rect bounds(0, 0, 500, 500);
742 int64 target_area = 400 * 400;
743 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
744 in, target_area, bounds, NULL);
745 EXPECT_EQ(bounds.right(), out.right());
746 EXPECT_EQ(bounds.bottom(), out.bottom());
747 EXPECT_LE(out.width() * out.height(), target_area);
748 EXPECT_GT(out.width() * out.height(),
749 target_area - out.width() - out.height());
750 EXPECT_TRUE(bounds.Contains(out));
753 TEST(PictureLayerTilingTest, EmptyStartingRect) {
754 // If a layer has a non-invertible transform, then the starting rect
755 // for the layer would be empty.
756 gfx::Rect in(40, 40, 0, 0);
757 gfx::Rect bounds(0, 0, 10, 10);
758 int64 target_area = 400 * 400;
759 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
760 in, target_area, bounds, NULL);
761 EXPECT_TRUE(out.IsEmpty());
764 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) {
765 FakePictureLayerTilingClient client;
766 scoped_ptr<TestablePictureLayerTiling> tiling;
768 gfx::Rect viewport(50, 50, 100, 100);
769 gfx::Size layer_bounds(200, 200);
771 client.SetTileSize(gfx::Size(30, 30));
773 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client);
774 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.0f, 1.0);
776 PictureLayerTiling::TilingRasterTileIterator empty_iterator;
777 EXPECT_FALSE(empty_iterator);
779 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting();
782 EXPECT_EQ(64u, all_tiles.size());
784 // The explanation of each iteration is as follows:
785 // 1. First iteration tests that we can get all of the tiles correctly.
786 // 2. Second iteration ensures that we can get all of the tiles again (first
787 // iteration didn't change any tiles), as well set all tiles to be ready to
789 // 3. Third iteration ensures that no tiles are returned, since they were all
790 // marked as ready to draw.
791 for (int i = 0; i < 3; ++i) {
792 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE);
794 // There are 3 bins in TilePriority.
795 bool have_tiles[3] = {};
797 // On the third iteration, we should get no tiles since everything was
798 // marked as ready to draw.
805 std::set<Tile*> unique_tiles;
806 unique_tiles.insert(*it);
807 Tile* last_tile = *it;
808 have_tiles[last_tile->priority(ACTIVE_TREE).priority_bin] = true;
810 // On the second iteration, mark everything as ready to draw (solid color).
812 ManagedTileState::TileVersion& tile_version =
813 last_tile->GetTileVersionForTesting(
814 last_tile->DetermineRasterModeForTree(ACTIVE_TREE));
815 tile_version.SetSolidColorForTesting(SK_ColorRED);
818 int eventually_bin_order_correct_count = 0;
819 int eventually_bin_order_incorrect_count = 0;
821 Tile* new_tile = *it;
823 unique_tiles.insert(new_tile);
825 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
826 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
827 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
828 if (last_priority.priority_bin == new_priority.priority_bin) {
829 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
830 bool order_correct = last_priority.distance_to_visible <=
831 new_priority.distance_to_visible;
832 eventually_bin_order_correct_count += order_correct;
833 eventually_bin_order_incorrect_count += !order_correct;
835 EXPECT_LE(last_priority.distance_to_visible,
836 new_priority.distance_to_visible);
839 have_tiles[new_priority.priority_bin] = true;
841 last_tile = new_tile;
843 // On the second iteration, mark everything as ready to draw (solid
846 ManagedTileState::TileVersion& tile_version =
847 last_tile->GetTileVersionForTesting(
848 last_tile->DetermineRasterModeForTree(ACTIVE_TREE));
849 tile_version.SetSolidColorForTesting(SK_ColorRED);
853 EXPECT_GT(eventually_bin_order_correct_count,
854 eventually_bin_order_incorrect_count);
856 // We should have now and eventually tiles, but not soon tiles because the
857 // viewport is static.
858 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
859 EXPECT_FALSE(have_tiles[TilePriority::SOON]);
860 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
862 EXPECT_EQ(unique_tiles.size(), all_tiles.size());
866 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) {
867 FakePictureLayerTilingClient client;
868 scoped_ptr<TestablePictureLayerTiling> tiling;
870 gfx::Rect viewport(50, 0, 100, 100);
871 gfx::Rect moved_viewport(50, 0, 100, 250);
872 gfx::Size layer_bounds(500, 500);
874 client.SetTileSize(gfx::Size(30, 30));
876 tiling = TestablePictureLayerTiling::Create(1.f, layer_bounds, &client);
877 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.0f, 1.0);
878 tiling->UpdateTilePriorities(ACTIVE_TREE, moved_viewport, 1.0f, 2.0);
880 // There are 3 bins in TilePriority.
881 bool have_tiles[3] = {};
882 Tile* last_tile = NULL;
883 int eventually_bin_order_correct_count = 0;
884 int eventually_bin_order_incorrect_count = 0;
885 for (PictureLayerTiling::TilingRasterTileIterator it(tiling.get(),
892 Tile* new_tile = *it;
894 TilePriority last_priority = last_tile->priority(ACTIVE_TREE);
895 TilePriority new_priority = new_tile->priority(ACTIVE_TREE);
897 have_tiles[new_priority.priority_bin] = true;
899 EXPECT_LE(last_priority.priority_bin, new_priority.priority_bin);
900 if (last_priority.priority_bin == new_priority.priority_bin) {
901 if (last_priority.priority_bin == TilePriority::EVENTUALLY) {
902 bool order_correct = last_priority.distance_to_visible <=
903 new_priority.distance_to_visible;
904 eventually_bin_order_correct_count += order_correct;
905 eventually_bin_order_incorrect_count += !order_correct;
907 EXPECT_LE(last_priority.distance_to_visible,
908 new_priority.distance_to_visible);
911 last_tile = new_tile;
914 EXPECT_GT(eventually_bin_order_correct_count,
915 eventually_bin_order_incorrect_count);
917 EXPECT_TRUE(have_tiles[TilePriority::NOW]);
918 EXPECT_TRUE(have_tiles[TilePriority::SOON]);
919 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]);
922 static void TileExists(bool exists, Tile* tile,
923 const gfx::Rect& geometry_rect) {
924 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString();
927 TEST_F(PictureLayerTilingIteratorTest, TilesExist) {
928 gfx::Size layer_bounds(1099, 801);
929 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
930 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
931 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
933 tiling_->UpdateTilePriorities(
935 gfx::Rect(layer_bounds), // visible content rect
936 1.f, // current contents scale
937 1.0); // current frame time
938 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true));
940 // Make the viewport rect empty. All tiles are killed and become zombies.
941 tiling_->UpdateTilePriorities(ACTIVE_TREE,
942 gfx::Rect(), // visible content rect
943 1.f, // current contents scale
944 2.0); // current frame time
945 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
948 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) {
949 gfx::Size layer_bounds(1099, 801);
950 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
951 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
952 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
954 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000);
956 tiling_->UpdateTilePriorities(
958 gfx::Rect(layer_bounds), // visible content rect
959 1.f, // current contents scale
960 1.0); // current frame time
961 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true));
963 // If the visible content rect is empty, it should still have live tiles.
964 tiling_->UpdateTilePriorities(ACTIVE_TREE,
965 giant_rect, // visible content rect
966 1.f, // current contents scale
967 2.0); // current frame time
968 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true));
971 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) {
972 gfx::Size layer_bounds(1099, 801);
973 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
974 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
975 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
977 // This rect does not intersect with the layer, as the layer is outside the
979 gfx::Rect viewport_rect(1100, 0, 1000, 1000);
980 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds)));
982 tiling_->UpdateTilePriorities(ACTIVE_TREE,
983 viewport_rect, // visible content rect
984 1.f, // current contents scale
985 1.0); // current frame time
986 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true));
989 static void TilesIntersectingRectExist(const gfx::Rect& rect,
990 bool intersect_exists,
992 const gfx::Rect& geometry_rect) {
993 bool intersects = rect.Intersects(geometry_rect);
994 bool expected_exists = intersect_exists ? intersects : !intersects;
995 EXPECT_EQ(expected_exists, tile != NULL)
996 << "Rects intersecting " << rect.ToString() << " should exist. "
997 << "Current tile rect is " << geometry_rect.ToString();
1000 TEST_F(PictureLayerTilingIteratorTest,
1001 TilesExistLargeViewportAndLayerWithSmallVisibleArea) {
1002 gfx::Size layer_bounds(10000, 10000);
1003 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
1004 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
1005 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
1007 gfx::Rect visible_rect(8000, 8000, 50, 50);
1009 set_max_tiles_for_interest_area(1);
1010 tiling_->UpdateTilePriorities(ACTIVE_TREE,
1011 visible_rect, // visible content rect
1012 1.f, // current contents scale
1013 1.0); // current frame time
1015 gfx::Rect(layer_bounds),
1016 base::Bind(&TilesIntersectingRectExist, visible_rect, true));
1019 static void CountExistingTiles(int *count,
1021 const gfx::Rect& geometry_rect) {
1026 TEST_F(PictureLayerTilingIteratorTest,
1027 TilesExistLargeViewportAndLayerWithLargeVisibleArea) {
1028 gfx::Size layer_bounds(10000, 10000);
1029 Initialize(gfx::Size(100, 100), 1.f, layer_bounds);
1030 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
1031 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
1033 set_max_tiles_for_interest_area(1);
1034 tiling_->UpdateTilePriorities(
1036 gfx::Rect(layer_bounds), // visible content rect
1037 1.f, // current contents scale
1038 1.0); // current frame time
1042 gfx::Rect(layer_bounds),
1043 base::Bind(&CountExistingTiles, &num_tiles));
1044 // If we're making a rect the size of one tile, it can only overlap up to 4
1045 // tiles depending on its position.
1046 EXPECT_LE(num_tiles, 4);
1047 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false));
1050 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) {
1051 gfx::Size layer_bounds(1099, 801);
1052 gfx::Size tile_size(100, 100);
1054 client_.SetTileSize(tile_size);
1056 PictureLayerTilingSet active_set(&client_, layer_bounds);
1058 active_set.AddTiling(1.f);
1060 VerifyTiles(active_set.tiling_at(0),
1062 gfx::Rect(layer_bounds),
1063 base::Bind(&TileExists, false));
1065 active_set.UpdateTilePriorities(
1067 gfx::Rect(layer_bounds), // visible content rect
1068 1.f, // current contents scale
1069 1.0); // current frame time
1071 // The active tiling has tiles now.
1072 VerifyTiles(active_set.tiling_at(0),
1074 gfx::Rect(layer_bounds),
1075 base::Bind(&TileExists, true));
1077 // Add the same tilings to the pending set.
1078 PictureLayerTilingSet pending_set(&client_, layer_bounds);
1079 Region invalidation;
1080 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f);
1082 // The pending tiling starts with no tiles.
1083 VerifyTiles(pending_set.tiling_at(0),
1085 gfx::Rect(layer_bounds),
1086 base::Bind(&TileExists, false));
1088 // UpdateTilePriorities on the pending tiling at the same frame time. The
1089 // pending tiling should get tiles.
1090 pending_set.UpdateTilePriorities(
1092 gfx::Rect(layer_bounds), // visible content rect
1093 1.f, // current contents scale
1094 1.0); // current frame time
1096 VerifyTiles(pending_set.tiling_at(0),
1098 gfx::Rect(layer_bounds),
1099 base::Bind(&TileExists, true));
1102 TEST(UpdateTilePrioritiesTest, VisibleTiles) {
1103 // The TilePriority of visible tiles should have zero distance_to_visible
1104 // and time_to_visible.
1106 FakePictureLayerTilingClient client;
1107 scoped_ptr<TestablePictureLayerTiling> tiling;
1109 gfx::Size device_viewport(800, 600);
1110 gfx::Size last_layer_bounds(200, 200);
1111 gfx::Size current_layer_bounds(200, 200);
1112 float current_layer_contents_scale = 1.f;
1113 gfx::Transform current_screen_transform;
1114 double current_frame_time_in_seconds = 1.0;
1116 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1117 current_screen_transform, device_viewport);
1119 client.SetTileSize(gfx::Size(100, 100));
1120 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1121 current_layer_bounds,
1124 tiling->UpdateTilePriorities(ACTIVE_TREE,
1125 viewport_in_layer_space,
1126 current_layer_contents_scale,
1127 current_frame_time_in_seconds);
1129 ASSERT_TRUE(tiling->TileAt(0, 0));
1130 ASSERT_TRUE(tiling->TileAt(0, 1));
1131 ASSERT_TRUE(tiling->TileAt(1, 0));
1132 ASSERT_TRUE(tiling->TileAt(1, 1));
1134 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1135 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1136 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1138 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1139 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1140 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1142 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1143 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1144 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1146 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1147 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1148 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1151 TEST(UpdateTilePrioritiesTest, OffscreenTiles) {
1152 // The TilePriority of offscreen tiles (without movement) should have nonzero
1153 // distance_to_visible and infinite time_to_visible.
1155 FakePictureLayerTilingClient client;
1156 scoped_ptr<TestablePictureLayerTiling> tiling;
1158 gfx::Size device_viewport(800, 600);
1159 gfx::Size last_layer_bounds(200, 200);
1160 gfx::Size current_layer_bounds(200, 200);
1161 float current_layer_contents_scale = 1.f;
1162 gfx::Transform last_screen_transform;
1163 gfx::Transform current_screen_transform;
1164 double current_frame_time_in_seconds = 1.0;
1166 current_screen_transform.Translate(850, 0);
1167 last_screen_transform = current_screen_transform;
1169 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1170 current_screen_transform, device_viewport);
1172 client.SetTileSize(gfx::Size(100, 100));
1173 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1174 current_layer_bounds,
1177 tiling->UpdateTilePriorities(ACTIVE_TREE,
1178 viewport_in_layer_space,
1179 current_layer_contents_scale,
1180 current_frame_time_in_seconds);
1182 ASSERT_TRUE(tiling->TileAt(0, 0));
1183 ASSERT_TRUE(tiling->TileAt(0, 1));
1184 ASSERT_TRUE(tiling->TileAt(1, 0));
1185 ASSERT_TRUE(tiling->TileAt(1, 1));
1187 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1188 EXPECT_GT(priority.distance_to_visible, 0.f);
1189 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1191 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1192 EXPECT_GT(priority.distance_to_visible, 0.f);
1193 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1195 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1196 EXPECT_GT(priority.distance_to_visible, 0.f);
1197 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1199 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1200 EXPECT_GT(priority.distance_to_visible, 0.f);
1201 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1203 // Furthermore, in this scenario tiles on the right hand side should have a
1204 // larger distance to visible.
1205 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1206 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1207 EXPECT_GT(right.distance_to_visible, left.distance_to_visible);
1209 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1210 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1211 EXPECT_GT(right.distance_to_visible, left.distance_to_visible);
1214 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) {
1215 // Sanity check that a layer with some tiles visible and others offscreen has
1216 // correct TilePriorities for each tile.
1218 FakePictureLayerTilingClient client;
1219 scoped_ptr<TestablePictureLayerTiling> tiling;
1221 gfx::Size device_viewport(800, 600);
1222 gfx::Size last_layer_bounds(200, 200);
1223 gfx::Size current_layer_bounds(200, 200);
1224 float current_layer_contents_scale = 1.f;
1225 gfx::Transform last_screen_transform;
1226 gfx::Transform current_screen_transform;
1227 double current_frame_time_in_seconds = 1.0;
1229 current_screen_transform.Translate(705, 505);
1230 last_screen_transform = current_screen_transform;
1232 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1233 current_screen_transform, device_viewport);
1235 client.SetTileSize(gfx::Size(100, 100));
1236 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1237 current_layer_bounds,
1240 tiling->UpdateTilePriorities(ACTIVE_TREE,
1241 viewport_in_layer_space,
1242 current_layer_contents_scale,
1243 current_frame_time_in_seconds);
1245 ASSERT_TRUE(tiling->TileAt(0, 0));
1246 ASSERT_TRUE(tiling->TileAt(0, 1));
1247 ASSERT_TRUE(tiling->TileAt(1, 0));
1248 ASSERT_TRUE(tiling->TileAt(1, 1));
1250 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1251 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1252 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1254 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1255 EXPECT_GT(priority.distance_to_visible, 0.f);
1256 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1258 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1259 EXPECT_GT(priority.distance_to_visible, 0.f);
1260 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1262 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1263 EXPECT_GT(priority.distance_to_visible, 0.f);
1264 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1267 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) {
1268 // Each tile of a layer may be affected differently by a transform; Check
1269 // that UpdateTilePriorities correctly accounts for the transform between
1270 // layer space and screen space.
1272 FakePictureLayerTilingClient client;
1273 scoped_ptr<TestablePictureLayerTiling> tiling;
1275 gfx::Size device_viewport(800, 600);
1276 gfx::Size last_layer_bounds(200, 200);
1277 gfx::Size current_layer_bounds(200, 200);
1278 float current_layer_contents_scale = 1.f;
1279 gfx::Transform last_screen_transform;
1280 gfx::Transform current_screen_transform;
1281 double current_frame_time_in_seconds = 1.0;
1283 // A diagonally rotated layer that is partially off the bottom of the screen.
1284 // In this configuration, only the top-left tile would be visible.
1285 current_screen_transform.Translate(600, 750);
1286 current_screen_transform.RotateAboutZAxis(45);
1287 last_screen_transform = current_screen_transform;
1289 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1290 current_screen_transform, device_viewport);
1292 client.SetTileSize(gfx::Size(100, 100));
1293 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1294 current_layer_bounds,
1297 tiling->UpdateTilePriorities(ACTIVE_TREE,
1298 viewport_in_layer_space,
1299 current_layer_contents_scale,
1300 current_frame_time_in_seconds);
1302 ASSERT_TRUE(tiling->TileAt(0, 0));
1303 ASSERT_TRUE(tiling->TileAt(0, 1));
1304 ASSERT_TRUE(tiling->TileAt(1, 0));
1305 ASSERT_TRUE(tiling->TileAt(1, 1));
1307 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1308 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1309 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1311 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1312 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1313 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1315 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1316 EXPECT_GT(priority.distance_to_visible, 0.f);
1317 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1319 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1320 EXPECT_GT(priority.distance_to_visible, 0.f);
1321 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1323 // Furthermore, in this scenario the bottom-right tile should have the larger
1324 // distance to visible.
1325 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1326 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1327 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1328 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible);
1330 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible);
1333 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) {
1334 // Perspective transforms need to take a different code path.
1335 // This test checks tile priorities of a perspective layer.
1337 FakePictureLayerTilingClient client;
1338 scoped_ptr<TestablePictureLayerTiling> tiling;
1340 gfx::Size device_viewport(800, 600);
1341 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen.
1342 gfx::Size last_layer_bounds(200, 200);
1343 gfx::Size current_layer_bounds(200, 200);
1344 float current_layer_contents_scale = 1.f;
1345 gfx::Transform last_screen_transform;
1346 gfx::Transform current_screen_transform;
1347 double current_frame_time_in_seconds = 1.0;
1349 // A 3d perspective layer rotated about its Y axis, translated to almost
1350 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1351 // the right side, so the top-left tile will technically be closer than the
1354 // Translate layer to offscreen
1355 current_screen_transform.Translate(400.0, 630.0);
1356 // Apply perspective about the center of the layer
1357 current_screen_transform.Translate(100.0, 100.0);
1358 current_screen_transform.ApplyPerspectiveDepth(100.0);
1359 current_screen_transform.RotateAboutYAxis(10.0);
1360 current_screen_transform.Translate(-100.0, -100.0);
1361 last_screen_transform = current_screen_transform;
1363 // Sanity check that this transform wouldn't cause w<0 clipping.
1365 MathUtil::MapQuad(current_screen_transform,
1366 gfx::QuadF(gfx::RectF(0, 0, 200, 200)),
1368 ASSERT_FALSE(clipped);
1370 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1371 current_screen_transform, device_viewport);
1373 client.SetTileSize(gfx::Size(100, 100));
1374 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1375 current_layer_bounds,
1378 tiling->UpdateTilePriorities(ACTIVE_TREE,
1379 viewport_in_layer_space,
1380 current_layer_contents_scale,
1381 current_frame_time_in_seconds);
1383 ASSERT_TRUE(tiling->TileAt(0, 0));
1384 ASSERT_TRUE(tiling->TileAt(0, 1));
1385 ASSERT_TRUE(tiling->TileAt(1, 0));
1386 ASSERT_TRUE(tiling->TileAt(1, 1));
1388 // All tiles will have a positive distance_to_visible
1389 // and an infinite time_to_visible.
1390 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1391 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f);
1392 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1394 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1395 EXPECT_GT(priority.distance_to_visible, 0.f);
1396 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1398 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1399 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f);
1400 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1402 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1403 EXPECT_GT(priority.distance_to_visible, 0.f);
1404 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1406 // Furthermore, in this scenario the top-left distance_to_visible
1407 // will be smallest, followed by top-right. The bottom layers
1408 // will of course be further than the top layers.
1409 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1410 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1411 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1412 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1414 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible);
1416 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible);
1419 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) {
1420 // Perspective transforms need to take a different code path.
1421 // This test checks tile priorities of a perspective layer.
1423 FakePictureLayerTilingClient client;
1424 scoped_ptr<TestablePictureLayerTiling> tiling;
1426 gfx::Size device_viewport(800, 600);
1427 gfx::Size last_layer_bounds(200, 200);
1428 gfx::Size current_layer_bounds(200, 200);
1429 float current_layer_contents_scale = 1.f;
1430 gfx::Transform last_screen_transform;
1431 gfx::Transform current_screen_transform;
1432 double current_frame_time_in_seconds = 1.0;
1434 // A 3d perspective layer rotated about its Y axis, translated to almost
1435 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than
1436 // the right side, so the top-left tile will technically be closer than the
1439 // Translate layer to offscreen
1440 current_screen_transform.Translate(400.0, 970.0);
1441 // Apply perspective and rotation about the center of the layer
1442 current_screen_transform.Translate(100.0, 100.0);
1443 current_screen_transform.ApplyPerspectiveDepth(10.0);
1444 current_screen_transform.RotateAboutYAxis(10.0);
1445 current_screen_transform.Translate(-100.0, -100.0);
1446 last_screen_transform = current_screen_transform;
1448 // Sanity check that this transform does cause w<0 clipping for the left side
1449 // of the layer, but not the right side.
1451 MathUtil::MapQuad(current_screen_transform,
1452 gfx::QuadF(gfx::RectF(0, 0, 100, 200)),
1454 ASSERT_TRUE(clipped);
1456 MathUtil::MapQuad(current_screen_transform,
1457 gfx::QuadF(gfx::RectF(100, 0, 100, 200)),
1459 ASSERT_FALSE(clipped);
1461 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1462 current_screen_transform, device_viewport);
1464 client.SetTileSize(gfx::Size(100, 100));
1465 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1466 current_layer_bounds,
1469 tiling->UpdateTilePriorities(ACTIVE_TREE,
1470 viewport_in_layer_space,
1471 current_layer_contents_scale,
1472 current_frame_time_in_seconds);
1474 ASSERT_TRUE(tiling->TileAt(0, 0));
1475 ASSERT_TRUE(tiling->TileAt(0, 1));
1476 ASSERT_TRUE(tiling->TileAt(1, 0));
1477 ASSERT_TRUE(tiling->TileAt(1, 1));
1479 // Left-side tiles will be clipped by the transform, so we have to assume
1480 // they are visible just in case.
1481 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1482 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1483 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin);
1485 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1486 EXPECT_GT(priority.distance_to_visible, 0.f);
1487 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1489 // Right-side tiles will have a positive distance_to_visible
1490 // and an infinite time_to_visible.
1491 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1492 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f);
1493 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1495 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1496 EXPECT_GT(priority.distance_to_visible, 0.f);
1497 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1500 TEST(UpdateTilePrioritiesTest, BasicMotion) {
1501 // Test that time_to_visible is computed correctly when
1502 // there is some motion.
1504 FakePictureLayerTilingClient client;
1505 scoped_ptr<TestablePictureLayerTiling> tiling;
1507 gfx::Size device_viewport(800, 600);
1508 gfx::Rect visible_layer_rect(0, 0, 0, 0);
1509 gfx::Size last_layer_bounds(200, 200);
1510 gfx::Size current_layer_bounds(200, 200);
1511 float last_layer_contents_scale = 1.f;
1512 float current_layer_contents_scale = 1.f;
1513 gfx::Transform last_screen_transform;
1514 gfx::Transform current_screen_transform;
1515 double last_frame_time_in_seconds = 1.0;
1516 double current_frame_time_in_seconds = 2.0;
1518 // Offscreen layer is coming closer to viewport at 1000 pixels per second.
1519 current_screen_transform.Translate(1800, 0);
1520 last_screen_transform.Translate(2800, 0);
1522 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1523 current_screen_transform, device_viewport);
1525 client.SetTileSize(gfx::Size(100, 100));
1526 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1527 current_layer_bounds,
1530 // previous ("last") frame
1531 tiling->UpdateTilePriorities(ACTIVE_TREE,
1532 viewport_in_layer_space,
1533 last_layer_contents_scale,
1534 last_frame_time_in_seconds);
1537 tiling->UpdateTilePriorities(ACTIVE_TREE,
1538 viewport_in_layer_space,
1539 current_layer_contents_scale,
1540 current_frame_time_in_seconds);
1542 ASSERT_TRUE(tiling->TileAt(0, 0));
1543 ASSERT_TRUE(tiling->TileAt(0, 1));
1544 ASSERT_TRUE(tiling->TileAt(1, 0));
1545 ASSERT_TRUE(tiling->TileAt(1, 1));
1547 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1548 EXPECT_GT(priority.distance_to_visible, 0.f);
1549 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1551 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1552 EXPECT_GT(priority.distance_to_visible, 0.f);
1553 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1555 // time_to_visible for the right hand side layers needs an extra 0.099
1556 // seconds because this tile is 99 pixels further away.
1557 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1558 EXPECT_GT(priority.distance_to_visible, 0.f);
1559 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1561 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE);
1562 EXPECT_GT(priority.distance_to_visible, 0.f);
1563 EXPECT_NE(TilePriority::NOW, priority.priority_bin);
1566 TEST(UpdateTilePrioritiesTest, RotationMotion) {
1567 // Each tile of a layer may be affected differently by a transform; Check
1568 // that UpdateTilePriorities correctly accounts for the transform between
1569 // layer space and screen space.
1571 FakePictureLayerTilingClient client;
1572 scoped_ptr<TestablePictureLayerTiling> tiling;
1574 gfx::Size device_viewport(800, 600);
1575 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren.
1576 gfx::Size last_layer_bounds(200, 200);
1577 gfx::Size current_layer_bounds(200, 200);
1578 float last_layer_contents_scale = 1.f;
1579 float current_layer_contents_scale = 1.f;
1580 gfx::Transform last_screen_transform;
1581 gfx::Transform current_screen_transform;
1582 double last_frame_time_in_seconds = 1.0;
1583 double current_frame_time_in_seconds = 2.0;
1585 // Rotation motion is set up specifically so that:
1586 // - rotation occurs about the center of the layer
1587 // - the top-left tile becomes visible on rotation
1588 // - the top-right tile will have an infinite time_to_visible
1589 // because it is rotating away from viewport.
1590 // - bottom-left layer will have a positive non-zero time_to_visible
1591 // because it is rotating toward the viewport.
1592 current_screen_transform.Translate(400, 550);
1593 current_screen_transform.RotateAboutZAxis(45);
1595 last_screen_transform.Translate(400, 550);
1597 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace(
1598 current_screen_transform, device_viewport);
1600 client.SetTileSize(gfx::Size(100, 100));
1601 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale
1602 current_layer_bounds,
1605 // previous ("last") frame
1606 tiling->UpdateTilePriorities(ACTIVE_TREE,
1607 viewport_in_layer_space,
1608 last_layer_contents_scale,
1609 last_frame_time_in_seconds);
1612 tiling->UpdateTilePriorities(ACTIVE_TREE,
1613 viewport_in_layer_space,
1614 current_layer_contents_scale,
1615 current_frame_time_in_seconds);
1617 ASSERT_TRUE(tiling->TileAt(0, 0));
1618 ASSERT_TRUE(tiling->TileAt(0, 1));
1619 ASSERT_TRUE(tiling->TileAt(1, 0));
1620 ASSERT_TRUE(tiling->TileAt(1, 1));
1622 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE);
1623 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1624 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1626 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE);
1627 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1628 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);
1630 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE);
1631 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible);
1632 EXPECT_EQ(TilePriority::NOW, priority.priority_bin);