Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 222903005: cc: Let skia veto gpu rasterization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added comment about SetNeedsCommit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/picture_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/layers/append_quads_data.h" 12 #include "cc/layers/append_quads_data.h"
13 #include "cc/layers/picture_layer.h" 13 #include "cc/layers/picture_layer.h"
14 #include "cc/test/fake_content_layer_client.h" 14 #include "cc/test/fake_content_layer_client.h"
15 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_output_surface.h" 17 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_picture_layer_impl.h" 18 #include "cc/test/fake_picture_layer_impl.h"
19 #include "cc/test/fake_picture_pile_impl.h" 19 #include "cc/test/fake_picture_pile_impl.h"
20 #include "cc/test/geometry_test_utils.h" 20 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/gpu_rasterization_settings.h"
22 #include "cc/test/hybrid_rasterization_settings.h"
23 #include "cc/test/impl_side_painting_settings.h" 21 #include "cc/test/impl_side_painting_settings.h"
24 #include "cc/test/mock_quad_culler.h" 22 #include "cc/test/mock_quad_culler.h"
25 #include "cc/test/test_shared_bitmap_manager.h" 23 #include "cc/test/test_shared_bitmap_manager.h"
26 #include "cc/test/test_web_graphics_context_3d.h" 24 #include "cc/test/test_web_graphics_context_3d.h"
27 #include "cc/trees/layer_tree_impl.h" 25 #include "cc/trees/layer_tree_impl.h"
28 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/gfx/rect_conversions.h" 27 #include "ui/gfx/rect_conversions.h"
30 28
31 namespace cc { 29 namespace cc {
32 namespace { 30 namespace {
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 // ReleaseResources has set needs update draw properties so that the 1625 // ReleaseResources has set needs update draw properties so that the
1628 // new tiling gets the appropriate resolution set in ManageTilings. 1626 // new tiling gets the appropriate resolution set in ManageTilings.
1629 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); 1627 EXPECT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
1630 host_impl_.active_tree()->UpdateDrawProperties(); 1628 host_impl_.active_tree()->UpdateDrawProperties();
1631 PictureLayerTiling* high_res = 1629 PictureLayerTiling* high_res =
1632 active_layer_->tilings()->TilingAtScale(new_scale); 1630 active_layer_->tilings()->TilingAtScale(new_scale);
1633 ASSERT_TRUE(!!high_res); 1631 ASSERT_TRUE(!!high_res);
1634 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution()); 1632 EXPECT_EQ(HIGH_RESOLUTION, high_res->resolution());
1635 } 1633 }
1636 1634
1637 TEST_F(PictureLayerImplTest, TilingWithoutGpuRasterization) { 1635 TEST_F(PictureLayerImplTest, NoLowResTilingWithGpuRasterization) {
1638 gfx::Size default_tile_size(host_impl_.settings().default_tile_size); 1636 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1639 gfx::Size layer_bounds(default_tile_size.width() * 4, 1637 gfx::Size layer_bounds(default_tile_size.width() * 4,
1640 default_tile_size.height() * 4); 1638 default_tile_size.height() * 4);
1641 float result_scale_x, result_scale_y; 1639 float result_scale_x, result_scale_y;
1642 gfx::Size result_bounds; 1640 gfx::Size result_bounds;
1643 1641
1644 SetupDefaultTrees(layer_bounds); 1642 SetupDefaultTrees(layer_bounds);
1645 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization()); 1643 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization());
1646 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings()); 1644 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1647 pending_layer_->CalculateContentsScale(1.f, 1645 pending_layer_->CalculateContentsScale(1.f,
1648 1.f, 1646 1.f,
1649 1.f, 1647 1.f,
1650 1.f, 1648 1.f,
1651 false, 1649 false,
1652 &result_scale_x, 1650 &result_scale_x,
1653 &result_scale_y, 1651 &result_scale_y,
1654 &result_bounds); 1652 &result_bounds);
1655 // Should have a low-res and a high-res tiling. 1653 // Should have a low-res and a high-res tiling.
1656 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings()); 1654 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1655
1656 pending_layer_->SetUseGpuRasterization(true);
1657 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization());
1658 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1659 pending_layer_->CalculateContentsScale(1.f,
1660 1.f,
1661 1.f,
1662 1.f,
1663 false,
1664 &result_scale_x,
1665 &result_scale_y,
1666 &result_bounds);
1667 // Should only have the high-res tiling.
1668 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1657 } 1669 }
1658 1670
1659 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) { 1671 TEST_F(PictureLayerImplTest, NoTilingIfDoesNotDrawContent) {
1660 // Set up layers with tilings. 1672 // Set up layers with tilings.
1661 SetupDefaultTrees(gfx::Size(10, 10)); 1673 SetupDefaultTrees(gfx::Size(10, 10));
1662 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false); 1674 SetContentsScaleOnBothLayers(1.f, 1.f, 1.f, 1.f, false);
1663 pending_layer_->PushPropertiesTo(active_layer_); 1675 pending_layer_->PushPropertiesTo(active_layer_);
1664 EXPECT_TRUE(pending_layer_->DrawsContent()); 1676 EXPECT_TRUE(pending_layer_->DrawsContent());
1665 EXPECT_TRUE(pending_layer_->CanHaveTilings()); 1677 EXPECT_TRUE(pending_layer_->CanHaveTilings());
1666 EXPECT_GE(pending_layer_->num_tilings(), 0u); 1678 EXPECT_GE(pending_layer_->num_tilings(), 0u);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 static_cast<FakeOutputSurface*>(host_impl_.output_surface()); 1773 static_cast<FakeOutputSurface*>(host_impl_.output_surface());
1762 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d( 1774 ASSERT_TRUE(fake_output_surface->InitializeAndSetContext3d(
1763 TestContextProvider::Create(), NULL)); 1775 TestContextProvider::Create(), NULL));
1764 1776
1765 // These will crash PictureLayerImpl if this is not true. 1777 // These will crash PictureLayerImpl if this is not true.
1766 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties()); 1778 ASSERT_TRUE(host_impl_.pending_tree()->needs_update_draw_properties());
1767 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties()); 1779 ASSERT_TRUE(host_impl_.active_tree()->needs_update_draw_properties());
1768 host_impl_.active_tree()->UpdateDrawProperties(); 1780 host_impl_.active_tree()->UpdateDrawProperties();
1769 } 1781 }
1770 1782
1771 class HybridRasterizationPictureLayerImplTest : public PictureLayerImplTest { 1783 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForCpuRasterization) {
1772 public:
1773 HybridRasterizationPictureLayerImplTest()
1774 : PictureLayerImplTest(HybridRasterizationSettings()) {}
1775 };
1776
1777 TEST_F(HybridRasterizationPictureLayerImplTest, Tiling) {
1778 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1779 gfx::Size layer_bounds(default_tile_size.width() * 4,
1780 default_tile_size.height() * 4);
1781 float result_scale_x, result_scale_y;
1782 gfx::Size result_bounds;
1783
1784 SetupDefaultTrees(layer_bounds);
1785 EXPECT_FALSE(pending_layer_->ShouldUseGpuRasterization());
1786 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1787 pending_layer_->CalculateContentsScale(1.f,
1788 1.f,
1789 1.f,
1790 1.f,
1791 false,
1792 &result_scale_x,
1793 &result_scale_y,
1794 &result_bounds);
1795 // Should have a low-res and a high-res tiling.
1796 ASSERT_EQ(2u, pending_layer_->tilings()->num_tilings());
1797
1798 pending_layer_->SetHasGpuRasterizationHint(true);
1799 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization());
1800 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1801 pending_layer_->CalculateContentsScale(1.f,
1802 1.f,
1803 1.f,
1804 1.f,
1805 false,
1806 &result_scale_x,
1807 &result_scale_y,
1808 &result_bounds);
1809 // Should only have the high-res tiling.
1810 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1811 }
1812
1813 TEST_F(HybridRasterizationPictureLayerImplTest,
1814 HighResTilingDuringAnimationForCpuRasterization) {
1815 gfx::Size tile_size(host_impl_.settings().default_tile_size); 1784 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1816 SetupDefaultTrees(tile_size); 1785 SetupDefaultTrees(tile_size);
1817 pending_layer_->SetHasGpuRasterizationHint(false);
1818 active_layer_->SetHasGpuRasterizationHint(false);
1819 1786
1820 float contents_scale = 1.f; 1787 float contents_scale = 1.f;
1821 float device_scale = 1.3f; 1788 float device_scale = 1.3f;
1822 float page_scale = 1.4f; 1789 float page_scale = 1.4f;
1823 float maximum_animation_scale = 1.f; 1790 float maximum_animation_scale = 1.f;
1824 bool animating_transform = false; 1791 bool animating_transform = false;
1825 1792
1826 SetContentsScaleOnBothLayers(contents_scale, 1793 SetContentsScaleOnBothLayers(contents_scale,
1827 device_scale, 1794 device_scale,
1828 page_scale, 1795 page_scale,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 contents_scale = 4.f; 1861 contents_scale = 4.f;
1895 1862
1896 SetContentsScaleOnBothLayers(contents_scale, 1863 SetContentsScaleOnBothLayers(contents_scale,
1897 device_scale, 1864 device_scale,
1898 page_scale, 1865 page_scale,
1899 maximum_animation_scale, 1866 maximum_animation_scale,
1900 animating_transform); 1867 animating_transform);
1901 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 1868 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
1902 } 1869 }
1903 1870
1904 TEST_F(HybridRasterizationPictureLayerImplTest, 1871 TEST_F(PictureLayerImplTest, HighResTilingDuringAnimationForGpuRasterization) {
1905 HighResTilingDuringAnimationForGpuRasterization) {
1906 gfx::Size tile_size(host_impl_.settings().default_tile_size); 1872 gfx::Size tile_size(host_impl_.settings().default_tile_size);
1907 SetupDefaultTrees(tile_size); 1873 SetupDefaultTrees(tile_size);
1908 pending_layer_->SetHasGpuRasterizationHint(true); 1874 pending_layer_->SetUseGpuRasterization(true);
1909 active_layer_->SetHasGpuRasterizationHint(true); 1875 active_layer_->SetUseGpuRasterization(true);
1910 1876
1911 float contents_scale = 1.f; 1877 float contents_scale = 1.f;
1912 float device_scale = 1.f; 1878 float device_scale = 1.f;
1913 float page_scale = 1.f; 1879 float page_scale = 1.f;
1914 float maximum_animation_scale = 1.f; 1880 float maximum_animation_scale = 1.f;
1915 bool animating_transform = false; 1881 bool animating_transform = false;
1916 1882
1917 SetContentsScaleOnBothLayers(contents_scale, 1883 SetContentsScaleOnBothLayers(contents_scale,
1918 device_scale, 1884 device_scale,
1919 page_scale, 1885 page_scale,
(...skipping 29 matching lines...) Expand all
1949 contents_scale = 4.f; 1915 contents_scale = 4.f;
1950 animating_transform = false; 1916 animating_transform = false;
1951 SetContentsScaleOnBothLayers(contents_scale, 1917 SetContentsScaleOnBothLayers(contents_scale,
1952 device_scale, 1918 device_scale,
1953 page_scale, 1919 page_scale,
1954 maximum_animation_scale, 1920 maximum_animation_scale,
1955 animating_transform); 1921 animating_transform);
1956 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f); 1922 EXPECT_BOTH_EQ(HighResTiling()->contents_scale(), 4.f);
1957 } 1923 }
1958 1924
1959 class GpuRasterizationPictureLayerImplTest : public PictureLayerImplTest {
1960 public:
1961 GpuRasterizationPictureLayerImplTest()
1962 : PictureLayerImplTest(GpuRasterizationSettings()) {}
1963 };
1964
1965 TEST_F(GpuRasterizationPictureLayerImplTest, Tiling) {
1966 gfx::Size default_tile_size(host_impl_.settings().default_tile_size);
1967 gfx::Size layer_bounds(default_tile_size.width() * 4,
1968 default_tile_size.height() * 4);
1969 float result_scale_x, result_scale_y;
1970 gfx::Size result_bounds;
1971
1972 SetupDefaultTrees(layer_bounds);
1973 pending_layer_->SetHasGpuRasterizationHint(true);
1974 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization());
1975 EXPECT_EQ(0u, pending_layer_->tilings()->num_tilings());
1976 pending_layer_->CalculateContentsScale(1.f,
1977 1.f,
1978 1.f,
1979 1.f,
1980 false,
1981 &result_scale_x,
1982 &result_scale_y,
1983 &result_bounds);
1984 // Should only have the high-res tiling.
1985 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
1986
1987 pending_layer_->SetHasGpuRasterizationHint(false);
1988 EXPECT_TRUE(pending_layer_->ShouldUseGpuRasterization());
1989 // Should still have the high-res tiling.
1990 EXPECT_EQ(1u, pending_layer_->tilings()->num_tilings());
1991 pending_layer_->CalculateContentsScale(1.f,
1992 1.f,
1993 1.f,
1994 1.f,
1995 false,
1996 &result_scale_x,
1997 &result_scale_y,
1998 &result_bounds);
1999 // Should still only have the high-res tiling.
2000 ASSERT_EQ(1u, pending_layer_->tilings()->num_tilings());
2001 }
2002
2003 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) { 1925 TEST_F(PictureLayerImplTest, LayerRasterTileIterator) {
2004 gfx::Size tile_size(100, 100); 1926 gfx::Size tile_size(100, 100);
2005 gfx::Size layer_bounds(1000, 1000); 1927 gfx::Size layer_bounds(1000, 1000);
2006 1928
2007 scoped_refptr<FakePicturePileImpl> pending_pile = 1929 scoped_refptr<FakePicturePileImpl> pending_pile =
2008 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 1930 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
2009 1931
2010 SetupPendingTree(pending_pile); 1932 SetupPendingTree(pending_pile);
2011 1933
2012 ASSERT_TRUE(pending_layer_->CanHaveTilings()); 1934 ASSERT_TRUE(pending_layer_->CanHaveTilings());
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]); 2155 EXPECT_FLOAT_EQ(tile->contents_scale(), expected_scales[scale_index]);
2234 unique_tiles.insert(tile); 2156 unique_tiles.insert(tile);
2235 } 2157 }
2236 2158
2237 EXPECT_TRUE(reached_required); 2159 EXPECT_TRUE(reached_required);
2238 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size()); 2160 EXPECT_EQ(all_tiles_set.size(), unique_tiles.size());
2239 } 2161 }
2240 2162
2241 } // namespace 2163 } // namespace
2242 } // namespace cc 2164 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/layers/picture_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698