| 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 <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "cc/layers/append_quads_data.h" | 10 #include "cc/layers/append_quads_data.h" |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 // Contrived unit test of a real crash. A layer is transparent during a | 1493 // Contrived unit test of a real crash. A layer is transparent during a |
| 1494 // context loss, and later becomes opaque, causing active layer SyncTiling to | 1494 // context loss, and later becomes opaque, causing active layer SyncTiling to |
| 1495 // be called. | 1495 // be called. |
| 1496 const float tile_scale = 2.f; | 1496 const float tile_scale = 2.f; |
| 1497 active_layer_->ReleaseResources(); | 1497 active_layer_->ReleaseResources(); |
| 1498 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1498 EXPECT_FALSE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1499 pending_layer_->AddTiling(2.f); | 1499 pending_layer_->AddTiling(2.f); |
| 1500 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); | 1500 EXPECT_TRUE(active_layer_->tilings()->TilingAtScale(tile_scale)); |
| 1501 } | 1501 } |
| 1502 | 1502 |
| 1503 TEST_F(PictureLayerImplTest, TilingWithoutGpuRasterization) { | 1503 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) { |
| 1504 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | 1504 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); |
| 1505 gfx::Size layer_bounds(default_tile_size.width() * 4, | 1505 gfx::Size layer_bounds(default_tile_size.width() * 4, |
| 1506 default_tile_size.height() * 4); | 1506 default_tile_size.height() * 4); |
| 1507 float result_scale_x, result_scale_y; | 1507 float result_scale_x, result_scale_y; |
| 1508 gfx::Size result_bounds; | 1508 gfx::Size result_bounds; |
| 1509 | 1509 |
| 1510 SetupDefaultTrees(layer_bounds); | 1510 SetupDefaultTrees(layer_bounds); |
| 1511 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); | 1511 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); |
| 1512 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | 1512 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1513 pending_layer_->CalculateContentsScale( | 1513 pending_layer_->CalculateContentsScale( |
| 1514 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | 1514 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1515 // Should have a low-res and a high-res tiling. | 1515 // Should have a low-res and a high-res tiling. |
| 1516 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | 1516 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); |
| 1517 |
| 1518 pending_layer_->SetUseGpuRasterization(true); |
| 1519 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); |
| 1520 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); |
| 1521 pending_layer_->CalculateContentsScale( |
| 1522 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); |
| 1523 // Should only have the high-res tiling. |
| 1524 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); |
| 1517 } | 1525 } |
| 1518 | 1526 |
| 1519 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { | 1527 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { |
| 1520 // Set up layers with tilings. | 1528 // Set up layers with tilings. |
| 1521 SetupDefaultTrees(gfx::Size(10, 10)); | 1529 SetupDefaultTrees(gfx::Size(10, 10)); |
| 1522 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); | 1530 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, false); |
| 1523 pending_layer_->PushPropertiesTo(active_layer_); | 1531 pending_layer_->PushPropertiesTo(active_layer_); |
| 1524 EXPECT_TRUE(pending_layer_->DrawsContent()); | 1532 EXPECT_TRUE(pending_layer_->DrawsContent()); |
| 1525 EXPECT_TRUE(pending_layer_->CanHaveTilings()); | 1533 EXPECT_TRUE(pending_layer_->CanHaveTilings()); |
| 1526 EXPECT_GE(pending_layer_->num_tilings(), 0u); | 1534 EXPECT_GE(pending_layer_->num_tilings(), 0u); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); | 1630 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); |
| 1623 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( | 1631 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( |
| 1624 TestContextProvider::Create(), NULL)); | 1632 TestContextProvider::Create(), NULL)); |
| 1625 | 1633 |
| 1626 // These will crash PictureLayerImpl if this is not true. | 1634 // These will crash PictureLayerImpl if this is not true. |
| 1627 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); | 1635 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); |
| 1628 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); | 1636 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); |
| 1629 host_impl_.active_tree()->UpdateDrawProperties(); | 1637 host_impl_.active_tree()->UpdateDrawProperties(); |
| 1630 } | 1638 } |
| 1631 | 1639 |
| 1632 class HybridRasterizationPictureLayerImplTest : public PictureLayerImplTest { | |
| 1633 public: | |
| 1634 HybridRasterizationPictureLayerImplTest() | |
| 1635 : PictureLayerImplTest(HybridRasterizationSettings()) {} | |
| 1636 }; | |
| 1637 | |
| 1638 TEST_F(HybridRasterizationPictureLayerImplTest, Tiling) { | |
| 1639 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | |
| 1640 gfx::Size layer_bounds(default_tile_size.width() * 4, | |
| 1641 default_tile_size.height() * 4); | |
| 1642 float result_scale_x, result_scale_y; | |
| 1643 gfx::Size result_bounds; | |
| 1644 | |
| 1645 SetupDefaultTrees(layer_bounds); | |
| 1646 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1647 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1648 pending_layer_->CalculateContentsScale( | |
| 1649 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1650 // Should have a low-res and a high-res tiling. | |
| 1651 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); | |
| 1652 | |
| 1653 pending_layer_->SetHasGpuRasterizationHint(true); | |
| 1654 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1655 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1656 pending_layer_->CalculateContentsScale( | |
| 1657 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1658 // Should only have the high-res tiling. | |
| 1659 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1660 } | |
| 1661 | |
| 1662 class GpuRasterizationPictureLayerImplTest : public PictureLayerImplTest { | |
| 1663 public: | |
| 1664 GpuRasterizationPictureLayerImplTest() | |
| 1665 : PictureLayerImplTest(GpuRasterizationSettings()) {} | |
| 1666 }; | |
| 1667 | |
| 1668 TEST_F(GpuRasterizationPictureLayerImplTest, Tiling) { | |
| 1669 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); | |
| 1670 gfx::Size layer_bounds(default_tile_size.width() * 4, | |
| 1671 default_tile_size.height() * 4); | |
| 1672 float result_scale_x, result_scale_y; | |
| 1673 gfx::Size result_bounds; | |
| 1674 | |
| 1675 SetupDefaultTrees(layer_bounds); | |
| 1676 pending_layer_->SetHasGpuRasterizationHint(true); | |
| 1677 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1678 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); | |
| 1679 pending_layer_->CalculateContentsScale( | |
| 1680 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1681 // Should only have the high-res tiling. | |
| 1682 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1683 | |
| 1684 pending_layer_->SetHasGpuRasterizationHint(false); | |
| 1685 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization()); | |
| 1686 // Should still have the high-res tiling. | |
| 1687 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1688 pending_layer_->CalculateContentsScale( | |
| 1689 1.f, 1.f, 1.f, false, &result_scale_x, &result_scale_y, &result_bounds); | |
| 1690 // Should still only have the high-res tiling. | |
| 1691 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings()); | |
| 1692 } | |
| 1693 | |
| 1694 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) { | 1640 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) { |
| 1695 gfx::Size tile_size(100, 100); | 1641 gfx::Size tile_size(100, 100); |
| 1696 gfx::Size layer_bounds(1000, 1000); | 1642 gfx::Size layer_bounds(1000, 1000); |
| 1697 | 1643 |
| 1698 scoped_refptr<FakePicturePileImpl> pending_pile = | 1644 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 1699 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1645 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 1700 | 1646 |
| 1701 SetupPendingTree(pending_pile); | 1647 SetupPendingTree(pending_pile); |
| 1702 | 1648 |
| 1703 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | 1649 ASSERT_TRUE(pending_layer_->CanHaveTilings()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; | 1725 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; |
| 1780 } | 1726 } |
| 1781 | 1727 |
| 1782 EXPECT_EQ(0u, non_ideal_tile_count); | 1728 EXPECT_EQ(0u, non_ideal_tile_count); |
| 1783 EXPECT_EQ(1u, low_res_tile_count); | 1729 EXPECT_EQ(1u, low_res_tile_count); |
| 1784 EXPECT_EQ(0u, high_res_tile_count); | 1730 EXPECT_EQ(0u, high_res_tile_count); |
| 1785 } | 1731 } |
| 1786 | 1732 |
| 1787 } // namespace | 1733 } // namespace |
| 1788 } // namespace cc | 1734 } // namespace cc |
| OLD | NEW |