| 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> | |
| 9 | 8 |
| 10 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 11 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
| 12 #include "cc/test/fake_picture_layer_tiling_client.h" | 11 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 13 #include "cc/test/fake_tile_manager.h" | |
| 14 #include "cc/test/fake_tile_manager_client.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
| 17 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
| 18 | 15 |
| 19 namespace cc { | 16 namespace cc { |
| 20 namespace { | 17 namespace { |
| 21 | 18 |
| 22 const int kTileBundleWidth = 2; | |
| 23 const int kTileBundleHeight = 2; | |
| 24 std::pair<int, int> ComputeTileBundleIndex(int i, int j) { | |
| 25 return std::make_pair(i / kTileBundleWidth, j / kTileBundleHeight); | |
| 26 } | |
| 27 | |
| 28 static gfx::Rect ViewportInLayerSpace( | 19 static gfx::Rect ViewportInLayerSpace( |
| 29 const gfx::Transform& transform, | 20 const gfx::Transform& transform, |
| 30 gfx::Size device_viewport) { | 21 gfx::Size device_viewport) { |
| 31 | 22 |
| 32 gfx::Transform inverse; | 23 gfx::Transform inverse; |
| 33 if (!transform.GetInverse(&inverse)) | 24 if (!transform.GetInverse(&inverse)) |
| 34 return gfx::Rect(); | 25 return gfx::Rect(); |
| 35 | 26 |
| 36 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
| 37 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
| 38 | 29 |
| 39 return ToEnclosingRect(viewport_in_layer_space); | 30 return ToEnclosingRect(viewport_in_layer_space); |
| 40 } | 31 } |
| 41 | 32 |
| 42 class TestablePictureLayerTiling : public PictureLayerTiling { | 33 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 43 public: | 34 public: |
| 44 using PictureLayerTiling::SetLiveTilesRect; | 35 using PictureLayerTiling::SetLiveTilesRect; |
| 45 using PictureLayerTiling::TileAt; | 36 using PictureLayerTiling::TileAt; |
| 46 using PictureLayerTiling::TileBundleAt; | |
| 47 | 37 |
| 48 static scoped_ptr<TestablePictureLayerTiling> Create( | 38 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 49 float contents_scale, | 39 float contents_scale, |
| 50 gfx::Size layer_bounds, | 40 gfx::Size layer_bounds, |
| 51 PictureLayerTilingClient* client) { | 41 PictureLayerTilingClient* client) { |
| 52 return make_scoped_ptr(new TestablePictureLayerTiling( | 42 return make_scoped_ptr(new TestablePictureLayerTiling( |
| 53 contents_scale, | 43 contents_scale, |
| 54 layer_bounds, | 44 layer_bounds, |
| 55 client)); | 45 client)); |
| 56 } | 46 } |
| 57 | 47 |
| 58 TilingData tiling_data() const { return tiling_data_; } | |
| 59 TilingData bundle_tiling_data() const { return bundle_tiling_data_; } | |
| 60 | |
| 61 protected: | 48 protected: |
| 62 TestablePictureLayerTiling(float contents_scale, | 49 TestablePictureLayerTiling(float contents_scale, |
| 63 gfx::Size layer_bounds, | 50 gfx::Size layer_bounds, |
| 64 PictureLayerTilingClient* client) | 51 PictureLayerTilingClient* client) |
| 65 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
| 66 }; | 53 }; |
| 67 | 54 |
| 68 class PictureLayerTilingIteratorTest : public testing::Test { | 55 class PictureLayerTilingIteratorTest : public testing::Test { |
| 69 public: | 56 public: |
| 70 PictureLayerTilingIteratorTest() | 57 PictureLayerTilingIteratorTest() {} |
| 71 : tile_manager_(&tile_manager_client_), client_(&tile_manager_) {} | |
| 72 | |
| 73 virtual ~PictureLayerTilingIteratorTest() {} | 58 virtual ~PictureLayerTilingIteratorTest() {} |
| 74 | 59 |
| 75 void Initialize(gfx::Size tile_size, | 60 void Initialize(gfx::Size tile_size, |
| 76 float contents_scale, | 61 float contents_scale, |
| 77 gfx::Size layer_bounds) { | 62 gfx::Size layer_bounds) { |
| 78 client_.SetTileSize(tile_size); | 63 client_.SetTileSize(tile_size); |
| 79 tiling_ = TestablePictureLayerTiling::Create(contents_scale, | 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, |
| 80 layer_bounds, | 65 layer_bounds, |
| 81 &client_); | 66 &client_); |
| 82 } | 67 } |
| 83 | 68 |
| 84 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { | 69 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { |
| 85 tiling_->SetTreeForTesting(ACTIVE_TREE); | |
| 86 tiling_->SetLiveTilesRect(live_tiles_rect); | 70 tiling_->SetLiveTilesRect(live_tiles_rect); |
| 87 | 71 |
| 88 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
| 89 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 73 for (std::vector<Tile*>::iterator iter = tiles.begin(); |
| 90 iter != tiles.end(); | 74 iter != tiles.end(); |
| 91 ++iter) { | 75 ++iter) { |
| 92 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 76 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
| 93 } | 77 } |
| 94 } | 78 } |
| 95 | 79 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 146 |
| 163 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { | 147 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { |
| 164 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 148 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
| 165 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | 149 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( |
| 166 tiling_->ContentRect(), 1.f / dest_to_contents_scale); | 150 tiling_->ContentRect(), 1.f / dest_to_contents_scale); |
| 167 clamped_rect.Intersect(dest_rect); | 151 clamped_rect.Intersect(dest_rect); |
| 168 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 152 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
| 169 } | 153 } |
| 170 | 154 |
| 171 protected: | 155 protected: |
| 172 FakeTileManagerClient tile_manager_client_; | |
| 173 FakeTileManager tile_manager_; | |
| 174 FakePictureLayerTilingClient client_; | 156 FakePictureLayerTilingClient client_; |
| 175 scoped_ptr<TestablePictureLayerTiling> tiling_; | 157 scoped_ptr<TestablePictureLayerTiling> tiling_; |
| 176 | 158 |
| 177 private: | 159 private: |
| 178 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 160 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
| 179 }; | 161 }; |
| 180 | 162 |
| 181 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 163 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
| 182 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 164 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
| 183 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); | 165 SetLiveRectAndVerifyTiles(gfx::Rect(100, 100)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); | 254 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); |
| 273 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 255 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
| 274 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 256 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
| 275 | 257 |
| 276 // Partially covering content, but too large | 258 // Partially covering content, but too large |
| 277 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); | 259 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); |
| 278 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | 260 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); |
| 279 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | 261 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); |
| 280 } | 262 } |
| 281 | 263 |
| 282 TEST(PictureLayerTilingTest, BundleAtContainsTileAt) { | |
| 283 FakeTileManagerClient tile_manager_client; | |
| 284 FakeTileManager tile_manager(&tile_manager_client); | |
| 285 FakePictureLayerTilingClient client(&tile_manager); | |
| 286 | |
| 287 gfx::Size current_layer_bounds(400, 400); | |
| 288 client.SetTileSize(gfx::Size(100, 100)); | |
| 289 scoped_ptr<TestablePictureLayerTiling> tiling = | |
| 290 TestablePictureLayerTiling::Create(1.0f, current_layer_bounds, &client); | |
| 291 | |
| 292 tiling->CreateTilesForTesting(ACTIVE_TREE); | |
| 293 for (int bundle_y = 0; | |
| 294 bundle_y < (current_layer_bounds.height() / (kTileBundleHeight * 100)); | |
| 295 ++bundle_y) { | |
| 296 for (int bundle_x = 0; | |
| 297 bundle_x < (current_layer_bounds.width() / (kTileBundleWidth * 100)); | |
| 298 ++bundle_x) { | |
| 299 EXPECT_TRUE(tiling->TileBundleAt(bundle_x, bundle_y)) | |
| 300 << "bundle_x " << bundle_x << " bundle_y " << bundle_y; | |
| 301 | |
| 302 TileBundle* bundle = tiling->TileBundleAt(bundle_x, bundle_y); | |
| 303 for (int tile_y = 0; tile_y < kTileBundleWidth; ++tile_y) { | |
| 304 for (int tile_x = 0; tile_x < kTileBundleHeight; ++tile_x) { | |
| 305 int global_tile_x = bundle_x * kTileBundleWidth + tile_x; | |
| 306 int global_tile_y = bundle_y * kTileBundleHeight + tile_y; | |
| 307 | |
| 308 EXPECT_TRUE(tiling->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y)) | |
| 309 << "x " << global_tile_x << " y " << global_tile_y; | |
| 310 EXPECT_EQ(tiling->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y), | |
| 311 bundle->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y)) | |
| 312 << "x " << global_tile_x << " y " << global_tile_y; | |
| 313 } | |
| 314 } | |
| 315 } | |
| 316 } | |
| 317 } | |
| 318 | |
| 319 TEST(PictureLayerTilingTest, TilesCleanedUp) { | |
| 320 FakeTileManagerClient tile_manager_client; | |
| 321 FakeTileManager tile_manager(&tile_manager_client); | |
| 322 FakePictureLayerTilingClient client(&tile_manager); | |
| 323 FakePictureLayerTilingClient twin_client(&tile_manager); | |
| 324 | |
| 325 gfx::Size current_layer_bounds(400, 400); | |
| 326 client.SetTileSize(gfx::Size(100, 100)); | |
| 327 twin_client.SetTileSize(gfx::Size(100, 100)); | |
| 328 scoped_ptr<TestablePictureLayerTiling> tiling = | |
| 329 TestablePictureLayerTiling::Create(1.0f, current_layer_bounds, &client); | |
| 330 scoped_ptr<TestablePictureLayerTiling> twin_tiling = | |
| 331 TestablePictureLayerTiling::Create( | |
| 332 1.0f, current_layer_bounds, &twin_client); | |
| 333 | |
| 334 client.set_twin_tiling(twin_tiling.get()); | |
| 335 twin_client.set_twin_tiling(tiling.get()); | |
| 336 | |
| 337 tiling->CreateTilesForTesting(ACTIVE_TREE); | |
| 338 twin_tiling->CreateTilesForTesting(PENDING_TREE); | |
| 339 for (int tile_y = 0; tile_y < 4; ++tile_y) { | |
| 340 for (int tile_x = 0; tile_x < 4; ++tile_x) { | |
| 341 EXPECT_TRUE(tiling->TileAt(ACTIVE_TREE, tile_x, tile_y) == | |
| 342 twin_tiling->TileAt(ACTIVE_TREE, tile_x, tile_y)); | |
| 343 EXPECT_TRUE(tiling->TileAt(PENDING_TREE, tile_x, tile_y) == | |
| 344 twin_tiling->TileAt(PENDING_TREE, tile_x, tile_y)); | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 client.set_twin_tiling(NULL); | |
| 349 twin_tiling.reset(); | |
| 350 | |
| 351 for (int tile_y = 0; tile_y < 4; ++tile_y) { | |
| 352 for (int tile_x = 0; tile_x < 4; ++tile_x) { | |
| 353 EXPECT_TRUE(tiling->TileAt(ACTIVE_TREE, tile_x, tile_y) != NULL); | |
| 354 EXPECT_TRUE(tiling->TileAt(PENDING_TREE, tile_x, tile_y) == NULL); | |
| 355 } | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 TEST(PictureLayerTilingTest, DidBecomeActiveSwapsTiles) { | |
| 360 FakeTileManagerClient tile_manager_client; | |
| 361 FakeTileManager tile_manager(&tile_manager_client); | |
| 362 FakePictureLayerTilingClient client(&tile_manager); | |
| 363 | |
| 364 gfx::Size current_layer_bounds(400, 400); | |
| 365 client.SetTileSize(gfx::Size(100, 100)); | |
| 366 scoped_ptr<TestablePictureLayerTiling> tiling = | |
| 367 TestablePictureLayerTiling::Create(1.0f, current_layer_bounds, &client); | |
| 368 | |
| 369 tiling->CreateTilesForTesting(ACTIVE_TREE); | |
| 370 std::vector<Tile*> old_active_tiles = tiling->TilesForTesting(ACTIVE_TREE); | |
| 371 tiling->DidBecomeActive(); | |
| 372 std::vector<Tile*> pending_tiles = tiling->TilesForTesting(PENDING_TREE); | |
| 373 EXPECT_EQ(old_active_tiles.size(), pending_tiles.size()); | |
| 374 std::vector<Tile*>::const_iterator old_it = old_active_tiles.begin(); | |
| 375 for (std::vector<Tile*>::const_iterator it = pending_tiles.begin(); | |
| 376 it != pending_tiles.end(); | |
| 377 ++it) { | |
| 378 EXPECT_EQ(*it, *old_it); | |
| 379 ++old_it; | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 264 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
| 384 gfx::Rect in(40, 50, 100, 200); | 265 gfx::Rect in(40, 50, 100, 200); |
| 385 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 266 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
| 386 int64 target_area = 100 * 200; | 267 int64 target_area = 100 * 200; |
| 387 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 268 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 388 in, target_area, bounds, NULL); | 269 in, target_area, bounds, NULL); |
| 389 EXPECT_EQ(in.ToString(), out.ToString()); | 270 EXPECT_EQ(in.ToString(), out.ToString()); |
| 390 } | 271 } |
| 391 | 272 |
| 392 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 273 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 gfx::Transform(), // current screen transform | 725 gfx::Transform(), // current screen transform |
| 845 1.0, // current frame time | 726 1.0, // current frame time |
| 846 10000); // max tiles in tile manager | 727 10000); // max tiles in tile manager |
| 847 | 728 |
| 848 VerifyTiles(pending_set.tiling_at(0), | 729 VerifyTiles(pending_set.tiling_at(0), |
| 849 1.f, | 730 1.f, |
| 850 gfx::Rect(layer_bounds), | 731 gfx::Rect(layer_bounds), |
| 851 base::Bind(&TileExists, true)); | 732 base::Bind(&TileExists, true)); |
| 852 } | 733 } |
| 853 | 734 |
| 854 TEST_F(PictureLayerTilingIteratorTest, BundlesAndTilesAlign) { | |
| 855 Initialize(gfx::Size(100, 100), 1, gfx::Size(850, 850)); | |
| 856 for (int y = -20; y <= 102; ++y) { | |
| 857 for (int x = 0; x <= 103; ++x) { | |
| 858 for (int size = 1; size <= 201; size += 50) { | |
| 859 gfx::Rect rect(x, y, size, size); | |
| 860 | |
| 861 TilingData tiling_data = tiling_->tiling_data(); | |
| 862 | |
| 863 std::set<std::pair<int, int> > tile_positions; | |
| 864 std::set<std::pair<int, int> > predicted_bundle_positions; | |
| 865 size_t iteration_count = 0; | |
| 866 for (TilingData::Iterator iter(&tiling_data, rect); iter; ++iter) { | |
| 867 ++iteration_count; | |
| 868 tile_positions.insert(std::make_pair(iter.index_x(), iter.index_y())); | |
| 869 predicted_bundle_positions.insert( | |
| 870 ComputeTileBundleIndex(iter.index_x(), iter.index_y())); | |
| 871 } | |
| 872 | |
| 873 ASSERT_EQ(tile_positions.size(), iteration_count) << rect.ToString(); | |
| 874 | |
| 875 TilingData bundle_tiling_data = tiling_->bundle_tiling_data(); | |
| 876 std::set<std::pair<int, int> > bundle_positions; | |
| 877 iteration_count = 0; | |
| 878 for (TilingData::Iterator iter(&bundle_tiling_data, rect); | |
| 879 iter; | |
| 880 ++iter) { | |
| 881 ++iteration_count; | |
| 882 bundle_positions.insert( | |
| 883 std::make_pair(iter.index_x(), iter.index_y())); | |
| 884 } | |
| 885 | |
| 886 ASSERT_EQ(bundle_positions.size(), iteration_count) << rect.ToString(); | |
| 887 ASSERT_EQ(predicted_bundle_positions.size(), iteration_count) | |
| 888 << rect.ToString(); | |
| 889 | |
| 890 std::set<std::pair<int, int> >::const_iterator predicted_iterator = | |
| 891 predicted_bundle_positions.begin(); | |
| 892 for (std::set<std::pair<int, int> >::const_iterator actual_iterator = | |
| 893 bundle_positions.begin(); | |
| 894 actual_iterator != bundle_positions.end(); | |
| 895 ++actual_iterator) { | |
| 896 ASSERT_EQ(*actual_iterator, *predicted_iterator) << rect.ToString(); | |
| 897 ++predicted_iterator; | |
| 898 } | |
| 899 } | |
| 900 } | |
| 901 } | |
| 902 } | |
| 903 | |
| 904 | |
| 905 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 735 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
| 906 // The TilePriority of visible tiles should have zero distance_to_visible | 736 // The TilePriority of visible tiles should have zero distance_to_visible |
| 907 // and time_to_visible. | 737 // and time_to_visible. |
| 908 | 738 |
| 909 FakeTileManagerClient tile_manager_client; | 739 FakePictureLayerTilingClient client; |
| 910 FakeTileManager tile_manager(&tile_manager_client); | |
| 911 FakePictureLayerTilingClient client(&tile_manager); | |
| 912 scoped_ptr<TestablePictureLayerTiling> tiling; | 740 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 913 | 741 |
| 914 gfx::Size device_viewport(800, 600); | 742 gfx::Size device_viewport(800, 600); |
| 915 gfx::Rect visible_layer_rect(0, 0, 200, 200); | 743 gfx::Rect visible_layer_rect(0, 0, 200, 200); |
| 916 gfx::Size last_layer_bounds(200, 200); | 744 gfx::Size last_layer_bounds(200, 200); |
| 917 gfx::Size current_layer_bounds(200, 200); | 745 gfx::Size current_layer_bounds(200, 200); |
| 918 float last_layer_contents_scale = 1.f; | 746 float last_layer_contents_scale = 1.f; |
| 919 float current_layer_contents_scale = 1.f; | 747 float current_layer_contents_scale = 1.f; |
| 920 gfx::Transform last_screen_transform; | 748 gfx::Transform last_screen_transform; |
| 921 gfx::Transform current_screen_transform; | 749 gfx::Transform current_screen_transform; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 937 visible_layer_rect, | 765 visible_layer_rect, |
| 938 last_layer_bounds, | 766 last_layer_bounds, |
| 939 current_layer_bounds, | 767 current_layer_bounds, |
| 940 last_layer_contents_scale, | 768 last_layer_contents_scale, |
| 941 current_layer_contents_scale, | 769 current_layer_contents_scale, |
| 942 last_screen_transform, | 770 last_screen_transform, |
| 943 current_screen_transform, | 771 current_screen_transform, |
| 944 current_frame_time_in_seconds, | 772 current_frame_time_in_seconds, |
| 945 max_tiles_for_interest_area); | 773 max_tiles_for_interest_area); |
| 946 | 774 |
| 947 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); | 775 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 948 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); | 776 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 949 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); | 777 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 950 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); | 778 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 951 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 952 | 779 |
| 953 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 780 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 781 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 782 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 783 |
| 784 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 787 |
| 788 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 791 |
| 792 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 954 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 955 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 956 } | 795 } |
| 957 | 796 |
| 958 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 797 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
| 959 // The TilePriority of offscreen tiles (without movement) should have nonzero | 798 // The TilePriority of offscreen tiles (without movement) should have nonzero |
| 960 // distance_to_visible and infinite time_to_visible. | 799 // distance_to_visible and infinite time_to_visible. |
| 961 | 800 |
| 962 FakeTileManagerClient tile_manager_client; | 801 FakePictureLayerTilingClient client; |
| 963 FakeTileManager tile_manager(&tile_manager_client); | |
| 964 FakePictureLayerTilingClient client(&tile_manager); | |
| 965 scoped_ptr<TestablePictureLayerTiling> tiling; | 802 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 966 | 803 |
| 967 gfx::Size device_viewport(800, 600); | 804 gfx::Size device_viewport(800, 600); |
| 968 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | 805 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. |
| 969 gfx::Size last_layer_bounds(400, 400); | 806 gfx::Size last_layer_bounds(200, 200); |
| 970 gfx::Size current_layer_bounds(400, 400); | 807 gfx::Size current_layer_bounds(200, 200); |
| 971 float last_layer_contents_scale = 1.f; | 808 float last_layer_contents_scale = 1.f; |
| 972 float current_layer_contents_scale = 1.f; | 809 float current_layer_contents_scale = 1.f; |
| 973 gfx::Transform last_screen_transform; | 810 gfx::Transform last_screen_transform; |
| 974 gfx::Transform current_screen_transform; | 811 gfx::Transform current_screen_transform; |
| 975 double current_frame_time_in_seconds = 1.0; | 812 double current_frame_time_in_seconds = 1.0; |
| 976 size_t max_tiles_for_interest_area = 10000; | 813 size_t max_tiles_for_interest_area = 10000; |
| 977 | 814 |
| 978 current_screen_transform.Translate(850, 0); | 815 current_screen_transform.Translate(850, 0); |
| 979 last_screen_transform = current_screen_transform; | 816 last_screen_transform = current_screen_transform; |
| 980 | 817 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 993 visible_layer_rect, | 830 visible_layer_rect, |
| 994 last_layer_bounds, | 831 last_layer_bounds, |
| 995 current_layer_bounds, | 832 current_layer_bounds, |
| 996 last_layer_contents_scale, | 833 last_layer_contents_scale, |
| 997 current_layer_contents_scale, | 834 current_layer_contents_scale, |
| 998 last_screen_transform, | 835 last_screen_transform, |
| 999 current_screen_transform, | 836 current_screen_transform, |
| 1000 current_frame_time_in_seconds, | 837 current_frame_time_in_seconds, |
| 1001 max_tiles_for_interest_area); | 838 max_tiles_for_interest_area); |
| 1002 | 839 |
| 1003 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); | 840 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1004 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); | 841 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1005 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); | 842 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1006 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); | 843 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1007 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 1008 | 844 |
| 1009 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 845 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1010 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 846 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1011 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 847 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1012 priority.time_to_visible_in_seconds); | 848 priority.time_to_visible_in_seconds); |
| 1013 | 849 |
| 1014 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 2)); | 850 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1015 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 3)); | 851 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1016 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 2)); | 852 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1017 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 3)); | 853 priority.time_to_visible_in_seconds); |
| 1018 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | |
| 1019 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | |
| 1020 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | |
| 1021 | 854 |
| 1022 // Furthermore, in this scenario bundles on the right hand side should have a | 855 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 856 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 857 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 858 priority.time_to_visible_in_seconds); |
| 859 |
| 860 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 861 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 862 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 863 priority.time_to_visible_in_seconds); |
| 864 |
| 865 // Furthermore, in this scenario tiles on the right hand side should have a |
| 1023 // larger distance to visible. | 866 // larger distance to visible. |
| 1024 TilePriority left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 867 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1025 TilePriority right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 868 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1026 EXPECT_GT(right.distance_to_visible_in_pixels, | 869 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 1027 left.distance_to_visible_in_pixels); | 870 left.distance_to_visible_in_pixels); |
| 1028 | 871 |
| 1029 left = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 872 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1030 right = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 873 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1031 EXPECT_GT(right.distance_to_visible_in_pixels, | 874 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 1032 left.distance_to_visible_in_pixels); | 875 left.distance_to_visible_in_pixels); |
| 1033 } | 876 } |
| 1034 | 877 |
| 1035 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 878 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
| 1036 // Sanity check that a layer with some tiles visible and others offscreen has | 879 // Sanity check that a layer with some tiles visible and others offscreen has |
| 1037 // correct TilePriorities for each tile. | 880 // correct TilePriorities for each tile. |
| 1038 | 881 |
| 1039 FakeTileManagerClient tile_manager_client; | 882 FakePictureLayerTilingClient client; |
| 1040 FakeTileManager tile_manager(&tile_manager_client); | |
| 1041 FakePictureLayerTilingClient client(&tile_manager); | |
| 1042 scoped_ptr<TestablePictureLayerTiling> tiling; | 883 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1043 | 884 |
| 1044 gfx::Size device_viewport(800, 600); | 885 gfx::Size device_viewport(800, 600); |
| 1045 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | 886 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. |
| 1046 gfx::Size last_layer_bounds(400, 400); | 887 gfx::Size last_layer_bounds(200, 200); |
| 1047 gfx::Size current_layer_bounds(400, 400); | 888 gfx::Size current_layer_bounds(200, 200); |
| 1048 float last_layer_contents_scale = 1.f; | 889 float last_layer_contents_scale = 1.f; |
| 1049 float current_layer_contents_scale = 1.f; | 890 float current_layer_contents_scale = 1.f; |
| 1050 gfx::Transform last_screen_transform; | 891 gfx::Transform last_screen_transform; |
| 1051 gfx::Transform current_screen_transform; | 892 gfx::Transform current_screen_transform; |
| 1052 double current_frame_time_in_seconds = 1.0; | 893 double current_frame_time_in_seconds = 1.0; |
| 1053 size_t max_tiles_for_interest_area = 10000; | 894 size_t max_tiles_for_interest_area = 10000; |
| 1054 | 895 |
| 1055 current_screen_transform.Translate(705, 505); | 896 current_screen_transform.Translate(705, 505); |
| 1056 last_screen_transform = current_screen_transform; | 897 last_screen_transform = current_screen_transform; |
| 1057 | 898 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1070 visible_layer_rect, | 911 visible_layer_rect, |
| 1071 last_layer_bounds, | 912 last_layer_bounds, |
| 1072 current_layer_bounds, | 913 current_layer_bounds, |
| 1073 last_layer_contents_scale, | 914 last_layer_contents_scale, |
| 1074 current_layer_contents_scale, | 915 current_layer_contents_scale, |
| 1075 last_screen_transform, | 916 last_screen_transform, |
| 1076 current_screen_transform, | 917 current_screen_transform, |
| 1077 current_frame_time_in_seconds, | 918 current_frame_time_in_seconds, |
| 1078 max_tiles_for_interest_area); | 919 max_tiles_for_interest_area); |
| 1079 | 920 |
| 1080 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); | 921 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1081 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); | 922 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1082 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); | 923 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1083 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); | 924 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1084 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 1085 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | |
| 1086 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | |
| 1087 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | |
| 1088 | 925 |
| 1089 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 926 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1090 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 927 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1091 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 928 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1092 | 929 |
| 1093 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 930 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1094 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 931 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1095 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 932 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1096 priority.time_to_visible_in_seconds); | 933 priority.time_to_visible_in_seconds); |
| 1097 | 934 |
| 1098 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 935 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1099 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 936 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1100 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 937 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1101 priority.time_to_visible_in_seconds); | 938 priority.time_to_visible_in_seconds); |
| 1102 | 939 |
| 1103 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 940 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1104 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 941 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1105 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 942 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1106 priority.time_to_visible_in_seconds); | 943 priority.time_to_visible_in_seconds); |
| 1107 } | 944 } |
| 1108 | 945 |
| 1109 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 946 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
| 1110 // Each tile of a layer may be affected differently by a transform; Check | 947 // Each tile of a layer may be affected differently by a transform; Check |
| 1111 // that UpdateTilePriorities correctly accounts for the transform between | 948 // that UpdateTilePriorities correctly accounts for the transform between |
| 1112 // layer space and screen space. | 949 // layer space and screen space. |
| 1113 | 950 |
| 1114 FakeTileManagerClient tile_manager_client; | 951 FakePictureLayerTilingClient client; |
| 1115 FakeTileManager tile_manager(&tile_manager_client); | |
| 1116 FakePictureLayerTilingClient client(&tile_manager); | |
| 1117 scoped_ptr<TestablePictureLayerTiling> tiling; | 952 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1118 | 953 |
| 1119 gfx::Size device_viewport(800, 600); | 954 gfx::Size device_viewport(800, 600); |
| 1120 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | 955 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. |
| 1121 gfx::Size last_layer_bounds(400, 400); | 956 gfx::Size last_layer_bounds(200, 200); |
| 1122 gfx::Size current_layer_bounds(400, 400); | 957 gfx::Size current_layer_bounds(200, 200); |
| 1123 float last_layer_contents_scale = 1.f; | 958 float last_layer_contents_scale = 1.f; |
| 1124 float current_layer_contents_scale = 1.f; | 959 float current_layer_contents_scale = 1.f; |
| 1125 gfx::Transform last_screen_transform; | 960 gfx::Transform last_screen_transform; |
| 1126 gfx::Transform current_screen_transform; | 961 gfx::Transform current_screen_transform; |
| 1127 double current_frame_time_in_seconds = 1.0; | 962 double current_frame_time_in_seconds = 1.0; |
| 1128 size_t max_tiles_for_interest_area = 10000; | 963 size_t max_tiles_for_interest_area = 10000; |
| 1129 | 964 |
| 1130 // A diagonally rotated layer that is partially off the bottom of the screen. | 965 // A diagonally rotated layer that is partially off the bottom of the screen. |
| 1131 // In this configuration, only the top-left tile would be visible. | 966 // In this configuration, only the top-left tile would be visible. |
| 1132 current_screen_transform.Translate(400, 550); | 967 current_screen_transform.Translate(400, 550); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1148 visible_layer_rect, | 983 visible_layer_rect, |
| 1149 last_layer_bounds, | 984 last_layer_bounds, |
| 1150 current_layer_bounds, | 985 current_layer_bounds, |
| 1151 last_layer_contents_scale, | 986 last_layer_contents_scale, |
| 1152 current_layer_contents_scale, | 987 current_layer_contents_scale, |
| 1153 last_screen_transform, | 988 last_screen_transform, |
| 1154 current_screen_transform, | 989 current_screen_transform, |
| 1155 current_frame_time_in_seconds, | 990 current_frame_time_in_seconds, |
| 1156 max_tiles_for_interest_area); | 991 max_tiles_for_interest_area); |
| 1157 | 992 |
| 1158 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | 993 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1159 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | 994 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1160 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | 995 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1161 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | 996 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1162 | 997 |
| 1163 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 998 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1164 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 999 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1165 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1000 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1166 | 1001 |
| 1167 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1002 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1168 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1003 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1169 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1004 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1170 priority.time_to_visible_in_seconds); | 1005 priority.time_to_visible_in_seconds); |
| 1171 | 1006 |
| 1172 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1007 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1173 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1008 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1174 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1009 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1175 priority.time_to_visible_in_seconds); | 1010 priority.time_to_visible_in_seconds); |
| 1176 | 1011 |
| 1177 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 1012 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1178 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1013 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1179 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1014 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1180 priority.time_to_visible_in_seconds); | 1015 priority.time_to_visible_in_seconds); |
| 1181 | 1016 |
| 1182 // Furthermore, in this scenario the bottom-right tile should have the larger | 1017 // Furthermore, in this scenario the bottom-right tile should have the larger |
| 1183 // distance to visible. | 1018 // distance to visible. |
| 1184 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1019 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1185 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1020 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1186 TilePriority bottom_left = | 1021 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1187 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1022 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1188 TilePriority bottom_right = | |
| 1189 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | |
| 1190 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1023 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1191 top_left.distance_to_visible_in_pixels); | 1024 top_left.distance_to_visible_in_pixels); |
| 1192 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1025 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1193 top_left.distance_to_visible_in_pixels); | 1026 top_left.distance_to_visible_in_pixels); |
| 1194 | 1027 |
| 1195 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1028 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1196 bottom_left.distance_to_visible_in_pixels); | 1029 bottom_left.distance_to_visible_in_pixels); |
| 1197 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1030 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1198 top_right.distance_to_visible_in_pixels); | 1031 top_right.distance_to_visible_in_pixels); |
| 1199 } | 1032 } |
| 1200 | 1033 |
| 1201 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 1034 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
| 1202 // Perspective transforms need to take a different code path. | 1035 // Perspective transforms need to take a different code path. |
| 1203 // This test checks tile priorities of a perspective layer. | 1036 // This test checks tile priorities of a perspective layer. |
| 1204 | 1037 |
| 1205 FakeTileManagerClient tile_manager_client; | 1038 FakePictureLayerTilingClient client; |
| 1206 FakeTileManager tile_manager(&tile_manager_client); | |
| 1207 FakePictureLayerTilingClient client(&tile_manager); | |
| 1208 scoped_ptr<TestablePictureLayerTiling> tiling; | 1039 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1209 | 1040 |
| 1210 gfx::Size device_viewport(800, 600); | 1041 gfx::Size device_viewport(800, 600); |
| 1211 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1042 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1212 gfx::Size last_layer_bounds(400, 400); | 1043 gfx::Size last_layer_bounds(200, 200); |
| 1213 gfx::Size current_layer_bounds(400, 400); | 1044 gfx::Size current_layer_bounds(200, 200); |
| 1214 float last_layer_contents_scale = 1.f; | 1045 float last_layer_contents_scale = 1.f; |
| 1215 float current_layer_contents_scale = 1.f; | 1046 float current_layer_contents_scale = 1.f; |
| 1216 gfx::Transform last_screen_transform; | 1047 gfx::Transform last_screen_transform; |
| 1217 gfx::Transform current_screen_transform; | 1048 gfx::Transform current_screen_transform; |
| 1218 double current_frame_time_in_seconds = 1.0; | 1049 double current_frame_time_in_seconds = 1.0; |
| 1219 size_t max_tiles_for_interest_area = 10000; | 1050 size_t max_tiles_for_interest_area = 10000; |
| 1220 | 1051 |
| 1221 // A 3d perspective layer rotated about its Y axis, translated to almost | 1052 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1222 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1053 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1223 // the right side, so the top-left tile will technically be closer than the | 1054 // the right side, so the top-left tile will technically be closer than the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1254 visible_layer_rect, | 1085 visible_layer_rect, |
| 1255 last_layer_bounds, | 1086 last_layer_bounds, |
| 1256 current_layer_bounds, | 1087 current_layer_bounds, |
| 1257 last_layer_contents_scale, | 1088 last_layer_contents_scale, |
| 1258 current_layer_contents_scale, | 1089 current_layer_contents_scale, |
| 1259 last_screen_transform, | 1090 last_screen_transform, |
| 1260 current_screen_transform, | 1091 current_screen_transform, |
| 1261 current_frame_time_in_seconds, | 1092 current_frame_time_in_seconds, |
| 1262 max_tiles_for_interest_area); | 1093 max_tiles_for_interest_area); |
| 1263 | 1094 |
| 1264 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | 1095 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1265 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | 1096 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1266 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | 1097 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1267 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | 1098 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1268 | 1099 |
| 1269 // All tiles will have a positive distance_to_visible | 1100 // All tiles will have a positive distance_to_visible |
| 1270 // and an infinite time_to_visible. | 1101 // and an infinite time_to_visible. |
| 1271 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1102 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1272 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1103 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1273 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1104 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1274 priority.time_to_visible_in_seconds); | 1105 priority.time_to_visible_in_seconds); |
| 1275 | 1106 |
| 1276 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1107 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1277 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1108 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1278 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1109 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1279 priority.time_to_visible_in_seconds); | 1110 priority.time_to_visible_in_seconds); |
| 1280 | 1111 |
| 1281 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1112 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1282 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1113 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1283 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1114 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1284 priority.time_to_visible_in_seconds); | 1115 priority.time_to_visible_in_seconds); |
| 1285 | 1116 |
| 1286 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 1117 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1287 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1118 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1288 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1119 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1289 priority.time_to_visible_in_seconds); | 1120 priority.time_to_visible_in_seconds); |
| 1290 | 1121 |
| 1291 // Furthermore, in this scenario the top-left distance_to_visible | 1122 // Furthermore, in this scenario the top-left distance_to_visible |
| 1292 // will be smallest, followed by top-right. The bottom layers | 1123 // will be smallest, followed by top-right. The bottom layers |
| 1293 // will of course be further than the top layers. | 1124 // will of course be further than the top layers. |
| 1294 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1125 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1295 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1126 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1296 TilePriority bottom_left = | 1127 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1297 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1128 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1298 TilePriority bottom_right = | |
| 1299 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | |
| 1300 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1129 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1301 top_left.distance_to_visible_in_pixels); | 1130 top_left.distance_to_visible_in_pixels); |
| 1302 | 1131 |
| 1303 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1132 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1304 top_right.distance_to_visible_in_pixels); | 1133 top_right.distance_to_visible_in_pixels); |
| 1305 | 1134 |
| 1306 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1135 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1307 top_left.distance_to_visible_in_pixels); | 1136 top_left.distance_to_visible_in_pixels); |
| 1308 } | 1137 } |
| 1309 | 1138 |
| 1310 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1139 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
| 1311 // Perspective transforms need to take a different code path. | 1140 // Perspective transforms need to take a different code path. |
| 1312 // This test checks tile priorities of a perspective layer. | 1141 // This test checks tile priorities of a perspective layer. |
| 1313 | 1142 |
| 1314 FakeTileManagerClient tile_manager_client; | 1143 FakePictureLayerTilingClient client; |
| 1315 FakeTileManager tile_manager(&tile_manager_client); | |
| 1316 FakePictureLayerTilingClient client(&tile_manager); | |
| 1317 scoped_ptr<TestablePictureLayerTiling> tiling; | 1144 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1318 | 1145 |
| 1319 gfx::Size device_viewport(800, 600); | 1146 gfx::Size device_viewport(800, 600); |
| 1320 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1147 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1321 gfx::Size last_layer_bounds(400, 400); | 1148 gfx::Size last_layer_bounds(200, 200); |
| 1322 gfx::Size current_layer_bounds(400, 400); | 1149 gfx::Size current_layer_bounds(200, 200); |
| 1323 float last_layer_contents_scale = 1.f; | 1150 float last_layer_contents_scale = 1.f; |
| 1324 float current_layer_contents_scale = 1.f; | 1151 float current_layer_contents_scale = 1.f; |
| 1325 gfx::Transform last_screen_transform; | 1152 gfx::Transform last_screen_transform; |
| 1326 gfx::Transform current_screen_transform; | 1153 gfx::Transform current_screen_transform; |
| 1327 double current_frame_time_in_seconds = 1.0; | 1154 double current_frame_time_in_seconds = 1.0; |
| 1328 size_t max_tiles_for_interest_area = 10000; | 1155 size_t max_tiles_for_interest_area = 10000; |
| 1329 | 1156 |
| 1330 // A 3d perspective layer rotated about its Y axis, translated to almost | 1157 // A 3d perspective layer rotated about its Y axis, translated to almost |
| 1331 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1158 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
| 1332 // the right side, so the top-left tile will technically be closer than the | 1159 // the right side, so the top-left tile will technically be closer than the |
| 1333 // top-right. | 1160 // top-right. |
| 1334 | 1161 |
| 1335 // Translate layer to offscreen | 1162 // Translate layer to offscreen |
| 1336 current_screen_transform.Translate(400.0, 970.0); | 1163 current_screen_transform.Translate(400.0, 970.0); |
| 1337 // Apply perspective and rotation about the center of the layer | 1164 // Apply perspective and rotation about the center of the layer |
| 1338 current_screen_transform.Translate(200.0, 200.0); | 1165 current_screen_transform.Translate(100.0, 100.0); |
| 1339 current_screen_transform.ApplyPerspectiveDepth(10.0); | 1166 current_screen_transform.ApplyPerspectiveDepth(10.0); |
| 1340 current_screen_transform.RotateAboutYAxis(10.0); | 1167 current_screen_transform.RotateAboutYAxis(10.0); |
| 1341 current_screen_transform.Translate(-200.0, -200.0); | 1168 current_screen_transform.Translate(-100.0, -100.0); |
| 1342 last_screen_transform = current_screen_transform; | 1169 last_screen_transform = current_screen_transform; |
| 1343 | 1170 |
| 1344 // Sanity check that this transform does cause w<0 clipping for the left side | 1171 // Sanity check that this transform does cause w<0 clipping for the left side |
| 1345 // of the layer, but not the right side. | 1172 // of the layer, but not the right side. |
| 1346 bool clipped; | 1173 bool clipped; |
| 1347 MathUtil::MapQuad(current_screen_transform, | 1174 MathUtil::MapQuad(current_screen_transform, |
| 1348 gfx::QuadF(gfx::RectF(0, 0, 200, 400)), | 1175 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), |
| 1349 &clipped); | 1176 &clipped); |
| 1350 ASSERT_TRUE(clipped); | 1177 ASSERT_TRUE(clipped); |
| 1351 | 1178 |
| 1352 MathUtil::MapQuad(current_screen_transform, | 1179 MathUtil::MapQuad(current_screen_transform, |
| 1353 gfx::QuadF(gfx::RectF(200, 0, 200, 400)), | 1180 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), |
| 1354 &clipped); | 1181 &clipped); |
| 1355 ASSERT_FALSE(clipped); | 1182 ASSERT_FALSE(clipped); |
| 1356 | 1183 |
| 1357 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1184 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1358 current_screen_transform, device_viewport); | 1185 current_screen_transform, device_viewport); |
| 1359 | 1186 |
| 1360 client.SetTileSize(gfx::Size(100, 100)); | 1187 client.SetTileSize(gfx::Size(100, 100)); |
| 1361 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1188 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1362 current_layer_bounds, | 1189 current_layer_bounds, |
| 1363 &client); | 1190 &client); |
| 1364 | 1191 |
| 1365 tiling->UpdateTilePriorities( | 1192 tiling->UpdateTilePriorities( |
| 1366 ACTIVE_TREE, | 1193 ACTIVE_TREE, |
| 1367 device_viewport, | 1194 device_viewport, |
| 1368 viewport_in_layer_space, | 1195 viewport_in_layer_space, |
| 1369 visible_layer_rect, | 1196 visible_layer_rect, |
| 1370 last_layer_bounds, | 1197 last_layer_bounds, |
| 1371 current_layer_bounds, | 1198 current_layer_bounds, |
| 1372 last_layer_contents_scale, | 1199 last_layer_contents_scale, |
| 1373 current_layer_contents_scale, | 1200 current_layer_contents_scale, |
| 1374 last_screen_transform, | 1201 last_screen_transform, |
| 1375 current_screen_transform, | 1202 current_screen_transform, |
| 1376 current_frame_time_in_seconds, | 1203 current_frame_time_in_seconds, |
| 1377 max_tiles_for_interest_area); | 1204 max_tiles_for_interest_area); |
| 1378 | 1205 |
| 1379 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | 1206 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1380 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | 1207 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1381 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | 1208 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1382 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | 1209 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1383 | 1210 |
| 1384 // Left-side tiles will be clipped by the transform, so we have to assume | 1211 // Left-side tiles will be clipped by the transform, so we have to assume |
| 1385 // they are visible just in case. | 1212 // they are visible just in case. |
| 1386 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1213 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1387 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1214 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1388 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1215 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1389 | 1216 |
| 1390 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1217 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1391 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1392 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1393 | 1220 |
| 1394 // Right-side tiles will have a positive distance_to_visible | 1221 // Right-side tiles will have a positive distance_to_visible |
| 1395 // and an infinite time_to_visible. | 1222 // and an infinite time_to_visible. |
| 1396 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1223 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1397 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1224 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1398 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1225 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1399 priority.time_to_visible_in_seconds); | 1226 priority.time_to_visible_in_seconds); |
| 1400 | 1227 |
| 1401 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 1228 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1402 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1229 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1403 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1230 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1404 priority.time_to_visible_in_seconds); | 1231 priority.time_to_visible_in_seconds); |
| 1405 } | 1232 } |
| 1406 | 1233 |
| 1407 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1234 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
| 1408 // Test that time_to_visible is computed correctly when | 1235 // Test that time_to_visible is computed correctly when |
| 1409 // there is some motion. | 1236 // there is some motion. |
| 1410 | 1237 |
| 1411 FakeTileManagerClient tile_manager_client; | 1238 FakePictureLayerTilingClient client; |
| 1412 FakeTileManager tile_manager(&tile_manager_client); | |
| 1413 FakePictureLayerTilingClient client(&tile_manager); | |
| 1414 scoped_ptr<TestablePictureLayerTiling> tiling; | 1239 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1415 | 1240 |
| 1416 gfx::Size device_viewport(800, 600); | 1241 gfx::Size device_viewport(800, 600); |
| 1417 gfx::Rect visible_layer_rect(0, 0, 0, 0); | 1242 gfx::Rect visible_layer_rect(0, 0, 0, 0); |
| 1418 gfx::Size last_layer_bounds(200, 200); | 1243 gfx::Size last_layer_bounds(200, 200); |
| 1419 gfx::Size current_layer_bounds(200, 200); | 1244 gfx::Size current_layer_bounds(200, 200); |
| 1420 float last_layer_contents_scale = 1.f; | 1245 float last_layer_contents_scale = 1.f; |
| 1421 float current_layer_contents_scale = 1.f; | 1246 float current_layer_contents_scale = 1.f; |
| 1422 gfx::Transform last_screen_transform; | 1247 gfx::Transform last_screen_transform; |
| 1423 gfx::Transform current_screen_transform; | 1248 gfx::Transform current_screen_transform; |
| 1424 double last_frame_time_in_seconds = 1.0; | 1249 double last_frame_time_in_seconds = 1.0; |
| 1425 double current_frame_time_in_seconds = 2.0; | 1250 double current_frame_time_in_seconds = 2.0; |
| 1426 size_t max_tiles_for_interest_area = 10000; | 1251 size_t max_tiles_for_interest_area = 10000; |
| 1427 | 1252 |
| 1428 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1253 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
| 1429 current_screen_transform.Translate(1800, 0); | 1254 current_screen_transform.Translate(1800, 0); |
| 1430 last_screen_transform.Translate(2800, 0); | 1255 last_screen_transform.Translate(2800, 0); |
| 1431 | 1256 |
| 1432 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1257 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1433 current_screen_transform, device_viewport); | 1258 current_screen_transform, device_viewport); |
| 1434 | 1259 |
| 1435 client.SetTileSize(gfx::Size(50, 50)); | 1260 client.SetTileSize(gfx::Size(100, 100)); |
| 1436 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1261 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1437 current_layer_bounds, | 1262 current_layer_bounds, |
| 1438 &client); | 1263 &client); |
| 1439 | 1264 |
| 1440 // previous ("last") frame | 1265 // previous ("last") frame |
| 1441 tiling->UpdateTilePriorities( | 1266 tiling->UpdateTilePriorities( |
| 1442 ACTIVE_TREE, | 1267 ACTIVE_TREE, |
| 1443 device_viewport, | 1268 device_viewport, |
| 1444 viewport_in_layer_space, | 1269 viewport_in_layer_space, |
| 1445 visible_layer_rect, | 1270 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1460 visible_layer_rect, | 1285 visible_layer_rect, |
| 1461 last_layer_bounds, | 1286 last_layer_bounds, |
| 1462 current_layer_bounds, | 1287 current_layer_bounds, |
| 1463 last_layer_contents_scale, | 1288 last_layer_contents_scale, |
| 1464 current_layer_contents_scale, | 1289 current_layer_contents_scale, |
| 1465 last_screen_transform, | 1290 last_screen_transform, |
| 1466 current_screen_transform, | 1291 current_screen_transform, |
| 1467 current_frame_time_in_seconds, | 1292 current_frame_time_in_seconds, |
| 1468 max_tiles_for_interest_area); | 1293 max_tiles_for_interest_area); |
| 1469 | 1294 |
| 1470 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | 1295 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1471 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | 1296 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1472 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | 1297 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1473 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | 1298 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1474 | 1299 |
| 1475 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1300 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1476 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1301 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1477 EXPECT_FLOAT_EQ(1.f, | 1302 EXPECT_FLOAT_EQ(1.f, |
| 1478 priority.time_to_visible_in_seconds); | 1303 priority.time_to_visible_in_seconds); |
| 1479 | 1304 |
| 1480 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1305 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1481 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1306 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1482 EXPECT_FLOAT_EQ(1.f, | 1307 EXPECT_FLOAT_EQ(1.f, |
| 1483 priority.time_to_visible_in_seconds); | 1308 priority.time_to_visible_in_seconds); |
| 1484 | 1309 |
| 1485 // time_to_visible for the right hand side layers needs an extra 0.097 | 1310 // time_to_visible for the right hand side layers needs an extra 0.099 |
| 1486 // seconds because this bundle is | 1311 // seconds because this tile is 99 pixels further away. |
| 1487 // |(50 - 2 * border_texels) * 2 + border_texels| = 97 pixels further away. | 1312 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1488 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | |
| 1489 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1313 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1490 EXPECT_FLOAT_EQ(1.097f, | 1314 EXPECT_FLOAT_EQ(1.099f, |
| 1491 priority.time_to_visible_in_seconds); | 1315 priority.time_to_visible_in_seconds); |
| 1492 | 1316 |
| 1493 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | 1317 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
| 1494 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1318 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1495 EXPECT_FLOAT_EQ(1.097f, | 1319 EXPECT_FLOAT_EQ(1.099f, |
| 1496 priority.time_to_visible_in_seconds); | 1320 priority.time_to_visible_in_seconds); |
| 1497 } | 1321 } |
| 1498 | 1322 |
| 1499 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1323 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
| 1500 // Each tile of a layer may be affected differently by a transform; Check | 1324 // Each tile of a layer may be affected differently by a transform; Check |
| 1501 // that UpdateTilePriorities correctly accounts for the transform between | 1325 // that UpdateTilePriorities correctly accounts for the transform between |
| 1502 // layer space and screen space. | 1326 // layer space and screen space. |
| 1503 | 1327 |
| 1504 FakeTileManagerClient tile_manager_client; | 1328 FakePictureLayerTilingClient client; |
| 1505 FakeTileManager tile_manager(&tile_manager_client); | |
| 1506 FakePictureLayerTilingClient client(&tile_manager); | |
| 1507 scoped_ptr<TestablePictureLayerTiling> tiling; | 1329 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1508 | 1330 |
| 1509 gfx::Size device_viewport(800, 600); | 1331 gfx::Size device_viewport(800, 600); |
| 1510 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. | 1332 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. |
| 1511 gfx::Size last_layer_bounds(200, 200); | 1333 gfx::Size last_layer_bounds(200, 200); |
| 1512 gfx::Size current_layer_bounds(200, 200); | 1334 gfx::Size current_layer_bounds(200, 200); |
| 1513 float last_layer_contents_scale = 1.f; | 1335 float last_layer_contents_scale = 1.f; |
| 1514 float current_layer_contents_scale = 1.f; | 1336 float current_layer_contents_scale = 1.f; |
| 1515 gfx::Transform last_screen_transform; | 1337 gfx::Transform last_screen_transform; |
| 1516 gfx::Transform current_screen_transform; | 1338 gfx::Transform current_screen_transform; |
| 1517 double last_frame_time_in_seconds = 1.0; | 1339 double last_frame_time_in_seconds = 1.0; |
| 1518 double current_frame_time_in_seconds = 2.0; | 1340 double current_frame_time_in_seconds = 2.0; |
| 1519 size_t max_tiles_for_interest_area = 10000; | 1341 size_t max_tiles_for_interest_area = 10000; |
| 1520 | 1342 |
| 1521 // Rotation motion is set up specifically so that: | 1343 // Rotation motion is set up specifically so that: |
| 1522 // - rotation occurs about the center of the layer | 1344 // - rotation occurs about the center of the layer |
| 1523 // - the top-left tile becomes visible on rotation | 1345 // - the top-left tile becomes visible on rotation |
| 1524 // - the top-right tile will have an infinite time_to_visible | 1346 // - the top-right tile will have an infinite time_to_visible |
| 1525 // because it is rotating away from viewport. | 1347 // because it is rotating away from viewport. |
| 1526 // - bottom-left layer will have a positive non-zero time_to_visible | 1348 // - bottom-left layer will have a positive non-zero time_to_visible |
| 1527 // because it is rotating toward the viewport. | 1349 // because it is rotating toward the viewport. |
| 1528 current_screen_transform.Translate(400, 550); | 1350 current_screen_transform.Translate(400, 550); |
| 1529 current_screen_transform.RotateAboutZAxis(45); | 1351 current_screen_transform.RotateAboutZAxis(45); |
| 1530 | 1352 |
| 1531 last_screen_transform.Translate(400, 550); | 1353 last_screen_transform.Translate(400, 550); |
| 1532 | 1354 |
| 1533 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1355 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1534 current_screen_transform, device_viewport); | 1356 current_screen_transform, device_viewport); |
| 1535 | 1357 |
| 1536 client.SetTileSize(gfx::Size(50, 50)); | 1358 client.SetTileSize(gfx::Size(100, 100)); |
| 1537 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1359 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1538 current_layer_bounds, | 1360 current_layer_bounds, |
| 1539 &client); | 1361 &client); |
| 1540 | 1362 |
| 1541 // previous ("last") frame | 1363 // previous ("last") frame |
| 1542 tiling->UpdateTilePriorities( | 1364 tiling->UpdateTilePriorities( |
| 1543 ACTIVE_TREE, | 1365 ACTIVE_TREE, |
| 1544 device_viewport, | 1366 device_viewport, |
| 1545 viewport_in_layer_space, | 1367 viewport_in_layer_space, |
| 1546 visible_layer_rect, | 1368 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1561 visible_layer_rect, | 1383 visible_layer_rect, |
| 1562 last_layer_bounds, | 1384 last_layer_bounds, |
| 1563 current_layer_bounds, | 1385 current_layer_bounds, |
| 1564 last_layer_contents_scale, | 1386 last_layer_contents_scale, |
| 1565 current_layer_contents_scale, | 1387 current_layer_contents_scale, |
| 1566 last_screen_transform, | 1388 last_screen_transform, |
| 1567 current_screen_transform, | 1389 current_screen_transform, |
| 1568 current_frame_time_in_seconds, | 1390 current_frame_time_in_seconds, |
| 1569 max_tiles_for_interest_area); | 1391 max_tiles_for_interest_area); |
| 1570 | 1392 |
| 1571 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | 1393 ASSERT_TRUE(tiling->TileAt(0, 0)); |
| 1572 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | 1394 ASSERT_TRUE(tiling->TileAt(0, 1)); |
| 1573 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | 1395 ASSERT_TRUE(tiling->TileAt(1, 0)); |
| 1574 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | 1396 ASSERT_TRUE(tiling->TileAt(1, 1)); |
| 1575 | 1397 |
| 1576 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); | 1398 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
| 1577 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1399 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1578 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1400 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1579 | 1401 |
| 1580 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); | 1402 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
| 1581 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1403 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1582 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1404 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); |
| 1583 | 1405 |
| 1584 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | 1406 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1585 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1586 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1408 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1587 priority.time_to_visible_in_seconds); | 1409 priority.time_to_visible_in_seconds); |
| 1588 } | 1410 } |
| 1589 | 1411 |
| 1590 } // namespace | 1412 } // namespace |
| 1591 } // namespace cc | 1413 } // namespace cc |
| OLD | NEW |