OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
11 #include "cc/test/fake_picture_layer_tiling_client.h" | 11 #include "cc/test/fake_picture_layer_tiling_client.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
14 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 static gfx::Rect ViewportInLayerSpace( | 19 static gfx::Rect ViewportInLayerSpace( |
20 const gfx::Transform& transform, | 20 const gfx::Transform& transform, |
21 const gfx::Size& device_viewport) { | 21 const gfx::Size& device_viewport) { |
22 | 22 |
23 gfx::Transform inverse; | 23 gfx::Transform inverse; |
24 if (!transform.GetInverse(&inverse)) | 24 if (!transform.GetInverse(&inverse)) |
25 return gfx::Rect(); | 25 return gfx::Rect(); |
26 | 26 |
27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
29 | |
30 return ToEnclosingRect(viewport_in_layer_space); | 29 return ToEnclosingRect(viewport_in_layer_space); |
31 } | 30 } |
32 | 31 |
33 class TestablePictureLayerTiling : public PictureLayerTiling { | 32 class TestablePictureLayerTiling : public PictureLayerTiling { |
34 public: | 33 public: |
35 using PictureLayerTiling::SetLiveTilesRect; | 34 using PictureLayerTiling::SetLiveTilesRect; |
36 using PictureLayerTiling::TileAt; | 35 using PictureLayerTiling::TileAt; |
37 | 36 |
38 static scoped_ptr<TestablePictureLayerTiling> Create( | 37 static scoped_ptr<TestablePictureLayerTiling> Create( |
39 float contents_scale, | 38 float contents_scale, |
40 const gfx::Size& layer_bounds, | 39 const gfx::Size& layer_bounds, |
41 PictureLayerTilingClient* client) { | 40 PictureLayerTilingClient* client) { |
42 return make_scoped_ptr(new TestablePictureLayerTiling( | 41 return make_scoped_ptr(new TestablePictureLayerTiling( |
43 contents_scale, | 42 contents_scale, |
44 layer_bounds, | 43 layer_bounds, |
45 client)); | 44 client)); |
46 } | 45 } |
47 | 46 |
47 using PictureLayerTiling::ComputeSkewport; | |
48 | |
48 protected: | 49 protected: |
49 TestablePictureLayerTiling(float contents_scale, | 50 TestablePictureLayerTiling(float contents_scale, |
50 const gfx::Size& layer_bounds, | 51 const gfx::Size& layer_bounds, |
51 PictureLayerTilingClient* client) | 52 PictureLayerTilingClient* client) |
52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 53 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
53 }; | 54 }; |
54 | 55 |
55 class PictureLayerTilingIteratorTest : public testing::Test { | 56 class PictureLayerTilingIteratorTest : public testing::Test { |
56 public: | 57 public: |
57 PictureLayerTilingIteratorTest() {} | 58 PictureLayerTilingIteratorTest() {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 149 |
149 void VerifyTilesCoverNonContainedRect(float rect_scale, | 150 void VerifyTilesCoverNonContainedRect(float rect_scale, |
150 const gfx::Rect& dest_rect) { | 151 const gfx::Rect& dest_rect) { |
151 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 152 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
152 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | 153 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( |
153 tiling_->ContentRect(), 1.f / dest_to_contents_scale); | 154 tiling_->ContentRect(), 1.f / dest_to_contents_scale); |
154 clamped_rect.Intersect(dest_rect); | 155 clamped_rect.Intersect(dest_rect); |
155 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 156 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
156 } | 157 } |
157 | 158 |
159 void set_max_tiles_for_interest_area(size_t area) { | |
160 client_.set_max_tiles_for_interest_area(area); | |
161 } | |
162 | |
158 protected: | 163 protected: |
159 FakePictureLayerTilingClient client_; | 164 FakePictureLayerTilingClient client_; |
160 scoped_ptr<TestablePictureLayerTiling> tiling_; | 165 scoped_ptr<TestablePictureLayerTiling> tiling_; |
161 | 166 |
162 private: | 167 private: |
163 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 168 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
164 }; | 169 }; |
165 | 170 |
166 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 171 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
167 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 172 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); | 262 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); |
258 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 263 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
259 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 264 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
260 | 265 |
261 // Partially covering content, but too large | 266 // Partially covering content, but too large |
262 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); | 267 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); |
263 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | 268 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); |
264 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | 269 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); |
265 } | 270 } |
266 | 271 |
272 TEST(PictureLayerTilingTest, SkewportLimits) { | |
273 FakePictureLayerTilingClient client; | |
274 client.set_skewport_extrapolation_limit_in_content_pixels(75); | |
275 scoped_ptr<TestablePictureLayerTiling> tiling; | |
276 | |
277 gfx::Rect viewport(0, 0, 100, 100); | |
278 gfx::Size layer_bounds(200, 200); | |
279 | |
280 client.SetTileSize(gfx::Size(100, 100)); | |
281 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | |
282 | |
283 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
284 | |
285 // Move viewport down 50 pixels in 0.5 seconds. | |
286 gfx::Rect down_skewport = | |
287 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | |
288 | |
289 EXPECT_EQ(0, down_skewport.x()); | |
290 EXPECT_EQ(50, down_skewport.y()); | |
291 EXPECT_EQ(100, down_skewport.width()); | |
292 EXPECT_EQ(175, down_skewport.height()); | |
293 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100))); | |
294 | |
295 // Move viewport down 50 and right 10 pixels. | |
296 gfx::Rect down_right_skewport = | |
297 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); | |
298 | |
299 EXPECT_EQ(10, down_right_skewport.x()); | |
300 EXPECT_EQ(50, down_right_skewport.y()); | |
301 EXPECT_EQ(120, down_right_skewport.width()); | |
302 EXPECT_EQ(175, down_right_skewport.height()); | |
303 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100))); | |
304 | |
305 // Move viewport left. | |
306 gfx::Rect left_skewport = | |
307 tiling->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100)); | |
308 | |
309 EXPECT_EQ(-125, left_skewport.x()); | |
310 EXPECT_EQ(0, left_skewport.y()); | |
311 EXPECT_EQ(175, left_skewport.width()); | |
312 EXPECT_EQ(100, left_skewport.height()); | |
313 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100))); | |
314 | |
315 // Expand viewport. | |
enne (OOO)
2014/02/12 00:35:35
Two more tests: one for a viewport expanded past t
vmpstr
2014/02/12 18:14:18
Added one more for expand, the shrink case is in C
| |
316 gfx::Rect expand_skewport = | |
317 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200)); | |
318 | |
319 // x and y moved by -75 (-50 - 75 = -125). | |
320 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75]. | |
321 EXPECT_EQ(-125, expand_skewport.x()); | |
322 EXPECT_EQ(-125, expand_skewport.y()); | |
323 EXPECT_EQ(350, expand_skewport.width()); | |
324 EXPECT_EQ(350, expand_skewport.height()); | |
325 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200))); | |
326 } | |
327 | |
328 TEST(PictureLayerTilingTest, ComputeSkewport) { | |
329 FakePictureLayerTilingClient client; | |
330 scoped_ptr<TestablePictureLayerTiling> tiling; | |
331 | |
332 gfx::Rect viewport(0, 0, 100, 100); | |
333 gfx::Size layer_bounds(200, 200); | |
334 | |
335 client.SetTileSize(gfx::Size(100, 100)); | |
336 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | |
337 | |
338 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
339 | |
340 // Move viewport down 50 pixels in 0.5 seconds. | |
341 gfx::Rect down_skewport = | |
342 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | |
343 | |
344 EXPECT_EQ(0, down_skewport.x()); | |
345 EXPECT_EQ(50, down_skewport.y()); | |
346 EXPECT_EQ(100, down_skewport.width()); | |
347 EXPECT_EQ(200, down_skewport.height()); | |
348 | |
349 // Shrink viewport. | |
350 gfx::Rect shrink_skewport = | |
351 tiling->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50)); | |
352 | |
353 EXPECT_EQ(25, shrink_skewport.x()); | |
354 EXPECT_EQ(25, shrink_skewport.y()); | |
355 EXPECT_EQ(50, shrink_skewport.width()); | |
356 EXPECT_EQ(50, shrink_skewport.height()); | |
357 | |
358 // Move viewport down 50 and right 10 pixels. | |
359 gfx::Rect down_right_skewport = | |
360 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); | |
361 | |
362 EXPECT_EQ(10, down_right_skewport.x()); | |
363 EXPECT_EQ(50, down_right_skewport.y()); | |
364 EXPECT_EQ(120, down_right_skewport.width()); | |
365 EXPECT_EQ(200, down_right_skewport.height()); | |
366 | |
367 // Move viewport left. | |
368 gfx::Rect left_skewport = | |
369 tiling->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100)); | |
370 | |
371 EXPECT_EQ(-60, left_skewport.x()); | |
372 EXPECT_EQ(0, left_skewport.y()); | |
373 EXPECT_EQ(140, left_skewport.width()); | |
374 EXPECT_EQ(100, left_skewport.height()); | |
375 | |
376 // Expand viewport in 0.2 seconds. | |
377 gfx::Rect expanded_skewport = | |
378 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); | |
379 | |
380 EXPECT_EQ(-30, expanded_skewport.x()); | |
381 EXPECT_EQ(-30, expanded_skewport.y()); | |
382 EXPECT_EQ(160, expanded_skewport.width()); | |
383 EXPECT_EQ(160, expanded_skewport.height()); | |
384 } | |
385 | |
386 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { | |
387 FakePictureLayerTilingClient client; | |
388 scoped_ptr<TestablePictureLayerTiling> tiling; | |
389 | |
390 gfx::Rect viewport(0, 0, 100, 100); | |
391 gfx::Size layer_bounds(200, 200); | |
392 | |
393 client.SetTileSize(gfx::Size(10, 10)); | |
394 | |
395 // Tiling at 0.25 scale: this should create 36 tiles (6x6) of size 10x10. | |
396 // The reason is that each tile has a one pixel border, so tile at (1, 2) | |
397 // for instance begins at (8, 16) pixels. So tile at (5, 5) will begin at | |
398 // (40, 40) and extend right to the end of 200 * 0.25 = 50 edge of the | |
399 // tiling. | |
400 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); | |
401 gfx::Rect viewport_in_content_space = | |
402 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | |
403 | |
404 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
405 | |
406 // Sanity checks. | |
407 for (int i = 0; i < 6; ++i) { | |
408 for (int j = 0; j < 6; ++j) { | |
409 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; | |
410 } | |
411 } | |
412 for (int i = 0; i < 7; ++i) { | |
413 EXPECT_FALSE(tiling->TileAt(i, 6)) << "i: " << i; | |
414 EXPECT_FALSE(tiling->TileAt(6, i)) << "i: " << i; | |
415 } | |
416 | |
417 // No movement in the viewport implies that tiles will either be NOW | |
418 // or EVENTUALLY. | |
419 bool have_now = false; | |
420 bool have_eventually = false; | |
421 for (int i = 0; i < 6; ++i) { | |
422 for (int j = 0; j < 6; ++j) { | |
423 Tile* tile = tiling->TileAt(i, j); | |
424 TilePriority priority = tile->priority(ACTIVE_TREE); | |
425 | |
426 if (viewport_in_content_space.Intersects(tile->content_rect())) { | |
427 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
428 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
429 have_now = true; | |
430 } else { | |
431 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | |
432 EXPECT_GT(priority.distance_to_visible, 0.f); | |
433 have_eventually = true; | |
434 } | |
435 } | |
436 } | |
437 | |
438 EXPECT_TRUE(have_now); | |
439 EXPECT_TRUE(have_eventually); | |
440 | |
441 // Spot check some distances. | |
442 // Tile at 5, 1 should begin at 41x9 in content space (without borders), | |
443 // so the distance to a viewport that ends at 25x25 in content space | |
444 // should be 17 (41 - 25 + 1). In layer space, then that should be | |
445 // 17 / 0.25 = 68 pixels. | |
446 | |
447 // We can verify that the content rect (with borders) is one pixel off | |
448 // 41,9 8x8 on all sides. | |
449 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); | |
enne (OOO)
2014/02/12 00:35:35
That seems reasonable. I just wanted to test thes
| |
450 | |
451 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | |
452 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
453 | |
454 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | |
455 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
456 | |
457 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | |
458 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible); | |
459 | |
460 // Move the viewport down 40 pixels. | |
461 viewport = gfx::Rect(0, 40, 100, 100); | |
462 viewport_in_content_space = | |
463 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | |
464 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); | |
465 | |
466 EXPECT_EQ(0, skewport.x()); | |
467 EXPECT_EQ(10, skewport.y()); | |
468 EXPECT_EQ(25, skewport.width()); | |
469 EXPECT_EQ(35, skewport.height()); | |
470 | |
471 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 2.0); | |
472 | |
473 have_now = false; | |
474 have_eventually = false; | |
475 bool have_soon = false; | |
476 | |
477 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | |
478 // some EVENTUALLY tiles. | |
479 for (int i = 0; i < 6; ++i) { | |
480 for (int j = 0; j < 6; ++j) { | |
481 Tile* tile = tiling->TileAt(i, j); | |
482 TilePriority priority = tile->priority(ACTIVE_TREE); | |
483 | |
484 if (viewport_in_content_space.Intersects(tile->content_rect())) { | |
485 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | |
486 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
487 have_now = true; | |
488 } else if (skewport.Intersects(tile->content_rect())) { | |
489 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); | |
490 EXPECT_GT(priority.distance_to_visible, 0.f); | |
491 have_soon = true; | |
492 } else { | |
493 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | |
494 EXPECT_GT(priority.distance_to_visible, 0.f); | |
495 have_eventually = true; | |
496 } | |
497 } | |
498 } | |
499 | |
500 EXPECT_TRUE(have_now); | |
501 EXPECT_TRUE(have_soon); | |
502 EXPECT_TRUE(have_eventually); | |
503 | |
504 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | |
505 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | |
506 | |
507 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | |
508 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | |
509 | |
510 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | |
511 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
512 | |
513 // Change the underlying layer scale. | |
514 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 2.0f, 3.0); | |
515 | |
516 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | |
517 EXPECT_FLOAT_EQ(34.f, priority.distance_to_visible); | |
518 | |
519 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | |
520 EXPECT_FLOAT_EQ(14.f, priority.distance_to_visible); | |
521 | |
522 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | |
523 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | |
524 } | |
525 | |
267 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 526 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
268 gfx::Rect in(40, 50, 100, 200); | 527 gfx::Rect in(40, 50, 100, 200); |
269 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 528 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
270 int64 target_area = 100 * 200; | 529 int64 target_area = 100 * 200; |
271 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 530 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
272 in, target_area, bounds, NULL); | 531 in, target_area, bounds, NULL); |
273 EXPECT_EQ(in.ToString(), out.ToString()); | 532 EXPECT_EQ(in.ToString(), out.ToString()); |
274 } | 533 } |
275 | 534 |
276 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 535 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 } | 747 } |
489 | 748 |
490 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 749 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
491 gfx::Size layer_bounds(1099, 801); | 750 gfx::Size layer_bounds(1099, 801); |
492 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 751 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
493 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 752 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
494 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 753 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
495 | 754 |
496 tiling_->UpdateTilePriorities( | 755 tiling_->UpdateTilePriorities( |
497 ACTIVE_TREE, | 756 ACTIVE_TREE, |
498 layer_bounds, // device viewport | |
499 gfx::Rect(layer_bounds), // viewport in layer space | |
500 gfx::Rect(layer_bounds), // visible content rect | 757 gfx::Rect(layer_bounds), // visible content rect |
501 layer_bounds, // last layer bounds | 758 1.f, // current contents scale |
502 layer_bounds, // current layer bounds | 759 1.0); // current frame time |
503 1.f, // last contents scale | |
504 1.f, // current contents scale | |
505 gfx::Transform(), // last screen transform | |
506 gfx::Transform(), // current screen transform | |
507 1.0, // current frame time | |
508 10000); // max tiles in tile manager | |
509 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 760 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
510 | 761 |
511 // Make the viewport rect empty. All tiles are killed and become zombies. | 762 // Make the viewport rect empty. All tiles are killed and become zombies. |
512 tiling_->UpdateTilePriorities( | 763 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
513 ACTIVE_TREE, | 764 gfx::Rect(), // visible content rect |
514 layer_bounds, // device viewport | 765 1.f, // current contents scale |
515 gfx::Rect(), // viewport in layer space | 766 2.0); // current frame time |
516 gfx::Rect(), // visible content rect | |
517 layer_bounds, // last layer bounds | |
518 layer_bounds, // current layer bounds | |
519 1.f, // last contents scale | |
520 1.f, // current contents scale | |
521 gfx::Transform(), // last screen transform | |
522 gfx::Transform(), // current screen transform | |
523 2.0, // current frame time | |
524 10000); // max tiles in tile manager | |
525 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 767 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
526 } | 768 } |
527 | 769 |
528 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 770 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
529 gfx::Size layer_bounds(1099, 801); | 771 gfx::Size layer_bounds(1099, 801); |
530 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 772 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
531 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 773 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
532 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 774 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
533 | 775 |
534 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 776 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
535 | 777 |
536 tiling_->UpdateTilePriorities( | 778 tiling_->UpdateTilePriorities( |
537 ACTIVE_TREE, | 779 ACTIVE_TREE, |
538 layer_bounds, // device viewport | |
539 giant_rect, // viewport in layer space | |
540 gfx::Rect(layer_bounds), // visible content rect | 780 gfx::Rect(layer_bounds), // visible content rect |
541 layer_bounds, // last layer bounds | 781 1.f, // current contents scale |
542 layer_bounds, // current layer bounds | 782 1.0); // current frame time |
543 1.f, // last contents scale | |
544 1.f, // current contents scale | |
545 gfx::Transform(), // last screen transform | |
546 gfx::Transform(), // current screen transform | |
547 1.0, // current frame time | |
548 10000); // max tiles in tile manager | |
549 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 783 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
550 | 784 |
551 // If the visible content rect is empty, it should still have live tiles. | 785 // If the visible content rect is empty, it should still have live tiles. |
552 tiling_->UpdateTilePriorities( | 786 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
553 ACTIVE_TREE, | 787 giant_rect, // visible content rect |
554 layer_bounds, // device viewport | 788 1.f, // current contents scale |
555 giant_rect, // viewport in layer space | 789 2.0); // current frame time |
556 gfx::Rect(), // visible content rect | |
557 layer_bounds, // last layer bounds | |
558 layer_bounds, // current layer bounds | |
559 1.f, // last contents scale | |
560 1.f, // current contents scale | |
561 gfx::Transform(), // last screen transform | |
562 gfx::Transform(), // current screen transform | |
563 2.0, // current frame time | |
564 10000); // max tiles in tile manager | |
565 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 790 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
566 } | 791 } |
567 | 792 |
568 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | 793 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { |
569 gfx::Size layer_bounds(1099, 801); | 794 gfx::Size layer_bounds(1099, 801); |
570 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 795 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
571 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 796 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
572 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 797 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
573 | 798 |
574 // This rect does not intersect with the layer, as the layer is outside the | 799 // This rect does not intersect with the layer, as the layer is outside the |
575 // viewport. | 800 // viewport. |
576 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 801 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
577 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 802 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
578 | 803 |
579 tiling_->UpdateTilePriorities( | 804 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
580 ACTIVE_TREE, | 805 viewport_rect, // visible content rect |
581 layer_bounds, // device viewport | 806 1.f, // current contents scale |
582 viewport_rect, // viewport in layer space | 807 1.0); // current frame time |
583 gfx::Rect(), // visible content rect | |
584 layer_bounds, // last layer bounds | |
585 layer_bounds, // current layer bounds | |
586 1.f, // last contents scale | |
587 1.f, // current contents scale | |
588 gfx::Transform(), // last screen transform | |
589 gfx::Transform(), // current screen transform | |
590 1.0, // current frame time | |
591 10000); // max tiles in tile manager | |
592 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 808 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
593 } | 809 } |
594 | 810 |
595 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 811 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
596 bool intersect_exists, | 812 bool intersect_exists, |
597 Tile* tile, | 813 Tile* tile, |
598 const gfx::Rect& geometry_rect) { | 814 const gfx::Rect& geometry_rect) { |
599 bool intersects = rect.Intersects(geometry_rect); | 815 bool intersects = rect.Intersects(geometry_rect); |
600 bool expected_exists = intersect_exists ? intersects : !intersects; | 816 bool expected_exists = intersect_exists ? intersects : !intersects; |
601 EXPECT_EQ(expected_exists, tile != NULL) | 817 EXPECT_EQ(expected_exists, tile != NULL) |
602 << "Rects intersecting " << rect.ToString() << " should exist. " | 818 << "Rects intersecting " << rect.ToString() << " should exist. " |
603 << "Current tile rect is " << geometry_rect.ToString(); | 819 << "Current tile rect is " << geometry_rect.ToString(); |
604 } | 820 } |
605 | 821 |
606 TEST_F(PictureLayerTilingIteratorTest, | 822 TEST_F(PictureLayerTilingIteratorTest, |
607 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 823 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
608 gfx::Size layer_bounds(10000, 10000); | 824 gfx::Size layer_bounds(10000, 10000); |
609 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 825 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
610 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 826 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
611 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 827 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
612 | 828 |
613 gfx::Rect visible_rect(8000, 8000, 50, 50); | 829 gfx::Rect visible_rect(8000, 8000, 50, 50); |
614 | 830 |
615 tiling_->UpdateTilePriorities( | 831 set_max_tiles_for_interest_area(1); |
616 ACTIVE_TREE, | 832 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
617 layer_bounds, // device viewport | 833 visible_rect, // visible content rect |
618 gfx::Rect(layer_bounds), // viewport in layer space | 834 1.f, // current contents scale |
619 visible_rect, // visible content rect | 835 1.0); // current frame time |
620 layer_bounds, // last layer bounds | |
621 layer_bounds, // current layer bounds | |
622 1.f, // last contents scale | |
623 1.f, // current contents scale | |
624 gfx::Transform(), // last screen transform | |
625 gfx::Transform(), // current screen transform | |
626 1.0, // current frame time | |
627 1); // max tiles in tile manager | |
628 VerifyTiles(1.f, | 836 VerifyTiles(1.f, |
629 gfx::Rect(layer_bounds), | 837 gfx::Rect(layer_bounds), |
630 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 838 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
631 } | 839 } |
632 | 840 |
633 static void CountExistingTiles(int *count, | 841 static void CountExistingTiles(int *count, |
634 Tile* tile, | 842 Tile* tile, |
635 const gfx::Rect& geometry_rect) { | 843 const gfx::Rect& geometry_rect) { |
636 if (tile != NULL) | 844 if (tile != NULL) |
637 ++(*count); | 845 ++(*count); |
638 } | 846 } |
639 | 847 |
640 TEST_F(PictureLayerTilingIteratorTest, | 848 TEST_F(PictureLayerTilingIteratorTest, |
641 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 849 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
642 gfx::Size layer_bounds(10000, 10000); | 850 gfx::Size layer_bounds(10000, 10000); |
643 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 851 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
644 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 852 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
645 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 853 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
646 | 854 |
855 set_max_tiles_for_interest_area(1); | |
647 tiling_->UpdateTilePriorities( | 856 tiling_->UpdateTilePriorities( |
648 ACTIVE_TREE, | 857 ACTIVE_TREE, |
649 layer_bounds, // device viewport | |
650 gfx::Rect(layer_bounds), // viewport in layer space | |
651 gfx::Rect(layer_bounds), // visible content rect | 858 gfx::Rect(layer_bounds), // visible content rect |
652 layer_bounds, // last layer bounds | 859 1.f, // current contents scale |
653 layer_bounds, // current layer bounds | 860 1.0); // current frame time |
654 1.f, // last contents scale | |
655 1.f, // current contents scale | |
656 gfx::Transform(), // last screen transform | |
657 gfx::Transform(), // current screen transform | |
658 1.0, // current frame time | |
659 1); // max tiles in tile manager | |
660 | 861 |
661 int num_tiles = 0; | 862 int num_tiles = 0; |
662 VerifyTiles(1.f, | 863 VerifyTiles(1.f, |
663 gfx::Rect(layer_bounds), | 864 gfx::Rect(layer_bounds), |
664 base::Bind(&CountExistingTiles, &num_tiles)); | 865 base::Bind(&CountExistingTiles, &num_tiles)); |
665 // If we're making a rect the size of one tile, it can only overlap up to 4 | 866 // If we're making a rect the size of one tile, it can only overlap up to 4 |
666 // tiles depending on its position. | 867 // tiles depending on its position. |
667 EXPECT_LE(num_tiles, 4); | 868 EXPECT_LE(num_tiles, 4); |
668 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); | 869 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); |
669 } | 870 } |
670 | 871 |
671 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { | 872 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { |
672 gfx::Size layer_bounds(1099, 801); | 873 gfx::Size layer_bounds(1099, 801); |
673 gfx::Size tile_size(100, 100); | 874 gfx::Size tile_size(100, 100); |
674 | 875 |
675 client_.SetTileSize(tile_size); | 876 client_.SetTileSize(tile_size); |
676 | 877 |
677 PictureLayerTilingSet active_set(&client_, layer_bounds); | 878 PictureLayerTilingSet active_set(&client_, layer_bounds); |
678 | 879 |
679 active_set.AddTiling(1.f); | 880 active_set.AddTiling(1.f); |
680 | 881 |
681 VerifyTiles(active_set.tiling_at(0), | 882 VerifyTiles(active_set.tiling_at(0), |
682 1.f, | 883 1.f, |
683 gfx::Rect(layer_bounds), | 884 gfx::Rect(layer_bounds), |
684 base::Bind(&TileExists, false)); | 885 base::Bind(&TileExists, false)); |
685 | 886 |
686 active_set.UpdateTilePriorities( | 887 active_set.UpdateTilePriorities( |
687 PENDING_TREE, | 888 PENDING_TREE, |
688 layer_bounds, // device viewport | |
689 gfx::Rect(layer_bounds), // viewport in layer space | |
690 gfx::Rect(layer_bounds), // visible content rect | 889 gfx::Rect(layer_bounds), // visible content rect |
691 layer_bounds, // last layer bounds | 890 1.f, // current contents scale |
692 layer_bounds, // current layer bounds | 891 1.0); // current frame time |
693 1.f, // last contents scale | |
694 1.f, // current contents scale | |
695 gfx::Transform(), // last screen transform | |
696 gfx::Transform(), // current screen transform | |
697 1.0, // current frame time | |
698 10000); // max tiles in tile manager | |
699 | 892 |
700 // The active tiling has tiles now. | 893 // The active tiling has tiles now. |
701 VerifyTiles(active_set.tiling_at(0), | 894 VerifyTiles(active_set.tiling_at(0), |
702 1.f, | 895 1.f, |
703 gfx::Rect(layer_bounds), | 896 gfx::Rect(layer_bounds), |
704 base::Bind(&TileExists, true)); | 897 base::Bind(&TileExists, true)); |
705 | 898 |
706 // Add the same tilings to the pending set. | 899 // Add the same tilings to the pending set. |
707 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 900 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
708 Region invalidation; | 901 Region invalidation; |
709 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 902 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
710 | 903 |
711 // The pending tiling starts with no tiles. | 904 // The pending tiling starts with no tiles. |
712 VerifyTiles(pending_set.tiling_at(0), | 905 VerifyTiles(pending_set.tiling_at(0), |
713 1.f, | 906 1.f, |
714 gfx::Rect(layer_bounds), | 907 gfx::Rect(layer_bounds), |
715 base::Bind(&TileExists, false)); | 908 base::Bind(&TileExists, false)); |
716 | 909 |
717 // UpdateTilePriorities on the pending tiling at the same frame time. The | 910 // UpdateTilePriorities on the pending tiling at the same frame time. The |
718 // pending tiling should get tiles. | 911 // pending tiling should get tiles. |
719 pending_set.UpdateTilePriorities( | 912 pending_set.UpdateTilePriorities( |
720 PENDING_TREE, | 913 PENDING_TREE, |
721 layer_bounds, // device viewport | |
722 gfx::Rect(layer_bounds), // viewport in layer space | |
723 gfx::Rect(layer_bounds), // visible content rect | 914 gfx::Rect(layer_bounds), // visible content rect |
724 layer_bounds, // last layer bounds | 915 1.f, // current contents scale |
725 layer_bounds, // current layer bounds | 916 1.0); // current frame time |
726 1.f, // last contents scale | |
727 1.f, // current contents scale | |
728 gfx::Transform(), // last screen transform | |
729 gfx::Transform(), // current screen transform | |
730 1.0, // current frame time | |
731 10000); // max tiles in tile manager | |
732 | 917 |
733 VerifyTiles(pending_set.tiling_at(0), | 918 VerifyTiles(pending_set.tiling_at(0), |
734 1.f, | 919 1.f, |
735 gfx::Rect(layer_bounds), | 920 gfx::Rect(layer_bounds), |
736 base::Bind(&TileExists, true)); | 921 base::Bind(&TileExists, true)); |
737 } | 922 } |
738 | 923 |
739 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 924 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
740 // The TilePriority of visible tiles should have zero distance_to_visible | 925 // The TilePriority of visible tiles should have zero distance_to_visible |
741 // and time_to_visible. | 926 // and time_to_visible. |
742 | 927 |
743 FakePictureLayerTilingClient client; | 928 FakePictureLayerTilingClient client; |
744 scoped_ptr<TestablePictureLayerTiling> tiling; | 929 scoped_ptr<TestablePictureLayerTiling> tiling; |
745 | 930 |
746 gfx::Size device_viewport(800, 600); | 931 gfx::Size device_viewport(800, 600); |
747 gfx::Rect visible_layer_rect(0, 0, 200, 200); | |
748 gfx::Size last_layer_bounds(200, 200); | 932 gfx::Size last_layer_bounds(200, 200); |
749 gfx::Size current_layer_bounds(200, 200); | 933 gfx::Size current_layer_bounds(200, 200); |
750 float last_layer_contents_scale = 1.f; | |
751 float current_layer_contents_scale = 1.f; | 934 float current_layer_contents_scale = 1.f; |
752 gfx::Transform last_screen_transform; | |
753 gfx::Transform current_screen_transform; | 935 gfx::Transform current_screen_transform; |
754 double current_frame_time_in_seconds = 1.0; | 936 double current_frame_time_in_seconds = 1.0; |
755 size_t max_tiles_for_interest_area = 10000; | |
756 | 937 |
757 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 938 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
758 current_screen_transform, device_viewport); | 939 current_screen_transform, device_viewport); |
759 | 940 |
760 client.SetTileSize(gfx::Size(100, 100)); | 941 client.SetTileSize(gfx::Size(100, 100)); |
761 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 942 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
762 current_layer_bounds, | 943 current_layer_bounds, |
763 &client); | 944 &client); |
764 | 945 |
765 tiling->UpdateTilePriorities( | 946 tiling->UpdateTilePriorities(ACTIVE_TREE, |
766 ACTIVE_TREE, | 947 viewport_in_layer_space, |
767 device_viewport, | 948 current_layer_contents_scale, |
768 viewport_in_layer_space, | 949 current_frame_time_in_seconds); |
769 visible_layer_rect, | |
770 last_layer_bounds, | |
771 current_layer_bounds, | |
772 last_layer_contents_scale, | |
773 current_layer_contents_scale, | |
774 last_screen_transform, | |
775 current_screen_transform, | |
776 current_frame_time_in_seconds, | |
777 max_tiles_for_interest_area); | |
778 | 950 |
779 ASSERT_TRUE(tiling->TileAt(0, 0)); | 951 ASSERT_TRUE(tiling->TileAt(0, 0)); |
780 ASSERT_TRUE(tiling->TileAt(0, 1)); | 952 ASSERT_TRUE(tiling->TileAt(0, 1)); |
781 ASSERT_TRUE(tiling->TileAt(1, 0)); | 953 ASSERT_TRUE(tiling->TileAt(1, 0)); |
782 ASSERT_TRUE(tiling->TileAt(1, 1)); | 954 ASSERT_TRUE(tiling->TileAt(1, 1)); |
783 | 955 |
784 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 956 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 957 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 958 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
787 | 959 |
788 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 960 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 961 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 962 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
791 | 963 |
792 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 964 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 965 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 966 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
795 | 967 |
796 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 968 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
797 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 969 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
798 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 970 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
799 } | 971 } |
800 | 972 |
801 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 973 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
802 // The TilePriority of offscreen tiles (without movement) should have nonzero | 974 // The TilePriority of offscreen tiles (without movement) should have nonzero |
803 // distance_to_visible and infinite time_to_visible. | 975 // distance_to_visible and infinite time_to_visible. |
804 | 976 |
805 FakePictureLayerTilingClient client; | 977 FakePictureLayerTilingClient client; |
806 scoped_ptr<TestablePictureLayerTiling> tiling; | 978 scoped_ptr<TestablePictureLayerTiling> tiling; |
807 | 979 |
808 gfx::Size device_viewport(800, 600); | 980 gfx::Size device_viewport(800, 600); |
809 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | |
810 gfx::Size last_layer_bounds(200, 200); | 981 gfx::Size last_layer_bounds(200, 200); |
811 gfx::Size current_layer_bounds(200, 200); | 982 gfx::Size current_layer_bounds(200, 200); |
812 float last_layer_contents_scale = 1.f; | |
813 float current_layer_contents_scale = 1.f; | 983 float current_layer_contents_scale = 1.f; |
814 gfx::Transform last_screen_transform; | 984 gfx::Transform last_screen_transform; |
815 gfx::Transform current_screen_transform; | 985 gfx::Transform current_screen_transform; |
816 double current_frame_time_in_seconds = 1.0; | 986 double current_frame_time_in_seconds = 1.0; |
817 size_t max_tiles_for_interest_area = 10000; | |
818 | 987 |
819 current_screen_transform.Translate(850, 0); | 988 current_screen_transform.Translate(850, 0); |
820 last_screen_transform = current_screen_transform; | 989 last_screen_transform = current_screen_transform; |
821 | 990 |
822 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 991 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
823 current_screen_transform, device_viewport); | 992 current_screen_transform, device_viewport); |
824 | 993 |
825 client.SetTileSize(gfx::Size(100, 100)); | 994 client.SetTileSize(gfx::Size(100, 100)); |
826 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 995 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
827 current_layer_bounds, | 996 current_layer_bounds, |
828 &client); | 997 &client); |
829 | 998 |
830 tiling->UpdateTilePriorities( | 999 tiling->UpdateTilePriorities(ACTIVE_TREE, |
831 ACTIVE_TREE, | 1000 viewport_in_layer_space, |
832 device_viewport, | 1001 current_layer_contents_scale, |
833 viewport_in_layer_space, | 1002 current_frame_time_in_seconds); |
834 visible_layer_rect, | |
835 last_layer_bounds, | |
836 current_layer_bounds, | |
837 last_layer_contents_scale, | |
838 current_layer_contents_scale, | |
839 last_screen_transform, | |
840 current_screen_transform, | |
841 current_frame_time_in_seconds, | |
842 max_tiles_for_interest_area); | |
843 | 1003 |
844 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1004 ASSERT_TRUE(tiling->TileAt(0, 0)); |
845 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1005 ASSERT_TRUE(tiling->TileAt(0, 1)); |
846 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1006 ASSERT_TRUE(tiling->TileAt(1, 0)); |
847 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1007 ASSERT_TRUE(tiling->TileAt(1, 1)); |
848 | 1008 |
849 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1009 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
850 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1010 EXPECT_GT(priority.distance_to_visible, 0.f); |
851 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1011 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
852 priority.time_to_visible_in_seconds); | |
853 | 1012 |
854 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1013 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
855 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1014 EXPECT_GT(priority.distance_to_visible, 0.f); |
856 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1015 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
857 priority.time_to_visible_in_seconds); | |
858 | 1016 |
859 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1017 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
860 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1018 EXPECT_GT(priority.distance_to_visible, 0.f); |
861 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1019 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
862 priority.time_to_visible_in_seconds); | |
863 | 1020 |
864 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1021 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
865 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1022 EXPECT_GT(priority.distance_to_visible, 0.f); |
866 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1023 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
867 priority.time_to_visible_in_seconds); | |
868 | 1024 |
869 // Furthermore, in this scenario tiles on the right hand side should have a | 1025 // Furthermore, in this scenario tiles on the right hand side should have a |
870 // larger distance to visible. | 1026 // larger distance to visible. |
871 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1027 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
872 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1028 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
873 EXPECT_GT(right.distance_to_visible_in_pixels, | 1029 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
874 left.distance_to_visible_in_pixels); | |
875 | 1030 |
876 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1031 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
877 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1032 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
878 EXPECT_GT(right.distance_to_visible_in_pixels, | 1033 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
879 left.distance_to_visible_in_pixels); | |
880 } | 1034 } |
881 | 1035 |
882 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 1036 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
883 // Sanity check that a layer with some tiles visible and others offscreen has | 1037 // Sanity check that a layer with some tiles visible and others offscreen has |
884 // correct TilePriorities for each tile. | 1038 // correct TilePriorities for each tile. |
885 | 1039 |
886 FakePictureLayerTilingClient client; | 1040 FakePictureLayerTilingClient client; |
887 scoped_ptr<TestablePictureLayerTiling> tiling; | 1041 scoped_ptr<TestablePictureLayerTiling> tiling; |
888 | 1042 |
889 gfx::Size device_viewport(800, 600); | 1043 gfx::Size device_viewport(800, 600); |
890 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | |
891 gfx::Size last_layer_bounds(200, 200); | 1044 gfx::Size last_layer_bounds(200, 200); |
892 gfx::Size current_layer_bounds(200, 200); | 1045 gfx::Size current_layer_bounds(200, 200); |
893 float last_layer_contents_scale = 1.f; | |
894 float current_layer_contents_scale = 1.f; | 1046 float current_layer_contents_scale = 1.f; |
895 gfx::Transform last_screen_transform; | 1047 gfx::Transform last_screen_transform; |
896 gfx::Transform current_screen_transform; | 1048 gfx::Transform current_screen_transform; |
897 double current_frame_time_in_seconds = 1.0; | 1049 double current_frame_time_in_seconds = 1.0; |
898 size_t max_tiles_for_interest_area = 10000; | |
899 | 1050 |
900 current_screen_transform.Translate(705, 505); | 1051 current_screen_transform.Translate(705, 505); |
901 last_screen_transform = current_screen_transform; | 1052 last_screen_transform = current_screen_transform; |
902 | 1053 |
903 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1054 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
904 current_screen_transform, device_viewport); | 1055 current_screen_transform, device_viewport); |
905 | 1056 |
906 client.SetTileSize(gfx::Size(100, 100)); | 1057 client.SetTileSize(gfx::Size(100, 100)); |
907 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1058 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
908 current_layer_bounds, | 1059 current_layer_bounds, |
909 &client); | 1060 &client); |
910 | 1061 |
911 tiling->UpdateTilePriorities( | 1062 tiling->UpdateTilePriorities(ACTIVE_TREE, |
912 ACTIVE_TREE, | 1063 viewport_in_layer_space, |
913 device_viewport, | 1064 current_layer_contents_scale, |
914 viewport_in_layer_space, | 1065 current_frame_time_in_seconds); |
915 visible_layer_rect, | |
916 last_layer_bounds, | |
917 current_layer_bounds, | |
918 last_layer_contents_scale, | |
919 current_layer_contents_scale, | |
920 last_screen_transform, | |
921 current_screen_transform, | |
922 current_frame_time_in_seconds, | |
923 max_tiles_for_interest_area); | |
924 | 1066 |
925 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1067 ASSERT_TRUE(tiling->TileAt(0, 0)); |
926 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1068 ASSERT_TRUE(tiling->TileAt(0, 1)); |
927 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1069 ASSERT_TRUE(tiling->TileAt(1, 0)); |
928 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1070 ASSERT_TRUE(tiling->TileAt(1, 1)); |
929 | 1071 |
930 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1072 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
931 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1073 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
932 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1074 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
933 | 1075 |
934 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1076 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
935 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1077 EXPECT_GT(priority.distance_to_visible, 0.f); |
936 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1078 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
937 priority.time_to_visible_in_seconds); | |
938 | 1079 |
939 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1080 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
940 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1081 EXPECT_GT(priority.distance_to_visible, 0.f); |
941 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1082 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
942 priority.time_to_visible_in_seconds); | |
943 | 1083 |
944 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1084 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
945 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1085 EXPECT_GT(priority.distance_to_visible, 0.f); |
946 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1086 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
947 priority.time_to_visible_in_seconds); | |
948 } | 1087 } |
949 | 1088 |
950 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 1089 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
951 // Each tile of a layer may be affected differently by a transform; Check | 1090 // Each tile of a layer may be affected differently by a transform; Check |
952 // that UpdateTilePriorities correctly accounts for the transform between | 1091 // that UpdateTilePriorities correctly accounts for the transform between |
953 // layer space and screen space. | 1092 // layer space and screen space. |
954 | 1093 |
955 FakePictureLayerTilingClient client; | 1094 FakePictureLayerTilingClient client; |
956 scoped_ptr<TestablePictureLayerTiling> tiling; | 1095 scoped_ptr<TestablePictureLayerTiling> tiling; |
957 | 1096 |
958 gfx::Size device_viewport(800, 600); | 1097 gfx::Size device_viewport(800, 600); |
959 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | |
960 gfx::Size last_layer_bounds(200, 200); | 1098 gfx::Size last_layer_bounds(200, 200); |
961 gfx::Size current_layer_bounds(200, 200); | 1099 gfx::Size current_layer_bounds(200, 200); |
962 float last_layer_contents_scale = 1.f; | |
963 float current_layer_contents_scale = 1.f; | 1100 float current_layer_contents_scale = 1.f; |
964 gfx::Transform last_screen_transform; | 1101 gfx::Transform last_screen_transform; |
965 gfx::Transform current_screen_transform; | 1102 gfx::Transform current_screen_transform; |
966 double current_frame_time_in_seconds = 1.0; | 1103 double current_frame_time_in_seconds = 1.0; |
967 size_t max_tiles_for_interest_area = 10000; | |
968 | 1104 |
969 // A diagonally rotated layer that is partially off the bottom of the screen. | 1105 // A diagonally rotated layer that is partially off the bottom of the screen. |
970 // In this configuration, only the top-left tile would be visible. | 1106 // In this configuration, only the top-left tile would be visible. |
971 current_screen_transform.Translate(400, 550); | 1107 current_screen_transform.Translate(600, 750); |
972 current_screen_transform.RotateAboutZAxis(45); | 1108 current_screen_transform.RotateAboutZAxis(45); |
973 last_screen_transform = current_screen_transform; | 1109 last_screen_transform = current_screen_transform; |
974 | 1110 |
975 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1111 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
976 current_screen_transform, device_viewport); | 1112 current_screen_transform, device_viewport); |
977 | 1113 |
978 client.SetTileSize(gfx::Size(100, 100)); | 1114 client.SetTileSize(gfx::Size(100, 100)); |
979 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1115 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
980 current_layer_bounds, | 1116 current_layer_bounds, |
981 &client); | 1117 &client); |
982 | 1118 |
983 tiling->UpdateTilePriorities( | 1119 tiling->UpdateTilePriorities(ACTIVE_TREE, |
984 ACTIVE_TREE, | 1120 viewport_in_layer_space, |
985 device_viewport, | 1121 current_layer_contents_scale, |
986 viewport_in_layer_space, | 1122 current_frame_time_in_seconds); |
987 visible_layer_rect, | |
988 last_layer_bounds, | |
989 current_layer_bounds, | |
990 last_layer_contents_scale, | |
991 current_layer_contents_scale, | |
992 last_screen_transform, | |
993 current_screen_transform, | |
994 current_frame_time_in_seconds, | |
995 max_tiles_for_interest_area); | |
996 | 1123 |
997 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1124 ASSERT_TRUE(tiling->TileAt(0, 0)); |
998 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1125 ASSERT_TRUE(tiling->TileAt(0, 1)); |
999 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1126 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1000 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1127 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1001 | 1128 |
1002 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1129 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1003 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1130 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1004 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1131 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1005 | 1132 |
1006 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1133 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1007 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1134 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1008 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1135 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1009 priority.time_to_visible_in_seconds); | |
1010 | 1136 |
1011 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1137 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1012 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1138 EXPECT_GT(priority.distance_to_visible, 0.f); |
1013 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1139 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1014 priority.time_to_visible_in_seconds); | |
1015 | 1140 |
1016 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1141 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1017 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1142 EXPECT_GT(priority.distance_to_visible, 0.f); |
1018 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1143 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1019 priority.time_to_visible_in_seconds); | |
1020 | 1144 |
1021 // Furthermore, in this scenario the bottom-right tile should have the larger | 1145 // Furthermore, in this scenario the bottom-right tile should have the larger |
1022 // distance to visible. | 1146 // distance to visible. |
1023 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1147 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1024 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1148 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1025 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | |
1026 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1149 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1027 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1150 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible); |
1028 top_left.distance_to_visible_in_pixels); | |
1029 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | |
1030 top_left.distance_to_visible_in_pixels); | |
1031 | 1151 |
1032 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1152 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); |
1033 bottom_left.distance_to_visible_in_pixels); | |
1034 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | |
1035 top_right.distance_to_visible_in_pixels); | |
1036 } | 1153 } |
1037 | 1154 |
1038 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 1155 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
1039 // Perspective transforms need to take a different code path. | 1156 // Perspective transforms need to take a different code path. |
1040 // This test checks tile priorities of a perspective layer. | 1157 // This test checks tile priorities of a perspective layer. |
1041 | 1158 |
1042 FakePictureLayerTilingClient client; | 1159 FakePictureLayerTilingClient client; |
1043 scoped_ptr<TestablePictureLayerTiling> tiling; | 1160 scoped_ptr<TestablePictureLayerTiling> tiling; |
1044 | 1161 |
1045 gfx::Size device_viewport(800, 600); | 1162 gfx::Size device_viewport(800, 600); |
1046 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1163 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
1047 gfx::Size last_layer_bounds(200, 200); | 1164 gfx::Size last_layer_bounds(200, 200); |
1048 gfx::Size current_layer_bounds(200, 200); | 1165 gfx::Size current_layer_bounds(200, 200); |
1049 float last_layer_contents_scale = 1.f; | |
1050 float current_layer_contents_scale = 1.f; | 1166 float current_layer_contents_scale = 1.f; |
1051 gfx::Transform last_screen_transform; | 1167 gfx::Transform last_screen_transform; |
1052 gfx::Transform current_screen_transform; | 1168 gfx::Transform current_screen_transform; |
1053 double current_frame_time_in_seconds = 1.0; | 1169 double current_frame_time_in_seconds = 1.0; |
1054 size_t max_tiles_for_interest_area = 10000; | |
1055 | 1170 |
1056 // A 3d perspective layer rotated about its Y axis, translated to almost | 1171 // A 3d perspective layer rotated about its Y axis, translated to almost |
1057 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1172 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
1058 // the right side, so the top-left tile will technically be closer than the | 1173 // the right side, so the top-left tile will technically be closer than the |
1059 // top-right. | 1174 // top-right. |
1060 | 1175 |
1061 // Translate layer to offscreen | 1176 // Translate layer to offscreen |
1062 current_screen_transform.Translate(400.0, 630.0); | 1177 current_screen_transform.Translate(400.0, 630.0); |
1063 // Apply perspective about the center of the layer | 1178 // Apply perspective about the center of the layer |
1064 current_screen_transform.Translate(100.0, 100.0); | 1179 current_screen_transform.Translate(100.0, 100.0); |
(...skipping 10 matching lines...) Expand all Loading... | |
1075 ASSERT_FALSE(clipped); | 1190 ASSERT_FALSE(clipped); |
1076 | 1191 |
1077 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1192 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1078 current_screen_transform, device_viewport); | 1193 current_screen_transform, device_viewport); |
1079 | 1194 |
1080 client.SetTileSize(gfx::Size(100, 100)); | 1195 client.SetTileSize(gfx::Size(100, 100)); |
1081 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1196 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1082 current_layer_bounds, | 1197 current_layer_bounds, |
1083 &client); | 1198 &client); |
1084 | 1199 |
1085 tiling->UpdateTilePriorities( | 1200 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1086 ACTIVE_TREE, | 1201 viewport_in_layer_space, |
1087 device_viewport, | 1202 current_layer_contents_scale, |
1088 viewport_in_layer_space, | 1203 current_frame_time_in_seconds); |
1089 visible_layer_rect, | |
1090 last_layer_bounds, | |
1091 current_layer_bounds, | |
1092 last_layer_contents_scale, | |
1093 current_layer_contents_scale, | |
1094 last_screen_transform, | |
1095 current_screen_transform, | |
1096 current_frame_time_in_seconds, | |
1097 max_tiles_for_interest_area); | |
1098 | 1204 |
1099 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1205 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1100 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1206 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1101 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1207 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1102 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1208 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1103 | 1209 |
1104 // All tiles will have a positive distance_to_visible | 1210 // All tiles will have a positive distance_to_visible |
1105 // and an infinite time_to_visible. | 1211 // and an infinite time_to_visible. |
1106 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1212 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1107 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1213 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1108 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1214 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1109 priority.time_to_visible_in_seconds); | |
1110 | 1215 |
1111 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1216 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1112 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1217 EXPECT_GT(priority.distance_to_visible, 0.f); |
1113 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1218 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1114 priority.time_to_visible_in_seconds); | |
1115 | 1219 |
1116 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1220 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1117 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1221 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1118 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1222 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1119 priority.time_to_visible_in_seconds); | |
1120 | 1223 |
1121 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1224 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1122 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1225 EXPECT_GT(priority.distance_to_visible, 0.f); |
1123 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1226 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1124 priority.time_to_visible_in_seconds); | |
1125 | 1227 |
1126 // Furthermore, in this scenario the top-left distance_to_visible | 1228 // Furthermore, in this scenario the top-left distance_to_visible |
1127 // will be smallest, followed by top-right. The bottom layers | 1229 // will be smallest, followed by top-right. The bottom layers |
1128 // will of course be further than the top layers. | 1230 // will of course be further than the top layers. |
1129 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1231 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1130 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1232 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1131 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1233 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1132 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1234 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1133 EXPECT_GT(top_right.distance_to_visible_in_pixels, | |
1134 top_left.distance_to_visible_in_pixels); | |
1135 | 1235 |
1136 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1236 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); |
1137 top_right.distance_to_visible_in_pixels); | |
1138 | 1237 |
1139 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1238 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); |
1140 top_left.distance_to_visible_in_pixels); | |
1141 } | 1239 } |
1142 | 1240 |
1143 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1241 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
1144 // Perspective transforms need to take a different code path. | 1242 // Perspective transforms need to take a different code path. |
1145 // This test checks tile priorities of a perspective layer. | 1243 // This test checks tile priorities of a perspective layer. |
1146 | 1244 |
1147 FakePictureLayerTilingClient client; | 1245 FakePictureLayerTilingClient client; |
1148 scoped_ptr<TestablePictureLayerTiling> tiling; | 1246 scoped_ptr<TestablePictureLayerTiling> tiling; |
1149 | 1247 |
1150 gfx::Size device_viewport(800, 600); | 1248 gfx::Size device_viewport(800, 600); |
1151 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | |
1152 gfx::Size last_layer_bounds(200, 200); | 1249 gfx::Size last_layer_bounds(200, 200); |
1153 gfx::Size current_layer_bounds(200, 200); | 1250 gfx::Size current_layer_bounds(200, 200); |
1154 float last_layer_contents_scale = 1.f; | |
1155 float current_layer_contents_scale = 1.f; | 1251 float current_layer_contents_scale = 1.f; |
1156 gfx::Transform last_screen_transform; | 1252 gfx::Transform last_screen_transform; |
1157 gfx::Transform current_screen_transform; | 1253 gfx::Transform current_screen_transform; |
1158 double current_frame_time_in_seconds = 1.0; | 1254 double current_frame_time_in_seconds = 1.0; |
1159 size_t max_tiles_for_interest_area = 10000; | |
1160 | 1255 |
1161 // A 3d perspective layer rotated about its Y axis, translated to almost | 1256 // A 3d perspective layer rotated about its Y axis, translated to almost |
1162 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1257 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
1163 // the right side, so the top-left tile will technically be closer than the | 1258 // the right side, so the top-left tile will technically be closer than the |
1164 // top-right. | 1259 // top-right. |
1165 | 1260 |
1166 // Translate layer to offscreen | 1261 // Translate layer to offscreen |
1167 current_screen_transform.Translate(400.0, 970.0); | 1262 current_screen_transform.Translate(400.0, 970.0); |
1168 // Apply perspective and rotation about the center of the layer | 1263 // Apply perspective and rotation about the center of the layer |
1169 current_screen_transform.Translate(100.0, 100.0); | 1264 current_screen_transform.Translate(100.0, 100.0); |
(...skipping 16 matching lines...) Expand all Loading... | |
1186 ASSERT_FALSE(clipped); | 1281 ASSERT_FALSE(clipped); |
1187 | 1282 |
1188 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1283 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1189 current_screen_transform, device_viewport); | 1284 current_screen_transform, device_viewport); |
1190 | 1285 |
1191 client.SetTileSize(gfx::Size(100, 100)); | 1286 client.SetTileSize(gfx::Size(100, 100)); |
1192 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1287 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1193 current_layer_bounds, | 1288 current_layer_bounds, |
1194 &client); | 1289 &client); |
1195 | 1290 |
1196 tiling->UpdateTilePriorities( | 1291 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1197 ACTIVE_TREE, | 1292 viewport_in_layer_space, |
1198 device_viewport, | 1293 current_layer_contents_scale, |
1199 viewport_in_layer_space, | 1294 current_frame_time_in_seconds); |
1200 visible_layer_rect, | |
1201 last_layer_bounds, | |
1202 current_layer_bounds, | |
1203 last_layer_contents_scale, | |
1204 current_layer_contents_scale, | |
1205 last_screen_transform, | |
1206 current_screen_transform, | |
1207 current_frame_time_in_seconds, | |
1208 max_tiles_for_interest_area); | |
1209 | 1295 |
1210 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1296 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1211 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1297 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1212 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1298 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1213 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1299 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1214 | 1300 |
1215 // Left-side tiles will be clipped by the transform, so we have to assume | 1301 // Left-side tiles will be clipped by the transform, so we have to assume |
1216 // they are visible just in case. | 1302 // they are visible just in case. |
1217 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1303 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1304 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1305 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1220 | 1306 |
1221 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1307 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1222 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1308 EXPECT_GT(priority.distance_to_visible, 0.f); |
1223 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1309 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1224 | 1310 |
1225 // Right-side tiles will have a positive distance_to_visible | 1311 // Right-side tiles will have a positive distance_to_visible |
1226 // and an infinite time_to_visible. | 1312 // and an infinite time_to_visible. |
1227 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1313 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1228 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1314 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1229 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1315 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1230 priority.time_to_visible_in_seconds); | |
1231 | 1316 |
1232 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1317 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1233 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1318 EXPECT_GT(priority.distance_to_visible, 0.f); |
1234 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1319 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1235 priority.time_to_visible_in_seconds); | |
1236 } | 1320 } |
1237 | 1321 |
1238 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1322 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
1239 // Test that time_to_visible is computed correctly when | 1323 // Test that time_to_visible is computed correctly when |
1240 // there is some motion. | 1324 // there is some motion. |
1241 | 1325 |
1242 FakePictureLayerTilingClient client; | 1326 FakePictureLayerTilingClient client; |
1243 scoped_ptr<TestablePictureLayerTiling> tiling; | 1327 scoped_ptr<TestablePictureLayerTiling> tiling; |
1244 | 1328 |
1245 gfx::Size device_viewport(800, 600); | 1329 gfx::Size device_viewport(800, 600); |
1246 gfx::Rect visible_layer_rect(0, 0, 0, 0); | 1330 gfx::Rect visible_layer_rect(0, 0, 0, 0); |
1247 gfx::Size last_layer_bounds(200, 200); | 1331 gfx::Size last_layer_bounds(200, 200); |
1248 gfx::Size current_layer_bounds(200, 200); | 1332 gfx::Size current_layer_bounds(200, 200); |
1249 float last_layer_contents_scale = 1.f; | 1333 float last_layer_contents_scale = 1.f; |
1250 float current_layer_contents_scale = 1.f; | 1334 float current_layer_contents_scale = 1.f; |
1251 gfx::Transform last_screen_transform; | 1335 gfx::Transform last_screen_transform; |
1252 gfx::Transform current_screen_transform; | 1336 gfx::Transform current_screen_transform; |
1253 double last_frame_time_in_seconds = 1.0; | 1337 double last_frame_time_in_seconds = 1.0; |
1254 double current_frame_time_in_seconds = 2.0; | 1338 double current_frame_time_in_seconds = 2.0; |
1255 size_t max_tiles_for_interest_area = 10000; | |
1256 | 1339 |
1257 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1340 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
1258 current_screen_transform.Translate(1800, 0); | 1341 current_screen_transform.Translate(1800, 0); |
1259 last_screen_transform.Translate(2800, 0); | 1342 last_screen_transform.Translate(2800, 0); |
1260 | 1343 |
1261 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1344 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1262 current_screen_transform, device_viewport); | 1345 current_screen_transform, device_viewport); |
1263 | 1346 |
1264 client.SetTileSize(gfx::Size(100, 100)); | 1347 client.SetTileSize(gfx::Size(100, 100)); |
1265 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1348 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1266 current_layer_bounds, | 1349 current_layer_bounds, |
1267 &client); | 1350 &client); |
1268 | 1351 |
1269 // previous ("last") frame | 1352 // previous ("last") frame |
1270 tiling->UpdateTilePriorities( | 1353 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1271 ACTIVE_TREE, | 1354 viewport_in_layer_space, |
1272 device_viewport, | 1355 last_layer_contents_scale, |
1273 viewport_in_layer_space, | 1356 last_frame_time_in_seconds); |
1274 visible_layer_rect, | |
1275 last_layer_bounds, | |
1276 last_layer_bounds, | |
1277 last_layer_contents_scale, | |
1278 last_layer_contents_scale, | |
1279 last_screen_transform, | |
1280 last_screen_transform, | |
1281 last_frame_time_in_seconds, | |
1282 max_tiles_for_interest_area); | |
1283 | 1357 |
1284 // current frame | 1358 // current frame |
1285 tiling->UpdateTilePriorities( | 1359 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1286 ACTIVE_TREE, | 1360 viewport_in_layer_space, |
1287 device_viewport, | 1361 current_layer_contents_scale, |
1288 viewport_in_layer_space, | 1362 current_frame_time_in_seconds); |
1289 visible_layer_rect, | |
1290 last_layer_bounds, | |
1291 current_layer_bounds, | |
1292 last_layer_contents_scale, | |
1293 current_layer_contents_scale, | |
1294 last_screen_transform, | |
1295 current_screen_transform, | |
1296 current_frame_time_in_seconds, | |
1297 max_tiles_for_interest_area); | |
1298 | 1363 |
1299 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1364 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1300 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1365 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1301 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1366 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1302 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1367 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1303 | 1368 |
1304 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1369 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1305 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1370 EXPECT_GT(priority.distance_to_visible, 0.f); |
1306 EXPECT_FLOAT_EQ(1.f, | 1371 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1307 priority.time_to_visible_in_seconds); | |
1308 | 1372 |
1309 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1373 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1310 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1374 EXPECT_GT(priority.distance_to_visible, 0.f); |
1311 EXPECT_FLOAT_EQ(1.f, | 1375 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1312 priority.time_to_visible_in_seconds); | |
1313 | 1376 |
1314 // time_to_visible for the right hand side layers needs an extra 0.099 | 1377 // time_to_visible for the right hand side layers needs an extra 0.099 |
1315 // seconds because this tile is 99 pixels further away. | 1378 // seconds because this tile is 99 pixels further away. |
1316 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1379 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1317 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1380 EXPECT_GT(priority.distance_to_visible, 0.f); |
1318 EXPECT_FLOAT_EQ(1.099f, | 1381 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1319 priority.time_to_visible_in_seconds); | |
1320 | 1382 |
1321 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1383 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1322 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1384 EXPECT_GT(priority.distance_to_visible, 0.f); |
1323 EXPECT_FLOAT_EQ(1.099f, | 1385 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1324 priority.time_to_visible_in_seconds); | |
1325 } | 1386 } |
1326 | 1387 |
1327 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1388 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
1328 // Each tile of a layer may be affected differently by a transform; Check | 1389 // Each tile of a layer may be affected differently by a transform; Check |
1329 // that UpdateTilePriorities correctly accounts for the transform between | 1390 // that UpdateTilePriorities correctly accounts for the transform between |
1330 // layer space and screen space. | 1391 // layer space and screen space. |
1331 | 1392 |
1332 FakePictureLayerTilingClient client; | 1393 FakePictureLayerTilingClient client; |
1333 scoped_ptr<TestablePictureLayerTiling> tiling; | 1394 scoped_ptr<TestablePictureLayerTiling> tiling; |
1334 | 1395 |
1335 gfx::Size device_viewport(800, 600); | 1396 gfx::Size device_viewport(800, 600); |
1336 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. | 1397 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. |
1337 gfx::Size last_layer_bounds(200, 200); | 1398 gfx::Size last_layer_bounds(200, 200); |
1338 gfx::Size current_layer_bounds(200, 200); | 1399 gfx::Size current_layer_bounds(200, 200); |
1339 float last_layer_contents_scale = 1.f; | 1400 float last_layer_contents_scale = 1.f; |
1340 float current_layer_contents_scale = 1.f; | 1401 float current_layer_contents_scale = 1.f; |
1341 gfx::Transform last_screen_transform; | 1402 gfx::Transform last_screen_transform; |
1342 gfx::Transform current_screen_transform; | 1403 gfx::Transform current_screen_transform; |
1343 double last_frame_time_in_seconds = 1.0; | 1404 double last_frame_time_in_seconds = 1.0; |
1344 double current_frame_time_in_seconds = 2.0; | 1405 double current_frame_time_in_seconds = 2.0; |
1345 size_t max_tiles_for_interest_area = 10000; | |
1346 | 1406 |
1347 // Rotation motion is set up specifically so that: | 1407 // Rotation motion is set up specifically so that: |
1348 // - rotation occurs about the center of the layer | 1408 // - rotation occurs about the center of the layer |
1349 // - the top-left tile becomes visible on rotation | 1409 // - the top-left tile becomes visible on rotation |
1350 // - the top-right tile will have an infinite time_to_visible | 1410 // - the top-right tile will have an infinite time_to_visible |
1351 // because it is rotating away from viewport. | 1411 // because it is rotating away from viewport. |
1352 // - bottom-left layer will have a positive non-zero time_to_visible | 1412 // - bottom-left layer will have a positive non-zero time_to_visible |
1353 // because it is rotating toward the viewport. | 1413 // because it is rotating toward the viewport. |
1354 current_screen_transform.Translate(400, 550); | 1414 current_screen_transform.Translate(400, 550); |
1355 current_screen_transform.RotateAboutZAxis(45); | 1415 current_screen_transform.RotateAboutZAxis(45); |
1356 | 1416 |
1357 last_screen_transform.Translate(400, 550); | 1417 last_screen_transform.Translate(400, 550); |
1358 | 1418 |
1359 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1419 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1360 current_screen_transform, device_viewport); | 1420 current_screen_transform, device_viewport); |
1361 | 1421 |
1362 client.SetTileSize(gfx::Size(100, 100)); | 1422 client.SetTileSize(gfx::Size(100, 100)); |
1363 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1423 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1364 current_layer_bounds, | 1424 current_layer_bounds, |
1365 &client); | 1425 &client); |
1366 | 1426 |
1367 // previous ("last") frame | 1427 // previous ("last") frame |
1368 tiling->UpdateTilePriorities( | 1428 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1369 ACTIVE_TREE, | 1429 viewport_in_layer_space, |
1370 device_viewport, | 1430 last_layer_contents_scale, |
1371 viewport_in_layer_space, | 1431 last_frame_time_in_seconds); |
1372 visible_layer_rect, | |
1373 last_layer_bounds, | |
1374 last_layer_bounds, | |
1375 last_layer_contents_scale, | |
1376 last_layer_contents_scale, | |
1377 last_screen_transform, | |
1378 last_screen_transform, | |
1379 last_frame_time_in_seconds, | |
1380 max_tiles_for_interest_area); | |
1381 | 1432 |
1382 // current frame | 1433 // current frame |
1383 tiling->UpdateTilePriorities( | 1434 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1384 ACTIVE_TREE, | 1435 viewport_in_layer_space, |
1385 device_viewport, | 1436 current_layer_contents_scale, |
1386 viewport_in_layer_space, | 1437 current_frame_time_in_seconds); |
1387 visible_layer_rect, | |
1388 last_layer_bounds, | |
1389 current_layer_bounds, | |
1390 last_layer_contents_scale, | |
1391 current_layer_contents_scale, | |
1392 last_screen_transform, | |
1393 current_screen_transform, | |
1394 current_frame_time_in_seconds, | |
1395 max_tiles_for_interest_area); | |
1396 | 1438 |
1397 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1439 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1398 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1440 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1399 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1441 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1400 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1442 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1401 | 1443 |
1402 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1444 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1403 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1445 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1404 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1446 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1405 | 1447 |
1406 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1448 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1449 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1450 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1409 | 1451 |
1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1452 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1453 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1454 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1413 priority.time_to_visible_in_seconds); | |
1414 } | 1455 } |
1415 | 1456 |
1416 } // namespace | 1457 } // namespace |
1417 } // namespace cc | 1458 } // namespace cc |
OLD | NEW |