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 | 8 |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
11 #include "cc/test/fake_picture_layer_tiling_client.h" | 11 #include "cc/test/fake_picture_layer_tiling_client.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
14 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 namespace { | 17 namespace { |
18 | 18 |
19 static gfx::Rect ViewportInLayerSpace( | 19 static gfx::Rect ViewportInLayerSpace( |
20 const gfx::Transform& transform, | 20 const gfx::Transform& transform, |
21 const gfx::Size& device_viewport) { | 21 const gfx::Size& device_viewport) { |
22 | 22 |
23 gfx::Transform inverse; | 23 gfx::Transform inverse; |
24 if (!transform.GetInverse(&inverse)) | 24 if (!transform.GetInverse(&inverse)) |
25 return gfx::Rect(); | 25 return gfx::Rect(); |
26 | 26 |
27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 27 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 28 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
29 | |
30 return ToEnclosingRect(viewport_in_layer_space); | 29 return ToEnclosingRect(viewport_in_layer_space); |
31 } | 30 } |
32 | 31 |
33 class TestablePictureLayerTiling : public PictureLayerTiling { | 32 class TestablePictureLayerTiling : public PictureLayerTiling { |
34 public: | 33 public: |
35 using PictureLayerTiling::SetLiveTilesRect; | 34 using PictureLayerTiling::SetLiveTilesRect; |
36 using PictureLayerTiling::TileAt; | 35 using PictureLayerTiling::TileAt; |
37 | 36 |
38 static scoped_ptr<TestablePictureLayerTiling> Create( | 37 static scoped_ptr<TestablePictureLayerTiling> Create( |
39 float contents_scale, | 38 float contents_scale, |
40 const gfx::Size& layer_bounds, | 39 const gfx::Size& layer_bounds, |
41 PictureLayerTilingClient* client) { | 40 PictureLayerTilingClient* client) { |
42 return make_scoped_ptr(new TestablePictureLayerTiling( | 41 return make_scoped_ptr(new TestablePictureLayerTiling( |
43 contents_scale, | 42 contents_scale, |
44 layer_bounds, | 43 layer_bounds, |
45 client)); | 44 client)); |
46 } | 45 } |
47 | 46 |
| 47 using PictureLayerTiling::ComputeSkewport; |
| 48 |
48 protected: | 49 protected: |
49 TestablePictureLayerTiling(float contents_scale, | 50 TestablePictureLayerTiling(float contents_scale, |
50 const gfx::Size& layer_bounds, | 51 const gfx::Size& layer_bounds, |
51 PictureLayerTilingClient* client) | 52 PictureLayerTilingClient* client) |
52 : PictureLayerTiling(contents_scale, layer_bounds, client) { } | 53 : PictureLayerTiling(contents_scale, layer_bounds, client) { } |
53 }; | 54 }; |
54 | 55 |
55 class PictureLayerTilingIteratorTest : public testing::Test { | 56 class PictureLayerTilingIteratorTest : public testing::Test { |
56 public: | 57 public: |
57 PictureLayerTilingIteratorTest() {} | 58 PictureLayerTilingIteratorTest() {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 void VerifyTilesCoverNonContainedRect(float rect_scale, | 150 void VerifyTilesCoverNonContainedRect(float rect_scale, |
150 const gfx::Rect& dest_rect) { | 151 const gfx::Rect& dest_rect) { |
151 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 152 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
152 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | 153 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( |
153 tiling_->ContentRect(), 1.f / dest_to_contents_scale); | 154 tiling_->ContentRect(), 1.f / dest_to_contents_scale); |
154 clamped_rect.Intersect(dest_rect); | 155 clamped_rect.Intersect(dest_rect); |
155 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 156 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
156 } | 157 } |
157 | 158 |
| 159 void set_max_tiles_for_interest_area(size_t area) { |
| 160 client_.set_max_tiles_for_interest_area(area); |
| 161 } |
| 162 |
158 protected: | 163 protected: |
159 FakePictureLayerTilingClient client_; | 164 FakePictureLayerTilingClient client_; |
160 scoped_ptr<TestablePictureLayerTiling> tiling_; | 165 scoped_ptr<TestablePictureLayerTiling> tiling_; |
161 | 166 |
162 private: | 167 private: |
163 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); | 168 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); |
164 }; | 169 }; |
165 | 170 |
166 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { | 171 TEST_F(PictureLayerTilingIteratorTest, LiveTilesExactlyCoverLiveTileRect) { |
167 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); | 172 Initialize(gfx::Size(100, 100), 1, gfx::Size(1099, 801)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); | 262 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); |
258 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 263 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
259 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); | 264 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); |
260 | 265 |
261 // Partially covering content, but too large | 266 // Partially covering content, but too large |
262 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); | 267 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); |
263 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); | 268 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); |
264 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); | 269 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); |
265 } | 270 } |
266 | 271 |
| 272 TEST(PictureLayerTilingTest, SkewportLimits) { |
| 273 FakePictureLayerTilingClient client; |
| 274 client.set_skewport_extrapolation_limit_in_content_pixels(75); |
| 275 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 276 |
| 277 gfx::Rect viewport(0, 0, 100, 100); |
| 278 gfx::Size layer_bounds(200, 200); |
| 279 |
| 280 client.SetTileSize(gfx::Size(100, 100)); |
| 281 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
| 282 |
| 283 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 284 |
| 285 // Move viewport down 50 pixels in 0.5 seconds. |
| 286 gfx::Rect down_skewport = |
| 287 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); |
| 288 |
| 289 EXPECT_EQ(0, down_skewport.x()); |
| 290 EXPECT_EQ(50, down_skewport.y()); |
| 291 EXPECT_EQ(100, down_skewport.width()); |
| 292 EXPECT_EQ(175, down_skewport.height()); |
| 293 EXPECT_TRUE(down_skewport.Contains(gfx::Rect(0, 50, 100, 100))); |
| 294 |
| 295 // Move viewport down 50 and right 10 pixels. |
| 296 gfx::Rect down_right_skewport = |
| 297 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); |
| 298 |
| 299 EXPECT_EQ(10, down_right_skewport.x()); |
| 300 EXPECT_EQ(50, down_right_skewport.y()); |
| 301 EXPECT_EQ(120, down_right_skewport.width()); |
| 302 EXPECT_EQ(175, down_right_skewport.height()); |
| 303 EXPECT_TRUE(down_right_skewport.Contains(gfx::Rect(10, 50, 100, 100))); |
| 304 |
| 305 // Move viewport left. |
| 306 gfx::Rect left_skewport = |
| 307 tiling->ComputeSkewport(1.5, gfx::Rect(-50, 0, 100, 100)); |
| 308 |
| 309 EXPECT_EQ(-125, left_skewport.x()); |
| 310 EXPECT_EQ(0, left_skewport.y()); |
| 311 EXPECT_EQ(175, left_skewport.width()); |
| 312 EXPECT_EQ(100, left_skewport.height()); |
| 313 EXPECT_TRUE(left_skewport.Contains(gfx::Rect(-50, 0, 100, 100))); |
| 314 |
| 315 // Expand viewport. |
| 316 gfx::Rect expand_skewport = |
| 317 tiling->ComputeSkewport(1.5, gfx::Rect(-50, -50, 200, 200)); |
| 318 |
| 319 // x and y moved by -75 (-50 - 75 = -125). |
| 320 // right side and bottom side moved by 75 [(350 - 125) - (200 - 50) = 75]. |
| 321 EXPECT_EQ(-125, expand_skewport.x()); |
| 322 EXPECT_EQ(-125, expand_skewport.y()); |
| 323 EXPECT_EQ(350, expand_skewport.width()); |
| 324 EXPECT_EQ(350, expand_skewport.height()); |
| 325 EXPECT_TRUE(expand_skewport.Contains(gfx::Rect(-50, -50, 200, 200))); |
| 326 |
| 327 // Expand the viewport past the limit. |
| 328 gfx::Rect big_expand_skewport = |
| 329 tiling->ComputeSkewport(1.5, gfx::Rect(-500, -500, 1500, 1500)); |
| 330 |
| 331 EXPECT_EQ(-575, big_expand_skewport.x()); |
| 332 EXPECT_EQ(-575, big_expand_skewport.y()); |
| 333 EXPECT_EQ(1650, big_expand_skewport.width()); |
| 334 EXPECT_EQ(1650, big_expand_skewport.height()); |
| 335 EXPECT_TRUE(big_expand_skewport.Contains(gfx::Rect(-500, -500, 1500, 1500))); |
| 336 } |
| 337 |
| 338 TEST(PictureLayerTilingTest, ComputeSkewport) { |
| 339 FakePictureLayerTilingClient client; |
| 340 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 341 |
| 342 gfx::Rect viewport(0, 0, 100, 100); |
| 343 gfx::Size layer_bounds(200, 200); |
| 344 |
| 345 client.SetTileSize(gfx::Size(100, 100)); |
| 346 tiling = TestablePictureLayerTiling::Create(1.0f, layer_bounds, &client); |
| 347 |
| 348 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 349 |
| 350 // Move viewport down 50 pixels in 0.5 seconds. |
| 351 gfx::Rect down_skewport = |
| 352 tiling->ComputeSkewport(1.5, gfx::Rect(0, 50, 100, 100)); |
| 353 |
| 354 EXPECT_EQ(0, down_skewport.x()); |
| 355 EXPECT_EQ(50, down_skewport.y()); |
| 356 EXPECT_EQ(100, down_skewport.width()); |
| 357 EXPECT_EQ(200, down_skewport.height()); |
| 358 |
| 359 // Shrink viewport. |
| 360 gfx::Rect shrink_skewport = |
| 361 tiling->ComputeSkewport(1.5, gfx::Rect(25, 25, 50, 50)); |
| 362 |
| 363 EXPECT_EQ(25, shrink_skewport.x()); |
| 364 EXPECT_EQ(25, shrink_skewport.y()); |
| 365 EXPECT_EQ(50, shrink_skewport.width()); |
| 366 EXPECT_EQ(50, shrink_skewport.height()); |
| 367 |
| 368 // Move viewport down 50 and right 10 pixels. |
| 369 gfx::Rect down_right_skewport = |
| 370 tiling->ComputeSkewport(1.5, gfx::Rect(10, 50, 100, 100)); |
| 371 |
| 372 EXPECT_EQ(10, down_right_skewport.x()); |
| 373 EXPECT_EQ(50, down_right_skewport.y()); |
| 374 EXPECT_EQ(120, down_right_skewport.width()); |
| 375 EXPECT_EQ(200, down_right_skewport.height()); |
| 376 |
| 377 // Move viewport left. |
| 378 gfx::Rect left_skewport = |
| 379 tiling->ComputeSkewport(1.5, gfx::Rect(-20, 0, 100, 100)); |
| 380 |
| 381 EXPECT_EQ(-60, left_skewport.x()); |
| 382 EXPECT_EQ(0, left_skewport.y()); |
| 383 EXPECT_EQ(140, left_skewport.width()); |
| 384 EXPECT_EQ(100, left_skewport.height()); |
| 385 |
| 386 // Expand viewport in 0.2 seconds. |
| 387 gfx::Rect expanded_skewport = |
| 388 tiling->ComputeSkewport(1.2, gfx::Rect(-5, -5, 110, 110)); |
| 389 |
| 390 EXPECT_EQ(-30, expanded_skewport.x()); |
| 391 EXPECT_EQ(-30, expanded_skewport.y()); |
| 392 EXPECT_EQ(160, expanded_skewport.width()); |
| 393 EXPECT_EQ(160, expanded_skewport.height()); |
| 394 } |
| 395 |
| 396 TEST(PictureLayerTilingTest, ViewportDistanceWithScale) { |
| 397 FakePictureLayerTilingClient client; |
| 398 scoped_ptr<TestablePictureLayerTiling> tiling; |
| 399 |
| 400 gfx::Rect viewport(0, 0, 100, 100); |
| 401 gfx::Size layer_bounds(200, 200); |
| 402 |
| 403 client.SetTileSize(gfx::Size(10, 10)); |
| 404 |
| 405 // Tiling at 0.25 scale: this should create 36 tiles (6x6) of size 10x10. |
| 406 // The reason is that each tile has a one pixel border, so tile at (1, 2) |
| 407 // for instance begins at (8, 16) pixels. So tile at (5, 5) will begin at |
| 408 // (40, 40) and extend right to the end of 200 * 0.25 = 50 edge of the |
| 409 // tiling. |
| 410 tiling = TestablePictureLayerTiling::Create(0.25f, layer_bounds, &client); |
| 411 gfx::Rect viewport_in_content_space = |
| 412 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
| 413 |
| 414 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 1.0); |
| 415 |
| 416 // Sanity checks. |
| 417 for (int i = 0; i < 6; ++i) { |
| 418 for (int j = 0; j < 6; ++j) { |
| 419 EXPECT_TRUE(tiling->TileAt(i, j)) << "i: " << i << " j: " << j; |
| 420 } |
| 421 } |
| 422 for (int i = 0; i < 7; ++i) { |
| 423 EXPECT_FALSE(tiling->TileAt(i, 6)) << "i: " << i; |
| 424 EXPECT_FALSE(tiling->TileAt(6, i)) << "i: " << i; |
| 425 } |
| 426 |
| 427 // No movement in the viewport implies that tiles will either be NOW |
| 428 // or EVENTUALLY. |
| 429 bool have_now = false; |
| 430 bool have_eventually = false; |
| 431 for (int i = 0; i < 6; ++i) { |
| 432 for (int j = 0; j < 6; ++j) { |
| 433 Tile* tile = tiling->TileAt(i, j); |
| 434 TilePriority priority = tile->priority(ACTIVE_TREE); |
| 435 |
| 436 if (viewport_in_content_space.Intersects(tile->content_rect())) { |
| 437 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 438 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 439 have_now = true; |
| 440 } else { |
| 441 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); |
| 442 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 443 have_eventually = true; |
| 444 } |
| 445 } |
| 446 } |
| 447 |
| 448 EXPECT_TRUE(have_now); |
| 449 EXPECT_TRUE(have_eventually); |
| 450 |
| 451 // Spot check some distances. |
| 452 // Tile at 5, 1 should begin at 41x9 in content space (without borders), |
| 453 // so the distance to a viewport that ends at 25x25 in content space |
| 454 // should be 17 (41 - 25 + 1). In layer space, then that should be |
| 455 // 17 / 0.25 = 68 pixels. |
| 456 |
| 457 // We can verify that the content rect (with borders) is one pixel off |
| 458 // 41,9 8x8 on all sides. |
| 459 EXPECT_EQ(tiling->TileAt(5, 1)->content_rect().ToString(), "40,8 10x10"); |
| 460 |
| 461 TilePriority priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
| 462 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); |
| 463 |
| 464 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
| 465 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); |
| 466 |
| 467 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
| 468 EXPECT_FLOAT_EQ(40.f, priority.distance_to_visible); |
| 469 |
| 470 // Move the viewport down 40 pixels. |
| 471 viewport = gfx::Rect(0, 40, 100, 100); |
| 472 viewport_in_content_space = |
| 473 gfx::ToEnclosedRect(gfx::ScaleRect(viewport, 0.25f)); |
| 474 gfx::Rect skewport = tiling->ComputeSkewport(2.0, viewport_in_content_space); |
| 475 |
| 476 EXPECT_EQ(0, skewport.x()); |
| 477 EXPECT_EQ(10, skewport.y()); |
| 478 EXPECT_EQ(25, skewport.width()); |
| 479 EXPECT_EQ(35, skewport.height()); |
| 480 |
| 481 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 1.f, 2.0); |
| 482 |
| 483 have_now = false; |
| 484 have_eventually = false; |
| 485 bool have_soon = false; |
| 486 |
| 487 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
| 488 // some EVENTUALLY tiles. |
| 489 for (int i = 0; i < 6; ++i) { |
| 490 for (int j = 0; j < 6; ++j) { |
| 491 Tile* tile = tiling->TileAt(i, j); |
| 492 TilePriority priority = tile->priority(ACTIVE_TREE); |
| 493 |
| 494 if (viewport_in_content_space.Intersects(tile->content_rect())) { |
| 495 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 496 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 497 have_now = true; |
| 498 } else if (skewport.Intersects(tile->content_rect())) { |
| 499 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); |
| 500 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 501 have_soon = true; |
| 502 } else { |
| 503 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); |
| 504 EXPECT_GT(priority.distance_to_visible, 0.f); |
| 505 have_eventually = true; |
| 506 } |
| 507 } |
| 508 } |
| 509 |
| 510 EXPECT_TRUE(have_now); |
| 511 EXPECT_TRUE(have_soon); |
| 512 EXPECT_TRUE(have_eventually); |
| 513 |
| 514 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
| 515 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); |
| 516 |
| 517 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
| 518 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); |
| 519 |
| 520 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
| 521 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 522 |
| 523 // Change the underlying layer scale. |
| 524 tiling->UpdateTilePriorities(ACTIVE_TREE, viewport, 2.0f, 3.0); |
| 525 |
| 526 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
| 527 EXPECT_FLOAT_EQ(34.f, priority.distance_to_visible); |
| 528 |
| 529 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
| 530 EXPECT_FLOAT_EQ(14.f, priority.distance_to_visible); |
| 531 |
| 532 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
| 533 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 534 } |
| 535 |
267 TEST(PictureLayerTilingTest, ExpandRectEqual) { | 536 TEST(PictureLayerTilingTest, ExpandRectEqual) { |
268 gfx::Rect in(40, 50, 100, 200); | 537 gfx::Rect in(40, 50, 100, 200); |
269 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 538 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
270 int64 target_area = 100 * 200; | 539 int64 target_area = 100 * 200; |
271 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 540 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
272 in, target_area, bounds, NULL); | 541 in, target_area, bounds, NULL); |
273 EXPECT_EQ(in.ToString(), out.ToString()); | 542 EXPECT_EQ(in.ToString(), out.ToString()); |
274 } | 543 } |
275 | 544 |
276 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 545 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } | 757 } |
489 | 758 |
490 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 759 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
491 gfx::Size layer_bounds(1099, 801); | 760 gfx::Size layer_bounds(1099, 801); |
492 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 761 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
493 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 762 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
494 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 763 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
495 | 764 |
496 tiling_->UpdateTilePriorities( | 765 tiling_->UpdateTilePriorities( |
497 ACTIVE_TREE, | 766 ACTIVE_TREE, |
498 layer_bounds, // device viewport | |
499 gfx::Rect(layer_bounds), // viewport in layer space | |
500 gfx::Rect(layer_bounds), // visible content rect | 767 gfx::Rect(layer_bounds), // visible content rect |
501 layer_bounds, // last layer bounds | 768 1.f, // current contents scale |
502 layer_bounds, // current layer bounds | 769 1.0); // current frame time |
503 1.f, // last contents scale | |
504 1.f, // current contents scale | |
505 gfx::Transform(), // last screen transform | |
506 gfx::Transform(), // current screen transform | |
507 1.0, // current frame time | |
508 10000); // max tiles in tile manager | |
509 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 770 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
510 | 771 |
511 // Make the viewport rect empty. All tiles are killed and become zombies. | 772 // Make the viewport rect empty. All tiles are killed and become zombies. |
512 tiling_->UpdateTilePriorities( | 773 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
513 ACTIVE_TREE, | 774 gfx::Rect(), // visible content rect |
514 layer_bounds, // device viewport | 775 1.f, // current contents scale |
515 gfx::Rect(), // viewport in layer space | 776 2.0); // current frame time |
516 gfx::Rect(), // visible content rect | |
517 layer_bounds, // last layer bounds | |
518 layer_bounds, // current layer bounds | |
519 1.f, // last contents scale | |
520 1.f, // current contents scale | |
521 gfx::Transform(), // last screen transform | |
522 gfx::Transform(), // current screen transform | |
523 2.0, // current frame time | |
524 10000); // max tiles in tile manager | |
525 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 777 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
526 } | 778 } |
527 | 779 |
528 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { | 780 TEST_F(PictureLayerTilingIteratorTest, TilesExistGiantViewport) { |
529 gfx::Size layer_bounds(1099, 801); | 781 gfx::Size layer_bounds(1099, 801); |
530 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 782 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
531 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 783 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
532 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 784 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
533 | 785 |
534 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); | 786 gfx::Rect giant_rect(-10000000, -10000000, 1000000000, 1000000000); |
535 | 787 |
536 tiling_->UpdateTilePriorities( | 788 tiling_->UpdateTilePriorities( |
537 ACTIVE_TREE, | 789 ACTIVE_TREE, |
538 layer_bounds, // device viewport | |
539 giant_rect, // viewport in layer space | |
540 gfx::Rect(layer_bounds), // visible content rect | 790 gfx::Rect(layer_bounds), // visible content rect |
541 layer_bounds, // last layer bounds | 791 1.f, // current contents scale |
542 layer_bounds, // current layer bounds | 792 1.0); // current frame time |
543 1.f, // last contents scale | |
544 1.f, // current contents scale | |
545 gfx::Transform(), // last screen transform | |
546 gfx::Transform(), // current screen transform | |
547 1.0, // current frame time | |
548 10000); // max tiles in tile manager | |
549 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 793 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
550 | 794 |
551 // If the visible content rect is empty, it should still have live tiles. | 795 // If the visible content rect is empty, it should still have live tiles. |
552 tiling_->UpdateTilePriorities( | 796 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
553 ACTIVE_TREE, | 797 giant_rect, // visible content rect |
554 layer_bounds, // device viewport | 798 1.f, // current contents scale |
555 giant_rect, // viewport in layer space | 799 2.0); // current frame time |
556 gfx::Rect(), // visible content rect | |
557 layer_bounds, // last layer bounds | |
558 layer_bounds, // current layer bounds | |
559 1.f, // last contents scale | |
560 1.f, // current contents scale | |
561 gfx::Transform(), // last screen transform | |
562 gfx::Transform(), // current screen transform | |
563 2.0, // current frame time | |
564 10000); // max tiles in tile manager | |
565 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 800 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
566 } | 801 } |
567 | 802 |
568 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { | 803 TEST_F(PictureLayerTilingIteratorTest, TilesExistOutsideViewport) { |
569 gfx::Size layer_bounds(1099, 801); | 804 gfx::Size layer_bounds(1099, 801); |
570 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 805 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
571 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 806 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
572 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 807 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
573 | 808 |
574 // This rect does not intersect with the layer, as the layer is outside the | 809 // This rect does not intersect with the layer, as the layer is outside the |
575 // viewport. | 810 // viewport. |
576 gfx::Rect viewport_rect(1100, 0, 1000, 1000); | 811 gfx::Rect viewport_rect(1100, 0, 1000, 1000); |
577 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); | 812 EXPECT_FALSE(viewport_rect.Intersects(gfx::Rect(layer_bounds))); |
578 | 813 |
579 tiling_->UpdateTilePriorities( | 814 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
580 ACTIVE_TREE, | 815 viewport_rect, // visible content rect |
581 layer_bounds, // device viewport | 816 1.f, // current contents scale |
582 viewport_rect, // viewport in layer space | 817 1.0); // current frame time |
583 gfx::Rect(), // visible content rect | |
584 layer_bounds, // last layer bounds | |
585 layer_bounds, // current layer bounds | |
586 1.f, // last contents scale | |
587 1.f, // current contents scale | |
588 gfx::Transform(), // last screen transform | |
589 gfx::Transform(), // current screen transform | |
590 1.0, // current frame time | |
591 10000); // max tiles in tile manager | |
592 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 818 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
593 } | 819 } |
594 | 820 |
595 static void TilesIntersectingRectExist(const gfx::Rect& rect, | 821 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
596 bool intersect_exists, | 822 bool intersect_exists, |
597 Tile* tile, | 823 Tile* tile, |
598 const gfx::Rect& geometry_rect) { | 824 const gfx::Rect& geometry_rect) { |
599 bool intersects = rect.Intersects(geometry_rect); | 825 bool intersects = rect.Intersects(geometry_rect); |
600 bool expected_exists = intersect_exists ? intersects : !intersects; | 826 bool expected_exists = intersect_exists ? intersects : !intersects; |
601 EXPECT_EQ(expected_exists, tile != NULL) | 827 EXPECT_EQ(expected_exists, tile != NULL) |
602 << "Rects intersecting " << rect.ToString() << " should exist. " | 828 << "Rects intersecting " << rect.ToString() << " should exist. " |
603 << "Current tile rect is " << geometry_rect.ToString(); | 829 << "Current tile rect is " << geometry_rect.ToString(); |
604 } | 830 } |
605 | 831 |
606 TEST_F(PictureLayerTilingIteratorTest, | 832 TEST_F(PictureLayerTilingIteratorTest, |
607 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 833 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
608 gfx::Size layer_bounds(10000, 10000); | 834 gfx::Size layer_bounds(10000, 10000); |
609 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 835 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
610 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 836 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
611 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 837 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
612 | 838 |
613 gfx::Rect visible_rect(8000, 8000, 50, 50); | 839 gfx::Rect visible_rect(8000, 8000, 50, 50); |
614 | 840 |
615 tiling_->UpdateTilePriorities( | 841 set_max_tiles_for_interest_area(1); |
616 ACTIVE_TREE, | 842 tiling_->UpdateTilePriorities(ACTIVE_TREE, |
617 layer_bounds, // device viewport | 843 visible_rect, // visible content rect |
618 gfx::Rect(layer_bounds), // viewport in layer space | 844 1.f, // current contents scale |
619 visible_rect, // visible content rect | 845 1.0); // current frame time |
620 layer_bounds, // last layer bounds | |
621 layer_bounds, // current layer bounds | |
622 1.f, // last contents scale | |
623 1.f, // current contents scale | |
624 gfx::Transform(), // last screen transform | |
625 gfx::Transform(), // current screen transform | |
626 1.0, // current frame time | |
627 1); // max tiles in tile manager | |
628 VerifyTiles(1.f, | 846 VerifyTiles(1.f, |
629 gfx::Rect(layer_bounds), | 847 gfx::Rect(layer_bounds), |
630 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 848 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
631 } | 849 } |
632 | 850 |
633 static void CountExistingTiles(int *count, | 851 static void CountExistingTiles(int *count, |
634 Tile* tile, | 852 Tile* tile, |
635 const gfx::Rect& geometry_rect) { | 853 const gfx::Rect& geometry_rect) { |
636 if (tile != NULL) | 854 if (tile != NULL) |
637 ++(*count); | 855 ++(*count); |
638 } | 856 } |
639 | 857 |
640 TEST_F(PictureLayerTilingIteratorTest, | 858 TEST_F(PictureLayerTilingIteratorTest, |
641 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 859 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
642 gfx::Size layer_bounds(10000, 10000); | 860 gfx::Size layer_bounds(10000, 10000); |
643 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 861 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
644 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 862 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
645 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 863 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
646 | 864 |
| 865 set_max_tiles_for_interest_area(1); |
647 tiling_->UpdateTilePriorities( | 866 tiling_->UpdateTilePriorities( |
648 ACTIVE_TREE, | 867 ACTIVE_TREE, |
649 layer_bounds, // device viewport | |
650 gfx::Rect(layer_bounds), // viewport in layer space | |
651 gfx::Rect(layer_bounds), // visible content rect | 868 gfx::Rect(layer_bounds), // visible content rect |
652 layer_bounds, // last layer bounds | 869 1.f, // current contents scale |
653 layer_bounds, // current layer bounds | 870 1.0); // current frame time |
654 1.f, // last contents scale | |
655 1.f, // current contents scale | |
656 gfx::Transform(), // last screen transform | |
657 gfx::Transform(), // current screen transform | |
658 1.0, // current frame time | |
659 1); // max tiles in tile manager | |
660 | 871 |
661 int num_tiles = 0; | 872 int num_tiles = 0; |
662 VerifyTiles(1.f, | 873 VerifyTiles(1.f, |
663 gfx::Rect(layer_bounds), | 874 gfx::Rect(layer_bounds), |
664 base::Bind(&CountExistingTiles, &num_tiles)); | 875 base::Bind(&CountExistingTiles, &num_tiles)); |
665 // If we're making a rect the size of one tile, it can only overlap up to 4 | 876 // If we're making a rect the size of one tile, it can only overlap up to 4 |
666 // tiles depending on its position. | 877 // tiles depending on its position. |
667 EXPECT_LE(num_tiles, 4); | 878 EXPECT_LE(num_tiles, 4); |
668 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); | 879 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); |
669 } | 880 } |
670 | 881 |
671 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { | 882 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { |
672 gfx::Size layer_bounds(1099, 801); | 883 gfx::Size layer_bounds(1099, 801); |
673 gfx::Size tile_size(100, 100); | 884 gfx::Size tile_size(100, 100); |
674 | 885 |
675 client_.SetTileSize(tile_size); | 886 client_.SetTileSize(tile_size); |
676 | 887 |
677 PictureLayerTilingSet active_set(&client_, layer_bounds); | 888 PictureLayerTilingSet active_set(&client_, layer_bounds); |
678 | 889 |
679 active_set.AddTiling(1.f); | 890 active_set.AddTiling(1.f); |
680 | 891 |
681 VerifyTiles(active_set.tiling_at(0), | 892 VerifyTiles(active_set.tiling_at(0), |
682 1.f, | 893 1.f, |
683 gfx::Rect(layer_bounds), | 894 gfx::Rect(layer_bounds), |
684 base::Bind(&TileExists, false)); | 895 base::Bind(&TileExists, false)); |
685 | 896 |
686 active_set.UpdateTilePriorities( | 897 active_set.UpdateTilePriorities( |
687 PENDING_TREE, | 898 PENDING_TREE, |
688 layer_bounds, // device viewport | |
689 gfx::Rect(layer_bounds), // viewport in layer space | |
690 gfx::Rect(layer_bounds), // visible content rect | 899 gfx::Rect(layer_bounds), // visible content rect |
691 layer_bounds, // last layer bounds | 900 1.f, // current contents scale |
692 layer_bounds, // current layer bounds | 901 1.0); // current frame time |
693 1.f, // last contents scale | |
694 1.f, // current contents scale | |
695 gfx::Transform(), // last screen transform | |
696 gfx::Transform(), // current screen transform | |
697 1.0, // current frame time | |
698 10000); // max tiles in tile manager | |
699 | 902 |
700 // The active tiling has tiles now. | 903 // The active tiling has tiles now. |
701 VerifyTiles(active_set.tiling_at(0), | 904 VerifyTiles(active_set.tiling_at(0), |
702 1.f, | 905 1.f, |
703 gfx::Rect(layer_bounds), | 906 gfx::Rect(layer_bounds), |
704 base::Bind(&TileExists, true)); | 907 base::Bind(&TileExists, true)); |
705 | 908 |
706 // Add the same tilings to the pending set. | 909 // Add the same tilings to the pending set. |
707 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 910 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
708 Region invalidation; | 911 Region invalidation; |
709 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 912 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
710 | 913 |
711 // The pending tiling starts with no tiles. | 914 // The pending tiling starts with no tiles. |
712 VerifyTiles(pending_set.tiling_at(0), | 915 VerifyTiles(pending_set.tiling_at(0), |
713 1.f, | 916 1.f, |
714 gfx::Rect(layer_bounds), | 917 gfx::Rect(layer_bounds), |
715 base::Bind(&TileExists, false)); | 918 base::Bind(&TileExists, false)); |
716 | 919 |
717 // UpdateTilePriorities on the pending tiling at the same frame time. The | 920 // UpdateTilePriorities on the pending tiling at the same frame time. The |
718 // pending tiling should get tiles. | 921 // pending tiling should get tiles. |
719 pending_set.UpdateTilePriorities( | 922 pending_set.UpdateTilePriorities( |
720 PENDING_TREE, | 923 PENDING_TREE, |
721 layer_bounds, // device viewport | |
722 gfx::Rect(layer_bounds), // viewport in layer space | |
723 gfx::Rect(layer_bounds), // visible content rect | 924 gfx::Rect(layer_bounds), // visible content rect |
724 layer_bounds, // last layer bounds | 925 1.f, // current contents scale |
725 layer_bounds, // current layer bounds | 926 1.0); // current frame time |
726 1.f, // last contents scale | |
727 1.f, // current contents scale | |
728 gfx::Transform(), // last screen transform | |
729 gfx::Transform(), // current screen transform | |
730 1.0, // current frame time | |
731 10000); // max tiles in tile manager | |
732 | 927 |
733 VerifyTiles(pending_set.tiling_at(0), | 928 VerifyTiles(pending_set.tiling_at(0), |
734 1.f, | 929 1.f, |
735 gfx::Rect(layer_bounds), | 930 gfx::Rect(layer_bounds), |
736 base::Bind(&TileExists, true)); | 931 base::Bind(&TileExists, true)); |
737 } | 932 } |
738 | 933 |
739 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 934 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
740 // The TilePriority of visible tiles should have zero distance_to_visible | 935 // The TilePriority of visible tiles should have zero distance_to_visible |
741 // and time_to_visible. | 936 // and time_to_visible. |
742 | 937 |
743 FakePictureLayerTilingClient client; | 938 FakePictureLayerTilingClient client; |
744 scoped_ptr<TestablePictureLayerTiling> tiling; | 939 scoped_ptr<TestablePictureLayerTiling> tiling; |
745 | 940 |
746 gfx::Size device_viewport(800, 600); | 941 gfx::Size device_viewport(800, 600); |
747 gfx::Rect visible_layer_rect(0, 0, 200, 200); | |
748 gfx::Size last_layer_bounds(200, 200); | 942 gfx::Size last_layer_bounds(200, 200); |
749 gfx::Size current_layer_bounds(200, 200); | 943 gfx::Size current_layer_bounds(200, 200); |
750 float last_layer_contents_scale = 1.f; | |
751 float current_layer_contents_scale = 1.f; | 944 float current_layer_contents_scale = 1.f; |
752 gfx::Transform last_screen_transform; | |
753 gfx::Transform current_screen_transform; | 945 gfx::Transform current_screen_transform; |
754 double current_frame_time_in_seconds = 1.0; | 946 double current_frame_time_in_seconds = 1.0; |
755 size_t max_tiles_for_interest_area = 10000; | |
756 | 947 |
757 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 948 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
758 current_screen_transform, device_viewport); | 949 current_screen_transform, device_viewport); |
759 | 950 |
760 client.SetTileSize(gfx::Size(100, 100)); | 951 client.SetTileSize(gfx::Size(100, 100)); |
761 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 952 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
762 current_layer_bounds, | 953 current_layer_bounds, |
763 &client); | 954 &client); |
764 | 955 |
765 tiling->UpdateTilePriorities( | 956 tiling->UpdateTilePriorities(ACTIVE_TREE, |
766 ACTIVE_TREE, | 957 viewport_in_layer_space, |
767 device_viewport, | 958 current_layer_contents_scale, |
768 viewport_in_layer_space, | 959 current_frame_time_in_seconds); |
769 visible_layer_rect, | |
770 last_layer_bounds, | |
771 current_layer_bounds, | |
772 last_layer_contents_scale, | |
773 current_layer_contents_scale, | |
774 last_screen_transform, | |
775 current_screen_transform, | |
776 current_frame_time_in_seconds, | |
777 max_tiles_for_interest_area); | |
778 | 960 |
779 ASSERT_TRUE(tiling->TileAt(0, 0)); | 961 ASSERT_TRUE(tiling->TileAt(0, 0)); |
780 ASSERT_TRUE(tiling->TileAt(0, 1)); | 962 ASSERT_TRUE(tiling->TileAt(0, 1)); |
781 ASSERT_TRUE(tiling->TileAt(1, 0)); | 963 ASSERT_TRUE(tiling->TileAt(1, 0)); |
782 ASSERT_TRUE(tiling->TileAt(1, 1)); | 964 ASSERT_TRUE(tiling->TileAt(1, 1)); |
783 | 965 |
784 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 966 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
785 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 967 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
786 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 968 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
787 | 969 |
788 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 970 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
789 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 971 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
790 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 972 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
791 | 973 |
792 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 974 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
793 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 975 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
794 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 976 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
795 | 977 |
796 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 978 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
797 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 979 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
798 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 980 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
799 } | 981 } |
800 | 982 |
801 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { | 983 TEST(UpdateTilePrioritiesTest, OffscreenTiles) { |
802 // The TilePriority of offscreen tiles (without movement) should have nonzero | 984 // The TilePriority of offscreen tiles (without movement) should have nonzero |
803 // distance_to_visible and infinite time_to_visible. | 985 // distance_to_visible and infinite time_to_visible. |
804 | 986 |
805 FakePictureLayerTilingClient client; | 987 FakePictureLayerTilingClient client; |
806 scoped_ptr<TestablePictureLayerTiling> tiling; | 988 scoped_ptr<TestablePictureLayerTiling> tiling; |
807 | 989 |
808 gfx::Size device_viewport(800, 600); | 990 gfx::Size device_viewport(800, 600); |
809 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen; nothing is visible. | |
810 gfx::Size last_layer_bounds(200, 200); | 991 gfx::Size last_layer_bounds(200, 200); |
811 gfx::Size current_layer_bounds(200, 200); | 992 gfx::Size current_layer_bounds(200, 200); |
812 float last_layer_contents_scale = 1.f; | |
813 float current_layer_contents_scale = 1.f; | 993 float current_layer_contents_scale = 1.f; |
814 gfx::Transform last_screen_transform; | 994 gfx::Transform last_screen_transform; |
815 gfx::Transform current_screen_transform; | 995 gfx::Transform current_screen_transform; |
816 double current_frame_time_in_seconds = 1.0; | 996 double current_frame_time_in_seconds = 1.0; |
817 size_t max_tiles_for_interest_area = 10000; | |
818 | 997 |
819 current_screen_transform.Translate(850, 0); | 998 current_screen_transform.Translate(850, 0); |
820 last_screen_transform = current_screen_transform; | 999 last_screen_transform = current_screen_transform; |
821 | 1000 |
822 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1001 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
823 current_screen_transform, device_viewport); | 1002 current_screen_transform, device_viewport); |
824 | 1003 |
825 client.SetTileSize(gfx::Size(100, 100)); | 1004 client.SetTileSize(gfx::Size(100, 100)); |
826 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1005 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
827 current_layer_bounds, | 1006 current_layer_bounds, |
828 &client); | 1007 &client); |
829 | 1008 |
830 tiling->UpdateTilePriorities( | 1009 tiling->UpdateTilePriorities(ACTIVE_TREE, |
831 ACTIVE_TREE, | 1010 viewport_in_layer_space, |
832 device_viewport, | 1011 current_layer_contents_scale, |
833 viewport_in_layer_space, | 1012 current_frame_time_in_seconds); |
834 visible_layer_rect, | |
835 last_layer_bounds, | |
836 current_layer_bounds, | |
837 last_layer_contents_scale, | |
838 current_layer_contents_scale, | |
839 last_screen_transform, | |
840 current_screen_transform, | |
841 current_frame_time_in_seconds, | |
842 max_tiles_for_interest_area); | |
843 | 1013 |
844 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1014 ASSERT_TRUE(tiling->TileAt(0, 0)); |
845 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1015 ASSERT_TRUE(tiling->TileAt(0, 1)); |
846 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1016 ASSERT_TRUE(tiling->TileAt(1, 0)); |
847 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1017 ASSERT_TRUE(tiling->TileAt(1, 1)); |
848 | 1018 |
849 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1019 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
850 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1020 EXPECT_GT(priority.distance_to_visible, 0.f); |
851 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1021 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
852 priority.time_to_visible_in_seconds); | |
853 | 1022 |
854 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1023 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
855 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1024 EXPECT_GT(priority.distance_to_visible, 0.f); |
856 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1025 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
857 priority.time_to_visible_in_seconds); | |
858 | 1026 |
859 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1027 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
860 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1028 EXPECT_GT(priority.distance_to_visible, 0.f); |
861 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1029 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
862 priority.time_to_visible_in_seconds); | |
863 | 1030 |
864 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1031 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
865 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1032 EXPECT_GT(priority.distance_to_visible, 0.f); |
866 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1033 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
867 priority.time_to_visible_in_seconds); | |
868 | 1034 |
869 // Furthermore, in this scenario tiles on the right hand side should have a | 1035 // Furthermore, in this scenario tiles on the right hand side should have a |
870 // larger distance to visible. | 1036 // larger distance to visible. |
871 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1037 TilePriority left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
872 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1038 TilePriority right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
873 EXPECT_GT(right.distance_to_visible_in_pixels, | 1039 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
874 left.distance_to_visible_in_pixels); | |
875 | 1040 |
876 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1041 left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
877 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1042 right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
878 EXPECT_GT(right.distance_to_visible_in_pixels, | 1043 EXPECT_GT(right.distance_to_visible, left.distance_to_visible); |
879 left.distance_to_visible_in_pixels); | |
880 } | 1044 } |
881 | 1045 |
882 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { | 1046 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenLayer) { |
883 // Sanity check that a layer with some tiles visible and others offscreen has | 1047 // Sanity check that a layer with some tiles visible and others offscreen has |
884 // correct TilePriorities for each tile. | 1048 // correct TilePriorities for each tile. |
885 | 1049 |
886 FakePictureLayerTilingClient client; | 1050 FakePictureLayerTilingClient client; |
887 scoped_ptr<TestablePictureLayerTiling> tiling; | 1051 scoped_ptr<TestablePictureLayerTiling> tiling; |
888 | 1052 |
889 gfx::Size device_viewport(800, 600); | 1053 gfx::Size device_viewport(800, 600); |
890 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top quarter. | |
891 gfx::Size last_layer_bounds(200, 200); | 1054 gfx::Size last_layer_bounds(200, 200); |
892 gfx::Size current_layer_bounds(200, 200); | 1055 gfx::Size current_layer_bounds(200, 200); |
893 float last_layer_contents_scale = 1.f; | |
894 float current_layer_contents_scale = 1.f; | 1056 float current_layer_contents_scale = 1.f; |
895 gfx::Transform last_screen_transform; | 1057 gfx::Transform last_screen_transform; |
896 gfx::Transform current_screen_transform; | 1058 gfx::Transform current_screen_transform; |
897 double current_frame_time_in_seconds = 1.0; | 1059 double current_frame_time_in_seconds = 1.0; |
898 size_t max_tiles_for_interest_area = 10000; | |
899 | 1060 |
900 current_screen_transform.Translate(705, 505); | 1061 current_screen_transform.Translate(705, 505); |
901 last_screen_transform = current_screen_transform; | 1062 last_screen_transform = current_screen_transform; |
902 | 1063 |
903 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1064 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
904 current_screen_transform, device_viewport); | 1065 current_screen_transform, device_viewport); |
905 | 1066 |
906 client.SetTileSize(gfx::Size(100, 100)); | 1067 client.SetTileSize(gfx::Size(100, 100)); |
907 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1068 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
908 current_layer_bounds, | 1069 current_layer_bounds, |
909 &client); | 1070 &client); |
910 | 1071 |
911 tiling->UpdateTilePriorities( | 1072 tiling->UpdateTilePriorities(ACTIVE_TREE, |
912 ACTIVE_TREE, | 1073 viewport_in_layer_space, |
913 device_viewport, | 1074 current_layer_contents_scale, |
914 viewport_in_layer_space, | 1075 current_frame_time_in_seconds); |
915 visible_layer_rect, | |
916 last_layer_bounds, | |
917 current_layer_bounds, | |
918 last_layer_contents_scale, | |
919 current_layer_contents_scale, | |
920 last_screen_transform, | |
921 current_screen_transform, | |
922 current_frame_time_in_seconds, | |
923 max_tiles_for_interest_area); | |
924 | 1076 |
925 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1077 ASSERT_TRUE(tiling->TileAt(0, 0)); |
926 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1078 ASSERT_TRUE(tiling->TileAt(0, 1)); |
927 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1079 ASSERT_TRUE(tiling->TileAt(1, 0)); |
928 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1080 ASSERT_TRUE(tiling->TileAt(1, 1)); |
929 | 1081 |
930 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1082 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
931 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1083 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
932 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1084 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
933 | 1085 |
934 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1086 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
935 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1087 EXPECT_GT(priority.distance_to_visible, 0.f); |
936 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1088 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
937 priority.time_to_visible_in_seconds); | |
938 | 1089 |
939 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1090 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
940 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1091 EXPECT_GT(priority.distance_to_visible, 0.f); |
941 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1092 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
942 priority.time_to_visible_in_seconds); | |
943 | 1093 |
944 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1094 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
945 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1095 EXPECT_GT(priority.distance_to_visible, 0.f); |
946 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1096 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
947 priority.time_to_visible_in_seconds); | |
948 } | 1097 } |
949 | 1098 |
950 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { | 1099 TEST(UpdateTilePrioritiesTest, PartiallyOffscreenRotatedLayer) { |
951 // Each tile of a layer may be affected differently by a transform; Check | 1100 // Each tile of a layer may be affected differently by a transform; Check |
952 // that UpdateTilePriorities correctly accounts for the transform between | 1101 // that UpdateTilePriorities correctly accounts for the transform between |
953 // layer space and screen space. | 1102 // layer space and screen space. |
954 | 1103 |
955 FakePictureLayerTilingClient client; | 1104 FakePictureLayerTilingClient client; |
956 scoped_ptr<TestablePictureLayerTiling> tiling; | 1105 scoped_ptr<TestablePictureLayerTiling> tiling; |
957 | 1106 |
958 gfx::Size device_viewport(800, 600); | 1107 gfx::Size device_viewport(800, 600); |
959 gfx::Rect visible_layer_rect(0, 0, 100, 100); // only top-left quarter. | |
960 gfx::Size last_layer_bounds(200, 200); | 1108 gfx::Size last_layer_bounds(200, 200); |
961 gfx::Size current_layer_bounds(200, 200); | 1109 gfx::Size current_layer_bounds(200, 200); |
962 float last_layer_contents_scale = 1.f; | |
963 float current_layer_contents_scale = 1.f; | 1110 float current_layer_contents_scale = 1.f; |
964 gfx::Transform last_screen_transform; | 1111 gfx::Transform last_screen_transform; |
965 gfx::Transform current_screen_transform; | 1112 gfx::Transform current_screen_transform; |
966 double current_frame_time_in_seconds = 1.0; | 1113 double current_frame_time_in_seconds = 1.0; |
967 size_t max_tiles_for_interest_area = 10000; | |
968 | 1114 |
969 // A diagonally rotated layer that is partially off the bottom of the screen. | 1115 // A diagonally rotated layer that is partially off the bottom of the screen. |
970 // In this configuration, only the top-left tile would be visible. | 1116 // In this configuration, only the top-left tile would be visible. |
971 current_screen_transform.Translate(400, 550); | 1117 current_screen_transform.Translate(600, 750); |
972 current_screen_transform.RotateAboutZAxis(45); | 1118 current_screen_transform.RotateAboutZAxis(45); |
973 last_screen_transform = current_screen_transform; | 1119 last_screen_transform = current_screen_transform; |
974 | 1120 |
975 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1121 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
976 current_screen_transform, device_viewport); | 1122 current_screen_transform, device_viewport); |
977 | 1123 |
978 client.SetTileSize(gfx::Size(100, 100)); | 1124 client.SetTileSize(gfx::Size(100, 100)); |
979 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1125 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
980 current_layer_bounds, | 1126 current_layer_bounds, |
981 &client); | 1127 &client); |
982 | 1128 |
983 tiling->UpdateTilePriorities( | 1129 tiling->UpdateTilePriorities(ACTIVE_TREE, |
984 ACTIVE_TREE, | 1130 viewport_in_layer_space, |
985 device_viewport, | 1131 current_layer_contents_scale, |
986 viewport_in_layer_space, | 1132 current_frame_time_in_seconds); |
987 visible_layer_rect, | |
988 last_layer_bounds, | |
989 current_layer_bounds, | |
990 last_layer_contents_scale, | |
991 current_layer_contents_scale, | |
992 last_screen_transform, | |
993 current_screen_transform, | |
994 current_frame_time_in_seconds, | |
995 max_tiles_for_interest_area); | |
996 | 1133 |
997 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1134 ASSERT_TRUE(tiling->TileAt(0, 0)); |
998 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1135 ASSERT_TRUE(tiling->TileAt(0, 1)); |
999 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1136 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1000 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1137 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1001 | 1138 |
1002 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1139 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1003 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1140 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1004 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1141 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1005 | 1142 |
1006 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1143 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1007 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1144 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1008 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1145 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1009 priority.time_to_visible_in_seconds); | |
1010 | 1146 |
1011 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1147 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1012 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1148 EXPECT_GT(priority.distance_to_visible, 0.f); |
1013 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1149 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1014 priority.time_to_visible_in_seconds); | |
1015 | 1150 |
1016 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1151 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1017 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1152 EXPECT_GT(priority.distance_to_visible, 0.f); |
1018 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1153 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1019 priority.time_to_visible_in_seconds); | |
1020 | 1154 |
1021 // Furthermore, in this scenario the bottom-right tile should have the larger | 1155 // Furthermore, in this scenario the bottom-right tile should have the larger |
1022 // distance to visible. | 1156 // distance to visible. |
1023 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1157 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1024 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1158 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1025 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | |
1026 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1159 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1027 EXPECT_GT(top_right.distance_to_visible_in_pixels, | 1160 EXPECT_GT(top_right.distance_to_visible, top_left.distance_to_visible); |
1028 top_left.distance_to_visible_in_pixels); | |
1029 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | |
1030 top_left.distance_to_visible_in_pixels); | |
1031 | 1161 |
1032 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1162 EXPECT_EQ(bottom_right.distance_to_visible, top_right.distance_to_visible); |
1033 bottom_left.distance_to_visible_in_pixels); | |
1034 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | |
1035 top_right.distance_to_visible_in_pixels); | |
1036 } | 1163 } |
1037 | 1164 |
1038 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { | 1165 TEST(UpdateTilePrioritiesTest, PerspectiveLayer) { |
1039 // Perspective transforms need to take a different code path. | 1166 // Perspective transforms need to take a different code path. |
1040 // This test checks tile priorities of a perspective layer. | 1167 // This test checks tile priorities of a perspective layer. |
1041 | 1168 |
1042 FakePictureLayerTilingClient client; | 1169 FakePictureLayerTilingClient client; |
1043 scoped_ptr<TestablePictureLayerTiling> tiling; | 1170 scoped_ptr<TestablePictureLayerTiling> tiling; |
1044 | 1171 |
1045 gfx::Size device_viewport(800, 600); | 1172 gfx::Size device_viewport(800, 600); |
1046 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | 1173 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. |
1047 gfx::Size last_layer_bounds(200, 200); | 1174 gfx::Size last_layer_bounds(200, 200); |
1048 gfx::Size current_layer_bounds(200, 200); | 1175 gfx::Size current_layer_bounds(200, 200); |
1049 float last_layer_contents_scale = 1.f; | |
1050 float current_layer_contents_scale = 1.f; | 1176 float current_layer_contents_scale = 1.f; |
1051 gfx::Transform last_screen_transform; | 1177 gfx::Transform last_screen_transform; |
1052 gfx::Transform current_screen_transform; | 1178 gfx::Transform current_screen_transform; |
1053 double current_frame_time_in_seconds = 1.0; | 1179 double current_frame_time_in_seconds = 1.0; |
1054 size_t max_tiles_for_interest_area = 10000; | |
1055 | 1180 |
1056 // 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 |
1057 // 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 |
1058 // 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 |
1059 // top-right. | 1184 // top-right. |
1060 | 1185 |
1061 // Translate layer to offscreen | 1186 // Translate layer to offscreen |
1062 current_screen_transform.Translate(400.0, 630.0); | 1187 current_screen_transform.Translate(400.0, 630.0); |
1063 // Apply perspective about the center of the layer | 1188 // Apply perspective about the center of the layer |
1064 current_screen_transform.Translate(100.0, 100.0); | 1189 current_screen_transform.Translate(100.0, 100.0); |
(...skipping 10 matching lines...) Expand all Loading... |
1075 ASSERT_FALSE(clipped); | 1200 ASSERT_FALSE(clipped); |
1076 | 1201 |
1077 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1202 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1078 current_screen_transform, device_viewport); | 1203 current_screen_transform, device_viewport); |
1079 | 1204 |
1080 client.SetTileSize(gfx::Size(100, 100)); | 1205 client.SetTileSize(gfx::Size(100, 100)); |
1081 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1206 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1082 current_layer_bounds, | 1207 current_layer_bounds, |
1083 &client); | 1208 &client); |
1084 | 1209 |
1085 tiling->UpdateTilePriorities( | 1210 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1086 ACTIVE_TREE, | 1211 viewport_in_layer_space, |
1087 device_viewport, | 1212 current_layer_contents_scale, |
1088 viewport_in_layer_space, | 1213 current_frame_time_in_seconds); |
1089 visible_layer_rect, | |
1090 last_layer_bounds, | |
1091 current_layer_bounds, | |
1092 last_layer_contents_scale, | |
1093 current_layer_contents_scale, | |
1094 last_screen_transform, | |
1095 current_screen_transform, | |
1096 current_frame_time_in_seconds, | |
1097 max_tiles_for_interest_area); | |
1098 | 1214 |
1099 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1215 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1100 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1216 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1101 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1217 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1102 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1218 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1103 | 1219 |
1104 // All tiles will have a positive distance_to_visible | 1220 // All tiles will have a positive distance_to_visible |
1105 // and an infinite time_to_visible. | 1221 // and an infinite time_to_visible. |
1106 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1222 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1107 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1223 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1108 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1224 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1109 priority.time_to_visible_in_seconds); | |
1110 | 1225 |
1111 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1226 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1112 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1227 EXPECT_GT(priority.distance_to_visible, 0.f); |
1113 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1228 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1114 priority.time_to_visible_in_seconds); | |
1115 | 1229 |
1116 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1230 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1117 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1231 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1118 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1232 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1119 priority.time_to_visible_in_seconds); | |
1120 | 1233 |
1121 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1234 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1122 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1235 EXPECT_GT(priority.distance_to_visible, 0.f); |
1123 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1236 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1124 priority.time_to_visible_in_seconds); | |
1125 | 1237 |
1126 // Furthermore, in this scenario the top-left distance_to_visible | 1238 // Furthermore, in this scenario the top-left distance_to_visible |
1127 // will be smallest, followed by top-right. The bottom layers | 1239 // will be smallest, followed by top-right. The bottom layers |
1128 // will of course be further than the top layers. | 1240 // will of course be further than the top layers. |
1129 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1241 TilePriority top_left = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1130 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1242 TilePriority top_right = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1131 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1243 TilePriority bottom_left = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1132 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1244 TilePriority bottom_right = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1133 EXPECT_GT(top_right.distance_to_visible_in_pixels, | |
1134 top_left.distance_to_visible_in_pixels); | |
1135 | 1245 |
1136 EXPECT_GT(bottom_right.distance_to_visible_in_pixels, | 1246 EXPECT_GT(bottom_right.distance_to_visible, top_right.distance_to_visible); |
1137 top_right.distance_to_visible_in_pixels); | |
1138 | 1247 |
1139 EXPECT_GT(bottom_left.distance_to_visible_in_pixels, | 1248 EXPECT_GT(bottom_left.distance_to_visible, top_left.distance_to_visible); |
1140 top_left.distance_to_visible_in_pixels); | |
1141 } | 1249 } |
1142 | 1250 |
1143 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { | 1251 TEST(UpdateTilePrioritiesTest, PerspectiveLayerClippedByW) { |
1144 // Perspective transforms need to take a different code path. | 1252 // Perspective transforms need to take a different code path. |
1145 // This test checks tile priorities of a perspective layer. | 1253 // This test checks tile priorities of a perspective layer. |
1146 | 1254 |
1147 FakePictureLayerTilingClient client; | 1255 FakePictureLayerTilingClient client; |
1148 scoped_ptr<TestablePictureLayerTiling> tiling; | 1256 scoped_ptr<TestablePictureLayerTiling> tiling; |
1149 | 1257 |
1150 gfx::Size device_viewport(800, 600); | 1258 gfx::Size device_viewport(800, 600); |
1151 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscreen. | |
1152 gfx::Size last_layer_bounds(200, 200); | 1259 gfx::Size last_layer_bounds(200, 200); |
1153 gfx::Size current_layer_bounds(200, 200); | 1260 gfx::Size current_layer_bounds(200, 200); |
1154 float last_layer_contents_scale = 1.f; | |
1155 float current_layer_contents_scale = 1.f; | 1261 float current_layer_contents_scale = 1.f; |
1156 gfx::Transform last_screen_transform; | 1262 gfx::Transform last_screen_transform; |
1157 gfx::Transform current_screen_transform; | 1263 gfx::Transform current_screen_transform; |
1158 double current_frame_time_in_seconds = 1.0; | 1264 double current_frame_time_in_seconds = 1.0; |
1159 size_t max_tiles_for_interest_area = 10000; | |
1160 | 1265 |
1161 // A 3d perspective layer rotated about its Y axis, translated to almost | 1266 // A 3d perspective layer rotated about its Y axis, translated to almost |
1162 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than | 1267 // fully offscreen. The left side will appear closer (i.e. larger in 2d) than |
1163 // the right side, so the top-left tile will technically be closer than the | 1268 // the right side, so the top-left tile will technically be closer than the |
1164 // top-right. | 1269 // top-right. |
1165 | 1270 |
1166 // Translate layer to offscreen | 1271 // Translate layer to offscreen |
1167 current_screen_transform.Translate(400.0, 970.0); | 1272 current_screen_transform.Translate(400.0, 970.0); |
1168 // Apply perspective and rotation about the center of the layer | 1273 // Apply perspective and rotation about the center of the layer |
1169 current_screen_transform.Translate(100.0, 100.0); | 1274 current_screen_transform.Translate(100.0, 100.0); |
(...skipping 16 matching lines...) Expand all Loading... |
1186 ASSERT_FALSE(clipped); | 1291 ASSERT_FALSE(clipped); |
1187 | 1292 |
1188 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1293 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1189 current_screen_transform, device_viewport); | 1294 current_screen_transform, device_viewport); |
1190 | 1295 |
1191 client.SetTileSize(gfx::Size(100, 100)); | 1296 client.SetTileSize(gfx::Size(100, 100)); |
1192 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1297 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1193 current_layer_bounds, | 1298 current_layer_bounds, |
1194 &client); | 1299 &client); |
1195 | 1300 |
1196 tiling->UpdateTilePriorities( | 1301 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1197 ACTIVE_TREE, | 1302 viewport_in_layer_space, |
1198 device_viewport, | 1303 current_layer_contents_scale, |
1199 viewport_in_layer_space, | 1304 current_frame_time_in_seconds); |
1200 visible_layer_rect, | |
1201 last_layer_bounds, | |
1202 current_layer_bounds, | |
1203 last_layer_contents_scale, | |
1204 current_layer_contents_scale, | |
1205 last_screen_transform, | |
1206 current_screen_transform, | |
1207 current_frame_time_in_seconds, | |
1208 max_tiles_for_interest_area); | |
1209 | 1305 |
1210 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1306 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1211 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1307 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1212 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1308 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1213 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1309 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1214 | 1310 |
1215 // Left-side tiles will be clipped by the transform, so we have to assume | 1311 // Left-side tiles will be clipped by the transform, so we have to assume |
1216 // they are visible just in case. | 1312 // they are visible just in case. |
1217 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1313 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1218 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1314 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1219 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1315 EXPECT_FLOAT_EQ(TilePriority::NOW, priority.priority_bin); |
1220 | 1316 |
1221 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1317 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1222 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1318 EXPECT_GT(priority.distance_to_visible, 0.f); |
1223 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1319 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1224 | 1320 |
1225 // Right-side tiles will have a positive distance_to_visible | 1321 // Right-side tiles will have a positive distance_to_visible |
1226 // and an infinite time_to_visible. | 1322 // and an infinite time_to_visible. |
1227 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1323 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1228 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1324 EXPECT_FLOAT_EQ(priority.distance_to_visible, 0.f); |
1229 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1325 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1230 priority.time_to_visible_in_seconds); | |
1231 | 1326 |
1232 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1327 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1233 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1328 EXPECT_GT(priority.distance_to_visible, 0.f); |
1234 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1329 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1235 priority.time_to_visible_in_seconds); | |
1236 } | 1330 } |
1237 | 1331 |
1238 TEST(UpdateTilePrioritiesTest, BasicMotion) { | 1332 TEST(UpdateTilePrioritiesTest, BasicMotion) { |
1239 // Test that time_to_visible is computed correctly when | 1333 // Test that time_to_visible is computed correctly when |
1240 // there is some motion. | 1334 // there is some motion. |
1241 | 1335 |
1242 FakePictureLayerTilingClient client; | 1336 FakePictureLayerTilingClient client; |
1243 scoped_ptr<TestablePictureLayerTiling> tiling; | 1337 scoped_ptr<TestablePictureLayerTiling> tiling; |
1244 | 1338 |
1245 gfx::Size device_viewport(800, 600); | 1339 gfx::Size device_viewport(800, 600); |
1246 gfx::Rect visible_layer_rect(0, 0, 0, 0); | 1340 gfx::Rect visible_layer_rect(0, 0, 0, 0); |
1247 gfx::Size last_layer_bounds(200, 200); | 1341 gfx::Size last_layer_bounds(200, 200); |
1248 gfx::Size current_layer_bounds(200, 200); | 1342 gfx::Size current_layer_bounds(200, 200); |
1249 float last_layer_contents_scale = 1.f; | 1343 float last_layer_contents_scale = 1.f; |
1250 float current_layer_contents_scale = 1.f; | 1344 float current_layer_contents_scale = 1.f; |
1251 gfx::Transform last_screen_transform; | 1345 gfx::Transform last_screen_transform; |
1252 gfx::Transform current_screen_transform; | 1346 gfx::Transform current_screen_transform; |
1253 double last_frame_time_in_seconds = 1.0; | 1347 double last_frame_time_in_seconds = 1.0; |
1254 double current_frame_time_in_seconds = 2.0; | 1348 double current_frame_time_in_seconds = 2.0; |
1255 size_t max_tiles_for_interest_area = 10000; | |
1256 | 1349 |
1257 // Offscreen layer is coming closer to viewport at 1000 pixels per second. | 1350 // Offscreen layer is coming closer to viewport at 1000 pixels per second. |
1258 current_screen_transform.Translate(1800, 0); | 1351 current_screen_transform.Translate(1800, 0); |
1259 last_screen_transform.Translate(2800, 0); | 1352 last_screen_transform.Translate(2800, 0); |
1260 | 1353 |
1261 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1354 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1262 current_screen_transform, device_viewport); | 1355 current_screen_transform, device_viewport); |
1263 | 1356 |
1264 client.SetTileSize(gfx::Size(100, 100)); | 1357 client.SetTileSize(gfx::Size(100, 100)); |
1265 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1358 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1266 current_layer_bounds, | 1359 current_layer_bounds, |
1267 &client); | 1360 &client); |
1268 | 1361 |
1269 // previous ("last") frame | 1362 // previous ("last") frame |
1270 tiling->UpdateTilePriorities( | 1363 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1271 ACTIVE_TREE, | 1364 viewport_in_layer_space, |
1272 device_viewport, | 1365 last_layer_contents_scale, |
1273 viewport_in_layer_space, | 1366 last_frame_time_in_seconds); |
1274 visible_layer_rect, | |
1275 last_layer_bounds, | |
1276 last_layer_bounds, | |
1277 last_layer_contents_scale, | |
1278 last_layer_contents_scale, | |
1279 last_screen_transform, | |
1280 last_screen_transform, | |
1281 last_frame_time_in_seconds, | |
1282 max_tiles_for_interest_area); | |
1283 | 1367 |
1284 // current frame | 1368 // current frame |
1285 tiling->UpdateTilePriorities( | 1369 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1286 ACTIVE_TREE, | 1370 viewport_in_layer_space, |
1287 device_viewport, | 1371 current_layer_contents_scale, |
1288 viewport_in_layer_space, | 1372 current_frame_time_in_seconds); |
1289 visible_layer_rect, | |
1290 last_layer_bounds, | |
1291 current_layer_bounds, | |
1292 last_layer_contents_scale, | |
1293 current_layer_contents_scale, | |
1294 last_screen_transform, | |
1295 current_screen_transform, | |
1296 current_frame_time_in_seconds, | |
1297 max_tiles_for_interest_area); | |
1298 | 1373 |
1299 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1374 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1300 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1375 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1301 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1376 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1302 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1377 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1303 | 1378 |
1304 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1379 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1305 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1380 EXPECT_GT(priority.distance_to_visible, 0.f); |
1306 EXPECT_FLOAT_EQ(1.f, | 1381 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1307 priority.time_to_visible_in_seconds); | |
1308 | 1382 |
1309 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1383 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1310 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1384 EXPECT_GT(priority.distance_to_visible, 0.f); |
1311 EXPECT_FLOAT_EQ(1.f, | 1385 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1312 priority.time_to_visible_in_seconds); | |
1313 | 1386 |
1314 // time_to_visible for the right hand side layers needs an extra 0.099 | 1387 // time_to_visible for the right hand side layers needs an extra 0.099 |
1315 // seconds because this tile is 99 pixels further away. | 1388 // seconds because this tile is 99 pixels further away. |
1316 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1389 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1317 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1390 EXPECT_GT(priority.distance_to_visible, 0.f); |
1318 EXPECT_FLOAT_EQ(1.099f, | 1391 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1319 priority.time_to_visible_in_seconds); | |
1320 | 1392 |
1321 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); | 1393 priority = tiling->TileAt(1, 1)->priority(ACTIVE_TREE); |
1322 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1394 EXPECT_GT(priority.distance_to_visible, 0.f); |
1323 EXPECT_FLOAT_EQ(1.099f, | 1395 EXPECT_NE(TilePriority::NOW, priority.priority_bin); |
1324 priority.time_to_visible_in_seconds); | |
1325 } | 1396 } |
1326 | 1397 |
1327 TEST(UpdateTilePrioritiesTest, RotationMotion) { | 1398 TEST(UpdateTilePrioritiesTest, RotationMotion) { |
1328 // Each tile of a layer may be affected differently by a transform; Check | 1399 // Each tile of a layer may be affected differently by a transform; Check |
1329 // that UpdateTilePriorities correctly accounts for the transform between | 1400 // that UpdateTilePriorities correctly accounts for the transform between |
1330 // layer space and screen space. | 1401 // layer space and screen space. |
1331 | 1402 |
1332 FakePictureLayerTilingClient client; | 1403 FakePictureLayerTilingClient client; |
1333 scoped_ptr<TestablePictureLayerTiling> tiling; | 1404 scoped_ptr<TestablePictureLayerTiling> tiling; |
1334 | 1405 |
1335 gfx::Size device_viewport(800, 600); | 1406 gfx::Size device_viewport(800, 600); |
1336 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. | 1407 gfx::Rect visible_layer_rect(0, 0, 0, 0); // offscren. |
1337 gfx::Size last_layer_bounds(200, 200); | 1408 gfx::Size last_layer_bounds(200, 200); |
1338 gfx::Size current_layer_bounds(200, 200); | 1409 gfx::Size current_layer_bounds(200, 200); |
1339 float last_layer_contents_scale = 1.f; | 1410 float last_layer_contents_scale = 1.f; |
1340 float current_layer_contents_scale = 1.f; | 1411 float current_layer_contents_scale = 1.f; |
1341 gfx::Transform last_screen_transform; | 1412 gfx::Transform last_screen_transform; |
1342 gfx::Transform current_screen_transform; | 1413 gfx::Transform current_screen_transform; |
1343 double last_frame_time_in_seconds = 1.0; | 1414 double last_frame_time_in_seconds = 1.0; |
1344 double current_frame_time_in_seconds = 2.0; | 1415 double current_frame_time_in_seconds = 2.0; |
1345 size_t max_tiles_for_interest_area = 10000; | |
1346 | 1416 |
1347 // Rotation motion is set up specifically so that: | 1417 // Rotation motion is set up specifically so that: |
1348 // - rotation occurs about the center of the layer | 1418 // - rotation occurs about the center of the layer |
1349 // - the top-left tile becomes visible on rotation | 1419 // - the top-left tile becomes visible on rotation |
1350 // - the top-right tile will have an infinite time_to_visible | 1420 // - the top-right tile will have an infinite time_to_visible |
1351 // because it is rotating away from viewport. | 1421 // because it is rotating away from viewport. |
1352 // - bottom-left layer will have a positive non-zero time_to_visible | 1422 // - bottom-left layer will have a positive non-zero time_to_visible |
1353 // because it is rotating toward the viewport. | 1423 // because it is rotating toward the viewport. |
1354 current_screen_transform.Translate(400, 550); | 1424 current_screen_transform.Translate(400, 550); |
1355 current_screen_transform.RotateAboutZAxis(45); | 1425 current_screen_transform.RotateAboutZAxis(45); |
1356 | 1426 |
1357 last_screen_transform.Translate(400, 550); | 1427 last_screen_transform.Translate(400, 550); |
1358 | 1428 |
1359 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( | 1429 gfx::Rect viewport_in_layer_space = ViewportInLayerSpace( |
1360 current_screen_transform, device_viewport); | 1430 current_screen_transform, device_viewport); |
1361 | 1431 |
1362 client.SetTileSize(gfx::Size(100, 100)); | 1432 client.SetTileSize(gfx::Size(100, 100)); |
1363 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1433 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1364 current_layer_bounds, | 1434 current_layer_bounds, |
1365 &client); | 1435 &client); |
1366 | 1436 |
1367 // previous ("last") frame | 1437 // previous ("last") frame |
1368 tiling->UpdateTilePriorities( | 1438 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1369 ACTIVE_TREE, | 1439 viewport_in_layer_space, |
1370 device_viewport, | 1440 last_layer_contents_scale, |
1371 viewport_in_layer_space, | 1441 last_frame_time_in_seconds); |
1372 visible_layer_rect, | |
1373 last_layer_bounds, | |
1374 last_layer_bounds, | |
1375 last_layer_contents_scale, | |
1376 last_layer_contents_scale, | |
1377 last_screen_transform, | |
1378 last_screen_transform, | |
1379 last_frame_time_in_seconds, | |
1380 max_tiles_for_interest_area); | |
1381 | 1442 |
1382 // current frame | 1443 // current frame |
1383 tiling->UpdateTilePriorities( | 1444 tiling->UpdateTilePriorities(ACTIVE_TREE, |
1384 ACTIVE_TREE, | 1445 viewport_in_layer_space, |
1385 device_viewport, | 1446 current_layer_contents_scale, |
1386 viewport_in_layer_space, | 1447 current_frame_time_in_seconds); |
1387 visible_layer_rect, | |
1388 last_layer_bounds, | |
1389 current_layer_bounds, | |
1390 last_layer_contents_scale, | |
1391 current_layer_contents_scale, | |
1392 last_screen_transform, | |
1393 current_screen_transform, | |
1394 current_frame_time_in_seconds, | |
1395 max_tiles_for_interest_area); | |
1396 | 1448 |
1397 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1449 ASSERT_TRUE(tiling->TileAt(0, 0)); |
1398 ASSERT_TRUE(tiling->TileAt(0, 1)); | 1450 ASSERT_TRUE(tiling->TileAt(0, 1)); |
1399 ASSERT_TRUE(tiling->TileAt(1, 0)); | 1451 ASSERT_TRUE(tiling->TileAt(1, 0)); |
1400 ASSERT_TRUE(tiling->TileAt(1, 1)); | 1452 ASSERT_TRUE(tiling->TileAt(1, 1)); |
1401 | 1453 |
1402 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); | 1454 TilePriority priority = tiling->TileAt(0, 0)->priority(ACTIVE_TREE); |
1403 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible_in_pixels); | 1455 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1404 EXPECT_FLOAT_EQ(0.f, priority.time_to_visible_in_seconds); | 1456 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1405 | 1457 |
1406 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); | 1458 priority = tiling->TileAt(0, 1)->priority(ACTIVE_TREE); |
1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1459 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1460 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1409 | 1461 |
1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1462 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1463 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1464 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
1413 priority.time_to_visible_in_seconds); | |
1414 } | 1465 } |
1415 | 1466 |
1416 } // namespace | 1467 } // namespace |
1417 } // namespace cc | 1468 } // namespace cc |
OLD | NEW |