| 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/fake_picture_pile_impl.h" |
| 15 #include "cc/test/test_context_provider.h" | 16 #include "cc/test/test_context_provider.h" |
| 16 #include "cc/test/test_shared_bitmap_manager.h" | 17 #include "cc/test/test_shared_bitmap_manager.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gfx/geometry/quad_f.h" | 19 #include "ui/gfx/geometry/quad_f.h" |
| 19 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
| 20 #include "ui/gfx/geometry/size_conversions.h" | 21 #include "ui/gfx/geometry/size_conversions.h" |
| 21 | 22 |
| 22 namespace cc { | 23 namespace cc { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 return ToEnclosingRect(viewport_in_layer_space); | 36 return ToEnclosingRect(viewport_in_layer_space); |
| 36 } | 37 } |
| 37 | 38 |
| 38 class TestablePictureLayerTiling : public PictureLayerTiling { | 39 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 39 public: | 40 public: |
| 40 using PictureLayerTiling::SetLiveTilesRect; | 41 using PictureLayerTiling::SetLiveTilesRect; |
| 41 using PictureLayerTiling::TileAt; | 42 using PictureLayerTiling::TileAt; |
| 42 | 43 |
| 43 static scoped_ptr<TestablePictureLayerTiling> Create( | 44 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 44 float contents_scale, | 45 float contents_scale, |
| 45 const gfx::Size& layer_bounds, | 46 scoped_refptr<RasterSource> raster_source, |
| 46 PictureLayerTilingClient* client, | 47 PictureLayerTilingClient* client, |
| 47 const LayerTreeSettings& settings) { | 48 const LayerTreeSettings& settings) { |
| 48 return make_scoped_ptr(new TestablePictureLayerTiling( | 49 return make_scoped_ptr(new TestablePictureLayerTiling( |
| 49 contents_scale, layer_bounds, client, | 50 contents_scale, raster_source, client, |
| 50 settings.max_tiles_for_interest_area, | 51 settings.max_tiles_for_interest_area, |
| 51 settings.skewport_target_time_in_seconds, | 52 settings.skewport_target_time_in_seconds, |
| 52 settings.skewport_extrapolation_limit_in_content_pixels)); | 53 settings.skewport_extrapolation_limit_in_content_pixels)); |
| 53 } | 54 } |
| 54 | 55 |
| 55 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 56 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 56 | 57 |
| 57 using PictureLayerTiling::ComputeSkewport; | 58 using PictureLayerTiling::ComputeSkewport; |
| 58 using PictureLayerTiling::RemoveTileAt; | 59 using PictureLayerTiling::RemoveTileAt; |
| 59 | 60 |
| 60 protected: | 61 protected: |
| 61 TestablePictureLayerTiling(float contents_scale, | 62 TestablePictureLayerTiling(float contents_scale, |
| 62 const gfx::Size& layer_bounds, | 63 scoped_refptr<RasterSource> raster_source, |
| 63 PictureLayerTilingClient* client, | 64 PictureLayerTilingClient* client, |
| 64 size_t max_tiles_for_interest_area, | 65 size_t max_tiles_for_interest_area, |
| 65 float skewport_target_time, | 66 float skewport_target_time, |
| 66 int skewport_extrapolation_limit) | 67 int skewport_extrapolation_limit) |
| 67 : PictureLayerTiling(contents_scale, | 68 : PictureLayerTiling(contents_scale, |
| 68 layer_bounds, | 69 raster_source, |
| 69 client, | 70 client, |
| 70 max_tiles_for_interest_area, | 71 max_tiles_for_interest_area, |
| 71 skewport_target_time, | 72 skewport_target_time, |
| 72 skewport_extrapolation_limit) {} | 73 skewport_extrapolation_limit) {} |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 class PictureLayerTilingIteratorTest : public testing::Test { | 76 class PictureLayerTilingIteratorTest : public testing::Test { |
| 76 public: | 77 public: |
| 77 PictureLayerTilingIteratorTest() {} | 78 PictureLayerTilingIteratorTest() {} |
| 78 virtual ~PictureLayerTilingIteratorTest() {} | 79 virtual ~PictureLayerTilingIteratorTest() {} |
| 79 | 80 |
| 80 void Initialize(const gfx::Size& tile_size, | 81 void Initialize(const gfx::Size& tile_size, |
| 81 float contents_scale, | 82 float contents_scale, |
| 82 const gfx::Size& layer_bounds) { | 83 const gfx::Size& layer_bounds) { |
| 83 client_.SetTileSize(tile_size); | 84 client_.SetTileSize(tile_size); |
| 84 client_.set_tree(PENDING_TREE); | 85 client_.set_tree(PENDING_TREE); |
| 85 tiling_ = TestablePictureLayerTiling::Create(contents_scale, layer_bounds, | 86 scoped_refptr<FakePicturePileImpl> pile = |
| 86 &client_, LayerTreeSettings()); | 87 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 88 tiling_ = TestablePictureLayerTiling::Create(contents_scale, pile, &client_, |
| 89 LayerTreeSettings()); |
| 87 } | 90 } |
| 88 | 91 |
| 89 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { | 92 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { |
| 90 tiling_->SetLiveTilesRect(live_tiles_rect); | 93 tiling_->SetLiveTilesRect(live_tiles_rect); |
| 91 | 94 |
| 92 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 95 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
| 93 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 96 for (std::vector<Tile*>::iterator iter = tiles.begin(); |
| 94 iter != tiles.end(); | 97 iter != tiles.end(); |
| 95 ++iter) { | 98 ++iter) { |
| 96 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 99 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // deletes tiles that intersect that invalidation. | 191 // deletes tiles that intersect that invalidation. |
| 189 gfx::Size tile_size(100, 100); | 192 gfx::Size tile_size(100, 100); |
| 190 gfx::Size original_layer_size(10, 10); | 193 gfx::Size original_layer_size(10, 10); |
| 191 Initialize(tile_size, 1.f, original_layer_size); | 194 Initialize(tile_size, 1.f, original_layer_size); |
| 192 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 195 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
| 193 | 196 |
| 194 // Tiling only has one tile, since its total size is less than one. | 197 // Tiling only has one tile, since its total size is less than one. |
| 195 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 198 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 196 | 199 |
| 197 // Stop creating tiles so that any invalidations are left as holes. | 200 // Stop creating tiles so that any invalidations are left as holes. |
| 198 client_.set_allow_create_tile(false); | 201 gfx::Size new_layer_size(200, 200); |
| 202 scoped_refptr<FakePicturePileImpl> pile = |
| 203 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size); |
| 199 | 204 |
| 200 Region invalidation = | 205 Region invalidation = |
| 201 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 206 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
| 202 tiling_->Resize(gfx::Size(200, 200)); | 207 tiling_->SetRasterSourceAndResize(pile); |
| 203 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 208 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 204 tiling_->Invalidate(invalidation); | 209 tiling_->Invalidate(invalidation); |
| 205 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 210 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
| 206 } | 211 } |
| 207 | 212 |
| 208 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { | 213 TEST_F(PictureLayerTilingIteratorTest, CreateMissingTilesStaysInsideLiveRect) { |
| 209 // The tiling has three rows and columns. | 214 // The tiling has three rows and columns. |
| 210 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 250)); | 215 Initialize(gfx::Size(100, 100), 1.f, gfx::Size(250, 250)); |
| 211 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 216 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 212 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 217 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 EXPECT_TRUE(tiling_->TileAt(2, 2)); | 253 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
| 249 EXPECT_TRUE(tiling_->TileAt(2, 3)); | 254 EXPECT_TRUE(tiling_->TileAt(2, 3)); |
| 250 EXPECT_TRUE(tiling_->TileAt(1, 3)); | 255 EXPECT_TRUE(tiling_->TileAt(1, 3)); |
| 251 EXPECT_TRUE(tiling_->TileAt(0, 3)); | 256 EXPECT_TRUE(tiling_->TileAt(0, 3)); |
| 252 | 257 |
| 253 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); | 258 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); |
| 254 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); | 259 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 3).y(); |
| 255 | 260 |
| 256 // Shrink the tiling so that the last tile row/column is entirely in the | 261 // Shrink the tiling so that the last tile row/column is entirely in the |
| 257 // border pixels of the interior tiles. That row/column is removed. | 262 // border pixels of the interior tiles. That row/column is removed. |
| 258 tiling_->Resize(gfx::Size(right + 1, bottom + 1)); | 263 scoped_refptr<FakePicturePileImpl> pile = |
| 264 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 265 gfx::Size(right + 1, bottom + 1)); |
| 266 tiling_->SetRasterSourceAndResize(pile); |
| 259 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); | 267 EXPECT_EQ(2, tiling_->TilingDataForTesting().num_tiles_x()); |
| 260 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); | 268 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| 261 | 269 |
| 262 // The live tiles rect was clamped to the pile size. | 270 // The live tiles rect was clamped to the pile size. |
| 263 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 271 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
| 264 | 272 |
| 265 // Since the row/column is gone, the tiles should be gone too. | 273 // Since the row/column is gone, the tiles should be gone too. |
| 266 EXPECT_FALSE(tiling_->TileAt(2, 0)); | 274 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
| 267 EXPECT_FALSE(tiling_->TileAt(2, 1)); | 275 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
| 268 EXPECT_FALSE(tiling_->TileAt(2, 2)); | 276 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
| 269 EXPECT_FALSE(tiling_->TileAt(2, 3)); | 277 EXPECT_FALSE(tiling_->TileAt(2, 3)); |
| 270 EXPECT_FALSE(tiling_->TileAt(1, 3)); | 278 EXPECT_FALSE(tiling_->TileAt(1, 3)); |
| 271 EXPECT_FALSE(tiling_->TileAt(0, 3)); | 279 EXPECT_FALSE(tiling_->TileAt(0, 3)); |
| 272 | 280 |
| 273 // Growing outside the current right/bottom tiles border pixels should create | 281 // Growing outside the current right/bottom tiles border pixels should create |
| 274 // the tiles again, even though the live rect has not changed size. | 282 // the tiles again, even though the live rect has not changed size. |
| 275 tiling_->Resize(gfx::Size(right + 2, bottom + 2)); | 283 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 284 gfx::Size(right + 2, bottom + 2)); |
| 285 tiling_->SetRasterSourceAndResize(pile); |
| 276 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); | 286 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 277 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); | 287 EXPECT_EQ(4, tiling_->TilingDataForTesting().num_tiles_y()); |
| 278 | 288 |
| 279 // Not changed. | 289 // Not changed. |
| 280 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); | 290 EXPECT_EQ(gfx::Rect(right + 1, bottom + 1), tiling_->live_tiles_rect()); |
| 281 | 291 |
| 282 // The last row/column tiles are inside the live tiles rect. | 292 // The last row/column tiles are inside the live tiles rect. |
| 283 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 293 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
| 284 tiling_->TilingDataForTesting().TileBounds(2, 0))); | 294 tiling_->TilingDataForTesting().TileBounds(2, 0))); |
| 285 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( | 295 EXPECT_TRUE(gfx::Rect(right + 1, bottom + 1).Intersects( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // deletes tiles that intersect that invalidation. | 407 // deletes tiles that intersect that invalidation. |
| 398 gfx::Size tile_size(100, 100); | 408 gfx::Size tile_size(100, 100); |
| 399 gfx::Size original_layer_size(99, 99); | 409 gfx::Size original_layer_size(99, 99); |
| 400 Initialize(tile_size, 1.f, original_layer_size); | 410 Initialize(tile_size, 1.f, original_layer_size); |
| 401 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 411 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
| 402 | 412 |
| 403 // Tiling only has one tile, since its total size is less than one. | 413 // Tiling only has one tile, since its total size is less than one. |
| 404 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 414 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 405 | 415 |
| 406 // Stop creating tiles so that any invalidations are left as holes. | 416 // Stop creating tiles so that any invalidations are left as holes. |
| 407 client_.set_allow_create_tile(false); | 417 scoped_refptr<FakePicturePileImpl> pile = |
| 418 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize( |
| 419 gfx::Size(200, 200)); |
| 420 tiling_->SetRasterSourceAndResize(pile); |
| 408 | 421 |
| 409 Region invalidation = | 422 Region invalidation = |
| 410 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 423 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
| 411 tiling_->Resize(gfx::Size(200, 200)); | |
| 412 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 424 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 413 tiling_->Invalidate(invalidation); | 425 tiling_->Invalidate(invalidation); |
| 414 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 426 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
| 415 | 427 |
| 416 // The original tile was the same size after resize, but it would include new | 428 // The original tile was the same size after resize, but it would include new |
| 417 // border pixels. | 429 // border pixels. |
| 418 EXPECT_EQ(gfx::Rect(original_layer_size), | 430 EXPECT_EQ(gfx::Rect(original_layer_size), |
| 419 tiling_->TilingDataForTesting().TileBounds(0, 0)); | 431 tiling_->TilingDataForTesting().TileBounds(0, 0)); |
| 420 } | 432 } |
| 421 | 433 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 528 |
| 517 // Partially covering content, but too large | 529 // Partially covering content, but too large |
| 518 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); | 530 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); |
| 519 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | 531 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); |
| 520 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | 532 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); |
| 521 } | 533 } |
| 522 | 534 |
| 523 TEST(PictureLayerTilingTest, SkewportLimits) { | 535 TEST(PictureLayerTilingTest, SkewportLimits) { |
| 524 FakePictureLayerTilingClient client; | 536 FakePictureLayerTilingClient client; |
| 525 client.set_tree(ACTIVE_TREE); | 537 client.set_tree(ACTIVE_TREE); |
| 526 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 527 | 538 |
| 528 gfx::Rect viewport(0, 0, 100, 100); | 539 gfx::Rect viewport(0, 0, 100, 100); |
| 529 gfx::Size layer_bounds(200, 200); | 540 gfx::Size layer_bounds(200, 200); |
| 530 | 541 |
| 531 client.SetTileSize(gfx::Size(100, 100)); | 542 client.SetTileSize(gfx::Size(100, 100)); |
| 532 LayerTreeSettings settings; | 543 LayerTreeSettings settings; |
| 533 settings.max_tiles_for_interest_area = 10000; | 544 settings.max_tiles_for_interest_area = 10000; |
| 534 settings.skewport_extrapolation_limit_in_content_pixels = 75; | 545 settings.skewport_extrapolation_limit_in_content_pixels = 75; |
| 535 tiling = | 546 |
| 536 TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client, settings); | 547 scoped_refptr<FakePicturePileImpl> pile = |
| 548 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 549 auto tiling = |
| 550 TestablePictureLayerTiling::Create(1.0f, pile, &client, settings); |
| 537 | 551 |
| 538 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | 552 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); |
| 539 | 553 |
| 540 // Move viewport down 50 pixels in 0.5 seconds. | 554 // Move viewport down 50 pixels in 0.5 seconds. |
| 541 gfx::Rect down_skewport = | 555 gfx::Rect down_skewport = |
| 542 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | 556 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); |
| 543 | 557 |
| 544 EXPECT_EQ(0, down_skewport.x()); | 558 EXPECT_EQ(0, down_skewport.x()); |
| 545 EXPECT_EQ(50, down_skewport.y()); | 559 EXPECT_EQ(50, down_skewport.y()); |
| 546 EXPECT_EQ(100, down_skewport.width()); | 560 EXPECT_EQ(100, down_skewport.width()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 | 599 |
| 586 EXPECT_EQ(-575, big_expand_skewport.x()); | 600 EXPECT_EQ(-575, big_expand_skewport.x()); |
| 587 EXPECT_EQ(-575, big_expand_skewport.y()); | 601 EXPECT_EQ(-575, big_expand_skewport.y()); |
| 588 EXPECT_EQ(1650, big_expand_skewport.width()); | 602 EXPECT_EQ(1650, big_expand_skewport.width()); |
| 589 EXPECT_EQ(1650, big_expand_skewport.height()); | 603 EXPECT_EQ(1650, big_expand_skewport.height()); |
| 590 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); | 604 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); |
| 591 } | 605 } |
| 592 | 606 |
| 593 TEST(PictureLayerTilingTest, ComputeSkewport) { | 607 TEST(PictureLayerTilingTest, ComputeSkewport) { |
| 594 FakePictureLayerTilingClient client; | 608 FakePictureLayerTilingClient client; |
| 595 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 596 | 609 |
| 597 gfx::Rect viewport(0, 0, 100, 100); | 610 gfx::Rect viewport(0, 0, 100, 100); |
| 598 gfx::Size layer_bounds(200, 200); | 611 gfx::Size layer_bounds(200, 200); |
| 599 | 612 |
| 600 client.SetTileSize(gfx::Size(100, 100)); | 613 client.SetTileSize(gfx::Size(100, 100)); |
| 601 client.set_tree(ACTIVE_TREE); | 614 client.set_tree(ACTIVE_TREE); |
| 602 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client, | 615 |
| 603 LayerTreeSettings()); | 616 scoped_refptr<FakePicturePileImpl> pile = |
| 617 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 618 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 619 LayerTreeSettings()); |
| 604 | 620 |
| 605 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | 621 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); |
| 606 | 622 |
| 607 // Move viewport down 50 pixels in 0.5 seconds. | 623 // Move viewport down 50 pixels in 0.5 seconds. |
| 608 gfx::Rect down_skewport = | 624 gfx::Rect down_skewport = |
| 609 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); | 625 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); |
| 610 | 626 |
| 611 EXPECT_EQ(0, down_skewport.x()); | 627 EXPECT_EQ(0, down_skewport.x()); |
| 612 EXPECT_EQ(50, down_skewport.y()); | 628 EXPECT_EQ(50, down_skewport.y()); |
| 613 EXPECT_EQ(100, down_skewport.width()); | 629 EXPECT_EQ(100, down_skewport.width()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); | 661 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); |
| 646 | 662 |
| 647 EXPECT_EQ(-30, expanded_skewport.x()); | 663 EXPECT_EQ(-30, expanded_skewport.x()); |
| 648 EXPECT_EQ(-30, expanded_skewport.y()); | 664 EXPECT_EQ(-30, expanded_skewport.y()); |
| 649 EXPECT_EQ(160, expanded_skewport.width()); | 665 EXPECT_EQ(160, expanded_skewport.width()); |
| 650 EXPECT_EQ(160, expanded_skewport.height()); | 666 EXPECT_EQ(160, expanded_skewport.height()); |
| 651 } | 667 } |
| 652 | 668 |
| 653 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { | 669 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { |
| 654 FakePictureLayerTilingClient client; | 670 FakePictureLayerTilingClient client; |
| 655 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 656 | 671 |
| 657 gfx::Rect viewport(0, 0, 100, 100); | 672 gfx::Rect viewport(0, 0, 100, 100); |
| 658 gfx::Size layer_bounds(1500, 1500); | 673 gfx::Size layer_bounds(1500, 1500); |
| 659 | 674 |
| 660 client.SetTileSize(gfx::Size(10, 10)); | 675 client.SetTileSize(gfx::Size(10, 10)); |
| 661 client.set_tree(ACTIVE_TREE); | 676 client.set_tree(ACTIVE_TREE); |
| 662 LayerTreeSettings settings; | 677 LayerTreeSettings settings; |
| 663 settings.max_tiles_for_interest_area = 10000; | 678 settings.max_tiles_for_interest_area = 10000; |
| 664 | 679 |
| 665 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10. | 680 // Tiling at 0.25 scale: this should create 47x47 tiles of size 10x10. |
| 666 // The reason is that each tile has a one pixel border, so tile at (1, 2) | 681 // The reason is that each tile has a one pixel border, so tile at (1, 2) |
| 667 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at | 682 // for instance begins at (8, 16) pixels. So tile at (46, 46) will begin at |
| 668 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the | 683 // (368, 368) and extend to the end of 1500 * 0.25 = 375 edge of the |
| 669 // tiling. | 684 // tiling. |
| 670 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client, | 685 scoped_refptr<FakePicturePileImpl> pile = |
| 671 settings); | 686 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 687 auto tiling = |
| 688 TestablePictureLayerTiling::Create(0.25f, pile, &client, settings); |
| 672 gfx::Rect viewport_in_content_space = | 689 gfx::Rect viewport_in_content_space = |
| 673 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); | 690 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
| 674 | 691 |
| 675 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); | 692 tiling->ComputeTilePriorityRects(viewport, 1.f, 1.0, Occlusion()); |
| 676 tiling->UpdateAllTilePrioritiesForTesting(); | 693 tiling->UpdateAllTilePrioritiesForTesting(); |
| 677 | 694 |
| 678 gfx::Rect soon_rect = viewport; | 695 gfx::Rect soon_rect = viewport; |
| 679 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 696 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
| 680 gfx::Rect soon_rect_in_content_space = | 697 gfx::Rect soon_rect_in_content_space = |
| 681 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); | 698 gfx::ToEnclosedRect(gfx::ScaleRect(soon_rect, 0.25f)); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 832 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
| 816 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); | 833 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); |
| 817 | 834 |
| 818 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 835 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
| 819 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); | 836 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); |
| 820 | 837 |
| 821 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 838 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
| 822 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible); | 839 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible); |
| 823 | 840 |
| 824 // Test additional scales. | 841 // Test additional scales. |
| 825 tiling = TestablePictureLayerTiling::Create(0.2f, layer_bounds, &client, | 842 tiling = TestablePictureLayerTiling::Create(0.2f, pile, &client, |
| 826 LayerTreeSettings()); | 843 LayerTreeSettings()); |
| 827 tiling->ComputeTilePriorityRects(viewport, 1.0f, 4.0, Occlusion()); | 844 tiling->ComputeTilePriorityRects(viewport, 1.0f, 4.0, Occlusion()); |
| 828 tiling->UpdateAllTilePrioritiesForTesting(); | 845 tiling->UpdateAllTilePrioritiesForTesting(); |
| 829 | 846 |
| 830 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 847 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
| 831 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); | 848 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); |
| 832 | 849 |
| 833 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 850 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
| 834 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible); | 851 EXPECT_FLOAT_EQ(70.f, priority.distance_to_visible); |
| 835 | 852 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 gfx::Rect in(40, 40, 0, 0); | 1083 gfx::Rect in(40, 40, 0, 0); |
| 1067 gfx::Rect bounds(0, 0, 10, 10); | 1084 gfx::Rect bounds(0, 0, 10, 10); |
| 1068 int64 target_area = 400 * 400; | 1085 int64 target_area = 400 * 400; |
| 1069 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 1086 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 1070 in, target_area, bounds, NULL); | 1087 in, target_area, bounds, NULL); |
| 1071 EXPECT_TRUE(out.IsEmpty()); | 1088 EXPECT_TRUE(out.IsEmpty()); |
| 1072 } | 1089 } |
| 1073 | 1090 |
| 1074 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { | 1091 TEST(PictureLayerTilingTest, TilingRasterTileIteratorStaticViewport) { |
| 1075 FakePictureLayerTilingClient client; | 1092 FakePictureLayerTilingClient client; |
| 1076 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1077 | 1093 |
| 1078 gfx::Rect viewport(50, 50, 100, 100); | 1094 gfx::Rect viewport(50, 50, 100, 100); |
| 1079 gfx::Size layer_bounds(800, 800); | 1095 gfx::Size layer_bounds(800, 800); |
| 1080 | 1096 |
| 1081 gfx::Rect soon_rect = viewport; | 1097 gfx::Rect soon_rect = viewport; |
| 1082 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 1098 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
| 1083 | 1099 |
| 1084 client.SetTileSize(gfx::Size(30, 30)); | 1100 client.SetTileSize(gfx::Size(30, 30)); |
| 1085 client.set_tree(ACTIVE_TREE); | 1101 client.set_tree(ACTIVE_TREE); |
| 1086 LayerTreeSettings settings; | 1102 LayerTreeSettings settings; |
| 1087 settings.max_tiles_for_interest_area = 10000; | 1103 settings.max_tiles_for_interest_area = 10000; |
| 1088 | 1104 |
| 1089 tiling = | 1105 scoped_refptr<FakePicturePileImpl> pile = |
| 1090 TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client, settings); | 1106 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 1107 auto tiling = |
| 1108 TestablePictureLayerTiling::Create(1.0f, pile, &client, settings); |
| 1091 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); | 1109 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); |
| 1092 tiling->UpdateAllTilePrioritiesForTesting(); | 1110 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1093 | 1111 |
| 1094 PictureLayerTiling::TilingRasterTileIterator empty_iterator; | 1112 PictureLayerTiling::TilingRasterTileIterator empty_iterator; |
| 1095 EXPECT_FALSE(empty_iterator); | 1113 EXPECT_FALSE(empty_iterator); |
| 1096 | 1114 |
| 1097 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); | 1115 std::vector<Tile*> all_tiles = tiling->AllTilesForTesting(); |
| 1098 | 1116 |
| 1099 // Sanity check. | 1117 // Sanity check. |
| 1100 EXPECT_EQ(841u, all_tiles.size()); | 1118 EXPECT_EQ(841u, all_tiles.size()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 EXPECT_TRUE(have_tiles[TilePriority::NOW]); | 1194 EXPECT_TRUE(have_tiles[TilePriority::NOW]); |
| 1177 EXPECT_TRUE(have_tiles[TilePriority::SOON]); | 1195 EXPECT_TRUE(have_tiles[TilePriority::SOON]); |
| 1178 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); | 1196 EXPECT_TRUE(have_tiles[TilePriority::EVENTUALLY]); |
| 1179 | 1197 |
| 1180 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); | 1198 EXPECT_EQ(unique_tiles.size(), all_tiles.size()); |
| 1181 } | 1199 } |
| 1182 } | 1200 } |
| 1183 | 1201 |
| 1184 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { | 1202 TEST(PictureLayerTilingTest, TilingRasterTileIteratorMovingViewport) { |
| 1185 FakePictureLayerTilingClient client; | 1203 FakePictureLayerTilingClient client; |
| 1186 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1187 | 1204 |
| 1188 gfx::Rect viewport(50, 0, 100, 100); | 1205 gfx::Rect viewport(50, 0, 100, 100); |
| 1189 gfx::Rect moved_viewport(50, 0, 100, 500); | 1206 gfx::Rect moved_viewport(50, 0, 100, 500); |
| 1190 gfx::Size layer_bounds(1000, 1000); | 1207 gfx::Size layer_bounds(1000, 1000); |
| 1191 | 1208 |
| 1192 client.SetTileSize(gfx::Size(30, 30)); | 1209 client.SetTileSize(gfx::Size(30, 30)); |
| 1193 client.set_tree(ACTIVE_TREE); | 1210 client.set_tree(ACTIVE_TREE); |
| 1194 LayerTreeSettings settings; | 1211 LayerTreeSettings settings; |
| 1195 settings.max_tiles_for_interest_area = 10000; | 1212 settings.max_tiles_for_interest_area = 10000; |
| 1196 | 1213 |
| 1197 tiling = | 1214 scoped_refptr<FakePicturePileImpl> pile = |
| 1198 TestablePictureLayerTiling::Create(1.f, layer_bounds, &client, settings); | 1215 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 1216 auto tiling = |
| 1217 TestablePictureLayerTiling::Create(1.f, pile, &client, settings); |
| 1199 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); | 1218 tiling->ComputeTilePriorityRects(viewport, 1.0f, 1.0, Occlusion()); |
| 1200 tiling->ComputeTilePriorityRects(moved_viewport, 1.0f, 2.0, Occlusion()); | 1219 tiling->ComputeTilePriorityRects(moved_viewport, 1.0f, 2.0, Occlusion()); |
| 1201 tiling->UpdateAllTilePrioritiesForTesting(); | 1220 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1202 | 1221 |
| 1203 gfx::Rect soon_rect = moved_viewport; | 1222 gfx::Rect soon_rect = moved_viewport; |
| 1204 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); | 1223 soon_rect.Inset(-312.f, -312.f, -312.f, -312.f); |
| 1205 | 1224 |
| 1206 // There are 3 bins in TilePriority. | 1225 // There are 3 bins in TilePriority. |
| 1207 bool have_tiles[3] = {}; | 1226 bool have_tiles[3] = {}; |
| 1208 Tile* last_tile = NULL; | 1227 Tile* last_tile = NULL; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 } | 1347 } |
| 1329 | 1348 |
| 1330 TEST_F(PictureLayerTilingIteratorTest, | 1349 TEST_F(PictureLayerTilingIteratorTest, |
| 1331 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 1350 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
| 1332 gfx::Size layer_bounds(10000, 10000); | 1351 gfx::Size layer_bounds(10000, 10000); |
| 1333 client_.SetTileSize(gfx::Size(100, 100)); | 1352 client_.SetTileSize(gfx::Size(100, 100)); |
| 1334 client_.set_tree(PENDING_TREE); | 1353 client_.set_tree(PENDING_TREE); |
| 1335 LayerTreeSettings settings; | 1354 LayerTreeSettings settings; |
| 1336 settings.max_tiles_for_interest_area = 1; | 1355 settings.max_tiles_for_interest_area = 1; |
| 1337 | 1356 |
| 1338 tiling_ = | 1357 scoped_refptr<FakePicturePileImpl> pile = |
| 1339 TestablePictureLayerTiling::Create(1.f, layer_bounds, &client_, settings); | 1358 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); |
| 1359 tiling_ = TestablePictureLayerTiling::Create(1.f, pile, &client_, settings); |
| 1340 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 1360 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 1341 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 1361 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 1342 | 1362 |
| 1343 gfx::Rect visible_rect(8000, 8000, 50, 50); | 1363 gfx::Rect visible_rect(8000, 8000, 50, 50); |
| 1344 | 1364 |
| 1345 client_.set_tree(ACTIVE_TREE); | 1365 client_.set_tree(ACTIVE_TREE); |
| 1346 tiling_->ComputeTilePriorityRects(visible_rect, // visible content rect | 1366 tiling_->ComputeTilePriorityRects(visible_rect, // visible content rect |
| 1347 1.f, // current contents scale | 1367 1.f, // current contents scale |
| 1348 1.0, // current frame time | 1368 1.0, // current frame time |
| 1349 Occlusion()); | 1369 Occlusion()); |
| 1350 VerifyTiles(1.f, | 1370 VerifyTiles(1.f, |
| 1351 gfx::Rect(layer_bounds), | 1371 gfx::Rect(layer_bounds), |
| 1352 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 1372 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
| 1353 } | 1373 } |
| 1354 | 1374 |
| 1355 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { | 1375 TEST(ComputeTilePriorityRectsTest, VisibleTiles) { |
| 1356 // The TilePriority of visible tiles should have zero distance_to_visible | 1376 // The TilePriority of visible tiles should have zero distance_to_visible |
| 1357 // and time_to_visible. | 1377 // and time_to_visible. |
| 1358 | |
| 1359 FakePictureLayerTilingClient client; | 1378 FakePictureLayerTilingClient client; |
| 1360 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1361 | 1379 |
| 1362 gfx::Size device_viewport(800, 600); | 1380 gfx::Size device_viewport(800, 600); |
| 1363 gfx::Size last_layer_bounds(200, 200); | 1381 gfx::Size last_layer_bounds(200, 200); |
| 1364 gfx::Size current_layer_bounds(200, 200); | 1382 gfx::Size current_layer_bounds(200, 200); |
| 1365 float current_layer_contents_scale = 1.f; | 1383 float current_layer_contents_scale = 1.f; |
| 1366 gfx::Transform current_screen_transform; | 1384 gfx::Transform current_screen_transform; |
| 1367 double current_frame_time_in_seconds = 1.0; | 1385 double current_frame_time_in_seconds = 1.0; |
| 1368 | 1386 |
| 1369 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1387 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1370 current_screen_transform, device_viewport); | 1388 current_screen_transform, device_viewport); |
| 1371 | 1389 |
| 1372 client.SetTileSize(gfx::Size(100, 100)); | 1390 client.SetTileSize(gfx::Size(100, 100)); |
| 1373 client.set_tree(ACTIVE_TREE); | 1391 client.set_tree(ACTIVE_TREE); |
| 1374 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1392 |
| 1375 current_layer_bounds, &client, | 1393 scoped_refptr<FakePicturePileImpl> pile = |
| 1376 LayerTreeSettings()); | 1394 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1395 current_layer_bounds); |
| 1396 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1397 LayerTreeSettings()); |
| 1377 | 1398 |
| 1378 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1399 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1379 current_layer_contents_scale, | 1400 current_layer_contents_scale, |
| 1380 current_frame_time_in_seconds, Occlusion()); | 1401 current_frame_time_in_seconds, Occlusion()); |
| 1381 tiling->UpdateAllTilePrioritiesForTesting(); | 1402 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1382 | 1403 |
| 1383 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1404 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1384 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1405 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1385 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1406 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1386 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1407 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1398 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1419 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1399 | 1420 |
| 1400 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1421 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1401 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1422 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1402 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); | 1423 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1403 } | 1424 } |
| 1404 | 1425 |
| 1405 TEST(ComputeTilePriorityRectsTest, OffscreenTiles) { | 1426 TEST(ComputeTilePriorityRectsTest, OffscreenTiles) { |
| 1406 // The TilePriority of offscreen tiles (without movement) should have nonzero | 1427 // The TilePriority of offscreen tiles (without movement) should have nonzero |
| 1407 // distance_to_visible and infinite time_to_visible. | 1428 // distance_to_visible and infinite time_to_visible. |
| 1408 | |
| 1409 FakePictureLayerTilingClient client; | 1429 FakePictureLayerTilingClient client; |
| 1410 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1411 | 1430 |
| 1412 gfx::Size device_viewport(800, 600); | 1431 gfx::Size device_viewport(800, 600); |
| 1413 gfx::Size last_layer_bounds(200, 200); | 1432 gfx::Size last_layer_bounds(200, 200); |
| 1414 gfx::Size current_layer_bounds(200, 200); | 1433 gfx::Size current_layer_bounds(200, 200); |
| 1415 float current_layer_contents_scale = 1.f; | 1434 float current_layer_contents_scale = 1.f; |
| 1416 gfx::Transform last_screen_transform; | 1435 gfx::Transform last_screen_transform; |
| 1417 gfx::Transform current_screen_transform; | 1436 gfx::Transform current_screen_transform; |
| 1418 double current_frame_time_in_seconds = 1.0; | 1437 double current_frame_time_in_seconds = 1.0; |
| 1419 | 1438 |
| 1420 current_screen_transform.Translate(850, 0); | 1439 current_screen_transform.Translate(850, 0); |
| 1421 last_screen_transform = current_screen_transform; | 1440 last_screen_transform = current_screen_transform; |
| 1422 | 1441 |
| 1423 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1442 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1424 current_screen_transform, device_viewport); | 1443 current_screen_transform, device_viewport); |
| 1425 | 1444 |
| 1426 client.SetTileSize(gfx::Size(100, 100)); | 1445 client.SetTileSize(gfx::Size(100, 100)); |
| 1427 client.set_tree(ACTIVE_TREE); | 1446 client.set_tree(ACTIVE_TREE); |
| 1428 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1447 |
| 1429 current_layer_bounds, &client, | 1448 scoped_refptr<FakePicturePileImpl> pile = |
| 1430 LayerTreeSettings()); | 1449 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1450 current_layer_bounds); |
| 1451 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1452 LayerTreeSettings()); |
| 1431 | 1453 |
| 1432 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1454 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1433 current_layer_contents_scale, | 1455 current_layer_contents_scale, |
| 1434 current_frame_time_in_seconds, Occlusion()); | 1456 current_frame_time_in_seconds, Occlusion()); |
| 1435 tiling->UpdateAllTilePrioritiesForTesting(); | 1457 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1436 | 1458 |
| 1437 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1459 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1438 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1460 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1439 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1461 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1440 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1462 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1462 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1484 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
| 1463 | 1485 |
| 1464 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1486 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1465 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1487 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1466 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); | 1488 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
| 1467 } | 1489 } |
| 1468 | 1490 |
| 1469 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenLayer) { | 1491 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenLayer) { |
| 1470 // Sanity check that a layer with some tiles visible and others offscreen has | 1492 // Sanity check that a layer with some tiles visible and others offscreen has |
| 1471 // correct TilePriorities for each tile. | 1493 // correct TilePriorities for each tile. |
| 1472 | |
| 1473 FakePictureLayerTilingClient client; | 1494 FakePictureLayerTilingClient client; |
| 1474 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1475 | 1495 |
| 1476 gfx::Size device_viewport(800, 600); | 1496 gfx::Size device_viewport(800, 600); |
| 1477 gfx::Size last_layer_bounds(200, 200); | 1497 gfx::Size last_layer_bounds(200, 200); |
| 1478 gfx::Size current_layer_bounds(200, 200); | 1498 gfx::Size current_layer_bounds(200, 200); |
| 1479 float current_layer_contents_scale = 1.f; | 1499 float current_layer_contents_scale = 1.f; |
| 1480 gfx::Transform last_screen_transform; | 1500 gfx::Transform last_screen_transform; |
| 1481 gfx::Transform current_screen_transform; | 1501 gfx::Transform current_screen_transform; |
| 1482 double current_frame_time_in_seconds = 1.0; | 1502 double current_frame_time_in_seconds = 1.0; |
| 1483 | 1503 |
| 1484 current_screen_transform.Translate(705, 505); | 1504 current_screen_transform.Translate(705, 505); |
| 1485 last_screen_transform = current_screen_transform; | 1505 last_screen_transform = current_screen_transform; |
| 1486 | 1506 |
| 1487 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1507 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1488 current_screen_transform, device_viewport); | 1508 current_screen_transform, device_viewport); |
| 1489 | 1509 |
| 1490 client.SetTileSize(gfx::Size(100, 100)); | 1510 client.SetTileSize(gfx::Size(100, 100)); |
| 1491 client.set_tree(ACTIVE_TREE); | 1511 client.set_tree(ACTIVE_TREE); |
| 1492 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1512 |
| 1493 current_layer_bounds, &client, | 1513 scoped_refptr<FakePicturePileImpl> pile = |
| 1494 LayerTreeSettings()); | 1514 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1515 current_layer_bounds); |
| 1516 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1517 LayerTreeSettings()); |
| 1495 | 1518 |
| 1496 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1519 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1497 current_layer_contents_scale, | 1520 current_layer_contents_scale, |
| 1498 current_frame_time_in_seconds, Occlusion()); | 1521 current_frame_time_in_seconds, Occlusion()); |
| 1499 tiling->UpdateAllTilePrioritiesForTesting(); | 1522 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1500 | 1523 |
| 1501 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1524 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1502 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1525 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1503 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1526 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1504 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1527 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1517 | 1540 |
| 1518 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1541 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1519 EXPECT_GT(priority.distance_to_visible, 0.f); | 1542 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1520 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1543 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1521 } | 1544 } |
| 1522 | 1545 |
| 1523 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenRotatedLayer) { | 1546 TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenRotatedLayer) { |
| 1524 // Each tile of a layer may be affected differently by a transform; Check | 1547 // Each tile of a layer may be affected differently by a transform; Check |
| 1525 // that ComputeTilePriorityRects correctly accounts for the transform between | 1548 // that ComputeTilePriorityRects correctly accounts for the transform between |
| 1526 // layer space and screen space. | 1549 // layer space and screen space. |
| 1527 | |
| 1528 FakePictureLayerTilingClient client; | 1550 FakePictureLayerTilingClient client; |
| 1529 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1530 | 1551 |
| 1531 gfx::Size device_viewport(800, 600); | 1552 gfx::Size device_viewport(800, 600); |
| 1532 gfx::Size last_layer_bounds(200, 200); | 1553 gfx::Size last_layer_bounds(200, 200); |
| 1533 gfx::Size current_layer_bounds(200, 200); | 1554 gfx::Size current_layer_bounds(200, 200); |
| 1534 float current_layer_contents_scale = 1.f; | 1555 float current_layer_contents_scale = 1.f; |
| 1535 gfx::Transform last_screen_transform; | 1556 gfx::Transform last_screen_transform; |
| 1536 gfx::Transform current_screen_transform; | 1557 gfx::Transform current_screen_transform; |
| 1537 double current_frame_time_in_seconds = 1.0; | 1558 double current_frame_time_in_seconds = 1.0; |
| 1538 | 1559 |
| 1539 // A diagonally rotated layer that is partially off the bottom of the screen. | 1560 // A diagonally rotated layer that is partially off the bottom of the screen. |
| 1540 // In this configuration, only the top-left tile would be visible. | 1561 // In this configuration, only the top-left tile would be visible. |
| 1541 current_screen_transform.Translate(600, 750); | 1562 current_screen_transform.Translate(600, 750); |
| 1542 current_screen_transform.RotateAboutZAxis(45); | 1563 current_screen_transform.RotateAboutZAxis(45); |
| 1543 last_screen_transform = current_screen_transform; | 1564 last_screen_transform = current_screen_transform; |
| 1544 | 1565 |
| 1545 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1566 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1546 current_screen_transform, device_viewport); | 1567 current_screen_transform, device_viewport); |
| 1547 | 1568 |
| 1548 client.SetTileSize(gfx::Size(100, 100)); | 1569 client.SetTileSize(gfx::Size(100, 100)); |
| 1549 client.set_tree(ACTIVE_TREE); | 1570 client.set_tree(ACTIVE_TREE); |
| 1550 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1571 |
| 1551 current_layer_bounds, &client, | 1572 scoped_refptr<FakePicturePileImpl> pile = |
| 1552 LayerTreeSettings()); | 1573 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1574 current_layer_bounds); |
| 1575 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1576 LayerTreeSettings()); |
| 1553 | 1577 |
| 1554 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1578 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1555 current_layer_contents_scale, | 1579 current_layer_contents_scale, |
| 1556 current_frame_time_in_seconds, Occlusion()); | 1580 current_frame_time_in_seconds, Occlusion()); |
| 1557 tiling->UpdateAllTilePrioritiesForTesting(); | 1581 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1558 | 1582 |
| 1559 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1583 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1560 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1584 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1561 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1585 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1562 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1586 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1583 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1607 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1584 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1608 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1585 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible); | 1609 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible); |
| 1586 | 1610 |
| 1587 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); | 1611 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); |
| 1588 } | 1612 } |
| 1589 | 1613 |
| 1590 TEST(ComputeTilePriorityRectsTest, PerspectiveLayer) { | 1614 TEST(ComputeTilePriorityRectsTest, PerspectiveLayer) { |
| 1591 // Perspective transforms need to take a different code path. | 1615 // Perspective transforms need to take a different code path. |
| 1592 // This test checks tile priorities of a perspective layer. | 1616 // This test checks tile priorities of a perspective layer. |
| 1593 | |
| 1594 FakePictureLayerTilingClient client; | 1617 FakePictureLayerTilingClient client; |
| 1595 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1596 | 1618 |
| 1597 gfx::Size device_viewport(800, 600); | 1619 gfx::Size device_viewport(800, 600); |
| 1598 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1620 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1599 gfx::Size last_layer_bounds(200, 200); | 1621 gfx::Size last_layer_bounds(200, 200); |
| 1600 gfx::Size current_layer_bounds(200, 200); | 1622 gfx::Size current_layer_bounds(200, 200); |
| 1601 float current_layer_contents_scale = 1.f; | 1623 float current_layer_contents_scale = 1.f; |
| 1602 gfx::Transform last_screen_transform; | 1624 gfx::Transform last_screen_transform; |
| 1603 gfx::Transform current_screen_transform; | 1625 gfx::Transform current_screen_transform; |
| 1604 double current_frame_time_in_seconds = 1.0; | 1626 double current_frame_time_in_seconds = 1.0; |
| 1605 | 1627 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1622 MathUtil::MapQuad(current_screen_transform, | 1644 MathUtil::MapQuad(current_screen_transform, |
| 1623 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), | 1645 gfx::QuadF(gfx::RectF(0, 0, 200, 200)), |
| 1624 &clipped); | 1646 &clipped); |
| 1625 ASSERT_FALSE(clipped); | 1647 ASSERT_FALSE(clipped); |
| 1626 | 1648 |
| 1627 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1649 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1628 current_screen_transform, device_viewport); | 1650 current_screen_transform, device_viewport); |
| 1629 | 1651 |
| 1630 client.SetTileSize(gfx::Size(100, 100)); | 1652 client.SetTileSize(gfx::Size(100, 100)); |
| 1631 client.set_tree(ACTIVE_TREE); | 1653 client.set_tree(ACTIVE_TREE); |
| 1632 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1654 |
| 1633 current_layer_bounds, &client, | 1655 scoped_refptr<FakePicturePileImpl> pile = |
| 1634 LayerTreeSettings()); | 1656 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1657 current_layer_bounds); |
| 1658 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1659 LayerTreeSettings()); |
| 1635 | 1660 |
| 1636 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1661 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1637 current_layer_contents_scale, | 1662 current_layer_contents_scale, |
| 1638 current_frame_time_in_seconds, Occlusion()); | 1663 current_frame_time_in_seconds, Occlusion()); |
| 1639 tiling->UpdateAllTilePrioritiesForTesting(); | 1664 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1640 | 1665 |
| 1641 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1666 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1642 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1667 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1643 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1668 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1644 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1669 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1670 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1695 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1671 | 1696 |
| 1672 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); | 1697 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); |
| 1673 | 1698 |
| 1674 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); | 1699 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); |
| 1675 } | 1700 } |
| 1676 | 1701 |
| 1677 TEST(ComputeTilePriorityRectsTest, PerspectiveLayerClippedByW) { | 1702 TEST(ComputeTilePriorityRectsTest, PerspectiveLayerClippedByW) { |
| 1678 // Perspective transforms need to take a different code path. | 1703 // Perspective transforms need to take a different code path. |
| 1679 // This test checks tile priorities of a perspective layer. | 1704 // This test checks tile priorities of a perspective layer. |
| 1680 | |
| 1681 FakePictureLayerTilingClient client; | 1705 FakePictureLayerTilingClient client; |
| 1682 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1683 | 1706 |
| 1684 gfx::Size device_viewport(800, 600); | 1707 gfx::Size device_viewport(800, 600); |
| 1685 gfx::Size last_layer_bounds(200, 200); | 1708 gfx::Size last_layer_bounds(200, 200); |
| 1686 gfx::Size current_layer_bounds(200, 200); | 1709 gfx::Size current_layer_bounds(200, 200); |
| 1687 float current_layer_contents_scale = 1.f; | 1710 float current_layer_contents_scale = 1.f; |
| 1688 gfx::Transform last_screen_transform; | 1711 gfx::Transform last_screen_transform; |
| 1689 gfx::Transform current_screen_transform; | 1712 gfx::Transform current_screen_transform; |
| 1690 double current_frame_time_in_seconds = 1.0; | 1713 double current_frame_time_in_seconds = 1.0; |
| 1691 | 1714 |
| 1692 // A 3d perspective layer rotated about its Y axis, translated to almost | 1715 // A 3d perspective layer rotated about its Y axis, translated to almost |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1714 MathUtil::MapQuad(current_screen_transform, | 1737 MathUtil::MapQuad(current_screen_transform, |
| 1715 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1738 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), |
| 1716 &clipped); | 1739 &clipped); |
| 1717 ASSERT_FALSE(clipped); | 1740 ASSERT_FALSE(clipped); |
| 1718 | 1741 |
| 1719 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1742 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1720 current_screen_transform, device_viewport); | 1743 current_screen_transform, device_viewport); |
| 1721 | 1744 |
| 1722 client.SetTileSize(gfx::Size(100, 100)); | 1745 client.SetTileSize(gfx::Size(100, 100)); |
| 1723 client.set_tree(ACTIVE_TREE); | 1746 client.set_tree(ACTIVE_TREE); |
| 1724 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1747 |
| 1725 current_layer_bounds, &client, | 1748 scoped_refptr<FakePicturePileImpl> pile = |
| 1726 LayerTreeSettings()); | 1749 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1750 current_layer_bounds); |
| 1751 auto tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1752 LayerTreeSettings()); |
| 1727 | 1753 |
| 1728 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1754 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1729 current_layer_contents_scale, | 1755 current_layer_contents_scale, |
| 1730 current_frame_time_in_seconds, Occlusion()); | 1756 current_frame_time_in_seconds, Occlusion()); |
| 1731 tiling->UpdateAllTilePrioritiesForTesting(); | 1757 tiling->UpdateAllTilePrioritiesForTesting(); |
| 1732 | 1758 |
| 1733 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1759 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1734 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1760 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1735 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1761 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1736 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1762 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1752 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1778 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1753 | 1779 |
| 1754 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1780 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1755 EXPECT_GT(priority.distance_to_visible, 0.f); | 1781 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 1756 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 1782 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
| 1757 } | 1783 } |
| 1758 | 1784 |
| 1759 TEST(ComputeTilePriorityRectsTest, BasicMotion) { | 1785 TEST(ComputeTilePriorityRectsTest, BasicMotion) { |
| 1760 // Test that time_to_visible is computed correctly when | 1786 // Test that time_to_visible is computed correctly when |
| 1761 // there is some motion. | 1787 // there is some motion. |
| 1762 | |
| 1763 FakePictureLayerTilingClient client; | 1788 FakePictureLayerTilingClient client; |
| 1764 scoped_ptr<TestablePictureLayerTiling> tiling; | |
| 1765 | 1789 |
| 1766 gfx::Size device_viewport(800, 600); | 1790 gfx::Size device_viewport(800, 600); |
| 1767 gfx::Rect visible_layer_rect(0, 0, 0, 0); | 1791 gfx::Rect visible_layer_rect(0, 0, 0, 0); |
| 1768 gfx::Size last_layer_bounds(200, 200); | 1792 gfx::Size last_layer_bounds(200, 200); |
| 1769 gfx::Size current_layer_bounds(200, 200); | 1793 gfx::Size current_layer_bounds(200, 200); |
| 1770 float last_layer_contents_scale = 1.f; | 1794 float last_layer_contents_scale = 1.f; |
| 1771 float current_layer_contents_scale = 1.f; | 1795 float current_layer_contents_scale = 1.f; |
| 1772 gfx::Transform last_screen_transform; | 1796 gfx::Transform last_screen_transform; |
| 1773 gfx::Transform current_screen_transform; | 1797 gfx::Transform current_screen_transform; |
| 1774 double last_frame_time_in_seconds = 1.0; | 1798 double last_frame_time_in_seconds = 1.0; |
| 1775 double current_frame_time_in_seconds = 2.0; | 1799 double current_frame_time_in_seconds = 2.0; |
| 1776 | 1800 |
| 1777 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1801 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
| 1778 current_screen_transform.Translate(1800, 0); | 1802 current_screen_transform.Translate(1800, 0); |
| 1779 last_screen_transform.Translate(2800, 0); | 1803 last_screen_transform.Translate(2800, 0); |
| 1780 | 1804 |
| 1781 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1805 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1782 current_screen_transform, device_viewport); | 1806 current_screen_transform, device_viewport); |
| 1783 | 1807 |
| 1784 client.SetTileSize(gfx::Size(100, 100)); | 1808 client.SetTileSize(gfx::Size(100, 100)); |
| 1785 client.set_tree(ACTIVE_TREE); | 1809 client.set_tree(ACTIVE_TREE); |
| 1786 LayerTreeSettings settings; | 1810 LayerTreeSettings settings; |
| 1787 settings.max_tiles_for_interest_area = 10000; | 1811 settings.max_tiles_for_interest_area = 10000; |
| 1788 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1812 |
| 1789 current_layer_bounds, &client, | 1813 scoped_refptr<FakePicturePileImpl> pile = |
| 1790 settings); | 1814 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1815 current_layer_bounds); |
| 1816 auto tiling = |
| 1817 TestablePictureLayerTiling::Create(1.0f, pile, &client, settings); |
| 1791 | 1818 |
| 1792 // previous ("last") frame | 1819 // previous ("last") frame |
| 1793 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1820 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1794 last_layer_contents_scale, | 1821 last_layer_contents_scale, |
| 1795 last_frame_time_in_seconds, Occlusion()); | 1822 last_frame_time_in_seconds, Occlusion()); |
| 1796 | 1823 |
| 1797 // current frame | 1824 // current frame |
| 1798 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1825 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1799 current_layer_contents_scale, | 1826 current_layer_contents_scale, |
| 1800 current_frame_time_in_seconds, Occlusion()); | 1827 current_frame_time_in_seconds, Occlusion()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 current_screen_transform.Translate(400, 550); | 1880 current_screen_transform.Translate(400, 550); |
| 1854 current_screen_transform.RotateAboutZAxis(45); | 1881 current_screen_transform.RotateAboutZAxis(45); |
| 1855 | 1882 |
| 1856 last_screen_transform.Translate(400, 550); | 1883 last_screen_transform.Translate(400, 550); |
| 1857 | 1884 |
| 1858 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1885 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1859 current_screen_transform, device_viewport); | 1886 current_screen_transform, device_viewport); |
| 1860 | 1887 |
| 1861 client.SetTileSize(gfx::Size(100, 100)); | 1888 client.SetTileSize(gfx::Size(100, 100)); |
| 1862 client.set_tree(ACTIVE_TREE); | 1889 client.set_tree(ACTIVE_TREE); |
| 1863 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1890 |
| 1864 current_layer_bounds, &client, | 1891 scoped_refptr<FakePicturePileImpl> pile = |
| 1892 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1893 current_layer_bounds); |
| 1894 tiling = TestablePictureLayerTiling::Create(1.0f, pile, &client, |
| 1865 LayerTreeSettings()); | 1895 LayerTreeSettings()); |
| 1866 | 1896 |
| 1867 // previous ("last") frame | 1897 // previous ("last") frame |
| 1868 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1898 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1869 last_layer_contents_scale, | 1899 last_layer_contents_scale, |
| 1870 last_frame_time_in_seconds, Occlusion()); | 1900 last_frame_time_in_seconds, Occlusion()); |
| 1871 | 1901 |
| 1872 // current frame | 1902 // current frame |
| 1873 tiling->ComputeTilePriorityRects(viewport_in_layer_space, | 1903 tiling->ComputeTilePriorityRects(viewport_in_layer_space, |
| 1874 current_layer_contents_scale, | 1904 current_layer_contents_scale, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1898 // Setup: | 1928 // Setup: |
| 1899 // - Two tilings, one active one recycled with all tiles shared. | 1929 // - Two tilings, one active one recycled with all tiles shared. |
| 1900 // Procedure: | 1930 // Procedure: |
| 1901 // - Viewport moves somewhere far away and active tiling clears tiles. | 1931 // - Viewport moves somewhere far away and active tiling clears tiles. |
| 1902 // - Viewport moves back and a new active tiling tile is created. | 1932 // - Viewport moves back and a new active tiling tile is created. |
| 1903 // Result: | 1933 // Result: |
| 1904 // - Recycle tiling does _not_ have the tile in the same location (thus it | 1934 // - Recycle tiling does _not_ have the tile in the same location (thus it |
| 1905 // will be shared next time a pending tiling is created). | 1935 // will be shared next time a pending tiling is created). |
| 1906 | 1936 |
| 1907 FakePictureLayerTilingClient active_client; | 1937 FakePictureLayerTilingClient active_client; |
| 1908 scoped_ptr<TestablePictureLayerTiling> active_tiling; | |
| 1909 | 1938 |
| 1910 active_client.SetTileSize(gfx::Size(100, 100)); | 1939 active_client.SetTileSize(gfx::Size(100, 100)); |
| 1911 active_client.set_tree(ACTIVE_TREE); | 1940 active_client.set_tree(ACTIVE_TREE); |
| 1912 LayerTreeSettings settings; | 1941 LayerTreeSettings settings; |
| 1913 settings.max_tiles_for_interest_area = 10; | 1942 settings.max_tiles_for_interest_area = 10; |
| 1914 active_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1943 |
| 1915 gfx::Size(10000, 10000), | 1944 scoped_refptr<FakePicturePileImpl> pile = |
| 1916 &active_client, settings); | 1945 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1946 gfx::Size(10000, 10000)); |
| 1947 auto active_tiling = |
| 1948 TestablePictureLayerTiling::Create(1.0f, pile, &active_client, settings); |
| 1917 // Create all tiles on this tiling. | 1949 // Create all tiles on this tiling. |
| 1918 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, | 1950 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, |
| 1919 Occlusion()); | 1951 Occlusion()); |
| 1920 | 1952 |
| 1921 FakePictureLayerTilingClient recycle_client; | 1953 FakePictureLayerTilingClient recycle_client; |
| 1922 recycle_client.SetTileSize(gfx::Size(100, 100)); | 1954 recycle_client.SetTileSize(gfx::Size(100, 100)); |
| 1923 recycle_client.set_tree(PENDING_TREE); | 1955 recycle_client.set_tree(PENDING_TREE); |
| 1924 recycle_client.set_twin_tiling(active_tiling.get()); | 1956 recycle_client.set_twin_tiling(active_tiling.get()); |
| 1925 | 1957 |
| 1926 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; | 1958 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1927 recycle_tiling = TestablePictureLayerTiling::Create( | 1959 gfx::Size(10000, 10000)); |
| 1928 1.0f, // contents_scale | 1960 auto recycle_tiling = |
| 1929 gfx::Size(10000, 10000), &recycle_client, settings); | 1961 TestablePictureLayerTiling::Create(1.0f, pile, &recycle_client, settings); |
| 1930 | 1962 |
| 1931 // Create all tiles on the second tiling. All tiles should be shared. | 1963 // Create all tiles on the second tiling. All tiles should be shared. |
| 1932 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, | 1964 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, |
| 1933 1.0f, Occlusion()); | 1965 1.0f, Occlusion()); |
| 1934 | 1966 |
| 1935 // Set the second tiling as recycled. | 1967 // Set the second tiling as recycled. |
| 1936 active_client.set_twin_tiling(NULL); | 1968 active_client.set_twin_tiling(NULL); |
| 1937 active_client.set_recycled_twin_tiling(recycle_tiling.get()); | 1969 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
| 1938 recycle_client.set_twin_tiling(NULL); | 1970 recycle_client.set_twin_tiling(NULL); |
| 1939 | 1971 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1953 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 3.0, | 1985 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 3.0, |
| 1954 Occlusion()); | 1986 Occlusion()); |
| 1955 | 1987 |
| 1956 // Ensure that we now have a tile here on both tilings again. | 1988 // Ensure that we now have a tile here on both tilings again. |
| 1957 EXPECT_TRUE(active_tiling->TileAt(0, 0)); | 1989 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 1958 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); | 1990 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); |
| 1959 } | 1991 } |
| 1960 | 1992 |
| 1961 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { | 1993 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { |
| 1962 FakePictureLayerTilingClient active_client; | 1994 FakePictureLayerTilingClient active_client; |
| 1963 scoped_ptr<TestablePictureLayerTiling> active_tiling; | |
| 1964 | |
| 1965 active_client.SetTileSize(gfx::Size(100, 100)); | 1995 active_client.SetTileSize(gfx::Size(100, 100)); |
| 1966 active_client.set_tree(ACTIVE_TREE); | 1996 active_client.set_tree(ACTIVE_TREE); |
| 1967 active_tiling = TestablePictureLayerTiling::Create( | 1997 |
| 1968 1.0f, // contents_scale | 1998 scoped_refptr<FakePicturePileImpl> pile = |
| 1969 gfx::Size(100, 100), &active_client, LayerTreeSettings()); | 1999 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 2000 gfx::Size(100, 100)); |
| 2001 auto active_tiling = TestablePictureLayerTiling::Create( |
| 2002 1.0f, pile, &active_client, LayerTreeSettings()); |
| 1970 // Create all tiles on this tiling. | 2003 // Create all tiles on this tiling. |
| 1971 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, | 2004 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1.0f, |
| 1972 Occlusion()); | 2005 Occlusion()); |
| 1973 | 2006 |
| 1974 FakePictureLayerTilingClient recycle_client; | 2007 FakePictureLayerTilingClient recycle_client; |
| 1975 recycle_client.SetTileSize(gfx::Size(100, 100)); | 2008 recycle_client.SetTileSize(gfx::Size(100, 100)); |
| 1976 recycle_client.set_tree(PENDING_TREE); | 2009 recycle_client.set_tree(PENDING_TREE); |
| 1977 recycle_client.set_twin_tiling(active_tiling.get()); | 2010 recycle_client.set_twin_tiling(active_tiling.get()); |
| 1978 | 2011 |
| 1979 LayerTreeSettings settings; | 2012 LayerTreeSettings settings; |
| 1980 settings.max_tiles_for_interest_area = 10; | 2013 settings.max_tiles_for_interest_area = 10; |
| 1981 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; | 2014 |
| 1982 recycle_tiling = TestablePictureLayerTiling::Create( | 2015 pile = FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 1983 1.0f, // contents_scale | 2016 gfx::Size(100, 100)); |
| 1984 gfx::Size(100, 100), &recycle_client, settings); | 2017 auto recycle_tiling = |
| 2018 TestablePictureLayerTiling::Create(1.0f, pile, &recycle_client, settings); |
| 1985 | 2019 |
| 1986 // Create all tiles on the recycle tiling. All tiles should be shared. | 2020 // Create all tiles on the recycle tiling. All tiles should be shared. |
| 1987 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, | 2021 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, |
| 1988 1.0f, Occlusion()); | 2022 1.0f, Occlusion()); |
| 1989 | 2023 |
| 1990 // Set the second tiling as recycled. | 2024 // Set the second tiling as recycled. |
| 1991 active_client.set_twin_tiling(NULL); | 2025 active_client.set_twin_tiling(NULL); |
| 1992 active_client.set_recycled_twin_tiling(recycle_tiling.get()); | 2026 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
| 1993 recycle_client.set_twin_tiling(NULL); | 2027 recycle_client.set_twin_tiling(NULL); |
| 1994 | 2028 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2011 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2045 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2012 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); | 2046 EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); |
| 2013 | 2047 |
| 2014 client_.SetTileSize(gfx::Size(250, 200)); | 2048 client_.SetTileSize(gfx::Size(250, 200)); |
| 2015 client_.set_tree(PENDING_TREE); | 2049 client_.set_tree(PENDING_TREE); |
| 2016 | 2050 |
| 2017 // Tile size in the tiling should still be 150x100. | 2051 // Tile size in the tiling should still be 150x100. |
| 2018 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); | 2052 EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2019 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); | 2053 EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2020 | 2054 |
| 2021 tiling_->Resize(gfx::Size(250, 150)); | 2055 // The layer's size isn't changed, but the tile size was. |
| 2056 scoped_refptr<FakePicturePileImpl> pile = |
| 2057 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( |
| 2058 gfx::Size(250, 150)); |
| 2059 tiling_->SetRasterSourceAndResize(pile); |
| 2022 | 2060 |
| 2023 // Tile size in the tiling should be resized to 250x200. | 2061 // Tile size in the tiling should be resized to 250x200. |
| 2024 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); | 2062 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); |
| 2025 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); | 2063 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); |
| 2026 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); | 2064 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); |
| 2027 } | 2065 } |
| 2028 | 2066 |
| 2029 } // namespace | 2067 } // namespace |
| 2030 } // namespace cc | 2068 } // namespace cc |
| OLD | NEW |