OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 viewport, | 420 viewport, |
421 viewport_rect_for_tile_priority, | 421 viewport_rect_for_tile_priority, |
422 transform_for_tile_priority, | 422 transform_for_tile_priority, |
423 resourceless_software_draw); | 423 resourceless_software_draw); |
424 host_impl_.active_tree()->UpdateDrawProperties(); | 424 host_impl_.active_tree()->UpdateDrawProperties(); |
425 | 425 |
426 gfx::Rect viewport_rect_for_tile_priority_in_view_space = | 426 gfx::Rect viewport_rect_for_tile_priority_in_view_space = |
427 viewport_rect_for_tile_priority; | 427 viewport_rect_for_tile_priority; |
428 | 428 |
429 // Verify the viewport rect for tile priority is used in picture layer tiling. | 429 // Verify the viewport rect for tile priority is used in picture layer tiling. |
430 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space, | 430 EXPECT_EQ( |
431 active_layer_->GetViewportForTilePriorityInContentSpace()); | 431 viewport_rect_for_tile_priority_in_view_space, |
| 432 active_layer_->GetViewportForTilePriorityInContentSpaceForTesting()); |
432 PictureLayerTilingSet* tilings = active_layer_->tilings(); | 433 PictureLayerTilingSet* tilings = active_layer_->tilings(); |
433 for (size_t i = 0; i < tilings->num_tilings(); i++) { | 434 for (size_t i = 0; i < tilings->num_tilings(); i++) { |
434 PictureLayerTiling* tiling = tilings->tiling_at(i); | 435 PictureLayerTiling* tiling = tilings->tiling_at(i); |
435 EXPECT_EQ( | 436 EXPECT_EQ( |
436 tiling->GetCurrentVisibleRectForTesting(), | 437 tiling->GetCurrentVisibleRectForTesting(), |
437 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, | 438 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, |
438 tiling->contents_scale())); | 439 tiling->contents_scale())); |
439 } | 440 } |
440 | 441 |
441 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in | 442 // Update tiles with viewport for tile priority as (200, 200, 100, 100) in |
(...skipping 20 matching lines...) Expand all Loading... |
462 EXPECT_TRUE(success); | 463 EXPECT_TRUE(success); |
463 | 464 |
464 // Note that we don't clip this to the layer bounds, since it is expected that | 465 // Note that we don't clip this to the layer bounds, since it is expected that |
465 // the rect will sometimes be outside of the layer bounds. If we clip to | 466 // the rect will sometimes be outside of the layer bounds. If we clip to |
466 // bounds, then tile priorities will end up being incorrect in cases of fully | 467 // bounds, then tile priorities will end up being incorrect in cases of fully |
467 // offscreen layer. | 468 // offscreen layer. |
468 viewport_rect_for_tile_priority_in_view_space = | 469 viewport_rect_for_tile_priority_in_view_space = |
469 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 470 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
470 screen_to_view, viewport_rect_for_tile_priority)); | 471 screen_to_view, viewport_rect_for_tile_priority)); |
471 | 472 |
472 EXPECT_EQ(viewport_rect_for_tile_priority_in_view_space, | 473 EXPECT_EQ( |
473 active_layer_->GetViewportForTilePriorityInContentSpace()); | 474 viewport_rect_for_tile_priority_in_view_space, |
| 475 active_layer_->GetViewportForTilePriorityInContentSpaceForTesting()); |
474 tilings = active_layer_->tilings(); | 476 tilings = active_layer_->tilings(); |
475 for (size_t i = 0; i < tilings->num_tilings(); i++) { | 477 for (size_t i = 0; i < tilings->num_tilings(); i++) { |
476 PictureLayerTiling* tiling = tilings->tiling_at(i); | 478 PictureLayerTiling* tiling = tilings->tiling_at(i); |
477 EXPECT_EQ( | 479 EXPECT_EQ( |
478 tiling->GetCurrentVisibleRectForTesting(), | 480 tiling->GetCurrentVisibleRectForTesting(), |
479 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, | 481 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, |
480 tiling->contents_scale())); | 482 tiling->contents_scale())); |
481 } | 483 } |
482 } | 484 } |
483 | 485 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 viewport, | 559 viewport, |
558 transform, | 560 transform, |
559 resourceless_software_draw); | 561 resourceless_software_draw); |
560 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 562 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); |
561 | 563 |
562 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, | 564 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
563 active_layer_->screen_space_transform()); | 565 active_layer_->screen_space_transform()); |
564 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); | 566 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); |
565 } | 567 } |
566 | 568 |
| 569 TEST_F(PictureLayerImplTest, ViewportRectForTilePriorityIsCached) { |
| 570 base::TimeTicks time_ticks; |
| 571 time_ticks += base::TimeDelta::FromMilliseconds(1); |
| 572 host_impl_.SetCurrentBeginFrameArgs( |
| 573 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
| 574 gfx::Size tile_size(100, 100); |
| 575 gfx::Size layer_bounds(400, 400); |
| 576 |
| 577 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 578 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 579 scoped_refptr<FakePicturePileImpl> active_pile = |
| 580 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 581 |
| 582 SetupTreesWithInvalidation(pending_pile, active_pile, Region()); |
| 583 |
| 584 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); |
| 585 |
| 586 time_ticks += base::TimeDelta::FromMilliseconds(200); |
| 587 host_impl_.SetCurrentBeginFrameArgs( |
| 588 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
| 589 |
| 590 bool resourceless_software_draw = false; |
| 591 gfx::Rect viewport = gfx::Rect(layer_bounds); |
| 592 gfx::Rect viewport_rect_for_tile_priority(0, 0, 100, 100); |
| 593 gfx::Transform transform, transform_for_tile_priority; |
| 594 |
| 595 host_impl_.SetExternalDrawConstraints( |
| 596 transform, viewport, viewport, viewport_rect_for_tile_priority, |
| 597 transform_for_tile_priority, resourceless_software_draw); |
| 598 host_impl_.active_tree()->UpdateDrawProperties(); |
| 599 |
| 600 EXPECT_EQ( |
| 601 viewport_rect_for_tile_priority, |
| 602 active_layer_->GetViewportForTilePriorityInContentSpaceForTesting()); |
| 603 |
| 604 time_ticks += base::TimeDelta::FromMilliseconds(200); |
| 605 host_impl_.SetCurrentBeginFrameArgs( |
| 606 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
| 607 |
| 608 gfx::Rect another_viewport_rect_for_tile_priority(11, 11, 50, 50); |
| 609 host_impl_.SetExternalDrawConstraints( |
| 610 transform, viewport, viewport, another_viewport_rect_for_tile_priority, |
| 611 transform_for_tile_priority, resourceless_software_draw); |
| 612 |
| 613 // Didn't call UpdateDrawProperties yet. The viewport rect for tile priority |
| 614 // should remain to be the previously cached value. |
| 615 EXPECT_EQ( |
| 616 viewport_rect_for_tile_priority, |
| 617 active_layer_->GetViewportForTilePriorityInContentSpaceForTesting()); |
| 618 host_impl_.active_tree()->UpdateDrawProperties(); |
| 619 |
| 620 // Now the UpdateDrawProperties is called. The viewport rect for tile |
| 621 // priority should be the latest value. |
| 622 EXPECT_EQ( |
| 623 another_viewport_rect_for_tile_priority, |
| 624 active_layer_->GetViewportForTilePriorityInContentSpaceForTesting()); |
| 625 } |
| 626 |
567 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { | 627 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { |
568 gfx::Size tile_size(100, 100); | 628 gfx::Size tile_size(100, 100); |
569 gfx::Size layer_bounds(400, 400); | 629 gfx::Size layer_bounds(400, 400); |
570 gfx::Rect layer_invalidation(150, 200, 30, 180); | 630 gfx::Rect layer_invalidation(150, 200, 30, 180); |
571 | 631 |
572 scoped_refptr<FakePicturePileImpl> pending_pile = | 632 scoped_refptr<FakePicturePileImpl> pending_pile = |
573 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 633 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
574 scoped_refptr<FakePicturePileImpl> active_pile = | 634 scoped_refptr<FakePicturePileImpl> active_pile = |
575 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 635 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
576 scoped_refptr<FakePicturePileImpl> lost_pile = | 636 scoped_refptr<FakePicturePileImpl> lost_pile = |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 // external_viewport_for_tile_priority. | 1734 // external_viewport_for_tile_priority. |
1675 pending_layer_->draw_properties().visible_content_rect = visible_content_rect; | 1735 pending_layer_->draw_properties().visible_content_rect = visible_content_rect; |
1676 time_ticks += base::TimeDelta::FromMilliseconds(200); | 1736 time_ticks += base::TimeDelta::FromMilliseconds(200); |
1677 host_impl_.SetCurrentBeginFrameArgs( | 1737 host_impl_.SetCurrentBeginFrameArgs( |
1678 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | 1738 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
1679 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 1739 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); |
1680 | 1740 |
1681 // Intersect the two rects. Any tile outside should not be required for | 1741 // Intersect the two rects. Any tile outside should not be required for |
1682 // activation. | 1742 // activation. |
1683 gfx::Rect viewport_for_tile_priority = | 1743 gfx::Rect viewport_for_tile_priority = |
1684 pending_layer_->GetViewportForTilePriorityInContentSpace(); | 1744 pending_layer_->GetViewportForTilePriorityInContentSpaceForTesting(); |
1685 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect()); | 1745 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect()); |
1686 | 1746 |
1687 int num_inside = 0; | 1747 int num_inside = 0; |
1688 int num_outside = 0; | 1748 int num_outside = 0; |
1689 for (PictureLayerTiling::CoverageIterator iter( | 1749 for (PictureLayerTiling::CoverageIterator iter( |
1690 pending_layer_->HighResTiling(), 1.f, gfx::Rect(layer_bounds)); | 1750 pending_layer_->HighResTiling(), 1.f, gfx::Rect(layer_bounds)); |
1691 iter; ++iter) { | 1751 iter; ++iter) { |
1692 if (!*iter) | 1752 if (!*iter) |
1693 continue; | 1753 continue; |
1694 Tile* tile = *iter; | 1754 Tile* tile = *iter; |
(...skipping 3129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4824 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4884 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
4825 EXPECT_EQ(result.width(), 448); | 4885 EXPECT_EQ(result.width(), 448); |
4826 EXPECT_EQ(result.height(), 448); | 4886 EXPECT_EQ(result.height(), 448); |
4827 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4887 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
4828 EXPECT_EQ(result.width(), 512); | 4888 EXPECT_EQ(result.width(), 512); |
4829 EXPECT_EQ(result.height(), 500 + 2); | 4889 EXPECT_EQ(result.height(), 500 + 2); |
4830 } | 4890 } |
4831 | 4891 |
4832 } // namespace | 4892 } // namespace |
4833 } // namespace cc | 4893 } // namespace cc |
OLD | NEW |