Chromium Code Reviews| 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; bundle_y < 2; ++bundle_y) { | |
| 294 for (int bundle_x = 0; bundle_x < 2; ++bundle_x) { | |
| 295 EXPECT_TRUE(tiling->TileBundleAt(bundle_x, bundle_y)) | |
| 296 << "bundle_x " << bundle_x << " bundle_y " << bundle_y; | |
| 297 | |
| 298 TileBundle* bundle = tiling->TileBundleAt(bundle_x, bundle_y); | |
| 299 for (int tile_y = 0; tile_y < 2; ++tile_y) { | |
|
enne (OOO)
2013/12/03 02:28:37
Is it possible to not make this depend on the magi
vmpstr
2013/12/03 18:44:43
I changed this to be kTileBundle{Width,Height} whi
| |
| 300 for (int tile_x = 0; tile_x < 2; ++tile_x) { | |
| 301 int global_tile_x = bundle_x * 2 + tile_x; | |
| 302 int global_tile_y = bundle_y * 2 + tile_y; | |
| 303 | |
| 304 EXPECT_TRUE(tiling->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y)) | |
| 305 << "x " << global_tile_x << " y " << global_tile_y; | |
| 306 EXPECT_EQ(tiling->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y), | |
| 307 bundle->TileAt(ACTIVE_TREE, global_tile_x, global_tile_y)) | |
| 308 << "x " << global_tile_x << " y " << global_tile_y; | |
| 309 } | |
| 310 } | |
| 311 } | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 TEST(PictureLayerTilingTest, DidBecomeActiveSwapsTiles) { | |
| 316 FakeTileManagerClient tile_manager_client; | |
| 317 FakeTileManager tile_manager(&tile_manager_client); | |
| 318 FakePictureLayerTilingClient client(&tile_manager); | |
| 319 | |
| 320 gfx::Size current_layer_bounds(400, 400); | |
| 321 client.SetTileSize(gfx::Size(100, 100)); | |
| 322 scoped_ptr<TestablePictureLayerTiling> tiling = | |
| 323 TestablePictureLayerTiling::Create(1.0f, current_layer_bounds, &client); | |
| 324 | |
| 325 tiling->CreateTilesForTesting(ACTIVE_TREE); | |
| 326 std::vector<Tile*> old_active_tiles = tiling->TilesForTesting(ACTIVE_TREE); | |
| 327 tiling->DidBecomeActive(); | |
| 328 std::vector<Tile*> pending_tiles = tiling->TilesForTesting(PENDING_TREE); | |
| 329 EXPECT_EQ(old_active_tiles.size(), pending_tiles.size()); | |
| 330 std::vector<Tile*>::const_iterator old_it = old_active_tiles.begin(); | |
| 331 for (std::vector<Tile*>::const_iterator it = pending_tiles.begin(); | |
| 332 it != pending_tiles.end(); | |
| 333 ++it) { | |
| 334 EXPECT_EQ(*it, *old_it); | |
| 335 ++old_it; | |
| 336 } | |
| 337 } | |
| 338 | |
| 264 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 339 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
| 265 gfx::Rect in(40, 50, 100, 200); | 340 gfx::Rect in(40, 50, 100, 200); |
| 266 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 341 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
| 267 int64 target_area = 100 * 200; | 342 int64 target_area = 100 * 200; |
| 268 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 343 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 269 in, target_area, bounds, NULL); | 344 in, target_area, bounds, NULL); |
| 270 EXPECT_EQ(in.ToString(), out.ToString()); | 345 EXPECT_EQ(in.ToString(), out.ToString()); |
| 271 } | 346 } |
| 272 | 347 |
| 273 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 348 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 gfx::Transform(), // current screen transform | 800 gfx::Transform(), // current screen transform |
| 726 1.0, // current frame time | 801 1.0, // current frame time |
| 727 10000); // max tiles in tile manager | 802 10000); // max tiles in tile manager |
| 728 | 803 |
| 729 VerifyTiles(pending_set.tiling_at(0), | 804 VerifyTiles(pending_set.tiling_at(0), |
| 730 1.f, | 805 1.f, |
| 731 gfx::Rect(layer_bounds), | 806 gfx::Rect(layer_bounds), |
| 732 base::Bind(&TileExists, true)); | 807 base::Bind(&TileExists, true)); |
| 733 } | 808 } |
| 734 | 809 |
| 810 TEST_F(PictureLayerTilingIteratorTest, BundlesAndTilesAlign) { | |
| 811 Initialize(gfx::Size(100, 100), 1, gfx::Size(850, 850)); | |
| 812 bool success = true; | |
| 813 for (int y = -20; (y <= 102) && success; ++y) { | |
| 814 for (int x = 0; (x <= 103) && success; ++x) { | |
| 815 for (int size = 1; (size <= 201) && success; size += 50) { | |
| 816 gfx::Rect rect(x, y, size, size); | |
| 817 | |
| 818 TilingData tiling_data = tiling_->tiling_data(); | |
| 819 | |
| 820 std::set<std::pair<int, int> > tile_positions; | |
| 821 std::set<std::pair<int, int> > predicted_bundle_positions; | |
| 822 size_t iteration_count = 0; | |
| 823 for (TilingData::Iterator iter(&tiling_data, rect); iter; ++iter) { | |
| 824 ++iteration_count; | |
| 825 tile_positions.insert(std::make_pair(iter.index_x(), iter.index_y())); | |
| 826 predicted_bundle_positions.insert( | |
| 827 ComputeTileBundleIndex(iter.index_x(), iter.index_y())); | |
| 828 } | |
| 829 | |
| 830 EXPECT_EQ(tile_positions.size(), iteration_count) << rect.ToString(); | |
| 831 if (tile_positions.size() != iteration_count) | |
| 832 success = false; | |
|
enne (OOO)
2013/12/03 02:28:37
Why do you need this success variable with EXPECT_
vmpstr
2013/12/03 18:44:43
Oh this is just so it doesn't spam a lot of lines
enne (OOO)
2013/12/03 20:49:01
You could make them ASSERT instead of EXPECT and i
vmpstr
2013/12/03 22:01:36
Done.
| |
| 833 | |
| 834 TilingData bundle_tiling_data = tiling_->bundle_tiling_data(); | |
| 835 std::set<std::pair<int, int> > bundle_positions; | |
| 836 iteration_count = 0; | |
| 837 for (TilingData::Iterator iter(&bundle_tiling_data, rect); | |
| 838 iter; | |
| 839 ++iter) { | |
| 840 ++iteration_count; | |
| 841 bundle_positions.insert( | |
| 842 std::make_pair(iter.index_x(), iter.index_y())); | |
| 843 } | |
| 844 | |
| 845 EXPECT_EQ(bundle_positions.size(), iteration_count) << rect.ToString(); | |
| 846 EXPECT_EQ(predicted_bundle_positions.size(), iteration_count) | |
| 847 << rect.ToString(); | |
| 848 if ((bundle_positions.size() != iteration_count) || | |
| 849 (predicted_bundle_positions.size() != iteration_count)) | |
| 850 success = false; | |
| 851 | |
| 852 std::set<std::pair<int, int> >::const_iterator predicted_iterator = | |
| 853 predicted_bundle_positions.begin(); | |
| 854 for (std::set<std::pair<int, int> >::const_iterator actual_iterator = | |
| 855 bundle_positions.begin(); | |
| 856 actual_iterator != bundle_positions.end(); | |
| 857 ++actual_iterator) { | |
| 858 EXPECT_EQ(*actual_iterator, *predicted_iterator) << rect.ToString(); | |
| 859 if (*actual_iterator != *predicted_iterator) | |
| 860 success = false; | |
| 861 | |
| 862 ++predicted_iterator; | |
| 863 } | |
| 864 } | |
| 865 } | |
| 866 } | |
| 867 EXPECT_TRUE(success); | |
| 868 } | |
| 869 | |
| 870 | |
| 735 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 871 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
| 736 // The TilePriority of visible tiles should have zero distance_to_visible | 872 // The TilePriority of visible tiles should have zero distance_to_visible |
| 737 // and time_to_visible. | 873 // and time_to_visible. |
| 738 | 874 |
| 739 FakePictureLayerTilingClient client; | 875 FakeTileManagerClient tile_manager_client; |
| 876 FakeTileManager tile_manager(&tile_manager_client); | |
| 877 FakePictureLayerTilingClient client(&tile_manager); | |
| 740 scoped_ptr<TestablePictureLayerTiling> tiling; | 878 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 741 | 879 |
| 742 gfx::Size device_viewport(800, 600); | 880 gfx::Size device_viewport(800, 600); |
| 743 gfx::Rect visible_layer_rect(0, 0, 200, 200); | 881 gfx::Rect visible_layer_rect(0, 0, 200, 200); |
| 744 gfx::Size last_layer_bounds(200, 200); | 882 gfx::Size last_layer_bounds(200, 200); |
| 745 gfx::Size current_layer_bounds(200, 200); | 883 gfx::Size current_layer_bounds(200, 200); |
| 746 float last_layer_contents_scale = 1.f; | 884 float last_layer_contents_scale = 1.f; |
| 747 float current_layer_contents_scale = 1.f; | 885 float current_layer_contents_scale = 1.f; |
| 748 gfx::Transform last_screen_transform; | 886 gfx::Transform last_screen_transform; |
| 749 gfx::Transform current_screen_transform; | 887 gfx::Transform current_screen_transform; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 765 visible_layer_rect, | 903 visible_layer_rect, |
| 766 last_layer_bounds, | 904 last_layer_bounds, |
| 767 current_layer_bounds, | 905 current_layer_bounds, |
| 768 last_layer_contents_scale, | 906 last_layer_contents_scale, |
| 769 current_layer_contents_scale, | 907 current_layer_contents_scale, |
| 770 last_screen_transform, | 908 last_screen_transform, |
| 771 current_screen_transform, | 909 current_screen_transform, |
| 772 current_frame_time_in_seconds, | 910 current_frame_time_in_seconds, |
| 773 max_tiles_for_interest_area); | 911 max_tiles_for_interest_area); |
| 774 | 912 |
| 775 ASSERT_TRUE(tiling->TileAt(0, 0)); | 913 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 776 ASSERT_TRUE(tiling->TileAt(0, 1)); | 914 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 777 ASSERT_TRUE(tiling->TileAt(1, 0)); | 915 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 778 ASSERT_TRUE(tiling->TileAt(1, 1)); | 916 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 917 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 779 | 918 |
| 780 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 919 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); | 920 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 921 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 795 } | 922 } |
| 796 | 923 |
| 797 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 924 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
| 798 // The TilePriority of offscreen tiles (without movement) should have nonzero | 925 // The TilePriority of offscreen tiles (without movement) should have nonzero |
| 799 // distance_to_visible and infinite time_to_visible. | 926 // distance_to_visible and infinite time_to_visible. |
| 800 | 927 |
| 801 FakePictureLayerTilingClient client; | 928 FakeTileManagerClient tile_manager_client; |
| 929 FakeTileManager tile_manager(&tile_manager_client); | |
| 930 FakePictureLayerTilingClient client(&tile_manager); | |
| 802 scoped_ptr<TestablePictureLayerTiling> tiling; | 931 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 803 | 932 |
| 804 gfx::Size device_viewport(800, 600); | 933 gfx::Size device_viewport(800, 600); |
| 805 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | 934 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. |
| 806 gfx::Size last_layer_bounds(200, 200); | 935 gfx::Size last_layer_bounds(400, 400); |
| 807 gfx::Size current_layer_bounds(200, 200); | 936 gfx::Size current_layer_bounds(400, 400); |
| 808 float last_layer_contents_scale = 1.f; | 937 float last_layer_contents_scale = 1.f; |
| 809 float current_layer_contents_scale = 1.f; | 938 float current_layer_contents_scale = 1.f; |
| 810 gfx::Transform last_screen_transform; | 939 gfx::Transform last_screen_transform; |
| 811 gfx::Transform current_screen_transform; | 940 gfx::Transform current_screen_transform; |
| 812 double current_frame_time_in_seconds = 1.0; | 941 double current_frame_time_in_seconds = 1.0; |
| 813 size_t max_tiles_for_interest_area = 10000; | 942 size_t max_tiles_for_interest_area = 10000; |
| 814 | 943 |
| 815 current_screen_transform.Translate(850, 0); | 944 current_screen_transform.Translate(850, 0); |
| 816 last_screen_transform = current_screen_transform; | 945 last_screen_transform = current_screen_transform; |
| 817 | 946 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 830 visible_layer_rect, | 959 visible_layer_rect, |
| 831 last_layer_bounds, | 960 last_layer_bounds, |
| 832 current_layer_bounds, | 961 current_layer_bounds, |
| 833 last_layer_contents_scale, | 962 last_layer_contents_scale, |
| 834 current_layer_contents_scale, | 963 current_layer_contents_scale, |
| 835 last_screen_transform, | 964 last_screen_transform, |
| 836 current_screen_transform, | 965 current_screen_transform, |
| 837 current_frame_time_in_seconds, | 966 current_frame_time_in_seconds, |
| 838 max_tiles_for_interest_area); | 967 max_tiles_for_interest_area); |
| 839 | 968 |
| 840 ASSERT_TRUE(tiling->TileAt(0, 0)); | 969 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 841 ASSERT_TRUE(tiling->TileAt(0, 1)); | 970 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 842 ASSERT_TRUE(tiling->TileAt(1, 0)); | 971 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 843 ASSERT_TRUE(tiling->TileAt(1, 1)); | 972 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 973 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 844 | 974 |
| 845 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 975 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 846 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 976 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 847 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 977 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 848 priority.time_to_visible_in_seconds); | 978 priority.time_to_visible_in_seconds); |
| 849 | 979 |
| 850 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 980 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 2)); |
| 851 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 981 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 2, 3)); |
| 852 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 982 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 2)); |
| 853 priority.time_to_visible_in_seconds); | 983 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 3, 3)); |
| 984 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | |
| 985 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | |
| 986 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | |
| 854 | 987 |
| 855 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 988 // 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. | 989 // larger distance to visible. |
| 867 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 990 TilePriority left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 868 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 991 TilePriority right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 869 EXPECT_GT(right.distance_to_visible_in_pixels, | 992 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 870 left.distance_to_visible_in_pixels); | 993 left.distance_to_visible_in_pixels); |
| 871 | 994 |
| 872 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 995 left = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 873 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 996 right = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 874 EXPECT_GT(right.distance_to_visible_in_pixels, | 997 EXPECT_GT(right.distance_to_visible_in_pixels, |
| 875 left.distance_to_visible_in_pixels); | 998 left.distance_to_visible_in_pixels); |
| 876 } | 999 } |
| 877 | 1000 |
| 878 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 1001 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
| 879 // Sanity check that a layer with some tiles visible and others offscreen has | 1002 // Sanity check that a layer with some tiles visible and others offscreen has |
| 880 // correct TilePriorities for each tile. | 1003 // correct TilePriorities for each tile. |
| 881 | 1004 |
| 882 FakePictureLayerTilingClient client; | 1005 FakeTileManagerClient tile_manager_client; |
| 1006 FakeTileManager tile_manager(&tile_manager_client); | |
| 1007 FakePictureLayerTilingClient client(&tile_manager); | |
| 883 scoped_ptr<TestablePictureLayerTiling> tiling; | 1008 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 884 | 1009 |
| 885 gfx::Size device_viewport(800, 600); | 1010 gfx::Size device_viewport(800, 600); |
| 886 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | 1011 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. |
| 887 gfx::Size last_layer_bounds(200, 200); | 1012 gfx::Size last_layer_bounds(400, 400); |
| 888 gfx::Size current_layer_bounds(200, 200); | 1013 gfx::Size current_layer_bounds(400, 400); |
| 889 float last_layer_contents_scale = 1.f; | 1014 float last_layer_contents_scale = 1.f; |
| 890 float current_layer_contents_scale = 1.f; | 1015 float current_layer_contents_scale = 1.f; |
| 891 gfx::Transform last_screen_transform; | 1016 gfx::Transform last_screen_transform; |
| 892 gfx::Transform current_screen_transform; | 1017 gfx::Transform current_screen_transform; |
| 893 double current_frame_time_in_seconds = 1.0; | 1018 double current_frame_time_in_seconds = 1.0; |
| 894 size_t max_tiles_for_interest_area = 10000; | 1019 size_t max_tiles_for_interest_area = 10000; |
| 895 | 1020 |
| 896 current_screen_transform.Translate(705, 505); | 1021 current_screen_transform.Translate(705, 505); |
| 897 last_screen_transform = current_screen_transform; | 1022 last_screen_transform = current_screen_transform; |
| 898 | 1023 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 911 visible_layer_rect, | 1036 visible_layer_rect, |
| 912 last_layer_bounds, | 1037 last_layer_bounds, |
| 913 current_layer_bounds, | 1038 current_layer_bounds, |
| 914 last_layer_contents_scale, | 1039 last_layer_contents_scale, |
| 915 current_layer_contents_scale, | 1040 current_layer_contents_scale, |
| 916 last_screen_transform, | 1041 last_screen_transform, |
| 917 current_screen_transform, | 1042 current_screen_transform, |
| 918 current_frame_time_in_seconds, | 1043 current_frame_time_in_seconds, |
| 919 max_tiles_for_interest_area); | 1044 max_tiles_for_interest_area); |
| 920 | 1045 |
| 921 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1046 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 0)); |
| 922 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1047 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 0, 1)); |
| 923 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1048 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 0)); |
| 924 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1049 ASSERT_TRUE(tiling->TileAt(ACTIVE_TREE, 1, 1)); |
| 1050 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); | |
| 1051 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); | |
| 1052 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); | |
| 1053 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); | |
| 925 | 1054 |
| 926 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1055 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 927 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1056 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 928 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1057 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 929 | 1058 |
| 930 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1059 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 931 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1060 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 932 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1061 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 933 priority.time_to_visible_in_seconds); | 1062 priority.time_to_visible_in_seconds); |
| 934 | 1063 |
| 935 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1064 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 936 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1065 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 937 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1066 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 938 priority.time_to_visible_in_seconds); | 1067 priority.time_to_visible_in_seconds); |
| 939 | 1068 |
| 940 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1069 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 941 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1070 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 942 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1071 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 943 priority.time_to_visible_in_seconds); | 1072 priority.time_to_visible_in_seconds); |
| 944 } | 1073 } |
| 945 | 1074 |
| 946 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 1075 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
| 947 // Each tile of a layer may be affected differently by a transform; Check | 1076 // Each tile of a layer may be affected differently by a transform; Check |
| 948 // that UpdateTilePriorities correctly accounts for the transform between | 1077 // that UpdateTilePriorities correctly accounts for the transform between |
| 949 // layer space and screen space. | 1078 // layer space and screen space. |
| 950 | 1079 |
| 951 FakePictureLayerTilingClient client; | 1080 FakeTileManagerClient tile_manager_client; |
| 1081 FakeTileManager tile_manager(&tile_manager_client); | |
| 1082 FakePictureLayerTilingClient client(&tile_manager); | |
| 952 scoped_ptr<TestablePictureLayerTiling> tiling; | 1083 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 953 | 1084 |
| 954 gfx::Size device_viewport(800, 600); | 1085 gfx::Size device_viewport(800, 600); |
| 955 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | 1086 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. |
| 956 gfx::Size last_layer_bounds(200, 200); | 1087 gfx::Size last_layer_bounds(400, 400); |
| 957 gfx::Size current_layer_bounds(200, 200); | 1088 gfx::Size current_layer_bounds(400, 400); |
| 958 float last_layer_contents_scale = 1.f; | 1089 float last_layer_contents_scale = 1.f; |
| 959 float current_layer_contents_scale = 1.f; | 1090 float current_layer_contents_scale = 1.f; |
| 960 gfx::Transform last_screen_transform; | 1091 gfx::Transform last_screen_transform; |
| 961 gfx::Transform current_screen_transform; | 1092 gfx::Transform current_screen_transform; |
| 962 double current_frame_time_in_seconds = 1.0; | 1093 double current_frame_time_in_seconds = 1.0; |
| 963 size_t max_tiles_for_interest_area = 10000; | 1094 size_t max_tiles_for_interest_area = 10000; |
| 964 | 1095 |
| 965 // A diagonally rotated layer that is partially off the bottom of the screen. | 1096 // 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. | 1097 // In this configuration, only the top-left tile would be visible. |
| 967 current_screen_transform.Translate(400, 550); | 1098 current_screen_transform.Translate(400, 550); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 983 visible_layer_rect, | 1114 visible_layer_rect, |
| 984 last_layer_bounds, | 1115 last_layer_bounds, |
| 985 current_layer_bounds, | 1116 current_layer_bounds, |
| 986 last_layer_contents_scale, | 1117 last_layer_contents_scale, |
| 987 current_layer_contents_scale, | 1118 current_layer_contents_scale, |
| 988 last_screen_transform, | 1119 last_screen_transform, |
| 989 current_screen_transform, | 1120 current_screen_transform, |
| 990 current_frame_time_in_seconds, | 1121 current_frame_time_in_seconds, |
| 991 max_tiles_for_interest_area); | 1122 max_tiles_for_interest_area); |
| 992 | 1123 |
| 993 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1124 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 994 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1125 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 995 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1126 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 996 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1127 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 997 | 1128 |
| 998 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1129 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 999 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1130 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1000 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1131 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1001 | 1132 |
| 1002 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1133 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1003 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1134 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1004 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1135 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1005 priority.time_to_visible_in_seconds); | 1136 priority.time_to_visible_in_seconds); |
| 1006 | 1137 |
| 1007 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1138 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1008 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1139 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1009 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1140 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1010 priority.time_to_visible_in_seconds); | 1141 priority.time_to_visible_in_seconds); |
| 1011 | 1142 |
| 1012 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1143 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1013 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1144 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1014 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1145 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1015 priority.time_to_visible_in_seconds); | 1146 priority.time_to_visible_in_seconds); |
| 1016 | 1147 |
| 1017 // Furthermore, in this scenario the bottom-right tile should have the larger | 1148 // Furthermore, in this scenario the bottom-right tile should have the larger |
| 1018 // distance to visible. | 1149 // distance to visible. |
| 1019 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1150 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1020 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1151 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1021 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1152 TilePriority bottom_left = |
| 1022 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1153 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1154 TilePriority bottom_right = | |
| 1155 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | |
| 1023 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1156 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1024 top_left.distance_to_visible_in_pixels); | 1157 top_left.distance_to_visible_in_pixels); |
| 1025 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1158 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1026 top_left.distance_to_visible_in_pixels); | 1159 top_left.distance_to_visible_in_pixels); |
| 1027 | 1160 |
| 1028 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1161 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1029 bottom_left.distance_to_visible_in_pixels); | 1162 bottom_left.distance_to_visible_in_pixels); |
| 1030 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1163 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1031 top_right.distance_to_visible_in_pixels); | 1164 top_right.distance_to_visible_in_pixels); |
| 1032 } | 1165 } |
| 1033 | 1166 |
| 1034 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 1167 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
| 1035 // Perspective transforms need to take a different code path. | 1168 // Perspective transforms need to take a different code path. |
| 1036 // This test checks tile priorities of a perspective layer. | 1169 // This test checks tile priorities of a perspective layer. |
| 1037 | 1170 |
| 1038 FakePictureLayerTilingClient client; | 1171 FakeTileManagerClient tile_manager_client; |
| 1172 FakeTileManager tile_manager(&tile_manager_client); | |
| 1173 FakePictureLayerTilingClient client(&tile_manager); | |
| 1039 scoped_ptr<TestablePictureLayerTiling> tiling; | 1174 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1040 | 1175 |
| 1041 gfx::Size device_viewport(800, 600); | 1176 gfx::Size device_viewport(800, 600); |
| 1042 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1177 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1043 gfx::Size last_layer_bounds(200, 200); | 1178 gfx::Size last_layer_bounds(400, 400); |
| 1044 gfx::Size current_layer_bounds(200, 200); | 1179 gfx::Size current_layer_bounds(400, 400); |
| 1045 float last_layer_contents_scale = 1.f; | 1180 float last_layer_contents_scale = 1.f; |
| 1046 float current_layer_contents_scale = 1.f; | 1181 float current_layer_contents_scale = 1.f; |
| 1047 gfx::Transform last_screen_transform; | 1182 gfx::Transform last_screen_transform; |
| 1048 gfx::Transform current_screen_transform; | 1183 gfx::Transform current_screen_transform; |
| 1049 double current_frame_time_in_seconds = 1.0; | 1184 double current_frame_time_in_seconds = 1.0; |
| 1050 size_t max_tiles_for_interest_area = 10000; | 1185 size_t max_tiles_for_interest_area = 10000; |
| 1051 | 1186 |
| 1052 // A 3d perspective layer rotated about its Y axis, translated to almost | 1187 // 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 | 1188 // 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 | 1189 // 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, | 1220 visible_layer_rect, |
| 1086 last_layer_bounds, | 1221 last_layer_bounds, |
| 1087 current_layer_bounds, | 1222 current_layer_bounds, |
| 1088 last_layer_contents_scale, | 1223 last_layer_contents_scale, |
| 1089 current_layer_contents_scale, | 1224 current_layer_contents_scale, |
| 1090 last_screen_transform, | 1225 last_screen_transform, |
| 1091 current_screen_transform, | 1226 current_screen_transform, |
| 1092 current_frame_time_in_seconds, | 1227 current_frame_time_in_seconds, |
| 1093 max_tiles_for_interest_area); | 1228 max_tiles_for_interest_area); |
| 1094 | 1229 |
| 1095 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1230 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1096 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1231 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1097 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1232 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1098 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1233 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1099 | 1234 |
| 1100 // All tiles will have a positive distance_to_visible | 1235 // All tiles will have a positive distance_to_visible |
| 1101 // and an infinite time_to_visible. | 1236 // and an infinite time_to_visible. |
| 1102 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1237 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1103 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1238 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1104 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1239 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1105 priority.time_to_visible_in_seconds); | 1240 priority.time_to_visible_in_seconds); |
| 1106 | 1241 |
| 1107 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1242 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1108 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1243 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1109 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1244 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1110 priority.time_to_visible_in_seconds); | 1245 priority.time_to_visible_in_seconds); |
| 1111 | 1246 |
| 1112 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1247 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1113 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1248 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1114 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1249 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1115 priority.time_to_visible_in_seconds); | 1250 priority.time_to_visible_in_seconds); |
| 1116 | 1251 |
| 1117 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1252 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1118 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1253 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1119 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1254 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1120 priority.time_to_visible_in_seconds); | 1255 priority.time_to_visible_in_seconds); |
| 1121 | 1256 |
| 1122 // Furthermore, in this scenario the top-left distance_to_visible | 1257 // Furthermore, in this scenario the top-left distance_to_visible |
| 1123 // will be smallest, followed by top-right. The bottom layers | 1258 // will be smallest, followed by top-right. The bottom layers |
| 1124 // will of course be further than the top layers. | 1259 // will of course be further than the top layers. |
| 1125 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1260 TilePriority top_left = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1126 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1261 TilePriority top_right = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1127 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1262 TilePriority bottom_left = |
| 1128 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1263 tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1264 TilePriority bottom_right = | |
| 1265 tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); | |
| 1129 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1266 EXPECT_GT(top_right.distance_to_visible_in_pixels, |
| 1130 top_left.distance_to_visible_in_pixels); | 1267 top_left.distance_to_visible_in_pixels); |
| 1131 | 1268 |
| 1132 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1269 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, |
| 1133 top_right.distance_to_visible_in_pixels); | 1270 top_right.distance_to_visible_in_pixels); |
| 1134 | 1271 |
| 1135 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1272 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, |
| 1136 top_left.distance_to_visible_in_pixels); | 1273 top_left.distance_to_visible_in_pixels); |
| 1137 } | 1274 } |
| 1138 | 1275 |
| 1139 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1276 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
| 1140 // Perspective transforms need to take a different code path. | 1277 // Perspective transforms need to take a different code path. |
| 1141 // This test checks tile priorities of a perspective layer. | 1278 // This test checks tile priorities of a perspective layer. |
| 1142 | 1279 |
| 1143 FakePictureLayerTilingClient client; | 1280 FakeTileManagerClient tile_manager_client; |
| 1281 FakeTileManager tile_manager(&tile_manager_client); | |
| 1282 FakePictureLayerTilingClient client(&tile_manager); | |
| 1144 scoped_ptr<TestablePictureLayerTiling> tiling; | 1283 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1145 | 1284 |
| 1146 gfx::Size device_viewport(800, 600); | 1285 gfx::Size device_viewport(800, 600); |
| 1147 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1286 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
| 1148 gfx::Size last_layer_bounds(200, 200); | 1287 gfx::Size last_layer_bounds(400, 400); |
| 1149 gfx::Size current_layer_bounds(200, 200); | 1288 gfx::Size current_layer_bounds(400, 400); |
| 1150 float last_layer_contents_scale = 1.f; | 1289 float last_layer_contents_scale = 1.f; |
| 1151 float current_layer_contents_scale = 1.f; | 1290 float current_layer_contents_scale = 1.f; |
| 1152 gfx::Transform last_screen_transform; | 1291 gfx::Transform last_screen_transform; |
| 1153 gfx::Transform current_screen_transform; | 1292 gfx::Transform current_screen_transform; |
| 1154 double current_frame_time_in_seconds = 1.0; | 1293 double current_frame_time_in_seconds = 1.0; |
| 1155 size_t max_tiles_for_interest_area = 10000; | 1294 size_t max_tiles_for_interest_area = 10000; |
| 1156 | 1295 |
| 1157 // A 3d perspective layer rotated about its Y axis, translated to almost | 1296 // 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 | 1297 // 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 | 1298 // the right side, so the top-left tile will technically be closer than the |
| 1160 // top-right. | 1299 // top-right. |
| 1161 | 1300 |
| 1162 // Translate layer to offscreen | 1301 // Translate layer to offscreen |
| 1163 current_screen_transform.Translate(400.0, 970.0); | 1302 current_screen_transform.Translate(400.0, 970.0); |
| 1164 // Apply perspective and rotation about the center of the layer | 1303 // Apply perspective and rotation about the center of the layer |
| 1165 current_screen_transform.Translate(100.0, 100.0); | 1304 current_screen_transform.Translate(200.0, 200.0); |
| 1166 current_screen_transform.ApplyPerspectiveDepth(10.0); | 1305 current_screen_transform.ApplyPerspectiveDepth(10.0); |
| 1167 current_screen_transform.RotateAboutYAxis(10.0); | 1306 current_screen_transform.RotateAboutYAxis(10.0); |
| 1168 current_screen_transform.Translate(-100.0, -100.0); | 1307 current_screen_transform.Translate(-200.0, -200.0); |
| 1169 last_screen_transform = current_screen_transform; | 1308 last_screen_transform = current_screen_transform; |
| 1170 | 1309 |
| 1171 // Sanity check that this transform does cause w<0 clipping for the left side | 1310 // Sanity check that this transform does cause w<0 clipping for the left side |
| 1172 // of the layer, but not the right side. | 1311 // of the layer, but not the right side. |
| 1173 bool clipped; | 1312 bool clipped; |
| 1174 MathUtil::MapQuad(current_screen_transform, | 1313 MathUtil::MapQuad(current_screen_transform, |
| 1175 gfx::QuadF(gfx::RectF(0, 0, 100, 200)), | 1314 gfx::QuadF(gfx::RectF(0, 0, 200, 400)), |
| 1176 &clipped); | 1315 &clipped); |
| 1177 ASSERT_TRUE(clipped); | 1316 ASSERT_TRUE(clipped); |
| 1178 | 1317 |
| 1179 MathUtil::MapQuad(current_screen_transform, | 1318 MathUtil::MapQuad(current_screen_transform, |
| 1180 gfx::QuadF(gfx::RectF(100, 0, 100, 200)), | 1319 gfx::QuadF(gfx::RectF(200, 0, 200, 400)), |
| 1181 &clipped); | 1320 &clipped); |
| 1182 ASSERT_FALSE(clipped); | 1321 ASSERT_FALSE(clipped); |
| 1183 | 1322 |
| 1184 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1323 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1185 current_screen_transform, device_viewport); | 1324 current_screen_transform, device_viewport); |
| 1186 | 1325 |
| 1187 client.SetTileSize(gfx::Size(100, 100)); | 1326 client.SetTileSize(gfx::Size(100, 100)); |
| 1188 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1327 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1189 current_layer_bounds, | 1328 current_layer_bounds, |
| 1190 &client); | 1329 &client); |
| 1191 | 1330 |
| 1192 tiling->UpdateTilePriorities( | 1331 tiling->UpdateTilePriorities( |
| 1193 ACTIVE_TREE, | 1332 ACTIVE_TREE, |
| 1194 device_viewport, | 1333 device_viewport, |
| 1195 viewport_in_layer_space, | 1334 viewport_in_layer_space, |
| 1196 visible_layer_rect, | 1335 visible_layer_rect, |
| 1197 last_layer_bounds, | 1336 last_layer_bounds, |
| 1198 current_layer_bounds, | 1337 current_layer_bounds, |
| 1199 last_layer_contents_scale, | 1338 last_layer_contents_scale, |
| 1200 current_layer_contents_scale, | 1339 current_layer_contents_scale, |
| 1201 last_screen_transform, | 1340 last_screen_transform, |
| 1202 current_screen_transform, | 1341 current_screen_transform, |
| 1203 current_frame_time_in_seconds, | 1342 current_frame_time_in_seconds, |
| 1204 max_tiles_for_interest_area); | 1343 max_tiles_for_interest_area); |
| 1205 | 1344 |
| 1206 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1345 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1207 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1346 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1208 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1347 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1209 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1348 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1210 | 1349 |
| 1211 // Left-side tiles will be clipped by the transform, so we have to assume | 1350 // Left-side tiles will be clipped by the transform, so we have to assume |
| 1212 // they are visible just in case. | 1351 // they are visible just in case. |
| 1213 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1352 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1214 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1353 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1215 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1354 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1216 | 1355 |
| 1217 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1356 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1357 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1358 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1220 | 1359 |
| 1221 // Right-side tiles will have a positive distance_to_visible | 1360 // Right-side tiles will have a positive distance_to_visible |
| 1222 // and an infinite time_to_visible. | 1361 // and an infinite time_to_visible. |
| 1223 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1362 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1224 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1363 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1225 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1364 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1226 priority.time_to_visible_in_seconds); | 1365 priority.time_to_visible_in_seconds); |
| 1227 | 1366 |
| 1228 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1367 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1229 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1368 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1230 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1369 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1231 priority.time_to_visible_in_seconds); | 1370 priority.time_to_visible_in_seconds); |
| 1232 } | 1371 } |
| 1233 | 1372 |
| 1234 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1373 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
| 1235 // Test that time_to_visible is computed correctly when | 1374 // Test that time_to_visible is computed correctly when |
| 1236 // there is some motion. | 1375 // there is some motion. |
| 1237 | 1376 |
| 1238 FakePictureLayerTilingClient client; | 1377 FakeTileManagerClient tile_manager_client; |
| 1378 FakeTileManager tile_manager(&tile_manager_client); | |
| 1379 FakePictureLayerTilingClient client(&tile_manager); | |
| 1239 scoped_ptr<TestablePictureLayerTiling> tiling; | 1380 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1240 | 1381 |
| 1241 gfx::Size device_viewport(800, 600); | 1382 gfx::Size device_viewport(800, 600); |
| 1242 gfx::Rect visible_layer_rect(0, 0, 0, 0); | 1383 gfx::Rect visible_layer_rect(0, 0, 0, 0); |
| 1243 gfx::Size last_layer_bounds(200, 200); | 1384 gfx::Size last_layer_bounds(200, 200); |
| 1244 gfx::Size current_layer_bounds(200, 200); | 1385 gfx::Size current_layer_bounds(200, 200); |
| 1245 float last_layer_contents_scale = 1.f; | 1386 float last_layer_contents_scale = 1.f; |
| 1246 float current_layer_contents_scale = 1.f; | 1387 float current_layer_contents_scale = 1.f; |
| 1247 gfx::Transform last_screen_transform; | 1388 gfx::Transform last_screen_transform; |
| 1248 gfx::Transform current_screen_transform; | 1389 gfx::Transform current_screen_transform; |
| 1249 double last_frame_time_in_seconds = 1.0; | 1390 double last_frame_time_in_seconds = 1.0; |
| 1250 double current_frame_time_in_seconds = 2.0; | 1391 double current_frame_time_in_seconds = 2.0; |
| 1251 size_t max_tiles_for_interest_area = 10000; | 1392 size_t max_tiles_for_interest_area = 10000; |
| 1252 | 1393 |
| 1253 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1394 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
| 1254 current_screen_transform.Translate(1800, 0); | 1395 current_screen_transform.Translate(1800, 0); |
| 1255 last_screen_transform.Translate(2800, 0); | 1396 last_screen_transform.Translate(2800, 0); |
| 1256 | 1397 |
| 1257 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1398 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1258 current_screen_transform, device_viewport); | 1399 current_screen_transform, device_viewport); |
| 1259 | 1400 |
| 1260 client.SetTileSize(gfx::Size(100, 100)); | 1401 client.SetTileSize(gfx::Size(50, 50)); |
| 1261 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1402 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1262 current_layer_bounds, | 1403 current_layer_bounds, |
| 1263 &client); | 1404 &client); |
| 1264 | 1405 |
| 1265 // previous ("last") frame | 1406 // previous ("last") frame |
| 1266 tiling->UpdateTilePriorities( | 1407 tiling->UpdateTilePriorities( |
| 1267 ACTIVE_TREE, | 1408 ACTIVE_TREE, |
| 1268 device_viewport, | 1409 device_viewport, |
| 1269 viewport_in_layer_space, | 1410 viewport_in_layer_space, |
| 1270 visible_layer_rect, | 1411 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1285 visible_layer_rect, | 1426 visible_layer_rect, |
| 1286 last_layer_bounds, | 1427 last_layer_bounds, |
| 1287 current_layer_bounds, | 1428 current_layer_bounds, |
| 1288 last_layer_contents_scale, | 1429 last_layer_contents_scale, |
| 1289 current_layer_contents_scale, | 1430 current_layer_contents_scale, |
| 1290 last_screen_transform, | 1431 last_screen_transform, |
| 1291 current_screen_transform, | 1432 current_screen_transform, |
| 1292 current_frame_time_in_seconds, | 1433 current_frame_time_in_seconds, |
| 1293 max_tiles_for_interest_area); | 1434 max_tiles_for_interest_area); |
| 1294 | 1435 |
| 1295 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1436 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1296 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1437 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1297 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1438 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1298 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1439 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1299 | 1440 |
| 1300 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1441 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1301 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1442 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1302 EXPECT_FLOAT_EQ(1.f, | 1443 EXPECT_FLOAT_EQ(1.f, |
| 1303 priority.time_to_visible_in_seconds); | 1444 priority.time_to_visible_in_seconds); |
| 1304 | 1445 |
| 1305 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1446 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1306 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1447 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1307 EXPECT_FLOAT_EQ(1.f, | 1448 EXPECT_FLOAT_EQ(1.f, |
| 1308 priority.time_to_visible_in_seconds); | 1449 priority.time_to_visible_in_seconds); |
| 1309 | 1450 |
| 1310 // time_to_visible for the right hand side layers needs an extra 0.099 | 1451 // time_to_visible for the right hand side layers needs an extra 0.097 |
| 1311 // seconds because this tile is 99 pixels further away. | 1452 // seconds because this bundle is |
| 1312 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1453 // |(50 - 2 * border_texels) * 2 + border_texels| = 97 pixels further away. |
| 1454 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); | |
| 1313 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1455 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1314 EXPECT_FLOAT_EQ(1.099f, | 1456 EXPECT_FLOAT_EQ(1.097f, |
| 1315 priority.time_to_visible_in_seconds); | 1457 priority.time_to_visible_in_seconds); |
| 1316 | 1458 |
| 1317 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1459 priority = tiling->TileBundleAt(1, 1)->GetPriority(ACTIVE_TREE); |
| 1318 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1460 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1319 EXPECT_FLOAT_EQ(1.099f, | 1461 EXPECT_FLOAT_EQ(1.097f, |
| 1320 priority.time_to_visible_in_seconds); | 1462 priority.time_to_visible_in_seconds); |
| 1321 } | 1463 } |
| 1322 | 1464 |
| 1323 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1465 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
| 1324 // Each tile of a layer may be affected differently by a transform; Check | 1466 // Each tile of a layer may be affected differently by a transform; Check |
| 1325 // that UpdateTilePriorities correctly accounts for the transform between | 1467 // that UpdateTilePriorities correctly accounts for the transform between |
| 1326 // layer space and screen space. | 1468 // layer space and screen space. |
| 1327 | 1469 |
| 1328 FakePictureLayerTilingClient client; | 1470 FakeTileManagerClient tile_manager_client; |
| 1471 FakeTileManager tile_manager(&tile_manager_client); | |
| 1472 FakePictureLayerTilingClient client(&tile_manager); | |
| 1329 scoped_ptr<TestablePictureLayerTiling> tiling; | 1473 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 1330 | 1474 |
| 1331 gfx::Size device_viewport(800, 600); | 1475 gfx::Size device_viewport(800, 600); |
| 1332 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. | 1476 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. |
| 1333 gfx::Size last_layer_bounds(200, 200); | 1477 gfx::Size last_layer_bounds(200, 200); |
| 1334 gfx::Size current_layer_bounds(200, 200); | 1478 gfx::Size current_layer_bounds(200, 200); |
| 1335 float last_layer_contents_scale = 1.f; | 1479 float last_layer_contents_scale = 1.f; |
| 1336 float current_layer_contents_scale = 1.f; | 1480 float current_layer_contents_scale = 1.f; |
| 1337 gfx::Transform last_screen_transform; | 1481 gfx::Transform last_screen_transform; |
| 1338 gfx::Transform current_screen_transform; | 1482 gfx::Transform current_screen_transform; |
| 1339 double last_frame_time_in_seconds = 1.0; | 1483 double last_frame_time_in_seconds = 1.0; |
| 1340 double current_frame_time_in_seconds = 2.0; | 1484 double current_frame_time_in_seconds = 2.0; |
| 1341 size_t max_tiles_for_interest_area = 10000; | 1485 size_t max_tiles_for_interest_area = 10000; |
| 1342 | 1486 |
| 1343 // Rotation motion is set up specifically so that: | 1487 // Rotation motion is set up specifically so that: |
| 1344 // - rotation occurs about the center of the layer | 1488 // - rotation occurs about the center of the layer |
| 1345 // - the top-left tile becomes visible on rotation | 1489 // - the top-left tile becomes visible on rotation |
| 1346 // - the top-right tile will have an infinite time_to_visible | 1490 // - the top-right tile will have an infinite time_to_visible |
| 1347 // because it is rotating away from viewport. | 1491 // because it is rotating away from viewport. |
| 1348 // - bottom-left layer will have a positive non-zero time_to_visible | 1492 // - bottom-left layer will have a positive non-zero time_to_visible |
| 1349 // because it is rotating toward the viewport. | 1493 // because it is rotating toward the viewport. |
| 1350 current_screen_transform.Translate(400, 550); | 1494 current_screen_transform.Translate(400, 550); |
| 1351 current_screen_transform.RotateAboutZAxis(45); | 1495 current_screen_transform.RotateAboutZAxis(45); |
| 1352 | 1496 |
| 1353 last_screen_transform.Translate(400, 550); | 1497 last_screen_transform.Translate(400, 550); |
| 1354 | 1498 |
| 1355 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1499 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
| 1356 current_screen_transform, device_viewport); | 1500 current_screen_transform, device_viewport); |
| 1357 | 1501 |
| 1358 client.SetTileSize(gfx::Size(100, 100)); | 1502 client.SetTileSize(gfx::Size(50, 50)); |
| 1359 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1503 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1360 current_layer_bounds, | 1504 current_layer_bounds, |
| 1361 &client); | 1505 &client); |
| 1362 | 1506 |
| 1363 // previous ("last") frame | 1507 // previous ("last") frame |
| 1364 tiling->UpdateTilePriorities( | 1508 tiling->UpdateTilePriorities( |
| 1365 ACTIVE_TREE, | 1509 ACTIVE_TREE, |
| 1366 device_viewport, | 1510 device_viewport, |
| 1367 viewport_in_layer_space, | 1511 viewport_in_layer_space, |
| 1368 visible_layer_rect, | 1512 visible_layer_rect, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1383 visible_layer_rect, | 1527 visible_layer_rect, |
| 1384 last_layer_bounds, | 1528 last_layer_bounds, |
| 1385 current_layer_bounds, | 1529 current_layer_bounds, |
| 1386 last_layer_contents_scale, | 1530 last_layer_contents_scale, |
| 1387 current_layer_contents_scale, | 1531 current_layer_contents_scale, |
| 1388 last_screen_transform, | 1532 last_screen_transform, |
| 1389 current_screen_transform, | 1533 current_screen_transform, |
| 1390 current_frame_time_in_seconds, | 1534 current_frame_time_in_seconds, |
| 1391 max_tiles_for_interest_area); | 1535 max_tiles_for_interest_area); |
| 1392 | 1536 |
| 1393 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1537 ASSERT_TRUE(tiling->TileBundleAt(0, 0)); |
| 1394 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1538 ASSERT_TRUE(tiling->TileBundleAt(0, 1)); |
| 1395 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1539 ASSERT_TRUE(tiling->TileBundleAt(1, 0)); |
| 1396 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1540 ASSERT_TRUE(tiling->TileBundleAt(1, 1)); |
| 1397 | 1541 |
| 1398 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1542 TilePriority priority = tiling->TileBundleAt(0, 0)->GetPriority(ACTIVE_TREE); |
| 1399 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1543 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); |
| 1400 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1544 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); |
| 1401 | 1545 |
| 1402 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1546 priority = tiling->TileBundleAt(0, 1)->GetPriority(ACTIVE_TREE); |
| 1403 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1547 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1404 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1548 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); |
| 1405 | 1549 |
| 1406 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1550 priority = tiling->TileBundleAt(1, 0)->GetPriority(ACTIVE_TREE); |
| 1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1551 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1408 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1552 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1409 priority.time_to_visible_in_seconds); | 1553 priority.time_to_visible_in_seconds); |
| 1410 } | 1554 } |
| 1411 | 1555 |
| 1412 } // namespace | 1556 } // namespace |
| 1413 } // namespace cc | 1557 } // namespace cc |
| OLD | NEW |