| 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 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 // Contrived unit test of a real crash. A layer is transparent during a | 1495 // Contrived unit test of a real crash. A layer is transparent during a |
| 1496 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1496 // context loss, and later becomes opaque, causing active layer SyncTiling to |
| 1497 // be called. | 1497 // be called. |
| 1498 const float tile_scale = 2.f; | 1498 const float tile_scale = 2.f; |
| 1499 active_layer_->ReleaseResources(); | 1499 active_layer_->ReleaseResources(); |
| 1500 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1500 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1501 pending_layer_->AddTiling(2.f); | 1501 pending_layer_->AddTiling(2.f); |
| 1502 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1502 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 TEST_F(PictureLayerImplTest, TilingWithoutGpuRasterization) { | 1505 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
| 1506 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 1506 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1507 gfx::Size layer_bounds(default_tile_size.width() * 4, | 1507 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1508 default_tile_size.height() * 4); | 1508 default_tile_size.height() * 4); |
| 1509 float result_scale_x, result_scale_y; | 1509 float result_scale_x, result_scale_y; |
| 1510 gfx::Size result_bounds; | 1510 gfx::Size result_bounds; |
| 1511 | 1511 |
| 1512 SetupDefaultTrees(layer_bounds); | 1512 SetupDefaultTrees(layer_bounds); |
| 1513 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); | 1513 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1514 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1514 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1515 pending_layer_->CalculateContentsScale( | 1515 pending_layer_->CalculateContentsScale( |
| 1516 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 1516 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1517 // Should have a low-res and a high-res tiling. | 1517 // Should have a low-res and a high-res tiling. |
| 1518 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1518 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1519 |
| 1520 pending_layer_->SetUseGpuRasterization(true); |
| 1521 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1522 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1523 pending_layer_->CalculateContentsScale( |
| 1524 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1525 // Should only have the high-res tiling. |
| 1526 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1519 } | 1527 } |
| 1520 | 1528 |
| 1521 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { | 1529 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { |
| 1522 // Set up layers with tilings. | 1530 // Set up layers with tilings. |
| 1523 SetupDefaultTrees(gfx::Size(10, 10)); | 1531 SetupDefaultTrees(gfx::Size(10, 10)); |
| 1524 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); | 1532 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); |
| 1525 pending_layer_->PushPropertiesTo(active_layer_); | 1533 pending_layer_->PushPropertiesTo(active_layer_); |
| 1526 EXPECT_TRUE(pending_layer_->DrawsContent()); | 1534 EXPECT_TRUE(pending_layer_->DrawsContent()); |
| 1527 EXPECT_TRUE(pending_layer_->CanHaveTilings()); | 1535 EXPECT_TRUE(pending_layer_->CanHaveTilings()); |
| 1528 EXPECT_GE(pending_layer_->num_tilings(), 0u); | 1536 EXPECT_GE(pending_layer_->num_tilings(), 0u); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1638 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
| 1631 host_impl_.active_tree()->UpdateDrawProperties(); | 1639 host_impl_.active_tree()->UpdateDrawProperties(); |
| 1632 } | 1640 } |
| 1633 | 1641 |
| 1634 class HybridRasterizationPictureLayerImplTest : public PictureLayerImplTest { | 1642 class HybridRasterizationPictureLayerImplTest : public PictureLayerImplTest { |
| 1635 public: | 1643 public: |
| 1636 HybridRasterizationPictureLayerImplTest() | 1644 HybridRasterizationPictureLayerImplTest() |
| 1637 : PictureLayerImplTest(HybridRasterizationSettings()) {} | 1645 : PictureLayerImplTest(HybridRasterizationSettings()) {} |
| 1638 }; | 1646 }; |
| 1639 | 1647 |
| 1640 TEST_F(HybridRasterizationPictureLayerImplTest, Tiling) { | |
| 1641 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | |
| 1642 gfx::Size layer_bounds(default_tile_size.width() * 4, | |
| 1643 default_tile_size.height() * 4); | |
| 1644 float result_scale_x, result_scale_y; | |
| 1645 gfx::Size result_bounds; | |
| 1646 | |
| 1647 SetupDefaultTrees(layer_bounds); | |
| 1648 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1649 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1650 pending_layer_->CalculateContentsScale( | |
| 1651 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1652 // Should have a low-res and a high-res tiling. | |
| 1653 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | |
| 1654 | |
| 1655 pending_layer_->SetHasGpuRasterizationHint(true); | |
| 1656 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1657 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1658 pending_layer_->CalculateContentsScale( | |
| 1659 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1660 // Should only have the high-res tiling. | |
| 1661 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1662 } | |
| 1663 | |
| 1664 TEST_F(HybridRasterizationPictureLayerImplTest, | 1648 TEST_F(HybridRasterizationPictureLayerImplTest, |
| 1665 HighResTilingDuringAnimationForCpuRasterization) { | 1649 HighResTilingDuringAnimationForCpuRasterization) { |
| 1666 gfx::Size tile_size(host_impl_.settings().default_tile_size); | 1650 gfx::Size tile_size(host_impl_.settings().default_tile_size); |
| 1667 SetupDefaultTrees(tile_size); | 1651 SetupDefaultTrees(tile_size); |
| 1668 pending_layer_->SetHasGpuRasterizationHint(false); | 1652 pending_layer_->SetHasGpuRasterizationHint(false); |
| 1669 active_layer_->SetHasGpuRasterizationHint(false); | 1653 active_layer_->SetHasGpuRasterizationHint(false); |
| 1670 | 1654 |
| 1671 float contents_scale = 1.f; | 1655 float contents_scale = 1.f; |
| 1672 float device_scale = 1.f; | 1656 float device_scale = 1.f; |
| 1673 float page_scale = 1.f; | 1657 float page_scale = 1.f; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.5f); | 1710 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 0.5f); |
| 1727 | 1711 |
| 1728 // Tiling resolution should also update once we stop animating. | 1712 // Tiling resolution should also update once we stop animating. |
| 1729 contents_scale = 4.f; | 1713 contents_scale = 4.f; |
| 1730 animating_transform = false; | 1714 animating_transform = false; |
| 1731 SetContentsScaleOnBothLayers( | 1715 SetContentsScaleOnBothLayers( |
| 1732 contents_scale, device_scale, page_scale, animating_transform); | 1716 contents_scale, device_scale, page_scale, animating_transform); |
| 1733 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); | 1717 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); |
| 1734 } | 1718 } |
| 1735 | 1719 |
| 1736 class GpuRasterizationPictureLayerImplTest : public PictureLayerImplTest { | |
| 1737 public: | |
| 1738 GpuRasterizationPictureLayerImplTest() | |
| 1739 : PictureLayerImplTest(GpuRasterizationSettings()) {} | |
| 1740 }; | |
| 1741 | |
| 1742 TEST_F(GpuRasterizationPictureLayerImplTest, Tiling) { | |
| 1743 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | |
| 1744 gfx::Size layer_bounds(default_tile_size.width() * 4, | |
| 1745 default_tile_size.height() * 4); | |
| 1746 float result_scale_x, result_scale_y; | |
| 1747 gfx::Size result_bounds; | |
| 1748 | |
| 1749 SetupDefaultTrees(layer_bounds); | |
| 1750 pending_layer_->SetHasGpuRasterizationHint(true); | |
| 1751 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1752 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1753 pending_layer_->CalculateContentsScale( | |
| 1754 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1755 // Should only have the high-res tiling. | |
| 1756 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1757 | |
| 1758 pending_layer_->SetHasGpuRasterizationHint(false); | |
| 1759 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1760 // Should still have the high-res tiling. | |
| 1761 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1762 pending_layer_->CalculateContentsScale( | |
| 1763 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1764 // Should still only have the high-res tiling. | |
| 1765 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1766 } | |
| 1767 | |
| 1768 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) { | 1720 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) { |
| 1769 gfx::Size tile_size(100, 100); | 1721 gfx::Size tile_size(100, 100); |
| 1770 gfx::Size layer_bounds(1000, 1000); | 1722 gfx::Size layer_bounds(1000, 1000); |
| 1771 | 1723 |
| 1772 scoped_refptr<FakePicturePileImpl> pending_pile = | 1724 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1773 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1725 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1774 | 1726 |
| 1775 SetupPendingTree(pending_pile); | 1727 SetupPendingTree(pending_pile); |
| 1776 | 1728 |
| 1777 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | 1729 ASSERT_TRUE(pending_layer_->CanHaveTilings()); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); | 1950 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); |
| 1999 unique_tiles.insert(tile); | 1951 unique_tiles.insert(tile); |
| 2000 } | 1952 } |
| 2001 | 1953 |
| 2002 EXPECT_TRUE(reached_required); | 1954 EXPECT_TRUE(reached_required); |
| 2003 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size()); | 1955 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size()); |
| 2004 } | 1956 } |
| 2005 | 1957 |
| 2006 } // namespace | 1958 } // namespace |
| 2007 } // namespace cc | 1959 } // namespace cc |
| OLD | NEW |