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