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, ComputeSkewport) { | |
enne (OOO)
2014/02/11 00:43:56
Can you test the pixel limits too? It might make s
vmpstr
2014/02/11 23:45:25
Done.
| |
273 FakePictureLayerTilingClient client; | |
274 scoped_ptr<TestablePictureLayerTiling> tiling; | |
275 | |
276 gfx::Rect viewport(0, 0, 100, 100); | |
277 gfx::Size layer_bounds(200, 200); | |
278 | |
279 client.SetTileSize(gfx::Size(100, 100)); | |
280 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | |
281 | |
282 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); | |
283 | |
284 // Move viewport down 50 pixels in 0.5 seconds. | |
285 gfx::Rect down_skewport = | |
286 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | |
287 | |
288 EXPECT_EQ(0, down_skewport.x()); | |
289 EXPECT_EQ(50, down_skewport.y()); | |
290 EXPECT_EQ(100, down_skewport.width()); | |
291 EXPECT_EQ(200, down_skewport.height()); | |
292 | |
293 // Shrink viewport. | |
294 gfx::Rect shrink_skewport = | |
295 tiling->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50)); | |
296 | |
297 EXPECT_EQ(25, shrink_skewport.x()); | |
298 EXPECT_EQ(25, shrink_skewport.y()); | |
299 EXPECT_EQ(50, shrink_skewport.width()); | |
300 EXPECT_EQ(50, shrink_skewport.height()); | |
301 | |
302 // Move viewport down 50 and right 10 pixels. | |
303 gfx::Rect down_right_skewport = | |
304 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); | |
305 | |
306 EXPECT_EQ(10, down_right_skewport.x()); | |
307 EXPECT_EQ(50, down_right_skewport.y()); | |
308 EXPECT_EQ(120, down_right_skewport.width()); | |
309 EXPECT_EQ(200, down_right_skewport.height()); | |
310 | |
311 // Move viewport left. | |
312 gfx::Rect left_skewport = | |
313 tiling->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100)); | |
314 | |
315 EXPECT_EQ(-60, left_skewport.x()); | |
316 EXPECT_EQ(0, left_skewport.y()); | |
317 EXPECT_EQ(140, left_skewport.width()); | |
318 EXPECT_EQ(100, left_skewport.height()); | |
319 | |
320 // Expand viewport in 0.2 seconds. | |
321 gfx::Rect expanded_skewport = | |
322 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); | |
323 | |
324 EXPECT_EQ(-30, expanded_skewport.x()); | |
325 EXPECT_EQ(-30, expanded_skewport.y()); | |
326 EXPECT_EQ(160, expanded_skewport.width()); | |
327 EXPECT_EQ(160, expanded_skewport.height()); | |
328 } | |
329 | |
267 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 330 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
268 gfx::Rect in(40, 50, 100, 200); | 331 gfx::Rect in(40, 50, 100, 200); |
269 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 332 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
270 int64 target_area = 100 * 200; | 333 int64 target_area = 100 * 200; |
271 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 334 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
272 in, target_area, bounds, NULL); | 335 in, target_area, bounds, NULL); |
273 EXPECT_EQ(in.ToString(), out.ToString()); | 336 EXPECT_EQ(in.ToString(), out.ToString()); |
274 } | 337 } |
275 | 338 |
276 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 339 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 const gfx::Rect& geometry_rect) { | 549 const gfx::Rect& geometry_rect) { |
487 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 550 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
488 } | 551 } |
489 | 552 |
490 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 553 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
491 gfx::Size layer_bounds(1099, 801); | 554 gfx::Size layer_bounds(1099, 801); |
492 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 555 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
493 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 556 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
494 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 557 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
495 | 558 |
559 set_max_tiles_for_interest_area(1000); | |
496 tiling_->UpdateTilePriorities( | 560 tiling_->UpdateTilePriorities( |
497 ACTIVE_TREE, | 561 ACTIVE_TREE, |
498 layer_bounds, // device viewport | |
499 gfx::Rect(layer_bounds), // viewport in layer space | |
500 gfx::Rect(layer_bounds), // visible content rect | 562 gfx::Rect(layer_bounds), // visible content rect |
501 layer_bounds, // last layer bounds | 563 1.f, // current contents scale |
502 layer_bounds, // current layer bounds | 564 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)); | 565 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
510 | 566 |
511 // Make the viewport rect empty. All tiles are killed and become zombies. | 567 // Make the viewport rect empty. All tiles are killed and become zombies. |
512 tiling_->UpdateTilePriorities( | 568 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
513 ACTIVE_TREE, | 569 gfx::Rect(), // visible content rect |
514 layer_bounds, // device viewport | 570 1.f, // current contents scale |
515 gfx::Rect(), // viewport in layer space | 571 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)); | 572 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
526 } | 573 } |
527 | 574 |
528 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 575 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
529 gfx::Size layer_bounds(1099, 801); | 576 gfx::Size layer_bounds(1099, 801); |
530 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 577 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
531 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 578 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
532 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 579 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
533 | 580 |
534 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 581 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
535 | 582 |
583 set_max_tiles_for_interest_area(1000); | |
536 tiling_->UpdateTilePriorities( | 584 tiling_->UpdateTilePriorities( |
537 ACTIVE_TREE, | 585 ACTIVE_TREE, |
538 layer_bounds, // device viewport | |
539 giant_rect, // viewport in layer space | |
540 gfx::Rect(layer_bounds), // visible content rect | 586 gfx::Rect(layer_bounds), // visible content rect |
541 layer_bounds, // last layer bounds | 587 1.f, // current contents scale |
542 layer_bounds, // current layer bounds | 588 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)); | 589 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
550 | 590 |
551 // If the visible content rect is empty, it should still have live tiles. | 591 // If the visible content rect is empty, it should still have live tiles. |
552 tiling_->UpdateTilePriorities( | 592 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
553 ACTIVE_TREE, | 593 giant_rect, // visible content rect |
554 layer_bounds, // device viewport | 594 1.f, // current contents scale |
555 giant_rect, // viewport in layer space | 595 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)); | 596 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
566 } | 597 } |
567 | 598 |
568 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | 599 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { |
569 gfx::Size layer_bounds(1099, 801); | 600 gfx::Size layer_bounds(1099, 801); |
570 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 601 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
571 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 602 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
572 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 603 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
573 | 604 |
574 // This rect does not intersect with the layer, as the layer is outside the | 605 // This rect does not intersect with the layer, as the layer is outside the |
575 // viewport. | 606 // viewport. |
576 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 607 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
577 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 608 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
578 | 609 |
579 tiling_->UpdateTilePriorities( | 610 set_max_tiles_for_interest_area(1000); |
580 ACTIVE_TREE, | 611 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
581 layer_bounds, // device viewport | 612 viewport_rect, // visible content rect |
582 viewport_rect, // viewport in layer space | 613 1.f, // current contents scale |
583 gfx::Rect(), // visible content rect | 614 1.0); // current frame time |
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)); | 615 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
593 } | 616 } |
594 | 617 |
595 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 618 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
596 bool intersect_exists, | 619 bool intersect_exists, |
597 Tile* tile, | 620 Tile* tile, |
598 const gfx::Rect& geometry_rect) { | 621 const gfx::Rect& geometry_rect) { |
599 bool intersects = rect.Intersects(geometry_rect); | 622 bool intersects = rect.Intersects(geometry_rect); |
600 bool expected_exists = intersect_exists ? intersects : !intersects; | 623 bool expected_exists = intersect_exists ? intersects : !intersects; |
601 EXPECT_EQ(expected_exists, tile != NULL) | 624 EXPECT_EQ(expected_exists, tile != NULL) |
602 << "Rects intersecting " << rect.ToString() << " should exist. " | 625 << "Rects intersecting " << rect.ToString() << " should exist. " |
603 << "Current tile rect is " << geometry_rect.ToString(); | 626 << "Current tile rect is " << geometry_rect.ToString(); |
604 } | 627 } |
605 | 628 |
606 TEST_F(PictureLayerTilingIteratorTest, | 629 TEST_F(PictureLayerTilingIteratorTest, |
607 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 630 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
608 gfx::Size layer_bounds(10000, 10000); | 631 gfx::Size layer_bounds(10000, 10000); |
609 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 632 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
610 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 633 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
611 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 634 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
612 | 635 |
613 gfx::Rect visible_rect(8000, 8000, 50, 50); | 636 gfx::Rect visible_rect(8000, 8000, 50, 50); |
614 | 637 |
615 tiling_->UpdateTilePriorities( | 638 set_max_tiles_for_interest_area(1); |
616 ACTIVE_TREE, | 639 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
617 layer_bounds, // device viewport | 640 visible_rect, // visible content rect |
618 gfx::Rect(layer_bounds), // viewport in layer space | 641 1.f, // current contents scale |
619 visible_rect, // visible content rect | 642 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, | 643 VerifyTiles(1.f, |
629 gfx::Rect(layer_bounds), | 644 gfx::Rect(layer_bounds), |
630 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 645 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
631 } | 646 } |
632 | 647 |
633 static void CountExistingTiles(int *count, | 648 static void CountExistingTiles(int *count, |
634 Tile* tile, | 649 Tile* tile, |
635 const gfx::Rect& geometry_rect) { | 650 const gfx::Rect& geometry_rect) { |
636 if (tile != NULL) | 651 if (tile != NULL) |
637 ++(*count); | 652 ++(*count); |
638 } | 653 } |
639 | 654 |
640 TEST_F(PictureLayerTilingIteratorTest, | 655 TEST_F(PictureLayerTilingIteratorTest, |
641 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 656 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
642 gfx::Size layer_bounds(10000, 10000); | 657 gfx::Size layer_bounds(10000, 10000); |
643 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 658 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
644 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 659 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
645 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 660 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
646 | 661 |
662 set_max_tiles_for_interest_area(1); | |
647 tiling_->UpdateTilePriorities( | 663 tiling_->UpdateTilePriorities( |
648 ACTIVE_TREE, | 664 ACTIVE_TREE, |
649 layer_bounds, // device viewport | |
650 gfx::Rect(layer_bounds), // viewport in layer space | |
651 gfx::Rect(layer_bounds), // visible content rect | 665 gfx::Rect(layer_bounds), // visible content rect |
652 layer_bounds, // last layer bounds | 666 1.f, // current contents scale |
653 layer_bounds, // current layer bounds | 667 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 | 668 |
661 int num_tiles = 0; | 669 int num_tiles = 0; |
662 VerifyTiles(1.f, | 670 VerifyTiles(1.f, |
663 gfx::Rect(layer_bounds), | 671 gfx::Rect(layer_bounds), |
664 base::Bind(&CountExistingTiles, &num_tiles)); | 672 base::Bind(&CountExistingTiles, &num_tiles)); |
665 // If we're making a rect the size of one tile, it can only overlap up to 4 | 673 // If we're making a rect the size of one tile, it can only overlap up to 4 |
666 // tiles depending on its position. | 674 // tiles depending on its position. |
667 EXPECT_LE(num_tiles, 4); | 675 EXPECT_LE(num_tiles, 4); |
668 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); | 676 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); |
669 } | 677 } |
670 | 678 |
671 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { | 679 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { |
672 gfx::Size layer_bounds(1099, 801); | 680 gfx::Size layer_bounds(1099, 801); |
673 gfx::Size tile_size(100, 100); | 681 gfx::Size tile_size(100, 100); |
674 | 682 |
675 client_.SetTileSize(tile_size); | 683 client_.SetTileSize(tile_size); |
676 | 684 |
677 PictureLayerTilingSet active_set(&client_, layer_bounds); | 685 PictureLayerTilingSet active_set(&client_, layer_bounds); |
678 | 686 |
679 active_set.AddTiling(1.f); | 687 active_set.AddTiling(1.f); |
680 | 688 |
681 VerifyTiles(active_set.tiling_at(0), | 689 VerifyTiles(active_set.tiling_at(0), |
682 1.f, | 690 1.f, |
683 gfx::Rect(layer_bounds), | 691 gfx::Rect(layer_bounds), |
684 base::Bind(&TileExists, false)); | 692 base::Bind(&TileExists, false)); |
685 | 693 |
694 set_max_tiles_for_interest_area(10000); | |
686 active_set.UpdateTilePriorities( | 695 active_set.UpdateTilePriorities( |
687 PENDING_TREE, | 696 PENDING_TREE, |
688 layer_bounds, // device viewport | |
689 gfx::Rect(layer_bounds), // viewport in layer space | |
690 gfx::Rect(layer_bounds), // visible content rect | 697 gfx::Rect(layer_bounds), // visible content rect |
691 layer_bounds, // last layer bounds | 698 1.f, // current contents scale |
692 layer_bounds, // current layer bounds | 699 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 | 700 |
700 // The active tiling has tiles now. | 701 // The active tiling has tiles now. |
701 VerifyTiles(active_set.tiling_at(0), | 702 VerifyTiles(active_set.tiling_at(0), |
702 1.f, | 703 1.f, |
703 gfx::Rect(layer_bounds), | 704 gfx::Rect(layer_bounds), |
704 base::Bind(&TileExists, true)); | 705 base::Bind(&TileExists, true)); |
705 | 706 |
706 // Add the same tilings to the pending set. | 707 // Add the same tilings to the pending set. |
707 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 708 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
708 Region invalidation; | 709 Region invalidation; |
709 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 710 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
710 | 711 |
711 // The pending tiling starts with no tiles. | 712 // The pending tiling starts with no tiles. |
712 VerifyTiles(pending_set.tiling_at(0), | 713 VerifyTiles(pending_set.tiling_at(0), |
713 1.f, | 714 1.f, |
714 gfx::Rect(layer_bounds), | 715 gfx::Rect(layer_bounds), |
715 base::Bind(&TileExists, false)); | 716 base::Bind(&TileExists, false)); |
716 | 717 |
717 // UpdateTilePriorities on the pending tiling at the same frame time. The | 718 // UpdateTilePriorities on the pending tiling at the same frame time. The |
718 // pending tiling should get tiles. | 719 // pending tiling should get tiles. |
719 pending_set.UpdateTilePriorities( | 720 pending_set.UpdateTilePriorities( |
720 PENDING_TREE, | 721 PENDING_TREE, |
721 layer_bounds, // device viewport | |
722 gfx::Rect(layer_bounds), // viewport in layer space | |
723 gfx::Rect(layer_bounds), // visible content rect | 722 gfx::Rect(layer_bounds), // visible content rect |
724 layer_bounds, // last layer bounds | 723 1.f, // current contents scale |
725 layer_bounds, // current layer bounds | 724 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 | 725 |
733 VerifyTiles(pending_set.tiling_at(0), | 726 VerifyTiles(pending_set.tiling_at(0), |
734 1.f, | 727 1.f, |
735 gfx::Rect(layer_bounds), | 728 gfx::Rect(layer_bounds), |
736 base::Bind(&TileExists, true)); | 729 base::Bind(&TileExists, true)); |
737 } | 730 } |
738 | 731 |
739 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 732 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
740 // The TilePriority of visible tiles should have zero distance_to_visible | 733 // The TilePriority of visible tiles should have zero distance_to_visible |
741 // and time_to_visible. | 734 // and time_to_visible. |
742 | 735 |
743 FakePictureLayerTilingClient client; | 736 FakePictureLayerTilingClient client; |
744 scoped_ptr<TestablePictureLayerTiling> tiling; | 737 scoped_ptr<TestablePictureLayerTiling> tiling; |
745 | 738 |
746 gfx::Size device_viewport(800, 600); | 739 gfx::Size device_viewport(800, 600); |
747 gfx::Rect visible_layer_rect(0, 0, 200, 200); | |
748 gfx::Size last_layer_bounds(200, 200); | 740 gfx::Size last_layer_bounds(200, 200); |
749 gfx::Size current_layer_bounds(200, 200); | 741 gfx::Size current_layer_bounds(200, 200); |
750 float last_layer_contents_scale = 1.f; | |
751 float current_layer_contents_scale = 1.f; | 742 float current_layer_contents_scale = 1.f; |
752 gfx::Transform last_screen_transform; | |
753 gfx::Transform current_screen_transform; | 743 gfx::Transform current_screen_transform; |
754 double current_frame_time_in_seconds = 1.0; | 744 double current_frame_time_in_seconds = 1.0; |
755 size_t max_tiles_for_interest_area = 10000; | 745 size_t max_tiles_for_interest_area = 10000; |
756 | 746 |
757 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 747 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
758 current_screen_transform, device_viewport); | 748 current_screen_transform, device_viewport); |
759 | 749 |
760 client.SetTileSize(gfx::Size(100, 100)); | 750 client.SetTileSize(gfx::Size(100, 100)); |
761 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 751 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
762 current_layer_bounds, | 752 current_layer_bounds, |
763 &client); | 753 &client); |
764 | 754 |
765 tiling->UpdateTilePriorities( | 755 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
enne (OOO)
2014/02/11 00:43:56
Can the fake client just set a "really large" max
vmpstr
2014/02/11 23:45:25
Done.
| |
766 ACTIVE_TREE, | 756 tiling->UpdateTilePriorities(ACTIVE_TREE, |
767 device_viewport, | 757 viewport_in_layer_space, |
768 viewport_in_layer_space, | 758 current_layer_contents_scale, |
769 visible_layer_rect, | 759 current_frame_time_in_seconds); |
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 | 760 |
779 ASSERT_TRUE(tiling->TileAt(0, 0)); | 761 ASSERT_TRUE(tiling->TileAt(0, 0)); |
780 ASSERT_TRUE(tiling->TileAt(0, 1)); | 762 ASSERT_TRUE(tiling->TileAt(0, 1)); |
781 ASSERT_TRUE(tiling->TileAt(1, 0)); | 763 ASSERT_TRUE(tiling->TileAt(1, 0)); |
782 ASSERT_TRUE(tiling->TileAt(1, 1)); | 764 ASSERT_TRUE(tiling->TileAt(1, 1)); |
783 | 765 |
784 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 766 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 767 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 768 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
787 | 769 |
788 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 770 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 771 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 772 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
791 | 773 |
792 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 774 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 775 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 776 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
795 | 777 |
796 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 778 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
797 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 779 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
798 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 780 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
799 } | 781 } |
800 | 782 |
801 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 783 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
802 // The TilePriority of offscreen tiles (without movement) should have nonzero | 784 // The TilePriority of offscreen tiles (without movement) should have nonzero |
803 // distance_to_visible and infinite time_to_visible. | 785 // distance_to_visible and infinite time_to_visible. |
804 | 786 |
805 FakePictureLayerTilingClient client; | 787 FakePictureLayerTilingClient client; |
806 scoped_ptr<TestablePictureLayerTiling> tiling; | 788 scoped_ptr<TestablePictureLayerTiling> tiling; |
807 | 789 |
808 gfx::Size device_viewport(800, 600); | 790 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); | 791 gfx::Size last_layer_bounds(200, 200); |
811 gfx::Size current_layer_bounds(200, 200); | 792 gfx::Size current_layer_bounds(200, 200); |
812 float last_layer_contents_scale = 1.f; | |
813 float current_layer_contents_scale = 1.f; | 793 float current_layer_contents_scale = 1.f; |
814 gfx::Transform last_screen_transform; | 794 gfx::Transform last_screen_transform; |
815 gfx::Transform current_screen_transform; | 795 gfx::Transform current_screen_transform; |
816 double current_frame_time_in_seconds = 1.0; | 796 double current_frame_time_in_seconds = 1.0; |
817 size_t max_tiles_for_interest_area = 10000; | 797 size_t max_tiles_for_interest_area = 10000; |
818 | 798 |
819 current_screen_transform.Translate(850, 0); | 799 current_screen_transform.Translate(850, 0); |
820 last_screen_transform = current_screen_transform; | 800 last_screen_transform = current_screen_transform; |
821 | 801 |
822 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 802 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
823 current_screen_transform, device_viewport); | 803 current_screen_transform, device_viewport); |
824 | 804 |
825 client.SetTileSize(gfx::Size(100, 100)); | 805 client.SetTileSize(gfx::Size(100, 100)); |
826 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 806 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
827 current_layer_bounds, | 807 current_layer_bounds, |
828 &client); | 808 &client); |
829 | 809 |
830 tiling->UpdateTilePriorities( | 810 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
831 ACTIVE_TREE, | 811 tiling->UpdateTilePriorities(ACTIVE_TREE, |
832 device_viewport, | 812 viewport_in_layer_space, |
833 viewport_in_layer_space, | 813 current_layer_contents_scale, |
834 visible_layer_rect, | 814 current_frame_time_in_seconds); |
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 | 815 |
844 ASSERT_TRUE(tiling->TileAt(0, 0)); | 816 ASSERT_TRUE(tiling->TileAt(0, 0)); |
845 ASSERT_TRUE(tiling->TileAt(0, 1)); | 817 ASSERT_TRUE(tiling->TileAt(0, 1)); |
846 ASSERT_TRUE(tiling->TileAt(1, 0)); | 818 ASSERT_TRUE(tiling->TileAt(1, 0)); |
847 ASSERT_TRUE(tiling->TileAt(1, 1)); | 819 ASSERT_TRUE(tiling->TileAt(1, 1)); |
848 | 820 |
849 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 821 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
850 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 822 EXPECT_GT(priority.distance_to_visible, 0.f); |
851 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 823 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
852 priority.time_to_visible_in_seconds); | |
853 | 824 |
854 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 825 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
855 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 826 EXPECT_GT(priority.distance_to_visible, 0.f); |
856 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 827 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
857 priority.time_to_visible_in_seconds); | |
858 | 828 |
859 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 829 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
860 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 830 EXPECT_GT(priority.distance_to_visible, 0.f); |
861 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 831 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
862 priority.time_to_visible_in_seconds); | |
863 | 832 |
864 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 833 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
865 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 834 EXPECT_GT(priority.distance_to_visible, 0.f); |
866 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 835 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
867 priority.time_to_visible_in_seconds); | |
868 | 836 |
869 // Furthermore, in this scenario tiles on the right hand side should have a | 837 // Furthermore, in this scenario tiles on the right hand side should have a |
870 // larger distance to visible. | 838 // larger distance to visible. |
871 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 839 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
872 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 840 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
873 EXPECT_GT(right.distance_to_visible_in_pixels, | 841 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
874 left.distance_to_visible_in_pixels); | |
875 | 842 |
876 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 843 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
877 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 844 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
878 EXPECT_GT(right.distance_to_visible_in_pixels, | 845 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
879 left.distance_to_visible_in_pixels); | |
880 } | 846 } |
881 | 847 |
882 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 848 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
883 // Sanity check that a layer with some tiles visible and others offscreen has | 849 // Sanity check that a layer with some tiles visible and others offscreen has |
884 // correct TilePriorities for each tile. | 850 // correct TilePriorities for each tile. |
885 | 851 |
886 FakePictureLayerTilingClient client; | 852 FakePictureLayerTilingClient client; |
887 scoped_ptr<TestablePictureLayerTiling> tiling; | 853 scoped_ptr<TestablePictureLayerTiling> tiling; |
888 | 854 |
889 gfx::Size device_viewport(800, 600); | 855 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); | 856 gfx::Size last_layer_bounds(200, 200); |
892 gfx::Size current_layer_bounds(200, 200); | 857 gfx::Size current_layer_bounds(200, 200); |
893 float last_layer_contents_scale = 1.f; | |
894 float current_layer_contents_scale = 1.f; | 858 float current_layer_contents_scale = 1.f; |
895 gfx::Transform last_screen_transform; | 859 gfx::Transform last_screen_transform; |
896 gfx::Transform current_screen_transform; | 860 gfx::Transform current_screen_transform; |
897 double current_frame_time_in_seconds = 1.0; | 861 double current_frame_time_in_seconds = 1.0; |
898 size_t max_tiles_for_interest_area = 10000; | 862 size_t max_tiles_for_interest_area = 10000; |
899 | 863 |
900 current_screen_transform.Translate(705, 505); | 864 current_screen_transform.Translate(705, 505); |
901 last_screen_transform = current_screen_transform; | 865 last_screen_transform = current_screen_transform; |
902 | 866 |
903 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 867 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
904 current_screen_transform, device_viewport); | 868 current_screen_transform, device_viewport); |
905 | 869 |
906 client.SetTileSize(gfx::Size(100, 100)); | 870 client.SetTileSize(gfx::Size(100, 100)); |
907 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 871 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
908 current_layer_bounds, | 872 current_layer_bounds, |
909 &client); | 873 &client); |
910 | 874 |
911 tiling->UpdateTilePriorities( | 875 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
912 ACTIVE_TREE, | 876 tiling->UpdateTilePriorities(ACTIVE_TREE, |
913 device_viewport, | 877 viewport_in_layer_space, |
914 viewport_in_layer_space, | 878 current_layer_contents_scale, |
915 visible_layer_rect, | 879 current_frame_time_in_seconds); |
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 | 880 |
925 ASSERT_TRUE(tiling->TileAt(0, 0)); | 881 ASSERT_TRUE(tiling->TileAt(0, 0)); |
926 ASSERT_TRUE(tiling->TileAt(0, 1)); | 882 ASSERT_TRUE(tiling->TileAt(0, 1)); |
927 ASSERT_TRUE(tiling->TileAt(1, 0)); | 883 ASSERT_TRUE(tiling->TileAt(1, 0)); |
928 ASSERT_TRUE(tiling->TileAt(1, 1)); | 884 ASSERT_TRUE(tiling->TileAt(1, 1)); |
929 | 885 |
930 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 886 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
931 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 887 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
932 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 888 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
933 | 889 |
934 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 890 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
935 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 891 EXPECT_GT(priority.distance_to_visible, 0.f); |
936 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 892 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
937 priority.time_to_visible_in_seconds); | |
938 | 893 |
939 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 894 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
940 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 895 EXPECT_GT(priority.distance_to_visible, 0.f); |
941 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 896 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
942 priority.time_to_visible_in_seconds); | |
943 | 897 |
944 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 898 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
945 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 899 EXPECT_GT(priority.distance_to_visible, 0.f); |
946 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 900 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
947 priority.time_to_visible_in_seconds); | |
948 } | 901 } |
949 | 902 |
950 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 903 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
951 // Each tile of a layer may be affected differently by a transform; Check | 904 // Each tile of a layer may be affected differently by a transform; Check |
952 // that UpdateTilePriorities correctly accounts for the transform between | 905 // that UpdateTilePriorities correctly accounts for the transform between |
953 // layer space and screen space. | 906 // layer space and screen space. |
954 | 907 |
955 FakePictureLayerTilingClient client; | 908 FakePictureLayerTilingClient client; |
956 scoped_ptr<TestablePictureLayerTiling> tiling; | 909 scoped_ptr<TestablePictureLayerTiling> tiling; |
957 | 910 |
958 gfx::Size device_viewport(800, 600); | 911 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); | 912 gfx::Size last_layer_bounds(200, 200); |
961 gfx::Size current_layer_bounds(200, 200); | 913 gfx::Size current_layer_bounds(200, 200); |
962 float last_layer_contents_scale = 1.f; | |
963 float current_layer_contents_scale = 1.f; | 914 float current_layer_contents_scale = 1.f; |
964 gfx::Transform last_screen_transform; | 915 gfx::Transform last_screen_transform; |
965 gfx::Transform current_screen_transform; | 916 gfx::Transform current_screen_transform; |
966 double current_frame_time_in_seconds = 1.0; | 917 double current_frame_time_in_seconds = 1.0; |
967 size_t max_tiles_for_interest_area = 10000; | 918 size_t max_tiles_for_interest_area = 10000; |
968 | 919 |
969 // A diagonally rotated layer that is partially off the bottom of the screen. | 920 // 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. | 921 // In this configuration, only the top-left tile would be visible. |
971 current_screen_transform.Translate(400, 550); | 922 current_screen_transform.Translate(600, 750); |
972 current_screen_transform.RotateAboutZAxis(45); | 923 current_screen_transform.RotateAboutZAxis(45); |
973 last_screen_transform = current_screen_transform; | 924 last_screen_transform = current_screen_transform; |
974 | 925 |
975 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 926 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
976 current_screen_transform, device_viewport); | 927 current_screen_transform, device_viewport); |
977 | 928 |
978 client.SetTileSize(gfx::Size(100, 100)); | 929 client.SetTileSize(gfx::Size(100, 100)); |
979 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 930 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
980 current_layer_bounds, | 931 current_layer_bounds, |
981 &client); | 932 &client); |
982 | 933 |
983 tiling->UpdateTilePriorities( | 934 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
984 ACTIVE_TREE, | 935 tiling->UpdateTilePriorities(ACTIVE_TREE, |
985 device_viewport, | 936 viewport_in_layer_space, |
986 viewport_in_layer_space, | 937 current_layer_contents_scale, |
987 visible_layer_rect, | 938 current_frame_time_in_seconds); |
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 | 939 |
997 ASSERT_TRUE(tiling->TileAt(0, 0)); | 940 ASSERT_TRUE(tiling->TileAt(0, 0)); |
998 ASSERT_TRUE(tiling->TileAt(0, 1)); | 941 ASSERT_TRUE(tiling->TileAt(0, 1)); |
999 ASSERT_TRUE(tiling->TileAt(1, 0)); | 942 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1000 ASSERT_TRUE(tiling->TileAt(1, 1)); | 943 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1001 | 944 |
1002 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 945 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1003 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 946 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1004 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 947 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1005 | 948 |
1006 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 949 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1007 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 950 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1008 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 951 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1009 priority.time_to_visible_in_seconds); | |
1010 | 952 |
1011 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 953 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1012 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 954 EXPECT_GT(priority.distance_to_visible, 0.f); |
1013 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 955 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1014 priority.time_to_visible_in_seconds); | |
1015 | 956 |
1016 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 957 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1017 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 958 EXPECT_GT(priority.distance_to_visible, 0.f); |
1018 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 959 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1019 priority.time_to_visible_in_seconds); | |
1020 | 960 |
1021 // Furthermore, in this scenario the bottom-right tile should have the larger | 961 // Furthermore, in this scenario the bottom-right tile should have the larger |
1022 // distance to visible. | 962 // distance to visible. |
1023 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 963 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1024 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 964 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); | 965 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1027 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 966 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 | 967 |
1032 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 968 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 } | 969 } |
1037 | 970 |
1038 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 971 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
1039 // Perspective transforms need to take a different code path. | 972 // Perspective transforms need to take a different code path. |
1040 // This test checks tile priorities of a perspective layer. | 973 // This test checks tile priorities of a perspective layer. |
1041 | 974 |
1042 FakePictureLayerTilingClient client; | 975 FakePictureLayerTilingClient client; |
1043 scoped_ptr<TestablePictureLayerTiling> tiling; | 976 scoped_ptr<TestablePictureLayerTiling> tiling; |
1044 | 977 |
1045 gfx::Size device_viewport(800, 600); | 978 gfx::Size device_viewport(800, 600); |
1046 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 979 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
1047 gfx::Size last_layer_bounds(200, 200); | 980 gfx::Size last_layer_bounds(200, 200); |
1048 gfx::Size current_layer_bounds(200, 200); | 981 gfx::Size current_layer_bounds(200, 200); |
1049 float last_layer_contents_scale = 1.f; | |
1050 float current_layer_contents_scale = 1.f; | 982 float current_layer_contents_scale = 1.f; |
1051 gfx::Transform last_screen_transform; | 983 gfx::Transform last_screen_transform; |
1052 gfx::Transform current_screen_transform; | 984 gfx::Transform current_screen_transform; |
1053 double current_frame_time_in_seconds = 1.0; | 985 double current_frame_time_in_seconds = 1.0; |
1054 size_t max_tiles_for_interest_area = 10000; | 986 size_t max_tiles_for_interest_area = 10000; |
1055 | 987 |
1056 // A 3d perspective layer rotated about its Y axis, translated to almost | 988 // 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 | 989 // 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 | 990 // the right side, so the top-left tile will technically be closer than the |
1059 // top-right. | 991 // top-right. |
(...skipping 15 matching lines...) Expand all Loading... | |
1075 ASSERT_FALSE(clipped); | 1007 ASSERT_FALSE(clipped); |
1076 | 1008 |
1077 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1009 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1078 current_screen_transform, device_viewport); | 1010 current_screen_transform, device_viewport); |
1079 | 1011 |
1080 client.SetTileSize(gfx::Size(100, 100)); | 1012 client.SetTileSize(gfx::Size(100, 100)); |
1081 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1013 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1082 current_layer_bounds, | 1014 current_layer_bounds, |
1083 &client); | 1015 &client); |
1084 | 1016 |
1085 tiling->UpdateTilePriorities( | 1017 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
1086 ACTIVE_TREE, | 1018 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1087 device_viewport, | 1019 viewport_in_layer_space, |
1088 viewport_in_layer_space, | 1020 current_layer_contents_scale, |
1089 visible_layer_rect, | 1021 current_frame_time_in_seconds); |
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 | 1022 |
1099 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1023 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1100 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1024 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1101 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1025 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1102 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1026 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1103 | 1027 |
1104 // All tiles will have a positive distance_to_visible | 1028 // All tiles will have a positive distance_to_visible |
1105 // and an infinite time_to_visible. | 1029 // and an infinite time_to_visible. |
1106 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1030 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1107 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1031 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1108 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1032 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1109 priority.time_to_visible_in_seconds); | |
1110 | 1033 |
1111 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1034 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1112 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1035 EXPECT_GT(priority.distance_to_visible, 0.f); |
1113 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1036 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1114 priority.time_to_visible_in_seconds); | |
1115 | 1037 |
1116 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1038 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1117 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1039 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1118 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1040 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1119 priority.time_to_visible_in_seconds); | |
1120 | 1041 |
1121 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1042 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1122 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1043 EXPECT_GT(priority.distance_to_visible, 0.f); |
1123 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1044 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1124 priority.time_to_visible_in_seconds); | |
1125 | 1045 |
1126 // Furthermore, in this scenario the top-left distance_to_visible | 1046 // Furthermore, in this scenario the top-left distance_to_visible |
1127 // will be smallest, followed by top-right. The bottom layers | 1047 // will be smallest, followed by top-right. The bottom layers |
1128 // will of course be further than the top layers. | 1048 // will of course be further than the top layers. |
1129 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1049 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1130 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1050 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1131 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1051 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1132 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1052 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 | 1053 |
1136 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1054 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); |
1137 top_right.distance_to_visible_in_pixels); | |
1138 | 1055 |
1139 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1056 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); |
1140 top_left.distance_to_visible_in_pixels); | |
1141 } | 1057 } |
1142 | 1058 |
1143 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1059 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
1144 // Perspective transforms need to take a different code path. | 1060 // Perspective transforms need to take a different code path. |
1145 // This test checks tile priorities of a perspective layer. | 1061 // This test checks tile priorities of a perspective layer. |
1146 | 1062 |
1147 FakePictureLayerTilingClient client; | 1063 FakePictureLayerTilingClient client; |
1148 scoped_ptr<TestablePictureLayerTiling> tiling; | 1064 scoped_ptr<TestablePictureLayerTiling> tiling; |
1149 | 1065 |
1150 gfx::Size device_viewport(800, 600); | 1066 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); | 1067 gfx::Size last_layer_bounds(200, 200); |
1153 gfx::Size current_layer_bounds(200, 200); | 1068 gfx::Size current_layer_bounds(200, 200); |
1154 float last_layer_contents_scale = 1.f; | |
1155 float current_layer_contents_scale = 1.f; | 1069 float current_layer_contents_scale = 1.f; |
1156 gfx::Transform last_screen_transform; | 1070 gfx::Transform last_screen_transform; |
1157 gfx::Transform current_screen_transform; | 1071 gfx::Transform current_screen_transform; |
1158 double current_frame_time_in_seconds = 1.0; | 1072 double current_frame_time_in_seconds = 1.0; |
1159 size_t max_tiles_for_interest_area = 10000; | 1073 size_t max_tiles_for_interest_area = 10000; |
1160 | 1074 |
1161 // A 3d perspective layer rotated about its Y axis, translated to almost | 1075 // 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 | 1076 // 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 | 1077 // the right side, so the top-left tile will technically be closer than the |
1164 // top-right. | 1078 // top-right. |
(...skipping 21 matching lines...) Expand all Loading... | |
1186 ASSERT_FALSE(clipped); | 1100 ASSERT_FALSE(clipped); |
1187 | 1101 |
1188 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1102 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1189 current_screen_transform, device_viewport); | 1103 current_screen_transform, device_viewport); |
1190 | 1104 |
1191 client.SetTileSize(gfx::Size(100, 100)); | 1105 client.SetTileSize(gfx::Size(100, 100)); |
1192 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1106 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1193 current_layer_bounds, | 1107 current_layer_bounds, |
1194 &client); | 1108 &client); |
1195 | 1109 |
1196 tiling->UpdateTilePriorities( | 1110 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); |
1197 ACTIVE_TREE, | 1111 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1198 device_viewport, | 1112 viewport_in_layer_space, |
1199 viewport_in_layer_space, | 1113 current_layer_contents_scale, |
1200 visible_layer_rect, | 1114 current_frame_time_in_seconds); |
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 | 1115 |
1210 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1116 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1211 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1117 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1212 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1118 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1213 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1119 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1214 | 1120 |
1215 // Left-side tiles will be clipped by the transform, so we have to assume | 1121 // Left-side tiles will be clipped by the transform, so we have to assume |
1216 // they are visible just in case. | 1122 // they are visible just in case. |
1217 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1123 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1124 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1125 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1220 | 1126 |
1221 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1127 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1222 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1128 EXPECT_GT(priority.distance_to_visible, 0.f); |
1223 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1129 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1224 | 1130 |
1225 // Right-side tiles will have a positive distance_to_visible | 1131 // Right-side tiles will have a positive distance_to_visible |
1226 // and an infinite time_to_visible. | 1132 // and an infinite time_to_visible. |
1227 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1133 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1228 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1134 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1229 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1135 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1230 priority.time_to_visible_in_seconds); | |
1231 | 1136 |
1232 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1137 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1233 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1138 EXPECT_GT(priority.distance_to_visible, 0.f); |
1234 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1139 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1235 priority.time_to_visible_in_seconds); | |
1236 } | 1140 } |
1237 | 1141 |
1238 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1142 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
1239 // Test that time_to_visible is computed correctly when | 1143 // Test that time_to_visible is computed correctly when |
1240 // there is some motion. | 1144 // there is some motion. |
1241 | 1145 |
1242 FakePictureLayerTilingClient client; | 1146 FakePictureLayerTilingClient client; |
1243 scoped_ptr<TestablePictureLayerTiling> tiling; | 1147 scoped_ptr<TestablePictureLayerTiling> tiling; |
1244 | 1148 |
1245 gfx::Size device_viewport(800, 600); | 1149 gfx::Size device_viewport(800, 600); |
(...skipping 13 matching lines...) Expand all Loading... | |
1259 last_screen_transform.Translate(2800, 0); | 1163 last_screen_transform.Translate(2800, 0); |
1260 | 1164 |
1261 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1165 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1262 current_screen_transform, device_viewport); | 1166 current_screen_transform, device_viewport); |
1263 | 1167 |
1264 client.SetTileSize(gfx::Size(100, 100)); | 1168 client.SetTileSize(gfx::Size(100, 100)); |
1265 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1169 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1266 current_layer_bounds, | 1170 current_layer_bounds, |
1267 &client); | 1171 &client); |
1268 | 1172 |
1173 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); | |
1269 // previous ("last") frame | 1174 // previous ("last") frame |
1270 tiling->UpdateTilePriorities( | 1175 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1271 ACTIVE_TREE, | 1176 viewport_in_layer_space, |
1272 device_viewport, | 1177 last_layer_contents_scale, |
1273 viewport_in_layer_space, | 1178 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 | 1179 |
1284 // current frame | 1180 // current frame |
1285 tiling->UpdateTilePriorities( | 1181 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1286 ACTIVE_TREE, | 1182 viewport_in_layer_space, |
1287 device_viewport, | 1183 current_layer_contents_scale, |
1288 viewport_in_layer_space, | 1184 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 | 1185 |
1299 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1186 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1300 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1187 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1301 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1188 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1302 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1189 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1303 | 1190 |
1304 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1191 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1305 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1192 EXPECT_GT(priority.distance_to_visible, 0.f); |
1306 EXPECT_FLOAT_EQ(1.f, | 1193 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1307 priority.time_to_visible_in_seconds); | |
1308 | 1194 |
1309 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1195 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1310 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1196 EXPECT_GT(priority.distance_to_visible, 0.f); |
1311 EXPECT_FLOAT_EQ(1.f, | 1197 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1312 priority.time_to_visible_in_seconds); | |
1313 | 1198 |
1314 // time_to_visible for the right hand side layers needs an extra 0.099 | 1199 // time_to_visible for the right hand side layers needs an extra 0.099 |
1315 // seconds because this tile is 99 pixels further away. | 1200 // seconds because this tile is 99 pixels further away. |
1316 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1201 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1317 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1202 EXPECT_GT(priority.distance_to_visible, 0.f); |
1318 EXPECT_FLOAT_EQ(1.099f, | 1203 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1319 priority.time_to_visible_in_seconds); | |
1320 | 1204 |
1321 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1205 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1322 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1206 EXPECT_GT(priority.distance_to_visible, 0.f); |
1323 EXPECT_FLOAT_EQ(1.099f, | 1207 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1324 priority.time_to_visible_in_seconds); | |
1325 } | 1208 } |
1326 | 1209 |
1327 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1210 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
1328 // Each tile of a layer may be affected differently by a transform; Check | 1211 // Each tile of a layer may be affected differently by a transform; Check |
1329 // that UpdateTilePriorities correctly accounts for the transform between | 1212 // that UpdateTilePriorities correctly accounts for the transform between |
1330 // layer space and screen space. | 1213 // layer space and screen space. |
1331 | 1214 |
1332 FakePictureLayerTilingClient client; | 1215 FakePictureLayerTilingClient client; |
1333 scoped_ptr<TestablePictureLayerTiling> tiling; | 1216 scoped_ptr<TestablePictureLayerTiling> tiling; |
1334 | 1217 |
(...skipping 22 matching lines...) Expand all Loading... | |
1357 last_screen_transform.Translate(400, 550); | 1240 last_screen_transform.Translate(400, 550); |
1358 | 1241 |
1359 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1242 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1360 current_screen_transform, device_viewport); | 1243 current_screen_transform, device_viewport); |
1361 | 1244 |
1362 client.SetTileSize(gfx::Size(100, 100)); | 1245 client.SetTileSize(gfx::Size(100, 100)); |
1363 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1246 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1364 current_layer_bounds, | 1247 current_layer_bounds, |
1365 &client); | 1248 &client); |
1366 | 1249 |
1250 client.set_max_tiles_for_interest_area(max_tiles_for_interest_area); | |
1251 | |
1367 // previous ("last") frame | 1252 // previous ("last") frame |
1368 tiling->UpdateTilePriorities( | 1253 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1369 ACTIVE_TREE, | 1254 viewport_in_layer_space, |
1370 device_viewport, | 1255 last_layer_contents_scale, |
1371 viewport_in_layer_space, | 1256 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 | 1257 |
1382 // current frame | 1258 // current frame |
1383 tiling->UpdateTilePriorities( | 1259 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1384 ACTIVE_TREE, | 1260 viewport_in_layer_space, |
1385 device_viewport, | 1261 current_layer_contents_scale, |
1386 viewport_in_layer_space, | 1262 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 | 1263 |
1397 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1264 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1398 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1265 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1399 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1266 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1400 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1267 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1401 | 1268 |
1402 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1269 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1403 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1270 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1404 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1271 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1405 | 1272 |
1406 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1273 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1274 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1275 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1409 | 1276 |
1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1277 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1278 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1279 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1413 priority.time_to_visible_in_seconds); | |
1414 } | 1280 } |
1415 | 1281 |
1416 } // namespace | 1282 } // namespace |
1417 } // namespace cc | 1283 } // namespace cc |
OLD | NEW |