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 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
11 #include "cc/resources/picture_layer_tiling_set.h" | 11 #include "cc/resources/picture_layer_tiling_set.h" |
12 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
13 #include "cc/test/fake_output_surface_client.h" | 13 #include "cc/test/fake_output_surface_client.h" |
14 #include "cc/test/fake_picture_layer_tiling_client.h" | 14 #include "cc/test/fake_picture_layer_tiling_client.h" |
15 #include "cc/test/test_context_provider.h" | 15 #include "cc/test/test_context_provider.h" |
16 #include "cc/test/test_shared_bitmap_manager.h" | 16 #include "cc/test/test_shared_bitmap_manager.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/gfx/rect_conversions.h" | 18 #include "ui/gfx/rect_conversions.h" |
19 #include "ui/gfx/size_conversions.h" | 19 #include "ui/gfx/size_conversions.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 static gfx::Rect ViewportInLayerSpace( | 24 static gfx::Rect ViewportInLayerSpace(const gfx::Transform& transform, |
25 const gfx::Transform& transform, | 25 const gfx::Size& device_viewport) { |
26 const gfx::Size& device_viewport) { | |
27 | |
28 gfx::Transform inverse; | 26 gfx::Transform inverse; |
29 if (!transform.GetInverse(&inverse)) | 27 if (!transform.GetInverse(&inverse)) |
30 return gfx::Rect(); | 28 return gfx::Rect(); |
31 | 29 |
32 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 30 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
33 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 31 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
34 return ToEnclosingRect(viewport_in_layer_space); | 32 return ToEnclosingRect(viewport_in_layer_space); |
35 } | 33 } |
36 | 34 |
37 static void UpdateAllTilePriorities(PictureLayerTilingSet* set, | 35 static void UpdateAllTilePriorities(PictureLayerTilingSet* set, |
38 WhichTree tree, | 36 WhichTree tree, |
39 const gfx::Rect& visible_layer_rect, | 37 const gfx::Rect& visible_layer_rect, |
40 float layer_contents_scale, | 38 float layer_contents_scale, |
41 double current_frame_time_in_seconds) { | 39 double current_frame_time_in_seconds) { |
42 for (size_t i = 0; i < set->num_tilings(); ++i) { | 40 for (size_t i = 0; i < set->num_tilings(); ++i) { |
43 set->tiling_at(i)->UpdateTilePriorities(tree, | 41 set->tiling_at(i)->UpdateTilePriorities(tree, |
44 visible_layer_rect, | 42 visible_layer_rect, |
45 layer_contents_scale, | 43 layer_contents_scale, |
46 current_frame_time_in_seconds, | 44 current_frame_time_in_seconds, |
47 NULL, | 45 NULL, |
48 NULL, | 46 NULL, |
49 gfx::Transform()); | 47 gfx::Transform()); |
50 } | 48 } |
51 } | 49 } |
52 | 50 |
| 51 static void CreateAllTiles(PictureLayerTilingSet* set) { |
| 52 for (size_t i = 0; i < set->num_tilings(); ++i) |
| 53 set->tiling_at(i)->CreateAllTilesForTesting(); |
| 54 } |
| 55 |
53 class TestablePictureLayerTiling : public PictureLayerTiling { | 56 class TestablePictureLayerTiling : public PictureLayerTiling { |
54 public: | 57 public: |
55 using PictureLayerTiling::SetLiveTilesRect; | 58 using PictureLayerTiling::SetLiveTilesRect; |
56 using PictureLayerTiling::TileAt; | 59 using PictureLayerTiling::TileAt; |
57 | 60 |
58 static scoped_ptr<TestablePictureLayerTiling> Create( | 61 static scoped_ptr<TestablePictureLayerTiling> Create( |
59 float contents_scale, | 62 float contents_scale, |
60 const gfx::Size& layer_bounds, | 63 const gfx::Size& layer_bounds, |
61 PictureLayerTilingClient* client) { | 64 PictureLayerTilingClient* client) { |
62 return make_scoped_ptr(new TestablePictureLayerTiling( | 65 return make_scoped_ptr( |
63 contents_scale, | 66 new TestablePictureLayerTiling(contents_scale, layer_bounds, client)); |
64 layer_bounds, | |
65 client)); | |
66 } | 67 } |
67 | 68 |
68 using PictureLayerTiling::ComputeSkewport; | 69 using PictureLayerTiling::ComputeSkewport; |
69 | 70 |
70 protected: | 71 protected: |
71 TestablePictureLayerTiling(float contents_scale, | 72 TestablePictureLayerTiling(float contents_scale, |
72 const gfx::Size& layer_bounds, | 73 const gfx::Size& layer_bounds, |
73 PictureLayerTilingClient* client) | 74 PictureLayerTilingClient* client) |
74 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 75 : PictureLayerTiling(contents_scale, layer_bounds, client) {} |
75 }; | 76 }; |
76 | 77 |
77 class PictureLayerTilingIteratorTest : public testing::Test { | 78 class PictureLayerTilingIteratorTest : public testing::Test { |
78 public: | 79 public: |
79 PictureLayerTilingIteratorTest() {} | 80 PictureLayerTilingIteratorTest() {} |
80 virtual ~PictureLayerTilingIteratorTest() {} | 81 virtual ~PictureLayerTilingIteratorTest() {} |
81 | 82 |
82 void Initialize(const gfx::Size& tile_size, | 83 void Initialize(const gfx::Size& tile_size, |
83 float contents_scale, | 84 float contents_scale, |
84 const gfx::Size& layer_bounds) { | 85 const gfx::Size& layer_bounds) { |
85 client_.SetTileSize(tile_size); | 86 client_.SetTileSize(tile_size); |
86 tiling_ = TestablePictureLayerTiling::Create(contents_scale, | 87 tiling_ = TestablePictureLayerTiling::Create( |
87 layer_bounds, | 88 contents_scale, layer_bounds, &client_); |
88 &client_); | |
89 } | 89 } |
90 | 90 |
91 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { | 91 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { |
| 92 tiling_->CreateAllTilesForTesting(); |
92 tiling_->SetLiveTilesRect(live_tiles_rect); | 93 tiling_->SetLiveTilesRect(live_tiles_rect); |
93 | 94 |
94 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 95 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
95 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 96 for (std::vector<Tile*>::iterator iter = tiles.begin(); iter != tiles.end(); |
96 iter != tiles.end(); | |
97 ++iter) { | 97 ++iter) { |
98 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 98 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void VerifyTilesExactlyCoverRect( | 102 void VerifyTilesExactlyCoverRect(float rect_scale, |
103 float rect_scale, | 103 const gfx::Rect& request_rect, |
104 const gfx::Rect& request_rect, | 104 const gfx::Rect& expect_rect) { |
105 const gfx::Rect& expect_rect) { | |
106 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 105 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
107 | 106 |
108 // Iterators are not valid if this ratio is too large (i.e. the | 107 // Iterators are not valid if this ratio is too large (i.e. the |
109 // tiling is too high-res for a low-res destination rect.) This is an | 108 // tiling is too high-res for a low-res destination rect.) This is an |
110 // artifact of snapping geometry to integer coordinates and then mapping | 109 // artifact of snapping geometry to integer coordinates and then mapping |
111 // back to floating point texture coordinates. | 110 // back to floating point texture coordinates. |
112 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 111 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
113 ASSERT_LE(dest_to_contents_scale, 2.0); | 112 ASSERT_LE(dest_to_contents_scale, 2.0); |
114 | 113 |
115 Region remaining = expect_rect; | 114 Region remaining = expect_rect; |
116 for (PictureLayerTiling::CoverageIterator | 115 for (PictureLayerTiling::CoverageIterator iter( |
117 iter(tiling_.get(), rect_scale, request_rect); | 116 tiling_.get(), rect_scale, request_rect); |
118 iter; | 117 iter; |
119 ++iter) { | 118 ++iter) { |
120 // Geometry cannot overlap previous geometry at all | 119 // Geometry cannot overlap previous geometry at all |
121 gfx::Rect geometry = iter.geometry_rect(); | 120 gfx::Rect geometry = iter.geometry_rect(); |
122 EXPECT_TRUE(expect_rect.Contains(geometry)); | 121 EXPECT_TRUE(expect_rect.Contains(geometry)); |
123 EXPECT_TRUE(remaining.Contains(geometry)); | 122 EXPECT_TRUE(remaining.Contains(geometry)); |
124 remaining.Subtract(geometry); | 123 remaining.Subtract(geometry); |
125 | 124 |
126 // Sanity check that texture coords are within the texture rect. | 125 // Sanity check that texture coords are within the texture rect. |
127 gfx::RectF texture_rect = iter.texture_rect(); | 126 gfx::RectF texture_rect = iter.texture_rect(); |
128 EXPECT_GE(texture_rect.x(), 0); | 127 EXPECT_GE(texture_rect.x(), 0); |
129 EXPECT_GE(texture_rect.y(), 0); | 128 EXPECT_GE(texture_rect.y(), 0); |
130 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); | 129 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); |
131 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); | 130 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); |
132 | 131 |
133 EXPECT_EQ(iter.texture_size(), client_.TileSize()); | 132 EXPECT_EQ(iter.texture_size(), client_.TileSize()); |
134 } | 133 } |
135 | 134 |
136 // The entire rect must be filled by geometry from the tiling. | 135 // The entire rect must be filled by geometry from the tiling. |
137 EXPECT_TRUE(remaining.IsEmpty()); | 136 EXPECT_TRUE(remaining.IsEmpty()); |
138 } | 137 } |
139 | 138 |
140 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) { | 139 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) { |
141 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); | 140 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); |
142 } | 141 } |
143 | 142 |
144 void VerifyTiles( | 143 void VerifyTiles( |
145 float rect_scale, | 144 float rect_scale, |
146 const gfx::Rect& rect, | 145 const gfx::Rect& rect, |
147 base::Callback<void(Tile* tile, | 146 base::Callback<void(Tile* tile, const gfx::Rect& geometry_rect)> |
148 const gfx::Rect& geometry_rect)> callback) { | 147 callback) { |
149 VerifyTiles(tiling_.get(), | 148 VerifyTiles(tiling_.get(), rect_scale, rect, callback); |
150 rect_scale, | |
151 rect, | |
152 callback); | |
153 } | 149 } |
154 | 150 |
155 void VerifyTiles( | 151 void VerifyTiles( |
156 PictureLayerTiling* tiling, | 152 PictureLayerTiling* tiling, |
157 float rect_scale, | 153 float rect_scale, |
158 const gfx::Rect& rect, | 154 const gfx::Rect& rect, |
159 base::Callback<void(Tile* tile, | 155 base::Callback<void(Tile* tile, const gfx::Rect& geometry_rect)> |
160 const gfx::Rect& geometry_rect)> callback) { | 156 callback) { |
161 Region remaining = rect; | 157 Region remaining = rect; |
162 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect); | 158 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect); |
163 iter; | 159 iter; |
164 ++iter) { | 160 ++iter) { |
165 remaining.Subtract(iter.geometry_rect()); | 161 remaining.Subtract(iter.geometry_rect()); |
166 callback.Run(*iter, iter.geometry_rect()); | 162 callback.Run(*iter, iter.geometry_rect()); |
167 } | 163 } |
168 EXPECT_TRUE(remaining.IsEmpty()); | 164 EXPECT_TRUE(remaining.IsEmpty()); |
169 } | 165 } |
170 | 166 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // The reason is that each tile has a one pixel border, so tile at (1, 2) | 470 // The reason is that each tile has a one pixel border, so tile at (1, 2) |
475 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at | 471 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at |
476 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the | 472 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the |
477 // tiling. | 473 // tiling. |
478 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); | 474 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); |
479 gfx::Rect viewport_in_content_space = | 475 gfx::Rect viewport_in_content_space = |
480 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | 476 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
481 | 477 |
482 tiling->UpdateTilePriorities( | 478 tiling->UpdateTilePriorities( |
483 ACTIVE_TREE, viewport, 1.f, 1.0, NULL, NULL, gfx::Transform()); | 479 ACTIVE_TREE, viewport, 1.f, 1.0, NULL, NULL, gfx::Transform()); |
| 480 tiling->CreateInterestRectTilesForTesting(); |
484 | 481 |
485 gfx::Rect soon_rect = viewport; | 482 gfx::Rect soon_rect = viewport; |
486 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 483 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
487 gfx::Rect soon_rect_in_content_space = | 484 gfx::Rect soon_rect_in_content_space = |
488 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); | 485 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); |
489 | 486 |
490 // Sanity checks. | 487 // Sanity checks. |
491 for (int i = 0; i < 47; ++i) { | 488 for (int i = 0; i < 47; ++i) { |
492 for (int j = 0; j < 47; ++j) { | 489 for (int j = 0; j < 47; ++j) { |
493 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; | 490 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; |
(...skipping 28 matching lines...) Expand all Loading... |
522 have_eventually = true; | 519 have_eventually = true; |
523 } | 520 } |
524 } | 521 } |
525 } | 522 } |
526 | 523 |
527 EXPECT_TRUE(have_now); | 524 EXPECT_TRUE(have_now); |
528 EXPECT_TRUE(have_soon); | 525 EXPECT_TRUE(have_soon); |
529 EXPECT_TRUE(have_eventually); | 526 EXPECT_TRUE(have_eventually); |
530 | 527 |
531 // Spot check some distances. | 528 // Spot check some distances. |
532 // Tile at 5, 1 should begin at 41x9 in content space (without borders), | 529 // Tile at 5, 1 should begin at 40x8 in content space (with borders), |
533 // so the distance to a viewport that ends at 25x25 in content space | 530 // so the distance to a viewport that ends at 25x25 in content space |
534 // should be 17 (41 - 25 + 1). In layer space, then that should be | 531 // should be 17 (40 - 25 + 1). In layer space, then that should be |
535 // 17 / 0.25 = 68 pixels. | 532 // 17 / 0.25 = 64 pixels. |
536 | 533 |
537 // We can verify that the content rect (with borders) is one pixel off | 534 // We can verify that the content rect is what we expect it to be. |
538 // 41,9 8x8 on all sides. | |
539 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); | 535 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); |
540 | 536 |
541 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 537 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
542 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 538 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
543 | 539 |
544 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 540 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
545 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 541 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
546 | 542 |
547 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 543 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
548 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible); | 544 EXPECT_FLOAT_EQ(32.f, priority.distance_to_visible); |
549 | 545 |
550 // Move the viewport down 40 pixels. | 546 // Move the viewport down 40 pixels. |
551 viewport = gfx::Rect(0, 40, 100, 100); | 547 viewport = gfx::Rect(0, 40, 100, 100); |
552 viewport_in_content_space = | 548 viewport_in_content_space = |
553 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | 549 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
554 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); | 550 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); |
555 | 551 |
556 soon_rect = viewport; | 552 soon_rect = viewport; |
557 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 553 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
558 soon_rect_in_content_space = | 554 soon_rect_in_content_space = |
559 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); | 555 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); |
560 | 556 |
561 EXPECT_EQ(0, skewport.x()); | 557 EXPECT_EQ(0, skewport.x()); |
562 EXPECT_EQ(10, skewport.y()); | 558 EXPECT_EQ(10, skewport.y()); |
563 EXPECT_EQ(25, skewport.width()); | 559 EXPECT_EQ(25, skewport.width()); |
564 EXPECT_EQ(35, skewport.height()); | 560 EXPECT_EQ(35, skewport.height()); |
565 | 561 |
566 tiling->UpdateTilePriorities( | 562 tiling->UpdateTilePriorities( |
567 ACTIVE_TREE, viewport, 1.f, 2.0, NULL, NULL, gfx::Transform()); | 563 ACTIVE_TREE, viewport, 1.f, 2.0, NULL, NULL, gfx::Transform()); |
| 564 tiling->CreateAllTilesForTesting(); |
568 | 565 |
569 have_now = false; | 566 have_now = false; |
570 have_eventually = false; | 567 have_eventually = false; |
571 have_soon = false; | 568 have_soon = false; |
572 | 569 |
573 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | 570 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
574 // some EVENTUALLY tiles. | 571 // some EVENTUALLY tiles. |
575 for (int i = 0; i < 47; ++i) { | 572 for (int i = 0; i < 47; ++i) { |
576 for (int j = 0; j < 47; ++j) { | 573 for (int j = 0; j < 47; ++j) { |
577 Tile* tile = tiling->TileAt(i, j); | 574 Tile* tile = tiling->TileAt(i, j); |
(...skipping 20 matching lines...) Expand all Loading... |
598 have_eventually = true; | 595 have_eventually = true; |
599 } | 596 } |
600 } | 597 } |
601 } | 598 } |
602 | 599 |
603 EXPECT_TRUE(have_now); | 600 EXPECT_TRUE(have_now); |
604 EXPECT_TRUE(have_soon); | 601 EXPECT_TRUE(have_soon); |
605 EXPECT_TRUE(have_eventually); | 602 EXPECT_TRUE(have_eventually); |
606 | 603 |
607 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 604 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
608 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 605 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
609 | 606 |
610 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 607 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
611 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | 608 EXPECT_FLOAT_EQ(24.f, priority.distance_to_visible); |
612 | 609 |
613 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 610 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
614 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 611 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
615 | 612 |
616 // Change the underlying layer scale. | 613 // Change the underlying layer scale. |
617 tiling->UpdateTilePriorities( | 614 tiling->UpdateTilePriorities( |
618 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); | 615 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); |
| 616 tiling->CreateAllTilesForTesting(); |
619 | 617 |
620 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 618 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
621 EXPECT_FLOAT_EQ(34.f, priority.distance_to_visible); | 619 EXPECT_FLOAT_EQ(32.f, priority.distance_to_visible); |
622 | 620 |
623 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 621 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
624 EXPECT_FLOAT_EQ(14.f, priority.distance_to_visible); | 622 EXPECT_FLOAT_EQ(12.f, priority.distance_to_visible); |
625 | 623 |
626 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 624 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
627 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 625 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
628 } | 626 } |
629 | 627 |
630 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 628 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
631 gfx::Rect in(40, 50, 100, 200); | 629 gfx::Rect in(40, 50, 100, 200); |
632 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 630 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
633 int64 target_area = 100 * 200; | 631 int64 target_area = 100 * 200; |
634 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 632 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 723 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
726 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); | 724 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); |
727 EXPECT_LE(out.width() * out.height(), target_area); | 725 EXPECT_LE(out.width() * out.height(), target_area); |
728 EXPECT_GT(out.width() * out.height(), | 726 EXPECT_GT(out.width() * out.height(), |
729 target_area - out.width() - out.height() * 2); | 727 target_area - out.width() - out.height() * 2); |
730 EXPECT_TRUE(bounds.Contains(out)); | 728 EXPECT_TRUE(bounds.Contains(out)); |
731 } | 729 } |
732 | 730 |
733 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { | 731 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { |
734 gfx::Rect in(40, 50, 100, 200); | 732 gfx::Rect in(40, 50, 100, 200); |
735 gfx::Rect bounds(-1000, -1000, 1000+120, 10000); | 733 gfx::Rect bounds(-1000, -1000, 1000 + 120, 10000); |
736 int64 target_area = 200 * 200; | 734 int64 target_area = 200 * 200; |
737 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 735 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
738 in, target_area, bounds, NULL); | 736 in, target_area, bounds, NULL); |
739 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 737 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
740 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); | 738 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); |
741 EXPECT_LE(out.width() * out.height(), target_area); | 739 EXPECT_LE(out.width() * out.height(), target_area); |
742 EXPECT_GT(out.width() * out.height(), | 740 EXPECT_GT(out.width() * out.height(), |
743 target_area - out.width() - out.height() * 2); | 741 target_area - out.width() - out.height() * 2); |
744 EXPECT_TRUE(bounds.Contains(out)); | 742 EXPECT_TRUE(bounds.Contains(out)); |
745 } | 743 } |
(...skipping 21 matching lines...) Expand all Loading... |
767 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 765 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
768 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); | 766 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); |
769 EXPECT_LE(out.width() * out.height(), target_area); | 767 EXPECT_LE(out.width() * out.height(), target_area); |
770 EXPECT_GT(out.width() * out.height(), | 768 EXPECT_GT(out.width() * out.height(), |
771 target_area - out.width() * 2 - out.height()); | 769 target_area - out.width() * 2 - out.height()); |
772 EXPECT_TRUE(bounds.Contains(out)); | 770 EXPECT_TRUE(bounds.Contains(out)); |
773 } | 771 } |
774 | 772 |
775 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { | 773 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { |
776 gfx::Rect in(40, 50, 100, 200); | 774 gfx::Rect in(40, 50, 100, 200); |
777 gfx::Rect bounds(0, -4000, 100+40+20, 100000); | 775 gfx::Rect bounds(0, -4000, 100 + 40 + 20, 100000); |
778 int64 target_area = 400 * 400; | 776 int64 target_area = 400 * 400; |
779 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 777 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
780 in, target_area, bounds, NULL); | 778 in, target_area, bounds, NULL); |
781 EXPECT_EQ(20, out.right() - in.right()); | 779 EXPECT_EQ(20, out.right() - in.right()); |
782 EXPECT_EQ(40, in.x() - out.x()); | 780 EXPECT_EQ(40, in.x() - out.x()); |
783 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 781 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
784 EXPECT_LE(out.width() * out.height(), target_area); | 782 EXPECT_LE(out.width() * out.height(), target_area); |
785 EXPECT_GT(out.width() * out.height(), | 783 EXPECT_GT(out.width() * out.height(), target_area - out.width() * 2); |
786 target_area - out.width() * 2); | |
787 EXPECT_TRUE(bounds.Contains(out)); | 784 EXPECT_TRUE(bounds.Contains(out)); |
788 } | 785 } |
789 | 786 |
790 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { | 787 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { |
791 gfx::Rect in(40, 50, 100, 200); | 788 gfx::Rect in(40, 50, 100, 200); |
792 gfx::Rect bounds(-4000, 0, 100000, 200+50+30); | 789 gfx::Rect bounds(-4000, 0, 100000, 200 + 50 + 30); |
793 int64 target_area = 400 * 400; | 790 int64 target_area = 400 * 400; |
794 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 791 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
795 in, target_area, bounds, NULL); | 792 in, target_area, bounds, NULL); |
796 EXPECT_EQ(30, out.bottom() - in.bottom()); | 793 EXPECT_EQ(30, out.bottom() - in.bottom()); |
797 EXPECT_EQ(50, in.y() - out.y()); | 794 EXPECT_EQ(50, in.y() - out.y()); |
798 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 795 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
799 EXPECT_LE(out.width() * out.height(), target_area); | 796 EXPECT_LE(out.width() * out.height(), target_area); |
800 EXPECT_GT(out.width() * out.height(), | 797 EXPECT_GT(out.width() * out.height(), target_area - out.height() * 2); |
801 target_area - out.height() * 2); | |
802 EXPECT_TRUE(bounds.Contains(out)); | 798 EXPECT_TRUE(bounds.Contains(out)); |
803 } | 799 } |
804 | 800 |
805 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { | 801 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { |
806 gfx::Rect in(400, 500, 100, 200); | 802 gfx::Rect in(400, 500, 100, 200); |
807 gfx::Rect bounds(0, 0, 10, 10); | 803 gfx::Rect bounds(0, 0, 10, 10); |
808 int64 target_area = 400 * 400; | 804 int64 target_area = 400 * 400; |
809 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 805 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
810 in, target_area, bounds, NULL); | 806 in, target_area, bounds, NULL); |
811 EXPECT_TRUE(out.IsEmpty()); | 807 EXPECT_TRUE(out.IsEmpty()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 853 |
858 client.SetTileSize(gfx::Size(30, 30)); | 854 client.SetTileSize(gfx::Size(30, 30)); |
859 | 855 |
860 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | 856 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
861 tiling->UpdateTilePriorities( | 857 tiling->UpdateTilePriorities( |
862 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); | 858 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
863 | 859 |
864 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 860 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
865 EXPECT_FALSE(empty_iterator); | 861 EXPECT_FALSE(empty_iterator); |
866 | 862 |
867 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | |
868 | |
869 // Sanity check. | |
870 EXPECT_EQ(841u, all_tiles.size()); | |
871 | |
872 // The explanation of each iteration is as follows: | 863 // The explanation of each iteration is as follows: |
873 // 1. First iteration tests that we can get all of the tiles correctly. | 864 // 1. First iteration tests that we can get all of the tiles correctly. |
874 // 2. Second iteration ensures that we can get all of the tiles again (first | 865 // 2. Second iteration ensures that we can get all of the tiles again (first |
875 // iteration didn't change any tiles), as well set all tiles to be ready to | 866 // iteration didn't change any tiles), as well set all tiles to be ready to |
876 // draw. | 867 // draw. |
877 // 3. Third iteration ensures that no tiles are returned, since they were all | 868 // 3. Third iteration ensures that no tiles are returned, since they were all |
878 // marked as ready to draw. | 869 // marked as ready to draw. |
879 for (int i = 0; i < 3; ++i) { | 870 for (int i = 0; i < 3; ++i) { |
880 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE); | 871 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE); |
881 | 872 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 935 |
945 EXPECT_GT(eventually_bin_order_correct_count, | 936 EXPECT_GT(eventually_bin_order_correct_count, |
946 eventually_bin_order_incorrect_count); | 937 eventually_bin_order_incorrect_count); |
947 | 938 |
948 // We should have now and eventually tiles, as well as soon tiles from | 939 // We should have now and eventually tiles, as well as soon tiles from |
949 // the border region. | 940 // the border region. |
950 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 941 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
951 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 942 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
952 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 943 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
953 | 944 |
| 945 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
| 946 |
| 947 // Sanity check. |
| 948 EXPECT_EQ(841u, all_tiles.size()); |
954 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); | 949 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); |
955 } | 950 } |
956 } | 951 } |
957 | 952 |
958 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { | 953 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { |
959 FakePictureLayerTilingClient client; | 954 FakePictureLayerTilingClient client; |
960 scoped_ptr<TestablePictureLayerTiling> tiling; | 955 scoped_ptr<TestablePictureLayerTiling> tiling; |
961 | 956 |
962 gfx::Rect viewport(50, 0, 100, 100); | 957 gfx::Rect viewport(50, 0, 100, 100); |
963 gfx::Rect moved_viewport(50, 0, 100, 500); | 958 gfx::Rect moved_viewport(50, 0, 100, 500); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 } | 1007 } |
1013 | 1008 |
1014 EXPECT_GT(eventually_bin_order_correct_count, | 1009 EXPECT_GT(eventually_bin_order_correct_count, |
1015 eventually_bin_order_incorrect_count); | 1010 eventually_bin_order_incorrect_count); |
1016 | 1011 |
1017 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 1012 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
1018 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 1013 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
1019 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 1014 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
1020 } | 1015 } |
1021 | 1016 |
1022 static void TileExists(bool exists, Tile* tile, | 1017 static void TileExists(bool exists, |
| 1018 Tile* tile, |
1023 const gfx::Rect& geometry_rect) { | 1019 const gfx::Rect& geometry_rect) { |
1024 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 1020 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
1025 } | 1021 } |
1026 | 1022 |
1027 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { | 1023 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { |
1028 FakeOutputSurfaceClient output_surface_client; | 1024 FakeOutputSurfaceClient output_surface_client; |
1029 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); | 1025 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); |
1030 CHECK(output_surface->BindToClient(&output_surface_client)); | 1026 CHECK(output_surface->BindToClient(&output_surface_client)); |
1031 TestSharedBitmapManager shared_bitmap_manager; | 1027 TestSharedBitmapManager shared_bitmap_manager; |
1032 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( | 1028 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( |
1033 output_surface.get(), &shared_bitmap_manager, 0, false, 1, false); | 1029 output_surface.get(), &shared_bitmap_manager, 0, false, 1, false); |
1034 | 1030 |
1035 FakePictureLayerTilingClient client(resource_provider.get()); | 1031 FakePictureLayerTilingClient client(resource_provider.get()); |
1036 scoped_ptr<TestablePictureLayerTiling> tiling; | 1032 scoped_ptr<TestablePictureLayerTiling> tiling; |
1037 | 1033 |
1038 gfx::Rect viewport(50, 50, 100, 100); | 1034 gfx::Rect viewport(50, 50, 100, 100); |
1039 gfx::Size layer_bounds(200, 200); | 1035 gfx::Size layer_bounds(200, 200); |
1040 | 1036 |
1041 client.SetTileSize(gfx::Size(30, 30)); | 1037 client.SetTileSize(gfx::Size(30, 30)); |
1042 | 1038 |
1043 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | 1039 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
1044 tiling->UpdateTilePriorities( | 1040 tiling->UpdateTilePriorities( |
1045 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); | 1041 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
| 1042 tiling->CreateAllTilesForTesting(); |
1046 | 1043 |
1047 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 1044 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
1048 EXPECT_FALSE(empty_iterator); | 1045 EXPECT_FALSE(empty_iterator); |
1049 | 1046 |
1050 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | 1047 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
1051 | 1048 |
1052 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get(), | 1049 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get(), |
1053 SMOOTHNESS_TAKES_PRIORITY); | 1050 SMOOTHNESS_TAKES_PRIORITY); |
1054 | 1051 |
1055 // Tiles don't have resources to evict. | 1052 // Tiles don't have resources to evict. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1090 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
1094 | 1091 |
1095 tiling_->UpdateTilePriorities( | 1092 tiling_->UpdateTilePriorities( |
1096 ACTIVE_TREE, | 1093 ACTIVE_TREE, |
1097 gfx::Rect(layer_bounds), // visible content rect | 1094 gfx::Rect(layer_bounds), // visible content rect |
1098 1.f, // current contents scale | 1095 1.f, // current contents scale |
1099 1.0, // current frame time | 1096 1.0, // current frame time |
1100 NULL, // occlusion tracker | 1097 NULL, // occlusion tracker |
1101 NULL, // render target | 1098 NULL, // render target |
1102 gfx::Transform()); // draw transform | 1099 gfx::Transform()); // draw transform |
| 1100 tiling_->CreateAllTilesForTesting(); |
1103 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1101 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1104 | |
1105 // Make the viewport rect empty. All tiles are killed and become zombies. | |
1106 tiling_->UpdateTilePriorities(ACTIVE_TREE, | |
1107 gfx::Rect(), // visible content rect | |
1108 1.f, // current contents scale | |
1109 2.0, // current frame time | |
1110 NULL, // occlusion tracker | |
1111 NULL, // render target | |
1112 gfx::Transform()); // draw transform | |
1113 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1114 } | 1102 } |
1115 | 1103 |
1116 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 1104 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
1117 gfx::Size layer_bounds(1099, 801); | 1105 gfx::Size layer_bounds(1099, 801); |
1118 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1106 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
1119 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1107 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
1120 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1108 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
1121 | 1109 |
1122 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 1110 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
1123 | 1111 |
1124 tiling_->UpdateTilePriorities( | 1112 tiling_->UpdateTilePriorities( |
1125 ACTIVE_TREE, | 1113 ACTIVE_TREE, |
1126 gfx::Rect(layer_bounds), // visible content rect | 1114 gfx::Rect(layer_bounds), // visible content rect |
1127 1.f, // current contents scale | 1115 1.f, // current contents scale |
1128 1.0, // current frame time | 1116 1.0, // current frame time |
1129 NULL, // occlusion tracker | 1117 NULL, // occlusion tracker |
1130 NULL, // render target | 1118 NULL, // render target |
1131 gfx::Transform()); // draw transform | 1119 gfx::Transform()); // draw transform |
| 1120 tiling_->CreateAllTilesForTesting(); |
1132 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1121 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1133 | 1122 |
1134 // If the visible content rect is empty, it should still have live tiles. | 1123 // If the visible content rect is empty, it should still have live tiles. |
1135 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1124 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1136 giant_rect, // visible content rect | 1125 giant_rect, // visible content rect |
1137 1.f, // current contents scale | 1126 1.f, // current contents scale |
1138 2.0, // current frame time | 1127 2.0, // current frame time |
1139 NULL, // occlusion tracker | 1128 NULL, // occlusion tracker |
1140 NULL, // render target | 1129 NULL, // render target |
1141 gfx::Transform()); // draw transform | 1130 gfx::Transform()); // draw transform |
| 1131 tiling_->CreateAllTilesForTesting(); |
1142 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1132 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1143 } | 1133 } |
1144 | 1134 |
1145 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | 1135 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { |
1146 gfx::Size layer_bounds(1099, 801); | 1136 gfx::Size layer_bounds(1099, 801); |
1147 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1137 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
1148 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1138 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
1149 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1139 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
1150 | 1140 |
1151 // This rect does not intersect with the layer, as the layer is outside the | 1141 // This rect does not intersect with the layer, as the layer is outside the |
1152 // viewport. | 1142 // viewport. |
1153 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 1143 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
1154 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 1144 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
1155 | 1145 |
1156 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1146 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1157 viewport_rect, // visible content rect | 1147 viewport_rect, // visible content rect |
1158 1.f, // current contents scale | 1148 1.f, // current contents scale |
1159 1.0, // current frame time | 1149 1.0, // current frame time |
1160 NULL, // occlusion tracker | 1150 NULL, // occlusion tracker |
1161 NULL, // render target | 1151 NULL, // render target |
1162 gfx::Transform()); // draw transform | 1152 gfx::Transform()); // draw transform |
| 1153 tiling_->CreateInterestRectTilesForTesting(); |
1163 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1154 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1164 } | 1155 } |
1165 | 1156 |
1166 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 1157 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
1167 bool intersect_exists, | 1158 bool intersect_exists, |
1168 Tile* tile, | 1159 Tile* tile, |
1169 const gfx::Rect& geometry_rect) { | 1160 const gfx::Rect& geometry_rect) { |
1170 bool intersects = rect.Intersects(geometry_rect); | 1161 bool intersects = rect.Intersects(geometry_rect); |
1171 bool expected_exists = intersect_exists ? intersects : !intersects; | 1162 bool expected_exists = intersect_exists ? intersects : !intersects; |
1172 EXPECT_EQ(expected_exists, tile != NULL) | 1163 EXPECT_EQ(expected_exists, tile != NULL) |
(...skipping 11 matching lines...) Expand all Loading... |
1184 gfx::Rect visible_rect(8000, 8000, 50, 50); | 1175 gfx::Rect visible_rect(8000, 8000, 50, 50); |
1185 | 1176 |
1186 set_max_tiles_for_interest_area(1); | 1177 set_max_tiles_for_interest_area(1); |
1187 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1178 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1188 visible_rect, // visible content rect | 1179 visible_rect, // visible content rect |
1189 1.f, // current contents scale | 1180 1.f, // current contents scale |
1190 1.0, // current frame time | 1181 1.0, // current frame time |
1191 NULL, // occlusion tracker | 1182 NULL, // occlusion tracker |
1192 NULL, // render target | 1183 NULL, // render target |
1193 gfx::Transform()); // draw transform | 1184 gfx::Transform()); // draw transform |
| 1185 tiling_->CreateInterestRectTilesForTesting(); |
1194 VerifyTiles(1.f, | 1186 VerifyTiles(1.f, |
1195 gfx::Rect(layer_bounds), | 1187 gfx::Rect(layer_bounds), |
1196 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 1188 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
1197 } | 1189 } |
1198 | 1190 |
1199 static void CountExistingTiles(int *count, | 1191 static void CountExistingTiles(int* count, |
1200 Tile* tile, | 1192 Tile* tile, |
1201 const gfx::Rect& geometry_rect) { | 1193 const gfx::Rect& geometry_rect) { |
1202 if (tile != NULL) | 1194 if (tile != NULL) |
1203 ++(*count); | 1195 ++(*count); |
1204 } | 1196 } |
1205 | 1197 |
1206 TEST_F(PictureLayerTilingIteratorTest, | 1198 TEST_F(PictureLayerTilingIteratorTest, |
1207 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 1199 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
1208 gfx::Size layer_bounds(10000, 10000); | 1200 gfx::Size layer_bounds(10000, 10000); |
1209 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1201 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
(...skipping 29 matching lines...) Expand all Loading... |
1239 PictureLayerTilingSet active_set(&client_, layer_bounds); | 1231 PictureLayerTilingSet active_set(&client_, layer_bounds); |
1240 | 1232 |
1241 active_set.AddTiling(1.f); | 1233 active_set.AddTiling(1.f); |
1242 | 1234 |
1243 VerifyTiles(active_set.tiling_at(0), | 1235 VerifyTiles(active_set.tiling_at(0), |
1244 1.f, | 1236 1.f, |
1245 gfx::Rect(layer_bounds), | 1237 gfx::Rect(layer_bounds), |
1246 base::Bind(&TileExists, false)); | 1238 base::Bind(&TileExists, false)); |
1247 | 1239 |
1248 UpdateAllTilePriorities(&active_set, | 1240 UpdateAllTilePriorities(&active_set, |
1249 PENDING_TREE, | 1241 ACTIVE_TREE, |
1250 gfx::Rect(layer_bounds), // visible content rect | 1242 gfx::Rect(layer_bounds), // visible content rect |
1251 1.f, // current contents scale | 1243 1.f, // current contents scale |
1252 1.0); // current frame time | 1244 1.0); // current frame time |
| 1245 CreateAllTiles(&active_set); |
1253 | 1246 |
1254 // The active tiling has tiles now. | 1247 // The active tiling has tiles now. |
1255 VerifyTiles(active_set.tiling_at(0), | 1248 VerifyTiles(active_set.tiling_at(0), |
1256 1.f, | 1249 1.f, |
1257 gfx::Rect(layer_bounds), | 1250 gfx::Rect(layer_bounds), |
1258 base::Bind(&TileExists, true)); | 1251 base::Bind(&TileExists, true)); |
1259 | 1252 |
1260 // Add the same tilings to the pending set. | 1253 // Add the same tilings to the pending set. |
1261 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 1254 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
1262 Region invalidation; | 1255 Region invalidation; |
1263 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 1256 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
1264 | 1257 |
1265 // The pending tiling starts with no tiles. | 1258 // The pending tiling starts with no tiles. |
1266 VerifyTiles(pending_set.tiling_at(0), | 1259 VerifyTiles(pending_set.tiling_at(0), |
1267 1.f, | 1260 1.f, |
1268 gfx::Rect(layer_bounds), | 1261 gfx::Rect(layer_bounds), |
1269 base::Bind(&TileExists, false)); | 1262 base::Bind(&TileExists, false)); |
1270 | 1263 |
1271 // UpdateTilePriorities on the pending tiling at the same frame time. The | 1264 // UpdateTilePriorities on the pending tiling at the same frame time. The |
1272 // pending tiling should get tiles. | 1265 // pending tiling should get tiles. |
1273 UpdateAllTilePriorities(&pending_set, | 1266 UpdateAllTilePriorities(&pending_set, |
1274 PENDING_TREE, | 1267 PENDING_TREE, |
1275 gfx::Rect(layer_bounds), // visible content rect | 1268 gfx::Rect(layer_bounds), // visible content rect |
1276 1.f, // current contents scale | 1269 1.f, // current contents scale |
1277 1.0); // current frame time | 1270 1.0); // current frame time |
| 1271 CreateAllTiles(&pending_set); |
1278 | 1272 |
1279 VerifyTiles(pending_set.tiling_at(0), | 1273 VerifyTiles(pending_set.tiling_at(0), |
1280 1.f, | 1274 1.f, |
1281 gfx::Rect(layer_bounds), | 1275 gfx::Rect(layer_bounds), |
1282 base::Bind(&TileExists, true)); | 1276 base::Bind(&TileExists, true)); |
1283 } | 1277 } |
1284 | 1278 |
1285 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 1279 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
1286 // The TilePriority of visible tiles should have zero distance_to_visible | 1280 // The TilePriority of visible tiles should have zero distance_to_visible |
1287 // and time_to_visible. | 1281 // and time_to_visible. |
1288 | 1282 |
1289 FakePictureLayerTilingClient client; | 1283 FakePictureLayerTilingClient client; |
1290 scoped_ptr<TestablePictureLayerTiling> tiling; | 1284 scoped_ptr<TestablePictureLayerTiling> tiling; |
1291 | 1285 |
1292 gfx::Size device_viewport(800, 600); | 1286 gfx::Size device_viewport(800, 600); |
1293 gfx::Size last_layer_bounds(200, 200); | 1287 gfx::Size last_layer_bounds(200, 200); |
1294 gfx::Size current_layer_bounds(200, 200); | 1288 gfx::Size current_layer_bounds(200, 200); |
1295 float current_layer_contents_scale = 1.f; | 1289 float current_layer_contents_scale = 1.f; |
1296 gfx::Transform current_screen_transform; | 1290 gfx::Transform current_screen_transform; |
1297 double current_frame_time_in_seconds = 1.0; | 1291 double current_frame_time_in_seconds = 1.0; |
1298 | 1292 |
1299 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1293 gfx::Rect viewport_in_layer_space = |
1300 current_screen_transform, device_viewport); | 1294 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1301 | 1295 |
1302 client.SetTileSize(gfx::Size(100, 100)); | 1296 client.SetTileSize(gfx::Size(100, 100)); |
1303 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1297 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1304 current_layer_bounds, | 1298 current_layer_bounds, |
1305 &client); | 1299 &client); |
1306 | 1300 |
1307 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1301 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1308 viewport_in_layer_space, | 1302 viewport_in_layer_space, |
1309 current_layer_contents_scale, | 1303 current_layer_contents_scale, |
1310 current_frame_time_in_seconds, | 1304 current_frame_time_in_seconds, |
1311 NULL, // occlusion tracker | 1305 NULL, // occlusion tracker |
1312 NULL, // render target | 1306 NULL, // render target |
1313 gfx::Transform()); // draw transform | 1307 gfx::Transform()); // draw transform |
| 1308 tiling->CreateInterestRectTilesForTesting(); |
1314 | 1309 |
1315 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1310 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1316 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1311 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1317 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1312 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1318 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1313 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1319 | 1314 |
1320 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1315 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1321 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1316 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1322 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1317 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1323 | 1318 |
1324 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1319 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1325 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1320 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1326 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1321 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1327 | 1322 |
1328 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1323 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1329 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1324 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1330 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1325 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1331 | 1326 |
1332 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1327 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1333 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1328 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1334 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1329 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1335 } | 1330 } |
1336 | 1331 |
1337 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 1332 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
1338 // The TilePriority of offscreen tiles (without movement) should have nonzero | 1333 // The TilePriority of offscreen tiles (without movement) should have |
1339 // distance_to_visible and infinite time_to_visible. | 1334 // nonzero distance_to_visible and infinite time_to_visible. |
1340 | |
1341 FakePictureLayerTilingClient client; | 1335 FakePictureLayerTilingClient client; |
1342 scoped_ptr<TestablePictureLayerTiling> tiling; | 1336 scoped_ptr<TestablePictureLayerTiling> tiling; |
1343 | 1337 |
1344 gfx::Size device_viewport(800, 600); | 1338 gfx::Size device_viewport(800, 600); |
1345 gfx::Size last_layer_bounds(200, 200); | 1339 gfx::Size last_layer_bounds(200, 200); |
1346 gfx::Size current_layer_bounds(200, 200); | 1340 gfx::Size current_layer_bounds(200, 200); |
1347 float current_layer_contents_scale = 1.f; | 1341 float current_layer_contents_scale = 1.f; |
1348 gfx::Transform last_screen_transform; | 1342 gfx::Transform last_screen_transform; |
1349 gfx::Transform current_screen_transform; | 1343 gfx::Transform current_screen_transform; |
1350 double current_frame_time_in_seconds = 1.0; | 1344 double current_frame_time_in_seconds = 1.0; |
1351 | 1345 |
1352 current_screen_transform.Translate(850, 0); | 1346 current_screen_transform.Translate(850, 0); |
1353 last_screen_transform = current_screen_transform; | 1347 last_screen_transform = current_screen_transform; |
1354 | 1348 |
1355 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1349 gfx::Rect viewport_in_layer_space = |
1356 current_screen_transform, device_viewport); | 1350 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1357 | 1351 |
1358 client.SetTileSize(gfx::Size(100, 100)); | 1352 client.SetTileSize(gfx::Size(100, 100)); |
1359 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1353 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1360 current_layer_bounds, | 1354 current_layer_bounds, |
1361 &client); | 1355 &client); |
1362 | 1356 |
1363 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1357 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1364 viewport_in_layer_space, | 1358 viewport_in_layer_space, |
1365 current_layer_contents_scale, | 1359 current_layer_contents_scale, |
1366 current_frame_time_in_seconds, | 1360 current_frame_time_in_seconds, |
1367 NULL, // occlusion tracker | 1361 NULL, // occlusion tracker |
1368 NULL, // render target | 1362 NULL, // render target |
1369 gfx::Transform()); // draw transform | 1363 gfx::Transform()); // draw transform |
| 1364 tiling->CreateInterestRectTilesForTesting(); |
1370 | 1365 |
1371 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1366 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1372 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1367 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1373 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1368 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1374 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1369 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1375 | 1370 |
1376 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1371 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1377 EXPECT_GT(priority.distance_to_visible, 0.f); | 1372 EXPECT_GT(priority.distance_to_visible, 0.f); |
1378 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1373 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1379 | 1374 |
(...skipping 16 matching lines...) Expand all Loading... |
1396 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1391 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
1397 | 1392 |
1398 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1393 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1399 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1394 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1400 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1395 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
1401 } | 1396 } |
1402 | 1397 |
1403 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 1398 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
1404 // Sanity check that a layer with some tiles visible and others offscreen has | 1399 // Sanity check that a layer with some tiles visible and others offscreen has |
1405 // correct TilePriorities for each tile. | 1400 // correct TilePriorities for each tile. |
1406 | |
1407 FakePictureLayerTilingClient client; | 1401 FakePictureLayerTilingClient client; |
1408 scoped_ptr<TestablePictureLayerTiling> tiling; | 1402 scoped_ptr<TestablePictureLayerTiling> tiling; |
1409 | 1403 |
1410 gfx::Size device_viewport(800, 600); | 1404 gfx::Size device_viewport(800, 600); |
1411 gfx::Size last_layer_bounds(200, 200); | 1405 gfx::Size last_layer_bounds(200, 200); |
1412 gfx::Size current_layer_bounds(200, 200); | 1406 gfx::Size current_layer_bounds(200, 200); |
1413 float current_layer_contents_scale = 1.f; | 1407 float current_layer_contents_scale = 1.f; |
1414 gfx::Transform last_screen_transform; | 1408 gfx::Transform last_screen_transform; |
1415 gfx::Transform current_screen_transform; | 1409 gfx::Transform current_screen_transform; |
1416 double current_frame_time_in_seconds = 1.0; | 1410 double current_frame_time_in_seconds = 1.0; |
1417 | 1411 |
1418 current_screen_transform.Translate(705, 505); | 1412 current_screen_transform.Translate(705, 505); |
1419 last_screen_transform = current_screen_transform; | 1413 last_screen_transform = current_screen_transform; |
1420 | 1414 |
1421 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1415 gfx::Rect viewport_in_layer_space = |
1422 current_screen_transform, device_viewport); | 1416 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1423 | 1417 |
1424 client.SetTileSize(gfx::Size(100, 100)); | 1418 client.SetTileSize(gfx::Size(100, 100)); |
1425 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1419 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1426 current_layer_bounds, | 1420 current_layer_bounds, |
1427 &client); | 1421 &client); |
1428 | 1422 |
1429 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1423 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1430 viewport_in_layer_space, | 1424 viewport_in_layer_space, |
1431 current_layer_contents_scale, | 1425 current_layer_contents_scale, |
1432 current_frame_time_in_seconds, | 1426 current_frame_time_in_seconds, |
1433 NULL, // occlusion tracker | 1427 NULL, // occlusion tracker |
1434 NULL, // render target | 1428 NULL, // render target |
1435 gfx::Transform()); // draw transform | 1429 gfx::Transform()); // draw transform |
| 1430 tiling->CreateInterestRectTilesForTesting(); |
1436 | 1431 |
1437 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1432 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1438 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1433 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1439 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1434 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1440 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1435 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1441 | 1436 |
1442 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1437 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1443 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1438 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1444 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1439 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1445 | 1440 |
(...skipping 25 matching lines...) Expand all Loading... |
1471 gfx::Transform last_screen_transform; | 1466 gfx::Transform last_screen_transform; |
1472 gfx::Transform current_screen_transform; | 1467 gfx::Transform current_screen_transform; |
1473 double current_frame_time_in_seconds = 1.0; | 1468 double current_frame_time_in_seconds = 1.0; |
1474 | 1469 |
1475 // A diagonally rotated layer that is partially off the bottom of the screen. | 1470 // A diagonally rotated layer that is partially off the bottom of the screen. |
1476 // In this configuration, only the top-left tile would be visible. | 1471 // In this configuration, only the top-left tile would be visible. |
1477 current_screen_transform.Translate(600, 750); | 1472 current_screen_transform.Translate(600, 750); |
1478 current_screen_transform.RotateAboutZAxis(45); | 1473 current_screen_transform.RotateAboutZAxis(45); |
1479 last_screen_transform = current_screen_transform; | 1474 last_screen_transform = current_screen_transform; |
1480 | 1475 |
1481 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1476 gfx::Rect viewport_in_layer_space = |
1482 current_screen_transform, device_viewport); | 1477 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1483 | 1478 |
1484 client.SetTileSize(gfx::Size(100, 100)); | 1479 client.SetTileSize(gfx::Size(100, 100)); |
1485 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1480 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1486 current_layer_bounds, | 1481 current_layer_bounds, |
1487 &client); | 1482 &client); |
1488 | 1483 |
1489 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1484 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1490 viewport_in_layer_space, | 1485 viewport_in_layer_space, |
1491 current_layer_contents_scale, | 1486 current_layer_contents_scale, |
1492 current_frame_time_in_seconds, | 1487 current_frame_time_in_seconds, |
1493 NULL, // occlusion tracker | 1488 NULL, // occlusion tracker |
1494 NULL, // render target | 1489 NULL, // render target |
1495 gfx::Transform()); // draw transform | 1490 gfx::Transform()); // draw transform |
| 1491 tiling->CreateInterestRectTilesForTesting(); |
1496 | 1492 |
1497 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1493 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1498 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1494 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1499 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1495 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1500 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1496 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1501 | 1497 |
1502 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1498 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1503 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1499 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1504 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1500 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1505 | 1501 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 current_screen_transform.Translate(-100.0, -100.0); | 1551 current_screen_transform.Translate(-100.0, -100.0); |
1556 last_screen_transform = current_screen_transform; | 1552 last_screen_transform = current_screen_transform; |
1557 | 1553 |
1558 // Sanity check that this transform wouldn't cause w<0 clipping. | 1554 // Sanity check that this transform wouldn't cause w<0 clipping. |
1559 bool clipped; | 1555 bool clipped; |
1560 MathUtil::MapQuad(current_screen_transform, | 1556 MathUtil::MapQuad(current_screen_transform, |
1561 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), | 1557 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), |
1562 &clipped); | 1558 &clipped); |
1563 ASSERT_FALSE(clipped); | 1559 ASSERT_FALSE(clipped); |
1564 | 1560 |
1565 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1561 gfx::Rect viewport_in_layer_space = |
1566 current_screen_transform, device_viewport); | 1562 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1567 | 1563 |
1568 client.SetTileSize(gfx::Size(100, 100)); | 1564 client.SetTileSize(gfx::Size(100, 100)); |
1569 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1565 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1570 current_layer_bounds, | 1566 current_layer_bounds, |
1571 &client); | 1567 &client); |
1572 | 1568 |
1573 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1569 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1574 viewport_in_layer_space, | 1570 viewport_in_layer_space, |
1575 current_layer_contents_scale, | 1571 current_layer_contents_scale, |
1576 current_frame_time_in_seconds, | 1572 current_frame_time_in_seconds, |
1577 NULL, // occlusion tracker | 1573 NULL, // occlusion tracker |
1578 NULL, // render target | 1574 NULL, // render target |
1579 gfx::Transform()); // draw transform | 1575 gfx::Transform()); // draw transform |
| 1576 tiling->CreateInterestRectTilesForTesting(); |
1580 | 1577 |
1581 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1578 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1582 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1579 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1583 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1580 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1584 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1581 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1585 | 1582 |
1586 // All tiles will have a positive distance_to_visible | 1583 // All tiles will have a positive distance_to_visible |
1587 // and an infinite time_to_visible. | 1584 // and an infinite time_to_visible. |
1588 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1585 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1589 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); | 1586 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 MathUtil::MapQuad(current_screen_transform, | 1646 MathUtil::MapQuad(current_screen_transform, |
1650 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), | 1647 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), |
1651 &clipped); | 1648 &clipped); |
1652 ASSERT_TRUE(clipped); | 1649 ASSERT_TRUE(clipped); |
1653 | 1650 |
1654 MathUtil::MapQuad(current_screen_transform, | 1651 MathUtil::MapQuad(current_screen_transform, |
1655 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1652 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), |
1656 &clipped); | 1653 &clipped); |
1657 ASSERT_FALSE(clipped); | 1654 ASSERT_FALSE(clipped); |
1658 | 1655 |
1659 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1656 gfx::Rect viewport_in_layer_space = |
1660 current_screen_transform, device_viewport); | 1657 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1661 | 1658 |
1662 client.SetTileSize(gfx::Size(100, 100)); | 1659 client.SetTileSize(gfx::Size(100, 100)); |
1663 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1660 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1664 current_layer_bounds, | 1661 current_layer_bounds, |
1665 &client); | 1662 &client); |
1666 | 1663 |
1667 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1664 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1668 viewport_in_layer_space, | 1665 viewport_in_layer_space, |
1669 current_layer_contents_scale, | 1666 current_layer_contents_scale, |
1670 current_frame_time_in_seconds, | 1667 current_frame_time_in_seconds, |
1671 NULL, // occlusion tracker | 1668 NULL, // occlusion tracker |
1672 NULL, // render target | 1669 NULL, // render target |
1673 gfx::Transform()); // draw transform | 1670 gfx::Transform()); // draw transform |
| 1671 tiling->CreateInterestRectTilesForTesting(); |
1674 | 1672 |
1675 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1673 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1676 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1674 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1677 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1675 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1678 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1676 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1679 | 1677 |
1680 // Left-side tiles will be clipped by the transform, so we have to assume | 1678 // Left-side tiles will be clipped by the transform, so we have to assume |
1681 // they are visible just in case. | 1679 // they are visible just in case. |
1682 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1680 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1683 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1681 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
(...skipping 29 matching lines...) Expand all Loading... |
1713 float current_layer_contents_scale = 1.f; | 1711 float current_layer_contents_scale = 1.f; |
1714 gfx::Transform last_screen_transform; | 1712 gfx::Transform last_screen_transform; |
1715 gfx::Transform current_screen_transform; | 1713 gfx::Transform current_screen_transform; |
1716 double last_frame_time_in_seconds = 1.0; | 1714 double last_frame_time_in_seconds = 1.0; |
1717 double current_frame_time_in_seconds = 2.0; | 1715 double current_frame_time_in_seconds = 2.0; |
1718 | 1716 |
1719 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1717 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
1720 current_screen_transform.Translate(1800, 0); | 1718 current_screen_transform.Translate(1800, 0); |
1721 last_screen_transform.Translate(2800, 0); | 1719 last_screen_transform.Translate(2800, 0); |
1722 | 1720 |
1723 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1721 gfx::Rect viewport_in_layer_space = |
1724 current_screen_transform, device_viewport); | 1722 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1725 | 1723 |
1726 client.SetTileSize(gfx::Size(100, 100)); | 1724 client.SetTileSize(gfx::Size(100, 100)); |
1727 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1725 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1728 current_layer_bounds, | 1726 current_layer_bounds, |
1729 &client); | 1727 &client); |
1730 | 1728 |
1731 // previous ("last") frame | 1729 // previous ("last") frame |
1732 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1730 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1733 viewport_in_layer_space, | 1731 viewport_in_layer_space, |
1734 last_layer_contents_scale, | 1732 last_layer_contents_scale, |
1735 last_frame_time_in_seconds, | 1733 last_frame_time_in_seconds, |
1736 NULL, // occlusion tracker | 1734 NULL, // occlusion tracker |
1737 NULL, // render target | 1735 NULL, // render target |
1738 gfx::Transform()); // draw transform | 1736 gfx::Transform()); // draw transform |
1739 | 1737 |
1740 // current frame | 1738 // current frame |
1741 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1739 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1742 viewport_in_layer_space, | 1740 viewport_in_layer_space, |
1743 current_layer_contents_scale, | 1741 current_layer_contents_scale, |
1744 current_frame_time_in_seconds, | 1742 current_frame_time_in_seconds, |
1745 NULL, // occlusion tracker | 1743 NULL, // occlusion tracker |
1746 NULL, // render target | 1744 NULL, // render target |
1747 gfx::Transform()); // draw transform | 1745 gfx::Transform()); // draw transform |
| 1746 tiling->CreateInterestRectTilesForTesting(); |
1748 | 1747 |
1749 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1748 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1750 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1749 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1751 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1750 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1752 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1751 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1753 | 1752 |
1754 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1753 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1755 EXPECT_GT(priority.distance_to_visible, 0.f); | 1754 EXPECT_GT(priority.distance_to_visible, 0.f); |
1756 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1755 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1757 | 1756 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 // - the top-left tile becomes visible on rotation | 1793 // - the top-left tile becomes visible on rotation |
1795 // - the top-right tile will have an infinite time_to_visible | 1794 // - the top-right tile will have an infinite time_to_visible |
1796 // because it is rotating away from viewport. | 1795 // because it is rotating away from viewport. |
1797 // - bottom-left layer will have a positive non-zero time_to_visible | 1796 // - bottom-left layer will have a positive non-zero time_to_visible |
1798 // because it is rotating toward the viewport. | 1797 // because it is rotating toward the viewport. |
1799 current_screen_transform.Translate(400, 550); | 1798 current_screen_transform.Translate(400, 550); |
1800 current_screen_transform.RotateAboutZAxis(45); | 1799 current_screen_transform.RotateAboutZAxis(45); |
1801 | 1800 |
1802 last_screen_transform.Translate(400, 550); | 1801 last_screen_transform.Translate(400, 550); |
1803 | 1802 |
1804 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1803 gfx::Rect viewport_in_layer_space = |
1805 current_screen_transform, device_viewport); | 1804 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1806 | 1805 |
1807 client.SetTileSize(gfx::Size(100, 100)); | 1806 client.SetTileSize(gfx::Size(100, 100)); |
1808 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1807 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1809 current_layer_bounds, | 1808 current_layer_bounds, |
1810 &client); | 1809 &client); |
1811 | 1810 |
1812 // previous ("last") frame | 1811 // previous ("last") frame |
1813 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1812 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1814 viewport_in_layer_space, | 1813 viewport_in_layer_space, |
1815 last_layer_contents_scale, | 1814 last_layer_contents_scale, |
1816 last_frame_time_in_seconds, | 1815 last_frame_time_in_seconds, |
1817 NULL, // occlusion tracker | 1816 NULL, // occlusion tracker |
1818 NULL, // render target | 1817 NULL, // render target |
1819 gfx::Transform()); // draw transform | 1818 gfx::Transform()); // draw transform |
1820 | 1819 |
1821 // current frame | 1820 // current frame |
1822 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1821 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1823 viewport_in_layer_space, | 1822 viewport_in_layer_space, |
1824 current_layer_contents_scale, | 1823 current_layer_contents_scale, |
1825 current_frame_time_in_seconds, | 1824 current_frame_time_in_seconds, |
1826 NULL, // occlusion tracker | 1825 NULL, // occlusion tracker |
1827 NULL, // render target | 1826 NULL, // render target |
1828 gfx::Transform()); // draw transform | 1827 gfx::Transform()); // draw transform |
| 1828 tiling->CreateInterestRectTilesForTesting(); |
1829 | 1829 |
1830 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1830 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1831 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1831 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1832 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1832 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1833 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1833 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1834 | 1834 |
1835 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1835 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1836 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1836 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1837 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1837 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1838 | 1838 |
1839 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1839 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1840 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1840 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1841 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1841 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1842 | 1842 |
1843 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1843 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1844 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1844 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1845 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1845 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1846 } | 1846 } |
1847 | 1847 |
1848 } // namespace | 1848 } // namespace |
1849 } // namespace cc | 1849 } // namespace cc |
OLD | NEW |