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" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 | 203 |
204 // Stop creating tiles so that any invalidations are left as holes. | 204 // Stop creating tiles so that any invalidations are left as holes. |
205 client_.set_allow_create_tile(false); | 205 client_.set_allow_create_tile(false); |
206 | 206 |
207 Region invalidation = | 207 Region invalidation = |
208 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 208 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
209 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); | 209 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); |
210 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 210 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
211 } | 211 } |
212 | 212 |
213 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { | |
214 // The tiling has three rows and columns. | |
215 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | |
216 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
217 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
218 | |
219 // The live tiles rect covers the whole tiling. | |
220 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); | |
221 | |
222 // Tiles in the right row and column exist. | |
223 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
224 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
225 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
226 EXPECT_TRUE(tiling_->TileAt(1, 2)); | |
227 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
228 | |
229 // Shrink the live tiles rect to the very edge of the right-most and | |
230 // bottom-most tiles. Their border pixels would still be inside the live | |
231 // tiles rect, but the tiles should not exist just for that. | |
232 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | |
233 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); | |
234 | |
235 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); | |
236 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
237 EXPECT_FALSE(tiling_->TileAt(2, 1)); | |
238 EXPECT_FALSE(tiling_->TileAt(2, 2)); | |
239 EXPECT_FALSE(tiling_->TileAt(1, 2)); | |
240 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
241 | |
242 // Including the bottom row and right column again, should create the tiles. | |
243 SetLiveRectAndVerifyTiles(gfx::Rect(right + 1, bottom + 1)); | |
244 | |
245 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
246 EXPECT_TRUE(tiling_->TileAt(2, 1)); | |
247 EXPECT_TRUE(tiling_->TileAt(2, 2)); | |
248 EXPECT_TRUE(tiling_->TileAt(1, 2)); | |
249 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
250 | |
251 // Shrink the live tiles rect to the very edge of the left-most and | |
252 // top-most tiles. Their border pixels would still be inside the live | |
253 // tiles rect, but the tiles should not exist just for that. | |
254 int left = tiling_->TilingDataForTesting().TileBounds(0, 0).right(); | |
255 int top = tiling_->TilingDataForTesting().TileBounds(0, 0).bottom(); | |
256 | |
257 SetLiveRectAndVerifyTiles(gfx::Rect(left, top, 250 - left, 250 - top)); | |
258 EXPECT_FALSE(tiling_->TileAt(0, 2)); | |
259 EXPECT_FALSE(tiling_->TileAt(0, 1)); | |
260 EXPECT_FALSE(tiling_->TileAt(0, 0)); | |
261 EXPECT_FALSE(tiling_->TileAt(1, 0)); | |
262 EXPECT_FALSE(tiling_->TileAt(2, 0)); | |
263 | |
264 // Including the top row and left column again, should create the tiles. | |
265 SetLiveRectAndVerifyTiles( | |
266 gfx::Rect(left - 1, top - 1, 250 - left, 250 - top)); | |
267 | |
268 EXPECT_TRUE(tiling_->TileAt(0, 2)); | |
269 EXPECT_TRUE(tiling_->TileAt(0, 1)); | |
270 EXPECT_TRUE(tiling_->TileAt(0, 0)); | |
271 EXPECT_TRUE(tiling_->TileAt(1, 0)); | |
272 EXPECT_TRUE(tiling_->TileAt(2, 0)); | |
273 } | |
274 | |
275 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { | |
276 // The tiling has three rows and columns. | |
277 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); | |
278 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | |
279 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | |
280 | |
281 // The live tiles rect covers the whole tiling. | |
282 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); | |
283 | |
284 // All tiles exist. | |
285 for (int i = 0; i < 3; ++i) { | |
286 for (int j = 0; j < 3; ++j) | |
287 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
288 } | |
289 | |
290 // Shrink the live tiles rect, but still cover all the tiles. | |
291 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 249)); | |
292 | |
293 // All tiles still exist. | |
294 for (int i = 0; i < 3; ++i) { | |
295 for (int j = 0; j < 3; ++j) | |
296 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
297 } | |
298 | |
299 // Grow the live tiles rect, but still cover all the same tiles. | |
300 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 250)); | |
301 | |
302 // All tiles still exist. | |
303 for (int i = 0; i < 3; ++i) { | |
304 for (int j = 0; j < 3; ++j) | |
305 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; | |
306 } | |
307 } | |
308 | |
213 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { | 309 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { |
214 // Verifies that a resize with invalidation for newly exposed pixels will | 310 // Verifies that a resize with invalidation for newly exposed pixels will |
215 // deletes tiles that intersect that invalidation. | 311 // deletes tiles that intersect that invalidation. |
216 gfx::Size tile_size(100, 100); | 312 gfx::Size tile_size(100, 100); |
217 gfx::Size original_layer_size(99, 99); | 313 gfx::Size original_layer_size(99, 99); |
218 Initialize(tile_size, 1.f, original_layer_size); | 314 Initialize(tile_size, 1.f, original_layer_size); |
219 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 315 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
220 | 316 |
221 // Tiling only has one tile, since its total size is less than one. | 317 // Tiling only has one tile, since its total size is less than one. |
222 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 318 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 // or EVENTUALLY, with the exception of tiles that are between 0 and 312 | 602 // or EVENTUALLY, with the exception of tiles that are between 0 and 312 |
507 // pixels away from the viewport, which will be in the SOON bin. | 603 // pixels away from the viewport, which will be in the SOON bin. |
508 bool have_now = false; | 604 bool have_now = false; |
509 bool have_eventually = false; | 605 bool have_eventually = false; |
510 bool have_soon = false; | 606 bool have_soon = false; |
511 for (int i = 0; i < 47; ++i) { | 607 for (int i = 0; i < 47; ++i) { |
512 for (int j = 0; j < 47; ++j) { | 608 for (int j = 0; j < 47; ++j) { |
513 Tile* tile = tiling->TileAt(i, j); | 609 Tile* tile = tiling->TileAt(i, j); |
514 TilePriority priority = tile->priority(ACTIVE_TREE); | 610 TilePriority priority = tile->priority(ACTIVE_TREE); |
515 | 611 |
516 if (viewport_in_content_space.Intersects(tile->content_rect())) { | 612 int borders = tiling->TilingDataForTesting().border_texels(); |
danakj
2014/08/26 20:15:18
This test is the only one affected by the include_
| |
613 gfx::Rect tile_content_rect_inside_borders = tile->content_rect(); | |
614 tile_content_rect_inside_borders.Inset(borders, borders); | |
enne (OOO)
2014/08/26 20:20:27
This is not correct for edge tiles. You should as
danakj
2014/08/26 20:28:46
oh right i was trying to go thru Tile* but no need
| |
615 if (viewport_in_content_space.Intersects( | |
616 tile_content_rect_inside_borders)) { | |
517 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 617 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
518 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 618 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
519 have_now = true; | 619 have_now = true; |
520 } else if (soon_rect_in_content_space.Intersects(tile->content_rect())) { | 620 } else if (soon_rect_in_content_space.Intersects( |
621 tile_content_rect_inside_borders)) { | |
521 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); | 622 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); |
522 have_soon = true; | 623 have_soon = true; |
523 } else { | 624 } else { |
524 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | 625 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); |
525 EXPECT_GT(priority.distance_to_visible, 0.f); | 626 EXPECT_GT(priority.distance_to_visible, 0.f); |
526 have_eventually = true; | 627 have_eventually = true; |
527 } | 628 } |
528 } | 629 } |
529 } | 630 } |
530 | 631 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 have_eventually = false; | 675 have_eventually = false; |
575 have_soon = false; | 676 have_soon = false; |
576 | 677 |
577 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | 678 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
578 // some EVENTUALLY tiles. | 679 // some EVENTUALLY tiles. |
579 for (int i = 0; i < 47; ++i) { | 680 for (int i = 0; i < 47; ++i) { |
580 for (int j = 0; j < 47; ++j) { | 681 for (int j = 0; j < 47; ++j) { |
581 Tile* tile = tiling->TileAt(i, j); | 682 Tile* tile = tiling->TileAt(i, j); |
582 TilePriority priority = tile->priority(ACTIVE_TREE); | 683 TilePriority priority = tile->priority(ACTIVE_TREE); |
583 | 684 |
584 if (viewport_in_content_space.Intersects(tile->content_rect())) { | 685 int borders = tiling->TilingDataForTesting().border_texels(); |
686 gfx::Rect tile_content_rect_inside_borders = tile->content_rect(); | |
687 tile_content_rect_inside_borders.Inset(borders, borders); | |
688 if (viewport_in_content_space.Intersects( | |
689 tile_content_rect_inside_borders)) { | |
585 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i | 690 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i |
586 << " j: " << j; | 691 << " j: " << j; |
587 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i | 692 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i |
588 << " j: " << j; | 693 << " j: " << j; |
589 have_now = true; | 694 have_now = true; |
590 } else if (skewport.Intersects(tile->content_rect()) || | 695 } else if (skewport.Intersects(tile_content_rect_inside_borders) || |
591 soon_rect_in_content_space.Intersects(tile->content_rect())) { | 696 soon_rect_in_content_space.Intersects( |
697 tile_content_rect_inside_borders)) { | |
592 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i | 698 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i |
593 << " j: " << j; | 699 << " j: " << j; |
594 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | 700 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i |
595 << " j: " << j; | 701 << " j: " << j; |
596 have_soon = true; | 702 have_soon = true; |
597 } else { | 703 } else { |
598 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) | 704 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) |
599 << "i: " << i << " j: " << j; | 705 << "i: " << i << " j: " << j; |
600 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | 706 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i |
601 << " j: " << j; | 707 << " j: " << j; |
602 have_eventually = true; | 708 have_eventually = true; |
603 } | 709 } |
604 } | 710 } |
605 } | 711 } |
606 | 712 |
607 EXPECT_TRUE(have_now); | 713 EXPECT_TRUE(have_now); |
608 EXPECT_TRUE(have_soon); | 714 EXPECT_TRUE(have_soon); |
609 EXPECT_TRUE(have_eventually); | 715 EXPECT_TRUE(have_eventually); |
610 | 716 |
611 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 717 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
612 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 718 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); |
613 | 719 |
614 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 720 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
615 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | 721 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); |
616 | 722 |
617 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 723 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
618 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 724 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible); |
619 | 725 |
620 // Change the underlying layer scale. | 726 // Change the underlying layer scale. |
621 tiling->UpdateTilePriorities( | 727 tiling->UpdateTilePriorities( |
622 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); | 728 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); |
623 | 729 |
624 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 730 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
625 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); | 731 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); |
626 | 732 |
627 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 733 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
628 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); | 734 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); |
629 | 735 |
630 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 736 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
631 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 737 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible); |
632 | 738 |
633 // Test additional scales. | 739 // Test additional scales. |
634 tiling = TestablePictureLayerTiling::Create(0.2f, layer_bounds, &client); | 740 tiling = TestablePictureLayerTiling::Create(0.2f, layer_bounds, &client); |
635 tiling->UpdateTilePriorities( | 741 tiling->UpdateTilePriorities( |
636 ACTIVE_TREE, viewport, 1.0f, 4.0, NULL, NULL, gfx::Transform()); | 742 ACTIVE_TREE, viewport, 1.0f, 4.0, NULL, NULL, gfx::Transform()); |
637 | 743 |
638 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 744 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
639 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); | 745 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); |
640 | 746 |
641 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 747 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); | 2049 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); |
1944 it != tiles.end(); | 2050 it != tiles.end(); |
1945 ++it) { | 2051 ++it) { |
1946 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); | 2052 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); |
1947 } | 2053 } |
1948 tiles.clear(); | 2054 tiles.clear(); |
1949 } | 2055 } |
1950 | 2056 |
1951 } // namespace | 2057 } // namespace |
1952 } // namespace cc | 2058 } // namespace cc |
OLD | NEW |