| 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> |
| 11 | 11 |
| 12 #include "cc/base/math_util.h" | 12 #include "cc/base/math_util.h" |
| 13 #include "cc/layers/append_quads_data.h" | 13 #include "cc/layers/append_quads_data.h" |
| 14 #include "cc/layers/picture_layer.h" | 14 #include "cc/layers/picture_layer.h" |
| 15 #include "cc/quads/draw_quad.h" | 15 #include "cc/quads/draw_quad.h" |
| 16 #include "cc/quads/tile_draw_quad.h" | |
| 17 #include "cc/test/begin_frame_args_test.h" | 16 #include "cc/test/begin_frame_args_test.h" |
| 18 #include "cc/test/fake_content_layer_client.h" | 17 #include "cc/test/fake_content_layer_client.h" |
| 19 #include "cc/test/fake_impl_proxy.h" | 18 #include "cc/test/fake_impl_proxy.h" |
| 20 #include "cc/test/fake_layer_tree_host_impl.h" | 19 #include "cc/test/fake_layer_tree_host_impl.h" |
| 21 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
| 22 #include "cc/test/fake_picture_layer_impl.h" | 21 #include "cc/test/fake_picture_layer_impl.h" |
| 23 #include "cc/test/fake_picture_pile_impl.h" | 22 #include "cc/test/fake_picture_pile_impl.h" |
| 24 #include "cc/test/geometry_test_utils.h" | 23 #include "cc/test/geometry_test_utils.h" |
| 25 #include "cc/test/impl_side_painting_settings.h" | 24 #include "cc/test/impl_side_painting_settings.h" |
| 26 #include "cc/test/layer_test_common.h" | 25 #include "cc/test/layer_test_common.h" |
| (...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 AppendQuadsData data; | 1543 AppendQuadsData data; |
| 1545 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL); | 1544 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL); |
| 1546 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); | 1545 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); |
| 1547 active_layer_->DidDraw(NULL); | 1546 active_layer_->DidDraw(NULL); |
| 1548 | 1547 |
| 1549 // All tiles in activation rect is ready to draw. | 1548 // All tiles in activation rect is ready to draw. |
| 1550 EXPECT_EQ(0u, data.num_missing_tiles); | 1549 EXPECT_EQ(0u, data.num_missing_tiles); |
| 1551 EXPECT_EQ(0u, data.num_incomplete_tiles); | 1550 EXPECT_EQ(0u, data.num_incomplete_tiles); |
| 1552 } | 1551 } |
| 1553 | 1552 |
| 1554 TEST_F(PictureLayerImplTest, HighResTileIsComplete) { | |
| 1555 base::TimeTicks time_ticks; | |
| 1556 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
| 1557 host_impl_.SetCurrentBeginFrameArgs( | |
| 1558 CreateBeginFrameArgsForTesting(time_ticks)); | |
| 1559 | |
| 1560 gfx::Size tile_size(100, 100); | |
| 1561 gfx::Size layer_bounds(200, 200); | |
| 1562 | |
| 1563 host_impl_.SetViewportSize(layer_bounds); | |
| 1564 | |
| 1565 scoped_refptr<FakePicturePileImpl> pending_pile = | |
| 1566 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 1567 SetupPendingTree(pending_pile); | |
| 1568 ActivateTree(); | |
| 1569 | |
| 1570 // All high res tiles have resources. | |
| 1571 active_layer_->set_fixed_tile_size(tile_size); | |
| 1572 host_impl_.active_tree()->UpdateDrawProperties(); | |
| 1573 std::vector<Tile*> tiles = | |
| 1574 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); | |
| 1575 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); | |
| 1576 | |
| 1577 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 1578 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 1579 AppendQuadsData data; | |
| 1580 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL); | |
| 1581 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); | |
| 1582 active_layer_->DidDraw(NULL); | |
| 1583 | |
| 1584 // All high res tiles drew, nothing was incomplete. | |
| 1585 EXPECT_EQ(9u, render_pass->quad_list.size()); | |
| 1586 EXPECT_EQ(0u, data.num_missing_tiles); | |
| 1587 EXPECT_EQ(0u, data.num_incomplete_tiles); | |
| 1588 } | |
| 1589 | |
| 1590 TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) { | |
| 1591 base::TimeTicks time_ticks; | |
| 1592 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
| 1593 host_impl_.SetCurrentBeginFrameArgs( | |
| 1594 CreateBeginFrameArgsForTesting(time_ticks)); | |
| 1595 | |
| 1596 gfx::Size tile_size(100, 100); | |
| 1597 gfx::Size layer_bounds(200, 200); | |
| 1598 | |
| 1599 host_impl_.SetViewportSize(layer_bounds); | |
| 1600 | |
| 1601 scoped_refptr<FakePicturePileImpl> pending_pile = | |
| 1602 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 1603 SetupPendingTree(pending_pile); | |
| 1604 ActivateTree(); | |
| 1605 | |
| 1606 // All high res tiles have resources except one. | |
| 1607 active_layer_->set_fixed_tile_size(tile_size); | |
| 1608 host_impl_.active_tree()->UpdateDrawProperties(); | |
| 1609 std::vector<Tile*> high_tiles = | |
| 1610 active_layer_->tilings()->tiling_at(0)->AllTilesForTesting(); | |
| 1611 high_tiles.erase(high_tiles.begin()); | |
| 1612 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles); | |
| 1613 | |
| 1614 // All low res tiles have resources. | |
| 1615 std::vector<Tile*> low_tiles = | |
| 1616 active_layer_->tilings()->tiling_at(1)->AllTilesForTesting(); | |
| 1617 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(low_tiles); | |
| 1618 | |
| 1619 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 1620 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 1621 AppendQuadsData data; | |
| 1622 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL); | |
| 1623 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); | |
| 1624 active_layer_->DidDraw(NULL); | |
| 1625 | |
| 1626 // The missing high res tile was replaced by a low res tile. | |
| 1627 EXPECT_EQ(9u, render_pass->quad_list.size()); | |
| 1628 EXPECT_EQ(0u, data.num_missing_tiles); | |
| 1629 EXPECT_EQ(1u, data.num_incomplete_tiles); | |
| 1630 } | |
| 1631 | |
| 1632 TEST_F(PictureLayerImplTest, | |
| 1633 HighResAndIdealResTileIsCompleteWhenRasterScaleIsNotIdeal) { | |
| 1634 base::TimeTicks time_ticks; | |
| 1635 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
| 1636 host_impl_.SetCurrentBeginFrameArgs( | |
| 1637 CreateBeginFrameArgsForTesting(time_ticks)); | |
| 1638 | |
| 1639 gfx::Size tile_size(100, 100); | |
| 1640 gfx::Size layer_bounds(200, 200); | |
| 1641 | |
| 1642 host_impl_.SetViewportSize(layer_bounds); | |
| 1643 | |
| 1644 scoped_refptr<FakePicturePileImpl> pending_pile = | |
| 1645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 1646 scoped_refptr<FakePicturePileImpl> active_pile = | |
| 1647 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
| 1648 SetupTrees(pending_pile, active_pile); | |
| 1649 | |
| 1650 active_layer_->set_fixed_tile_size(tile_size); | |
| 1651 | |
| 1652 active_layer_->draw_properties().visible_content_rect = | |
| 1653 gfx::Rect(layer_bounds); | |
| 1654 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false); | |
| 1655 | |
| 1656 // One ideal tile exists, this will get used when drawing. | |
| 1657 std::vector<Tile*> ideal_tiles = | |
| 1658 active_layer_->HighResTiling()->AllTilesForTesting(); | |
| 1659 EXPECT_EQ(2.f, active_layer_->HighResTiling()->contents_scale()); | |
| 1660 while (ideal_tiles.size() > 1) | |
| 1661 ideal_tiles.erase(ideal_tiles.begin() + 1); | |
| 1662 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting( | |
| 1663 ideal_tiles); | |
| 1664 | |
| 1665 // Due to layer scale throttling, the raster contents scale is changed to 1, | |
| 1666 // while the ideal is still 2. | |
| 1667 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); | |
| 1668 SetupDrawPropertiesAndUpdateTiles(active_layer_, 2.f, 1.f, 1.f, 1.f, false); | |
| 1669 | |
| 1670 EXPECT_EQ(1.f, active_layer_->HighResTiling()->contents_scale()); | |
| 1671 EXPECT_EQ(1.f, active_layer_->raster_contents_scale()); | |
| 1672 EXPECT_EQ(2.f, active_layer_->ideal_contents_scale()); | |
| 1673 | |
| 1674 // Both tilings still exist. | |
| 1675 EXPECT_EQ(2.f, active_layer_->tilings()->tiling_at(0)->contents_scale()); | |
| 1676 EXPECT_EQ(1.f, active_layer_->tilings()->tiling_at(1)->contents_scale()); | |
| 1677 | |
| 1678 // All high res tiles have resources. | |
| 1679 std::vector<Tile*> high_tiles = | |
| 1680 active_layer_->HighResTiling()->AllTilesForTesting(); | |
| 1681 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(high_tiles); | |
| 1682 | |
| 1683 MockOcclusionTracker<LayerImpl> occlusion_tracker; | |
| 1684 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 1685 AppendQuadsData data; | |
| 1686 active_layer_->WillDraw(DRAW_MODE_SOFTWARE, NULL); | |
| 1687 active_layer_->AppendQuads(render_pass.get(), occlusion_tracker, &data); | |
| 1688 active_layer_->DidDraw(NULL); | |
| 1689 | |
| 1690 // All high res tiles drew, and the one ideal res tile drew. | |
| 1691 ASSERT_GT(render_pass->quad_list.size(), 9u); | |
| 1692 EXPECT_EQ(gfx::SizeF(99.f, 99.f), | |
| 1693 TileDrawQuad::MaterialCast(render_pass->quad_list[0]) | |
| 1694 ->tex_coord_rect.size()); | |
| 1695 EXPECT_EQ(gfx::SizeF(49.5f, 49.5f), | |
| 1696 TileDrawQuad::MaterialCast(render_pass->quad_list[1]) | |
| 1697 ->tex_coord_rect.size()); | |
| 1698 | |
| 1699 // Neither the high res nor the ideal tiles were considered as incomplete. | |
| 1700 EXPECT_EQ(0u, data.num_missing_tiles); | |
| 1701 EXPECT_EQ(0u, data.num_incomplete_tiles); | |
| 1702 } | |
| 1703 | |
| 1704 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { | 1553 TEST_F(PictureLayerImplTest, HighResRequiredWhenUnsharedActiveAllReady) { |
| 1705 gfx::Size layer_bounds(400, 400); | 1554 gfx::Size layer_bounds(400, 400); |
| 1706 gfx::Size tile_size(100, 100); | 1555 gfx::Size tile_size(100, 100); |
| 1707 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); | 1556 SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size); |
| 1708 | 1557 |
| 1709 // No tiles shared. | 1558 // No tiles shared. |
| 1710 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); | 1559 pending_layer_->set_invalidation(gfx::Rect(layer_bounds)); |
| 1711 | 1560 |
| 1712 CreateHighLowResAndSetAllTilesVisible(); | 1561 CreateHighLowResAndSetAllTilesVisible(); |
| 1713 | 1562 |
| (...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4142 | 3991 |
| 4143 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); | 3992 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles); |
| 4144 | 3993 |
| 4145 VerifyEvictionConsidersOcclusion(pending_layer_, | 3994 VerifyEvictionConsidersOcclusion(pending_layer_, |
| 4146 total_expected_occluded_tile_count); | 3995 total_expected_occluded_tile_count); |
| 4147 VerifyEvictionConsidersOcclusion(active_layer_, | 3996 VerifyEvictionConsidersOcclusion(active_layer_, |
| 4148 total_expected_occluded_tile_count); | 3997 total_expected_occluded_tile_count); |
| 4149 } | 3998 } |
| 4150 } // namespace | 3999 } // namespace |
| 4151 } // namespace cc | 4000 } // namespace cc |
| OLD | NEW |