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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 // The reason is that each tile has a one pixel border, so tile at (1, 2) | 442 // The reason is that each tile has a one pixel border, so tile at (1, 2) |
447 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at | 443 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at |
448 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the | 444 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the |
449 // tiling. | 445 // tiling. |
450 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); | 446 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); |
451 gfx::Rect viewport_in_content_space = | 447 gfx::Rect viewport_in_content_space = |
452 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | 448 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
453 | 449 |
454 tiling->UpdateTilePriorities( | 450 tiling->UpdateTilePriorities( |
455 ACTIVE_TREE, viewport, 1.f, 1.0, NULL, NULL, gfx::Transform()); | 451 ACTIVE_TREE, viewport, 1.f, 1.0, NULL, NULL, gfx::Transform()); |
452 tiling->CreateInterestRectTilesForTesting(); | |
456 | 453 |
457 gfx::Rect soon_rect = viewport; | 454 gfx::Rect soon_rect = viewport; |
458 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 455 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
459 gfx::Rect soon_rect_in_content_space = | 456 gfx::Rect soon_rect_in_content_space = |
460 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); | 457 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); |
461 | 458 |
462 // Sanity checks. | 459 // Sanity checks. |
463 for (int i = 0; i < 47; ++i) { | 460 for (int i = 0; i < 47; ++i) { |
464 for (int j = 0; j < 47; ++j) { | 461 for (int j = 0; j < 47; ++j) { |
465 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; | 462 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; |
(...skipping 28 matching lines...) Expand all Loading... | |
494 have_eventually = true; | 491 have_eventually = true; |
495 } | 492 } |
496 } | 493 } |
497 } | 494 } |
498 | 495 |
499 EXPECT_TRUE(have_now); | 496 EXPECT_TRUE(have_now); |
500 EXPECT_TRUE(have_soon); | 497 EXPECT_TRUE(have_soon); |
501 EXPECT_TRUE(have_eventually); | 498 EXPECT_TRUE(have_eventually); |
502 | 499 |
503 // Spot check some distances. | 500 // Spot check some distances. |
504 // Tile at 5, 1 should begin at 41x9 in content space (without borders), | 501 // Tile at 5, 1 should begin at 40x8 in content space (with borders), |
vmpstr
2014/07/02 23:51:29
I think it makes sense for us to use bordered rect
| |
505 // so the distance to a viewport that ends at 25x25 in content space | 502 // so the distance to a viewport that ends at 25x25 in content space |
506 // should be 17 (41 - 25 + 1). In layer space, then that should be | 503 // should be 17 (40 - 25 + 1). In layer space, then that should be |
507 // 17 / 0.25 = 68 pixels. | 504 // 17 / 0.25 = 64 pixels. |
508 | 505 |
509 // We can verify that the content rect (with borders) is one pixel off | 506 // We can verify that the content rect is what we expect it to be. |
510 // 41,9 8x8 on all sides. | |
511 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); | 507 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); |
512 | 508 |
513 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 509 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
514 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 510 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
515 | 511 |
516 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 512 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
517 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 513 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
518 | 514 |
519 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 515 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
520 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible); | 516 EXPECT_FLOAT_EQ(32.f, priority.distance_to_visible); |
521 | 517 |
522 // Move the viewport down 40 pixels. | 518 // Move the viewport down 40 pixels. |
523 viewport = gfx::Rect(0, 40, 100, 100); | 519 viewport = gfx::Rect(0, 40, 100, 100); |
524 viewport_in_content_space = | 520 viewport_in_content_space = |
525 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | 521 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
526 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); | 522 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); |
527 | 523 |
528 soon_rect = viewport; | 524 soon_rect = viewport; |
529 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 525 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
530 soon_rect_in_content_space = | 526 soon_rect_in_content_space = |
531 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); | 527 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); |
532 | 528 |
533 EXPECT_EQ(0, skewport.x()); | 529 EXPECT_EQ(0, skewport.x()); |
534 EXPECT_EQ(10, skewport.y()); | 530 EXPECT_EQ(10, skewport.y()); |
535 EXPECT_EQ(25, skewport.width()); | 531 EXPECT_EQ(25, skewport.width()); |
536 EXPECT_EQ(35, skewport.height()); | 532 EXPECT_EQ(35, skewport.height()); |
537 | 533 |
538 tiling->UpdateTilePriorities( | 534 tiling->UpdateTilePriorities( |
539 ACTIVE_TREE, viewport, 1.f, 2.0, NULL, NULL, gfx::Transform()); | 535 ACTIVE_TREE, viewport, 1.f, 2.0, NULL, NULL, gfx::Transform()); |
536 tiling->CreateAllTilesForTesting(); | |
540 | 537 |
541 have_now = false; | 538 have_now = false; |
542 have_eventually = false; | 539 have_eventually = false; |
543 have_soon = false; | 540 have_soon = false; |
544 | 541 |
545 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | 542 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
546 // some EVENTUALLY tiles. | 543 // some EVENTUALLY tiles. |
547 for (int i = 0; i < 47; ++i) { | 544 for (int i = 0; i < 47; ++i) { |
548 for (int j = 0; j < 47; ++j) { | 545 for (int j = 0; j < 47; ++j) { |
549 Tile* tile = tiling->TileAt(i, j); | 546 Tile* tile = tiling->TileAt(i, j); |
(...skipping 20 matching lines...) Expand all Loading... | |
570 have_eventually = true; | 567 have_eventually = true; |
571 } | 568 } |
572 } | 569 } |
573 } | 570 } |
574 | 571 |
575 EXPECT_TRUE(have_now); | 572 EXPECT_TRUE(have_now); |
576 EXPECT_TRUE(have_soon); | 573 EXPECT_TRUE(have_soon); |
577 EXPECT_TRUE(have_eventually); | 574 EXPECT_TRUE(have_eventually); |
578 | 575 |
579 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 576 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
580 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 577 EXPECT_FLOAT_EQ(64.f, priority.distance_to_visible); |
581 | 578 |
582 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 579 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
583 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | 580 EXPECT_FLOAT_EQ(24.f, priority.distance_to_visible); |
584 | 581 |
585 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 582 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
586 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 583 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
587 | 584 |
588 // Change the underlying layer scale. | 585 // Change the underlying layer scale. |
589 tiling->UpdateTilePriorities( | 586 tiling->UpdateTilePriorities( |
590 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); | 587 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); |
588 tiling->CreateAllTilesForTesting(); | |
591 | 589 |
592 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 590 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
593 EXPECT_FLOAT_EQ(34.f, priority.distance_to_visible); | 591 EXPECT_FLOAT_EQ(32.f, priority.distance_to_visible); |
594 | 592 |
595 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 593 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
596 EXPECT_FLOAT_EQ(14.f, priority.distance_to_visible); | 594 EXPECT_FLOAT_EQ(12.f, priority.distance_to_visible); |
597 | 595 |
598 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 596 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
599 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 597 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
600 } | 598 } |
601 | 599 |
602 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 600 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
603 gfx::Rect in(40, 50, 100, 200); | 601 gfx::Rect in(40, 50, 100, 200); |
604 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 602 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
605 int64 target_area = 100 * 200; | 603 int64 target_area = 100 * 200; |
606 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 604 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 695 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
698 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); | 696 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right()); |
699 EXPECT_LE(out.width() * out.height(), target_area); | 697 EXPECT_LE(out.width() * out.height(), target_area); |
700 EXPECT_GT(out.width() * out.height(), | 698 EXPECT_GT(out.width() * out.height(), |
701 target_area - out.width() - out.height() * 2); | 699 target_area - out.width() - out.height() * 2); |
702 EXPECT_TRUE(bounds.Contains(out)); | 700 EXPECT_TRUE(bounds.Contains(out)); |
703 } | 701 } |
704 | 702 |
705 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { | 703 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) { |
706 gfx::Rect in(40, 50, 100, 200); | 704 gfx::Rect in(40, 50, 100, 200); |
707 gfx::Rect bounds(-1000, -1000, 1000+120, 10000); | 705 gfx::Rect bounds(-1000, -1000, 1000 + 120, 10000); |
708 int64 target_area = 200 * 200; | 706 int64 target_area = 200 * 200; |
709 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 707 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
710 in, target_area, bounds, NULL); | 708 in, target_area, bounds, NULL); |
711 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 709 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
712 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); | 710 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x()); |
713 EXPECT_LE(out.width() * out.height(), target_area); | 711 EXPECT_LE(out.width() * out.height(), target_area); |
714 EXPECT_GT(out.width() * out.height(), | 712 EXPECT_GT(out.width() * out.height(), |
715 target_area - out.width() - out.height() * 2); | 713 target_area - out.width() - out.height() * 2); |
716 EXPECT_TRUE(bounds.Contains(out)); | 714 EXPECT_TRUE(bounds.Contains(out)); |
717 } | 715 } |
(...skipping 21 matching lines...) Expand all Loading... | |
739 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 737 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
740 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); | 738 EXPECT_EQ(out.right() - in.right(), in.y() - out.y()); |
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() * 2 - out.height()); | 741 target_area - out.width() * 2 - out.height()); |
744 EXPECT_TRUE(bounds.Contains(out)); | 742 EXPECT_TRUE(bounds.Contains(out)); |
745 } | 743 } |
746 | 744 |
747 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { | 745 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) { |
748 gfx::Rect in(40, 50, 100, 200); | 746 gfx::Rect in(40, 50, 100, 200); |
749 gfx::Rect bounds(0, -4000, 100+40+20, 100000); | 747 gfx::Rect bounds(0, -4000, 100 + 40 + 20, 100000); |
750 int64 target_area = 400 * 400; | 748 int64 target_area = 400 * 400; |
751 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 749 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
752 in, target_area, bounds, NULL); | 750 in, target_area, bounds, NULL); |
753 EXPECT_EQ(20, out.right() - in.right()); | 751 EXPECT_EQ(20, out.right() - in.right()); |
754 EXPECT_EQ(40, in.x() - out.x()); | 752 EXPECT_EQ(40, in.x() - out.x()); |
755 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 753 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
756 EXPECT_LE(out.width() * out.height(), target_area); | 754 EXPECT_LE(out.width() * out.height(), target_area); |
757 EXPECT_GT(out.width() * out.height(), | 755 EXPECT_GT(out.width() * out.height(), target_area - out.width() * 2); |
758 target_area - out.width() * 2); | |
759 EXPECT_TRUE(bounds.Contains(out)); | 756 EXPECT_TRUE(bounds.Contains(out)); |
760 } | 757 } |
761 | 758 |
762 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { | 759 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) { |
763 gfx::Rect in(40, 50, 100, 200); | 760 gfx::Rect in(40, 50, 100, 200); |
764 gfx::Rect bounds(-4000, 0, 100000, 200+50+30); | 761 gfx::Rect bounds(-4000, 0, 100000, 200 + 50 + 30); |
765 int64 target_area = 400 * 400; | 762 int64 target_area = 400 * 400; |
766 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 763 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
767 in, target_area, bounds, NULL); | 764 in, target_area, bounds, NULL); |
768 EXPECT_EQ(30, out.bottom() - in.bottom()); | 765 EXPECT_EQ(30, out.bottom() - in.bottom()); |
769 EXPECT_EQ(50, in.y() - out.y()); | 766 EXPECT_EQ(50, in.y() - out.y()); |
770 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 767 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
771 EXPECT_LE(out.width() * out.height(), target_area); | 768 EXPECT_LE(out.width() * out.height(), target_area); |
772 EXPECT_GT(out.width() * out.height(), | 769 EXPECT_GT(out.width() * out.height(), target_area - out.height() * 2); |
773 target_area - out.height() * 2); | |
774 EXPECT_TRUE(bounds.Contains(out)); | 770 EXPECT_TRUE(bounds.Contains(out)); |
775 } | 771 } |
776 | 772 |
777 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { | 773 TEST(PictureLayerTilingTest, ExpandRectOutOfBoundsFarAway) { |
778 gfx::Rect in(400, 500, 100, 200); | 774 gfx::Rect in(400, 500, 100, 200); |
779 gfx::Rect bounds(0, 0, 10, 10); | 775 gfx::Rect bounds(0, 0, 10, 10); |
780 int64 target_area = 400 * 400; | 776 int64 target_area = 400 * 400; |
781 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 777 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
782 in, target_area, bounds, NULL); | 778 in, target_area, bounds, NULL); |
783 EXPECT_TRUE(out.IsEmpty()); | 779 EXPECT_TRUE(out.IsEmpty()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 | 825 |
830 client.SetTileSize(gfx::Size(30, 30)); | 826 client.SetTileSize(gfx::Size(30, 30)); |
831 | 827 |
832 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | 828 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
833 tiling->UpdateTilePriorities( | 829 tiling->UpdateTilePriorities( |
834 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); | 830 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
835 | 831 |
836 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 832 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
837 EXPECT_FALSE(empty_iterator); | 833 EXPECT_FALSE(empty_iterator); |
838 | 834 |
839 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | |
840 | |
841 // Sanity check. | |
842 EXPECT_EQ(841u, all_tiles.size()); | |
843 | |
844 // The explanation of each iteration is as follows: | 835 // The explanation of each iteration is as follows: |
845 // 1. First iteration tests that we can get all of the tiles correctly. | 836 // 1. First iteration tests that we can get all of the tiles correctly. |
846 // 2. Second iteration ensures that we can get all of the tiles again (first | 837 // 2. Second iteration ensures that we can get all of the tiles again (first |
847 // iteration didn't change any tiles), as well set all tiles to be ready to | 838 // iteration didn't change any tiles), as well set all tiles to be ready to |
848 // draw. | 839 // draw. |
849 // 3. Third iteration ensures that no tiles are returned, since they were all | 840 // 3. Third iteration ensures that no tiles are returned, since they were all |
850 // marked as ready to draw. | 841 // marked as ready to draw. |
851 for (int i = 0; i < 3; ++i) { | 842 for (int i = 0; i < 3; ++i) { |
852 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE); | 843 PictureLayerTiling::TilingRasterTileIterator it(tiling.get(), ACTIVE_TREE); |
853 | 844 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 | 907 |
917 EXPECT_GT(eventually_bin_order_correct_count, | 908 EXPECT_GT(eventually_bin_order_correct_count, |
918 eventually_bin_order_incorrect_count); | 909 eventually_bin_order_incorrect_count); |
919 | 910 |
920 // We should have now and eventually tiles, as well as soon tiles from | 911 // We should have now and eventually tiles, as well as soon tiles from |
921 // the border region. | 912 // the border region. |
922 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 913 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
923 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 914 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
924 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 915 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
925 | 916 |
917 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | |
918 | |
919 // Sanity check. | |
920 EXPECT_EQ(841u, all_tiles.size()); | |
926 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); | 921 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); |
927 } | 922 } |
928 } | 923 } |
929 | 924 |
930 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { | 925 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { |
931 FakePictureLayerTilingClient client; | 926 FakePictureLayerTilingClient client; |
932 scoped_ptr<TestablePictureLayerTiling> tiling; | 927 scoped_ptr<TestablePictureLayerTiling> tiling; |
933 | 928 |
934 gfx::Rect viewport(50, 0, 100, 100); | 929 gfx::Rect viewport(50, 0, 100, 100); |
935 gfx::Rect moved_viewport(50, 0, 100, 500); | 930 gfx::Rect moved_viewport(50, 0, 100, 500); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 } | 979 } |
985 | 980 |
986 EXPECT_GT(eventually_bin_order_correct_count, | 981 EXPECT_GT(eventually_bin_order_correct_count, |
987 eventually_bin_order_incorrect_count); | 982 eventually_bin_order_incorrect_count); |
988 | 983 |
989 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 984 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
990 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 985 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
991 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 986 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
992 } | 987 } |
993 | 988 |
994 static void TileExists(bool exists, Tile* tile, | 989 static void TileExists(bool exists, |
990 Tile* tile, | |
995 const gfx::Rect& geometry_rect) { | 991 const gfx::Rect& geometry_rect) { |
996 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 992 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
997 } | 993 } |
998 | 994 |
999 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { | 995 TEST(PictureLayerTilingTest, TilingEvictionTileIteratorStaticViewport) { |
1000 FakeOutputSurfaceClient output_surface_client; | 996 FakeOutputSurfaceClient output_surface_client; |
1001 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); | 997 scoped_ptr<FakeOutputSurface> output_surface = FakeOutputSurface::Create3d(); |
1002 CHECK(output_surface->BindToClient(&output_surface_client)); | 998 CHECK(output_surface->BindToClient(&output_surface_client)); |
1003 TestSharedBitmapManager shared_bitmap_manager; | 999 TestSharedBitmapManager shared_bitmap_manager; |
1004 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( | 1000 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( |
1005 output_surface.get(), &shared_bitmap_manager, 0, false, 1, false); | 1001 output_surface.get(), &shared_bitmap_manager, 0, false, 1, false); |
1006 | 1002 |
1007 FakePictureLayerTilingClient client(resource_provider.get()); | 1003 FakePictureLayerTilingClient client(resource_provider.get()); |
1008 scoped_ptr<TestablePictureLayerTiling> tiling; | 1004 scoped_ptr<TestablePictureLayerTiling> tiling; |
1009 | 1005 |
1010 gfx::Rect viewport(50, 50, 100, 100); | 1006 gfx::Rect viewport(50, 50, 100, 100); |
1011 gfx::Size layer_bounds(200, 200); | 1007 gfx::Size layer_bounds(200, 200); |
1012 | 1008 |
1013 client.SetTileSize(gfx::Size(30, 30)); | 1009 client.SetTileSize(gfx::Size(30, 30)); |
1014 | 1010 |
1015 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); | 1011 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
1016 tiling->UpdateTilePriorities( | 1012 tiling->UpdateTilePriorities( |
1017 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); | 1013 ACTIVE_TREE, viewport, 1.0f, 1.0, NULL, NULL, gfx::Transform()); |
1014 tiling->CreateAllTilesForTesting(); | |
1018 | 1015 |
1019 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 1016 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
1020 EXPECT_FALSE(empty_iterator); | 1017 EXPECT_FALSE(empty_iterator); |
1021 | 1018 |
1022 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | 1019 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
1023 | 1020 |
1024 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get(), | 1021 PictureLayerTiling::TilingEvictionTileIterator it(tiling.get(), |
1025 SMOOTHNESS_TAKES_PRIORITY); | 1022 SMOOTHNESS_TAKES_PRIORITY); |
1026 | 1023 |
1027 // Tiles don't have resources to evict. | 1024 // Tiles don't have resources to evict. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1065 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1062 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
1066 | 1063 |
1067 tiling_->UpdateTilePriorities( | 1064 tiling_->UpdateTilePriorities( |
1068 ACTIVE_TREE, | 1065 ACTIVE_TREE, |
1069 gfx::Rect(layer_bounds), // visible content rect | 1066 gfx::Rect(layer_bounds), // visible content rect |
1070 1.f, // current contents scale | 1067 1.f, // current contents scale |
1071 1.0, // current frame time | 1068 1.0, // current frame time |
1072 NULL, // occlusion tracker | 1069 NULL, // occlusion tracker |
1073 NULL, // render target | 1070 NULL, // render target |
1074 gfx::Transform()); // draw transform | 1071 gfx::Transform()); // draw transform |
1072 tiling_->CreateAllTilesForTesting(); | |
1075 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1073 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1076 | |
1077 // Make the viewport rect empty. All tiles are killed and become zombies. | |
1078 tiling_->UpdateTilePriorities(ACTIVE_TREE, | |
1079 gfx::Rect(), // visible content rect | |
1080 1.f, // current contents scale | |
1081 2.0, // current frame time | |
1082 NULL, // occlusion tracker | |
1083 NULL, // render target | |
1084 gfx::Transform()); // draw transform | |
1085 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1086 } | 1074 } |
1087 | 1075 |
1088 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 1076 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
1089 gfx::Size layer_bounds(1099, 801); | 1077 gfx::Size layer_bounds(1099, 801); |
1090 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1078 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
1091 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1079 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
1092 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1080 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
1093 | 1081 |
1094 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 1082 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
1095 | 1083 |
1096 tiling_->UpdateTilePriorities( | 1084 tiling_->UpdateTilePriorities( |
1097 ACTIVE_TREE, | 1085 ACTIVE_TREE, |
1098 gfx::Rect(layer_bounds), // visible content rect | 1086 gfx::Rect(layer_bounds), // visible content rect |
1099 1.f, // current contents scale | 1087 1.f, // current contents scale |
1100 1.0, // current frame time | 1088 1.0, // current frame time |
1101 NULL, // occlusion tracker | 1089 NULL, // occlusion tracker |
1102 NULL, // render target | 1090 NULL, // render target |
1103 gfx::Transform()); // draw transform | 1091 gfx::Transform()); // draw transform |
1092 tiling_->CreateAllTilesForTesting(); | |
1104 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1093 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1105 | 1094 |
1106 // If the visible content rect is empty, it should still have live tiles. | 1095 // If the visible content rect is empty, it should still have live tiles. |
1107 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1096 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1108 giant_rect, // visible content rect | 1097 giant_rect, // visible content rect |
1109 1.f, // current contents scale | 1098 1.f, // current contents scale |
1110 2.0, // current frame time | 1099 2.0, // current frame time |
1111 NULL, // occlusion tracker | 1100 NULL, // occlusion tracker |
1112 NULL, // render target | 1101 NULL, // render target |
1113 gfx::Transform()); // draw transform | 1102 gfx::Transform()); // draw transform |
(...skipping 11 matching lines...) Expand all Loading... | |
1125 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 1114 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
1126 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 1115 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
1127 | 1116 |
1128 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1117 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1129 viewport_rect, // visible content rect | 1118 viewport_rect, // visible content rect |
1130 1.f, // current contents scale | 1119 1.f, // current contents scale |
1131 1.0, // current frame time | 1120 1.0, // current frame time |
1132 NULL, // occlusion tracker | 1121 NULL, // occlusion tracker |
1133 NULL, // render target | 1122 NULL, // render target |
1134 gfx::Transform()); // draw transform | 1123 gfx::Transform()); // draw transform |
1124 tiling_->CreateAllTilesForTesting(); | |
1135 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 1125 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
1136 } | 1126 } |
1137 | 1127 |
1138 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 1128 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
1139 bool intersect_exists, | 1129 bool intersect_exists, |
1140 Tile* tile, | 1130 Tile* tile, |
1141 const gfx::Rect& geometry_rect) { | 1131 const gfx::Rect& geometry_rect) { |
1142 bool intersects = rect.Intersects(geometry_rect); | 1132 bool intersects = rect.Intersects(geometry_rect); |
1143 bool expected_exists = intersect_exists ? intersects : !intersects; | 1133 bool expected_exists = intersect_exists ? intersects : !intersects; |
1144 EXPECT_EQ(expected_exists, tile != NULL) | 1134 EXPECT_EQ(expected_exists, tile != NULL) |
(...skipping 11 matching lines...) Expand all Loading... | |
1156 gfx::Rect visible_rect(8000, 8000, 50, 50); | 1146 gfx::Rect visible_rect(8000, 8000, 50, 50); |
1157 | 1147 |
1158 set_max_tiles_for_interest_area(1); | 1148 set_max_tiles_for_interest_area(1); |
1159 tiling_->UpdateTilePriorities(ACTIVE_TREE, | 1149 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
1160 visible_rect, // visible content rect | 1150 visible_rect, // visible content rect |
1161 1.f, // current contents scale | 1151 1.f, // current contents scale |
1162 1.0, // current frame time | 1152 1.0, // current frame time |
1163 NULL, // occlusion tracker | 1153 NULL, // occlusion tracker |
1164 NULL, // render target | 1154 NULL, // render target |
1165 gfx::Transform()); // draw transform | 1155 gfx::Transform()); // draw transform |
1156 tiling_->CreateInterestRectTilesForTesting(); | |
1166 VerifyTiles(1.f, | 1157 VerifyTiles(1.f, |
1167 gfx::Rect(layer_bounds), | 1158 gfx::Rect(layer_bounds), |
1168 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 1159 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
1169 } | 1160 } |
1170 | 1161 |
1171 static void CountExistingTiles(int *count, | 1162 static void CountExistingTiles(int* count, |
1172 Tile* tile, | 1163 Tile* tile, |
1173 const gfx::Rect& geometry_rect) { | 1164 const gfx::Rect& geometry_rect) { |
1174 if (tile != NULL) | 1165 if (tile != NULL) |
1175 ++(*count); | 1166 ++(*count); |
1176 } | 1167 } |
1177 | 1168 |
1178 TEST_F(PictureLayerTilingIteratorTest, | 1169 TEST_F(PictureLayerTilingIteratorTest, |
1179 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 1170 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
1180 gfx::Size layer_bounds(10000, 10000); | 1171 gfx::Size layer_bounds(10000, 10000); |
1181 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 1172 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
(...skipping 29 matching lines...) Expand all Loading... | |
1211 PictureLayerTilingSet active_set(&client_, layer_bounds); | 1202 PictureLayerTilingSet active_set(&client_, layer_bounds); |
1212 | 1203 |
1213 active_set.AddTiling(1.f); | 1204 active_set.AddTiling(1.f); |
1214 | 1205 |
1215 VerifyTiles(active_set.tiling_at(0), | 1206 VerifyTiles(active_set.tiling_at(0), |
1216 1.f, | 1207 1.f, |
1217 gfx::Rect(layer_bounds), | 1208 gfx::Rect(layer_bounds), |
1218 base::Bind(&TileExists, false)); | 1209 base::Bind(&TileExists, false)); |
1219 | 1210 |
1220 UpdateAllTilePriorities(&active_set, | 1211 UpdateAllTilePriorities(&active_set, |
1221 PENDING_TREE, | 1212 ACTIVE_TREE, |
1222 gfx::Rect(layer_bounds), // visible content rect | 1213 gfx::Rect(layer_bounds), // visible content rect |
1223 1.f, // current contents scale | 1214 1.f, // current contents scale |
1224 1.0); // current frame time | 1215 1.0); // current frame time |
1216 CreateAllTiles(&active_set); | |
1225 | 1217 |
1226 // The active tiling has tiles now. | 1218 // The active tiling has tiles now. |
1227 VerifyTiles(active_set.tiling_at(0), | 1219 VerifyTiles(active_set.tiling_at(0), |
1228 1.f, | 1220 1.f, |
1229 gfx::Rect(layer_bounds), | 1221 gfx::Rect(layer_bounds), |
1230 base::Bind(&TileExists, true)); | 1222 base::Bind(&TileExists, true)); |
1231 | 1223 |
1232 // Add the same tilings to the pending set. | 1224 // Add the same tilings to the pending set. |
1233 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 1225 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
1234 Region invalidation; | 1226 Region invalidation; |
1235 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 1227 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
1236 | 1228 |
1237 // The pending tiling starts with no tiles. | 1229 // The pending tiling starts with no tiles. |
1238 VerifyTiles(pending_set.tiling_at(0), | 1230 VerifyTiles(pending_set.tiling_at(0), |
1239 1.f, | 1231 1.f, |
1240 gfx::Rect(layer_bounds), | 1232 gfx::Rect(layer_bounds), |
1241 base::Bind(&TileExists, false)); | 1233 base::Bind(&TileExists, false)); |
1242 | 1234 |
1243 // UpdateTilePriorities on the pending tiling at the same frame time. The | 1235 // UpdateTilePriorities on the pending tiling at the same frame time. The |
1244 // pending tiling should get tiles. | 1236 // pending tiling should get tiles. |
1245 UpdateAllTilePriorities(&pending_set, | 1237 UpdateAllTilePriorities(&pending_set, |
1246 PENDING_TREE, | 1238 PENDING_TREE, |
1247 gfx::Rect(layer_bounds), // visible content rect | 1239 gfx::Rect(layer_bounds), // visible content rect |
1248 1.f, // current contents scale | 1240 1.f, // current contents scale |
1249 1.0); // current frame time | 1241 1.0); // current frame time |
1242 CreateAllTiles(&pending_set); | |
1250 | 1243 |
1251 VerifyTiles(pending_set.tiling_at(0), | 1244 VerifyTiles(pending_set.tiling_at(0), |
1252 1.f, | 1245 1.f, |
1253 gfx::Rect(layer_bounds), | 1246 gfx::Rect(layer_bounds), |
1254 base::Bind(&TileExists, true)); | 1247 base::Bind(&TileExists, true)); |
1255 } | 1248 } |
1256 | 1249 |
1257 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 1250 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
1258 // The TilePriority of visible tiles should have zero distance_to_visible | 1251 // The TilePriority of visible tiles should have zero distance_to_visible |
1259 // and time_to_visible. | 1252 // and time_to_visible. |
1260 | 1253 |
1261 FakePictureLayerTilingClient client; | 1254 FakePictureLayerTilingClient client; |
1262 scoped_ptr<TestablePictureLayerTiling> tiling; | 1255 scoped_ptr<TestablePictureLayerTiling> tiling; |
1263 | 1256 |
1264 gfx::Size device_viewport(800, 600); | 1257 gfx::Size device_viewport(800, 600); |
1265 gfx::Size last_layer_bounds(200, 200); | 1258 gfx::Size last_layer_bounds(200, 200); |
1266 gfx::Size current_layer_bounds(200, 200); | 1259 gfx::Size current_layer_bounds(200, 200); |
1267 float current_layer_contents_scale = 1.f; | 1260 float current_layer_contents_scale = 1.f; |
1268 gfx::Transform current_screen_transform; | 1261 gfx::Transform current_screen_transform; |
1269 double current_frame_time_in_seconds = 1.0; | 1262 double current_frame_time_in_seconds = 1.0; |
1270 | 1263 |
1271 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1264 gfx::Rect viewport_in_layer_space = |
1272 current_screen_transform, device_viewport); | 1265 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1273 | 1266 |
1274 client.SetTileSize(gfx::Size(100, 100)); | 1267 client.SetTileSize(gfx::Size(100, 100)); |
1275 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1268 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1276 current_layer_bounds, | 1269 current_layer_bounds, |
1277 &client); | 1270 &client); |
1278 | 1271 |
1279 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1272 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1280 viewport_in_layer_space, | 1273 viewport_in_layer_space, |
1281 current_layer_contents_scale, | 1274 current_layer_contents_scale, |
1282 current_frame_time_in_seconds, | 1275 current_frame_time_in_seconds, |
1283 NULL, // occlusion tracker | 1276 NULL, // occlusion tracker |
1284 NULL, // render target | 1277 NULL, // render target |
1285 gfx::Transform()); // draw transform | 1278 gfx::Transform()); // draw transform |
1279 tiling->CreateInterestRectTilesForTesting(); | |
1286 | 1280 |
1287 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1281 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1288 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1282 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1289 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1283 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1290 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1284 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1291 | 1285 |
1292 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1286 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1293 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1287 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1294 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1288 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1295 | 1289 |
1296 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1290 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1297 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1291 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1298 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1292 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1299 | 1293 |
1300 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1294 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1301 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1295 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1302 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1296 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1303 | 1297 |
1304 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1298 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1305 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1299 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1306 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1300 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1307 } | 1301 } |
1308 | 1302 |
1309 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 1303 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
1310 // The TilePriority of offscreen tiles (without movement) should have nonzero | 1304 // The TilePriority of offscreen tiles (without movement) should have |
1311 // distance_to_visible and infinite time_to_visible. | 1305 // nonzero distance_to_visible and infinite time_to_visible. |
1312 | |
1313 FakePictureLayerTilingClient client; | 1306 FakePictureLayerTilingClient client; |
1314 scoped_ptr<TestablePictureLayerTiling> tiling; | 1307 scoped_ptr<TestablePictureLayerTiling> tiling; |
1315 | 1308 |
1316 gfx::Size device_viewport(800, 600); | 1309 gfx::Size device_viewport(800, 600); |
1317 gfx::Size last_layer_bounds(200, 200); | 1310 gfx::Size last_layer_bounds(200, 200); |
1318 gfx::Size current_layer_bounds(200, 200); | 1311 gfx::Size current_layer_bounds(200, 200); |
1319 float current_layer_contents_scale = 1.f; | 1312 float current_layer_contents_scale = 1.f; |
1320 gfx::Transform last_screen_transform; | 1313 gfx::Transform last_screen_transform; |
1321 gfx::Transform current_screen_transform; | 1314 gfx::Transform current_screen_transform; |
1322 double current_frame_time_in_seconds = 1.0; | 1315 double current_frame_time_in_seconds = 1.0; |
1323 | 1316 |
1324 current_screen_transform.Translate(850, 0); | 1317 current_screen_transform.Translate(850, 0); |
1325 last_screen_transform = current_screen_transform; | 1318 last_screen_transform = current_screen_transform; |
1326 | 1319 |
1327 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1320 gfx::Rect viewport_in_layer_space = |
1328 current_screen_transform, device_viewport); | 1321 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1329 | 1322 |
1330 client.SetTileSize(gfx::Size(100, 100)); | 1323 client.SetTileSize(gfx::Size(100, 100)); |
1331 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1324 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1332 current_layer_bounds, | 1325 current_layer_bounds, |
1333 &client); | 1326 &client); |
1334 | 1327 |
1335 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1328 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1336 viewport_in_layer_space, | 1329 viewport_in_layer_space, |
1337 current_layer_contents_scale, | 1330 current_layer_contents_scale, |
1338 current_frame_time_in_seconds, | 1331 current_frame_time_in_seconds, |
1339 NULL, // occlusion tracker | 1332 NULL, // occlusion tracker |
1340 NULL, // render target | 1333 NULL, // render target |
1341 gfx::Transform()); // draw transform | 1334 gfx::Transform()); // draw transform |
1335 tiling->CreateInterestRectTilesForTesting(); | |
1342 | 1336 |
1343 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1337 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1344 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1338 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1345 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1339 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1346 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1340 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1347 | 1341 |
1348 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1342 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1349 EXPECT_GT(priority.distance_to_visible, 0.f); | 1343 EXPECT_GT(priority.distance_to_visible, 0.f); |
1350 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1344 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1351 | 1345 |
(...skipping 16 matching lines...) Expand all Loading... | |
1368 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1362 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
1369 | 1363 |
1370 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1364 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1371 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1365 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1372 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1366 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
1373 } | 1367 } |
1374 | 1368 |
1375 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 1369 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
1376 // Sanity check that a layer with some tiles visible and others offscreen has | 1370 // Sanity check that a layer with some tiles visible and others offscreen has |
1377 // correct TilePriorities for each tile. | 1371 // correct TilePriorities for each tile. |
1378 | |
1379 FakePictureLayerTilingClient client; | 1372 FakePictureLayerTilingClient client; |
1380 scoped_ptr<TestablePictureLayerTiling> tiling; | 1373 scoped_ptr<TestablePictureLayerTiling> tiling; |
1381 | 1374 |
1382 gfx::Size device_viewport(800, 600); | 1375 gfx::Size device_viewport(800, 600); |
1383 gfx::Size last_layer_bounds(200, 200); | 1376 gfx::Size last_layer_bounds(200, 200); |
1384 gfx::Size current_layer_bounds(200, 200); | 1377 gfx::Size current_layer_bounds(200, 200); |
1385 float current_layer_contents_scale = 1.f; | 1378 float current_layer_contents_scale = 1.f; |
1386 gfx::Transform last_screen_transform; | 1379 gfx::Transform last_screen_transform; |
1387 gfx::Transform current_screen_transform; | 1380 gfx::Transform current_screen_transform; |
1388 double current_frame_time_in_seconds = 1.0; | 1381 double current_frame_time_in_seconds = 1.0; |
1389 | 1382 |
1390 current_screen_transform.Translate(705, 505); | 1383 current_screen_transform.Translate(705, 505); |
1391 last_screen_transform = current_screen_transform; | 1384 last_screen_transform = current_screen_transform; |
1392 | 1385 |
1393 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1386 gfx::Rect viewport_in_layer_space = |
1394 current_screen_transform, device_viewport); | 1387 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1395 | 1388 |
1396 client.SetTileSize(gfx::Size(100, 100)); | 1389 client.SetTileSize(gfx::Size(100, 100)); |
1397 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1390 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1398 current_layer_bounds, | 1391 current_layer_bounds, |
1399 &client); | 1392 &client); |
1400 | 1393 |
1401 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1394 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1402 viewport_in_layer_space, | 1395 viewport_in_layer_space, |
1403 current_layer_contents_scale, | 1396 current_layer_contents_scale, |
1404 current_frame_time_in_seconds, | 1397 current_frame_time_in_seconds, |
1405 NULL, // occlusion tracker | 1398 NULL, // occlusion tracker |
1406 NULL, // render target | 1399 NULL, // render target |
1407 gfx::Transform()); // draw transform | 1400 gfx::Transform()); // draw transform |
1401 tiling->CreateInterestRectTilesForTesting(); | |
1408 | 1402 |
1409 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1403 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1410 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1404 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1411 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1405 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1412 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1406 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1413 | 1407 |
1414 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1408 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1415 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1409 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1416 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1410 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1417 | 1411 |
(...skipping 25 matching lines...) Expand all Loading... | |
1443 gfx::Transform last_screen_transform; | 1437 gfx::Transform last_screen_transform; |
1444 gfx::Transform current_screen_transform; | 1438 gfx::Transform current_screen_transform; |
1445 double current_frame_time_in_seconds = 1.0; | 1439 double current_frame_time_in_seconds = 1.0; |
1446 | 1440 |
1447 // A diagonally rotated layer that is partially off the bottom of the screen. | 1441 // A diagonally rotated layer that is partially off the bottom of the screen. |
1448 // In this configuration, only the top-left tile would be visible. | 1442 // In this configuration, only the top-left tile would be visible. |
1449 current_screen_transform.Translate(600, 750); | 1443 current_screen_transform.Translate(600, 750); |
1450 current_screen_transform.RotateAboutZAxis(45); | 1444 current_screen_transform.RotateAboutZAxis(45); |
1451 last_screen_transform = current_screen_transform; | 1445 last_screen_transform = current_screen_transform; |
1452 | 1446 |
1453 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1447 gfx::Rect viewport_in_layer_space = |
1454 current_screen_transform, device_viewport); | 1448 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1455 | 1449 |
1456 client.SetTileSize(gfx::Size(100, 100)); | 1450 client.SetTileSize(gfx::Size(100, 100)); |
1457 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1451 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1458 current_layer_bounds, | 1452 current_layer_bounds, |
1459 &client); | 1453 &client); |
1460 | 1454 |
1461 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1455 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1462 viewport_in_layer_space, | 1456 viewport_in_layer_space, |
1463 current_layer_contents_scale, | 1457 current_layer_contents_scale, |
1464 current_frame_time_in_seconds, | 1458 current_frame_time_in_seconds, |
1465 NULL, // occlusion tracker | 1459 NULL, // occlusion tracker |
1466 NULL, // render target | 1460 NULL, // render target |
1467 gfx::Transform()); // draw transform | 1461 gfx::Transform()); // draw transform |
1462 tiling->CreateInterestRectTilesForTesting(); | |
1468 | 1463 |
1469 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1464 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1470 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1465 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1471 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1466 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1472 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1467 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1473 | 1468 |
1474 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1469 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1475 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1470 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1476 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1471 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1477 | 1472 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1527 current_screen_transform.Translate(-100.0, -100.0); | 1522 current_screen_transform.Translate(-100.0, -100.0); |
1528 last_screen_transform = current_screen_transform; | 1523 last_screen_transform = current_screen_transform; |
1529 | 1524 |
1530 // Sanity check that this transform wouldn't cause w<0 clipping. | 1525 // Sanity check that this transform wouldn't cause w<0 clipping. |
1531 bool clipped; | 1526 bool clipped; |
1532 MathUtil::MapQuad(current_screen_transform, | 1527 MathUtil::MapQuad(current_screen_transform, |
1533 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), | 1528 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), |
1534 &clipped); | 1529 &clipped); |
1535 ASSERT_FALSE(clipped); | 1530 ASSERT_FALSE(clipped); |
1536 | 1531 |
1537 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1532 gfx::Rect viewport_in_layer_space = |
1538 current_screen_transform, device_viewport); | 1533 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1539 | 1534 |
1540 client.SetTileSize(gfx::Size(100, 100)); | 1535 client.SetTileSize(gfx::Size(100, 100)); |
1541 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1536 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1542 current_layer_bounds, | 1537 current_layer_bounds, |
1543 &client); | 1538 &client); |
1544 | 1539 |
1545 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1540 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1546 viewport_in_layer_space, | 1541 viewport_in_layer_space, |
1547 current_layer_contents_scale, | 1542 current_layer_contents_scale, |
1548 current_frame_time_in_seconds, | 1543 current_frame_time_in_seconds, |
1549 NULL, // occlusion tracker | 1544 NULL, // occlusion tracker |
1550 NULL, // render target | 1545 NULL, // render target |
1551 gfx::Transform()); // draw transform | 1546 gfx::Transform()); // draw transform |
1547 tiling->CreateInterestRectTilesForTesting(); | |
1552 | 1548 |
1553 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1549 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1554 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1550 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1555 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1551 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1556 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1552 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1557 | 1553 |
1558 // All tiles will have a positive distance_to_visible | 1554 // All tiles will have a positive distance_to_visible |
1559 // and an infinite time_to_visible. | 1555 // and an infinite time_to_visible. |
1560 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1556 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1561 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); | 1557 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 MathUtil::MapQuad(current_screen_transform, | 1617 MathUtil::MapQuad(current_screen_transform, |
1622 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), | 1618 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), |
1623 &clipped); | 1619 &clipped); |
1624 ASSERT_TRUE(clipped); | 1620 ASSERT_TRUE(clipped); |
1625 | 1621 |
1626 MathUtil::MapQuad(current_screen_transform, | 1622 MathUtil::MapQuad(current_screen_transform, |
1627 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1623 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), |
1628 &clipped); | 1624 &clipped); |
1629 ASSERT_FALSE(clipped); | 1625 ASSERT_FALSE(clipped); |
1630 | 1626 |
1631 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1627 gfx::Rect viewport_in_layer_space = |
1632 current_screen_transform, device_viewport); | 1628 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1633 | 1629 |
1634 client.SetTileSize(gfx::Size(100, 100)); | 1630 client.SetTileSize(gfx::Size(100, 100)); |
1635 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1631 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1636 current_layer_bounds, | 1632 current_layer_bounds, |
1637 &client); | 1633 &client); |
1638 | 1634 |
1639 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1635 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1640 viewport_in_layer_space, | 1636 viewport_in_layer_space, |
1641 current_layer_contents_scale, | 1637 current_layer_contents_scale, |
1642 current_frame_time_in_seconds, | 1638 current_frame_time_in_seconds, |
1643 NULL, // occlusion tracker | 1639 NULL, // occlusion tracker |
1644 NULL, // render target | 1640 NULL, // render target |
1645 gfx::Transform()); // draw transform | 1641 gfx::Transform()); // draw transform |
1642 tiling->CreateInterestRectTilesForTesting(); | |
1646 | 1643 |
1647 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1644 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1648 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1645 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1649 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1646 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1650 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1647 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1651 | 1648 |
1652 // Left-side tiles will be clipped by the transform, so we have to assume | 1649 // Left-side tiles will be clipped by the transform, so we have to assume |
1653 // they are visible just in case. | 1650 // they are visible just in case. |
1654 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1651 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1655 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1652 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
(...skipping 29 matching lines...) Expand all Loading... | |
1685 float current_layer_contents_scale = 1.f; | 1682 float current_layer_contents_scale = 1.f; |
1686 gfx::Transform last_screen_transform; | 1683 gfx::Transform last_screen_transform; |
1687 gfx::Transform current_screen_transform; | 1684 gfx::Transform current_screen_transform; |
1688 double last_frame_time_in_seconds = 1.0; | 1685 double last_frame_time_in_seconds = 1.0; |
1689 double current_frame_time_in_seconds = 2.0; | 1686 double current_frame_time_in_seconds = 2.0; |
1690 | 1687 |
1691 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1688 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
1692 current_screen_transform.Translate(1800, 0); | 1689 current_screen_transform.Translate(1800, 0); |
1693 last_screen_transform.Translate(2800, 0); | 1690 last_screen_transform.Translate(2800, 0); |
1694 | 1691 |
1695 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1692 gfx::Rect viewport_in_layer_space = |
1696 current_screen_transform, device_viewport); | 1693 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1697 | 1694 |
1698 client.SetTileSize(gfx::Size(100, 100)); | 1695 client.SetTileSize(gfx::Size(100, 100)); |
1699 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1696 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1700 current_layer_bounds, | 1697 current_layer_bounds, |
1701 &client); | 1698 &client); |
1702 | 1699 |
1703 // previous ("last") frame | 1700 // previous ("last") frame |
1704 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1701 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1705 viewport_in_layer_space, | 1702 viewport_in_layer_space, |
1706 last_layer_contents_scale, | 1703 last_layer_contents_scale, |
1707 last_frame_time_in_seconds, | 1704 last_frame_time_in_seconds, |
1708 NULL, // occlusion tracker | 1705 NULL, // occlusion tracker |
1709 NULL, // render target | 1706 NULL, // render target |
1710 gfx::Transform()); // draw transform | 1707 gfx::Transform()); // draw transform |
1711 | 1708 |
1712 // current frame | 1709 // current frame |
1713 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1710 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1714 viewport_in_layer_space, | 1711 viewport_in_layer_space, |
1715 current_layer_contents_scale, | 1712 current_layer_contents_scale, |
1716 current_frame_time_in_seconds, | 1713 current_frame_time_in_seconds, |
1717 NULL, // occlusion tracker | 1714 NULL, // occlusion tracker |
1718 NULL, // render target | 1715 NULL, // render target |
1719 gfx::Transform()); // draw transform | 1716 gfx::Transform()); // draw transform |
1717 tiling->CreateInterestRectTilesForTesting(); | |
1720 | 1718 |
1721 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1719 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1722 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1720 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1723 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1721 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1724 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1722 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1725 | 1723 |
1726 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1724 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1727 EXPECT_GT(priority.distance_to_visible, 0.f); | 1725 EXPECT_GT(priority.distance_to_visible, 0.f); |
1728 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1726 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1729 | 1727 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1766 // - the top-left tile becomes visible on rotation | 1764 // - the top-left tile becomes visible on rotation |
1767 // - the top-right tile will have an infinite time_to_visible | 1765 // - the top-right tile will have an infinite time_to_visible |
1768 // because it is rotating away from viewport. | 1766 // because it is rotating away from viewport. |
1769 // - bottom-left layer will have a positive non-zero time_to_visible | 1767 // - bottom-left layer will have a positive non-zero time_to_visible |
1770 // because it is rotating toward the viewport. | 1768 // because it is rotating toward the viewport. |
1771 current_screen_transform.Translate(400, 550); | 1769 current_screen_transform.Translate(400, 550); |
1772 current_screen_transform.RotateAboutZAxis(45); | 1770 current_screen_transform.RotateAboutZAxis(45); |
1773 | 1771 |
1774 last_screen_transform.Translate(400, 550); | 1772 last_screen_transform.Translate(400, 550); |
1775 | 1773 |
1776 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1774 gfx::Rect viewport_in_layer_space = |
1777 current_screen_transform, device_viewport); | 1775 ViewportInLayerSpace(current_screen_transform, device_viewport); |
1778 | 1776 |
1779 client.SetTileSize(gfx::Size(100, 100)); | 1777 client.SetTileSize(gfx::Size(100, 100)); |
1780 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1778 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1781 current_layer_bounds, | 1779 current_layer_bounds, |
1782 &client); | 1780 &client); |
1783 | 1781 |
1784 // previous ("last") frame | 1782 // previous ("last") frame |
1785 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1783 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1786 viewport_in_layer_space, | 1784 viewport_in_layer_space, |
1787 last_layer_contents_scale, | 1785 last_layer_contents_scale, |
1788 last_frame_time_in_seconds, | 1786 last_frame_time_in_seconds, |
1789 NULL, // occlusion tracker | 1787 NULL, // occlusion tracker |
1790 NULL, // render target | 1788 NULL, // render target |
1791 gfx::Transform()); // draw transform | 1789 gfx::Transform()); // draw transform |
1792 | 1790 |
1793 // current frame | 1791 // current frame |
1794 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1792 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1795 viewport_in_layer_space, | 1793 viewport_in_layer_space, |
1796 current_layer_contents_scale, | 1794 current_layer_contents_scale, |
1797 current_frame_time_in_seconds, | 1795 current_frame_time_in_seconds, |
1798 NULL, // occlusion tracker | 1796 NULL, // occlusion tracker |
1799 NULL, // render target | 1797 NULL, // render target |
1800 gfx::Transform()); // draw transform | 1798 gfx::Transform()); // draw transform |
1799 tiling->CreateInterestRectTilesForTesting(); | |
1801 | 1800 |
1802 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1801 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1803 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1802 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1804 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1803 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1805 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1804 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1806 | 1805 |
1807 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1806 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1808 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1807 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1809 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1808 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1810 | 1809 |
1811 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1810 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1812 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1811 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1813 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1812 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1814 | 1813 |
1815 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1814 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1816 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1815 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1817 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1816 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1818 } | 1817 } |
1819 | 1818 |
1820 } // namespace | 1819 } // namespace |
1821 } // namespace cc | 1820 } // namespace cc |
OLD | NEW |