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