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

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 12552004: Support bottom-right anchored fixed-position elements during a pinch gesture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forgot to save the comments. sorry. :( Created 7 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
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_impl.h » ('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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include "cc/animation/layer_animation_controller.h" 7 #include "cc/animation/layer_animation_controller.h"
8 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/base/thread.h" 9 #include "cc/base/thread.h"
10 #include "cc/layers/content_layer.h" 10 #include "cc/layers/content_layer.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 142
143 template <class LayerType> 143 template <class LayerType>
144 void ExecuteCalculateDrawProperties(LayerType* root_layer, 144 void ExecuteCalculateDrawProperties(LayerType* root_layer,
145 float device_scale_factor, 145 float device_scale_factor,
146 float page_scale_factor) { 146 float page_scale_factor) {
147 ExecuteCalculateDrawProperties( 147 ExecuteCalculateDrawProperties(
148 root_layer, device_scale_factor, page_scale_factor, false); 148 root_layer, device_scale_factor, page_scale_factor, false);
149 } 149 }
150 150
151 scoped_ptr<LayerImpl> CreateTreeForFixedPositionTests(
152 LayerTreeHostImpl* host_impl) {
153 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl->active_tree(), 1);
154 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl->active_tree(), 2);
155 scoped_ptr<LayerImpl> grand_child =
156 LayerImpl::Create(host_impl->active_tree(), 3);
157 scoped_ptr<LayerImpl> great_grand_child =
158 LayerImpl::Create(host_impl->active_tree(), 4);
159
160 gfx::Transform IdentityMatrix;
161 gfx::PointF anchor;
162 gfx::PointF position;
163 gfx::Size bounds(100, 100);
164 SetLayerPropertiesForTesting(root.get(),
165 IdentityMatrix,
166 IdentityMatrix,
167 anchor,
168 position,
169 bounds,
170 false);
171 SetLayerPropertiesForTesting(child.get(),
172 IdentityMatrix,
173 IdentityMatrix,
174 anchor,
175 position,
176 bounds,
177 false);
178 SetLayerPropertiesForTesting(grand_child.get(),
179 IdentityMatrix,
180 IdentityMatrix,
181 anchor,
182 position,
183 bounds,
184 false);
185 SetLayerPropertiesForTesting(great_grand_child.get(),
186 IdentityMatrix,
187 IdentityMatrix,
188 anchor,
189 position,
190 bounds,
191 false);
192
193 grand_child->AddChild(great_grand_child.Pass());
194 child->AddChild(grand_child.Pass());
195 root->AddChild(child.Pass());
196
197 return root.Pass();
198 }
199
200 class LayerWithForcedDrawsContent : public Layer { 151 class LayerWithForcedDrawsContent : public Layer {
201 public: 152 public:
202 LayerWithForcedDrawsContent() : Layer() {} 153 LayerWithForcedDrawsContent() : Layer() {}
203 154
204 virtual bool DrawsContent() const OVERRIDE; 155 virtual bool DrawsContent() const OVERRIDE;
205 156
206 private: 157 private:
207 virtual ~LayerWithForcedDrawsContent() {} 158 virtual ~LayerWithForcedDrawsContent() {}
208 }; 159 };
209 160
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1.f, 1628 1.f,
1678 1.f, 1629 1.f,
1679 dummy_max_texture_size, 1630 dummy_max_texture_size,
1680 false, 1631 false,
1681 &render_surface_layer_list); 1632 &render_surface_layer_list);
1682 EXPECT_TRUE(parent->render_surface()); 1633 EXPECT_TRUE(parent->render_surface());
1683 EXPECT_FALSE(render_surface1->render_surface()); 1634 EXPECT_FALSE(render_surface1->render_surface());
1684 EXPECT_EQ(1U, render_surface_layer_list.size()); 1635 EXPECT_EQ(1U, render_surface_layer_list.size());
1685 } 1636 }
1686 1637
1687 TEST(LayerTreeHostCommonTest,
1688 ScrollCompensationForFixedPositionLayerWithDirectContainer) {
1689 // This test checks for correct scroll compensation when the fixed-position
1690 // container is the direct parent of the fixed-position layer.
1691 FakeImplProxy proxy;
1692 FakeLayerTreeHostImpl host_impl(&proxy);
1693 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
1694 LayerImpl* child = root->children()[0];
1695 LayerImpl* grand_child = child->children()[0];
1696
1697 child->SetIsContainerForFixedPositionLayers(true);
1698 grand_child->SetFixedToContainerLayer(true);
1699
1700 // Case 1: scroll delta of 0, 0
1701 child->SetScrollDelta(gfx::Vector2d(0, 0));
1702 ExecuteCalculateDrawProperties(root.get());
1703
1704 gfx::Transform expected_child_transform;
1705 gfx::Transform expected_grand_child_transform = expected_child_transform;
1706
1707 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1708 child->draw_transform());
1709 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1710 grand_child->draw_transform());
1711
1712 // Case 2: scroll delta of 10, 10
1713 child->SetScrollDelta(gfx::Vector2d(10, 10));
1714 ExecuteCalculateDrawProperties(root.get());
1715
1716 // Here the child is affected by scroll delta, but the fixed position
1717 // grand_child should not be affected.
1718 expected_child_transform.MakeIdentity();
1719 expected_child_transform.Translate(-10.0, -10.0);
1720
1721 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1722 child->draw_transform());
1723 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1724 grand_child->draw_transform());
1725 }
1726
1727 TEST(LayerTreeHostCommonTest,
1728 ScrollCompensationForFixedPositionLayerWithTransformedDirectContainer) {
1729 // This test checks for correct scroll compensation when the fixed-position
1730 // container is the direct parent of the fixed-position layer, but that
1731 // container is transformed. In this case, the fixed position element
1732 // inherits the container's transform, but the scroll delta that has to be
1733 // undone should not be affected by that transform.
1734 //
1735 // gfx::Transforms are in general non-commutative; using something like a
1736 // non-uniform scale helps to verify that translations and non-uniform scales
1737 // are applied in the correct order.
1738 FakeImplProxy proxy;
1739 FakeLayerTreeHostImpl host_impl(&proxy);
1740 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
1741 LayerImpl* child = root->children()[0];
1742 LayerImpl* grand_child = child->children()[0];
1743
1744 // This scale will cause child and grand_child to be effectively 200 x 800
1745 // with respect to the render target.
1746 gfx::Transform non_uniform_scale;
1747 non_uniform_scale.Scale(2.0, 8.0);
1748 child->SetTransform(non_uniform_scale);
1749
1750 child->SetIsContainerForFixedPositionLayers(true);
1751 grand_child->SetFixedToContainerLayer(true);
1752
1753 // Case 1: scroll delta of 0, 0
1754 child->SetScrollDelta(gfx::Vector2d(0, 0));
1755 ExecuteCalculateDrawProperties(root.get());
1756
1757 gfx::Transform expected_child_transform;
1758 expected_child_transform.PreconcatTransform(non_uniform_scale);
1759
1760 gfx::Transform expected_grand_child_transform = expected_child_transform;
1761
1762 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1763 child->draw_transform());
1764 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1765 grand_child->draw_transform());
1766
1767 // Case 2: scroll delta of 10, 20
1768 child->SetScrollDelta(gfx::Vector2d(10, 20));
1769 ExecuteCalculateDrawProperties(root.get());
1770
1771 // The child should be affected by scroll delta, but the fixed position
1772 // grand_child should not be affected.
1773 expected_child_transform.MakeIdentity();
1774 expected_child_transform.Translate(-10.0, -20.0); // scroll delta
1775 expected_child_transform.PreconcatTransform(non_uniform_scale);
1776
1777 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1778 child->draw_transform());
1779 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1780 grand_child->draw_transform());
1781 }
1782
1783 TEST(LayerTreeHostCommonTest,
1784 ScrollCompensationForFixedPositionLayerWithDistantContainer) {
1785 // This test checks for correct scroll compensation when the fixed-position
1786 // container is NOT the direct parent of the fixed-position layer.
1787 FakeImplProxy proxy;
1788 FakeLayerTreeHostImpl host_impl(&proxy);
1789 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
1790 LayerImpl* child = root->children()[0];
1791 LayerImpl* grand_child = child->children()[0];
1792 LayerImpl* great_grand_child = grand_child->children()[0];
1793
1794 child->SetIsContainerForFixedPositionLayers(true);
1795 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
1796 great_grand_child->SetFixedToContainerLayer(true);
1797
1798 // Case 1: scroll delta of 0, 0
1799 child->SetScrollDelta(gfx::Vector2d(0, 0));
1800 ExecuteCalculateDrawProperties(root.get());
1801
1802 gfx::Transform expected_child_transform;
1803 gfx::Transform expected_grand_child_transform;
1804 expected_grand_child_transform.Translate(8.0, 6.0);
1805
1806 gfx::Transform expected_great_grand_child_transform =
1807 expected_grand_child_transform;
1808
1809 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1810 child->draw_transform());
1811 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1812 grand_child->draw_transform());
1813 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1814 great_grand_child->draw_transform());
1815
1816 // Case 2: scroll delta of 10, 10
1817 child->SetScrollDelta(gfx::Vector2d(10, 10));
1818 ExecuteCalculateDrawProperties(root.get());
1819
1820 // Here the child and grand_child are affected by scroll delta, but the fixed
1821 // position great_grand_child should not be affected.
1822 expected_child_transform.MakeIdentity();
1823 expected_child_transform.Translate(-10.0, -10.0);
1824 expected_grand_child_transform.MakeIdentity();
1825 expected_grand_child_transform.Translate(-2.0, -4.0);
1826 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1827 child->draw_transform());
1828 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1829 grand_child->draw_transform());
1830 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1831 great_grand_child->draw_transform());
1832 }
1833
1834 TEST(LayerTreeHostCommonTest,
1835 ScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms) {
1836 // This test checks for correct scroll compensation when the fixed-position
1837 // container is NOT the direct parent of the fixed-position layer, and the
1838 // hierarchy has various transforms that have to be processed in the correct
1839 // order.
1840 FakeImplProxy proxy;
1841 FakeLayerTreeHostImpl host_impl(&proxy);
1842 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
1843 LayerImpl* child = root->children()[0];
1844 LayerImpl* grand_child = child->children()[0];
1845 LayerImpl* great_grand_child = grand_child->children()[0];
1846
1847 gfx::Transform rotation_about_z;
1848 rotation_about_z.RotateAboutZAxis(90.0);
1849
1850 child->SetIsContainerForFixedPositionLayers(true);
1851 child->SetTransform(rotation_about_z);
1852 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
1853 grand_child->SetTransform(rotation_about_z);
1854 // great_grand_child is positioned upside-down with respect to the render
1855 // target.
1856 great_grand_child->SetFixedToContainerLayer(true);
1857
1858 // Case 1: scroll delta of 0, 0
1859 child->SetScrollDelta(gfx::Vector2d(0, 0));
1860 ExecuteCalculateDrawProperties(root.get());
1861
1862 gfx::Transform expected_child_transform;
1863 expected_child_transform.PreconcatTransform(rotation_about_z);
1864
1865 gfx::Transform expected_grand_child_transform;
1866 expected_grand_child_transform.PreconcatTransform(
1867 rotation_about_z); // child's local transform is inherited
1868 // translation because of position occurs before layer's local transform.
1869 expected_grand_child_transform.Translate(8.0, 6.0);
1870 expected_grand_child_transform.PreconcatTransform(
1871 rotation_about_z); // grand_child's local transform
1872
1873 gfx::Transform expected_great_grand_child_transform =
1874 expected_grand_child_transform;
1875
1876 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1877 child->draw_transform());
1878 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1879 grand_child->draw_transform());
1880 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1881 great_grand_child->draw_transform());
1882
1883 // Case 2: scroll delta of 10, 20
1884 child->SetScrollDelta(gfx::Vector2d(10, 20));
1885 ExecuteCalculateDrawProperties(root.get());
1886
1887 // Here the child and grand_child are affected by scroll delta, but the fixed
1888 // position great_grand_child should not be affected.
1889 expected_child_transform.MakeIdentity();
1890 expected_child_transform.Translate(-10.0, -20.0); // scroll delta
1891 expected_child_transform.PreconcatTransform(rotation_about_z);
1892
1893 expected_grand_child_transform.MakeIdentity();
1894 expected_grand_child_transform.Translate(
1895 -10.0, -20.0); // child's scroll delta is inherited
1896 expected_grand_child_transform.PreconcatTransform(
1897 rotation_about_z); // child's local transform is inherited
1898 // translation because of position occurs before layer's local transform.
1899 expected_grand_child_transform.Translate(8.0, 6.0);
1900 expected_grand_child_transform.PreconcatTransform(
1901 rotation_about_z); // grand_child's local transform
1902
1903 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1904 child->draw_transform());
1905 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1906 grand_child->draw_transform());
1907 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1908 great_grand_child->draw_transform());
1909 }
1910
1911 TEST(LayerTreeHostCommonTest,
1912 ScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas) {
1913 // This test checks for correct scroll compensation when the fixed-position
1914 // container has multiple ancestors that have nonzero scroll delta before
1915 // reaching the space where the layer is fixed. In this test, each scroll
1916 // delta occurs in a different space because of each layer's local transform.
1917 // This test checks for correct scroll compensation when the fixed-position
1918 // container is NOT the direct parent of the fixed-position layer, and the
1919 // hierarchy has various transforms that have to be processed in the correct
1920 // order.
1921 FakeImplProxy proxy;
1922 FakeLayerTreeHostImpl host_impl(&proxy);
1923 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
1924 LayerImpl* child = root->children()[0];
1925 LayerImpl* grand_child = child->children()[0];
1926 LayerImpl* great_grand_child = grand_child->children()[0];
1927
1928 gfx::Transform rotation_about_z;
1929 rotation_about_z.RotateAboutZAxis(90.0);
1930
1931 child->SetIsContainerForFixedPositionLayers(true);
1932 child->SetTransform(rotation_about_z);
1933 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
1934 grand_child->SetTransform(rotation_about_z);
1935 // great_grand_child is positioned upside-down with respect to the render
1936 // target.
1937 great_grand_child->SetFixedToContainerLayer(true);
1938
1939 // Case 1: scroll delta of 0, 0
1940 child->SetScrollDelta(gfx::Vector2d(0, 0));
1941 ExecuteCalculateDrawProperties(root.get());
1942
1943 gfx::Transform expected_child_transform;
1944 expected_child_transform.PreconcatTransform(rotation_about_z);
1945
1946 gfx::Transform expected_grand_child_transform;
1947 expected_grand_child_transform.PreconcatTransform(
1948 rotation_about_z); // child's local transform is inherited
1949 // translation because of position occurs before layer's local transform.
1950 expected_grand_child_transform.Translate(8.0, 6.0);
1951 expected_grand_child_transform.PreconcatTransform(
1952 rotation_about_z); // grand_child's local transform
1953
1954 gfx::Transform expected_great_grand_child_transform =
1955 expected_grand_child_transform;
1956
1957 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1958 child->draw_transform());
1959 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1960 grand_child->draw_transform());
1961 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1962 great_grand_child->draw_transform());
1963
1964 // Case 2: scroll delta of 10, 20
1965 child->SetScrollDelta(gfx::Vector2d(10, 0));
1966 grand_child->SetScrollDelta(gfx::Vector2d(5, 0));
1967 ExecuteCalculateDrawProperties(root.get());
1968
1969 // Here the child and grand_child are affected by scroll delta, but the fixed
1970 // position great_grand_child should not be affected.
1971 expected_child_transform.MakeIdentity();
1972 expected_child_transform.Translate(-10.0, 0.0); // scroll delta
1973 expected_child_transform.PreconcatTransform(rotation_about_z);
1974
1975 expected_grand_child_transform.MakeIdentity();
1976 expected_grand_child_transform.Translate(
1977 -10.0, 0.0); // child's scroll delta is inherited
1978 expected_grand_child_transform.PreconcatTransform(
1979 rotation_about_z); // child's local transform is inherited
1980 expected_grand_child_transform.Translate(-5.0,
1981 0.0); // grand_child's scroll delta
1982 // translation because of position occurs before layer's local transform.
1983 expected_grand_child_transform.Translate(8.0, 6.0);
1984 expected_grand_child_transform.PreconcatTransform(
1985 rotation_about_z); // grand_child's local transform
1986
1987 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
1988 child->draw_transform());
1989 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
1990 grand_child->draw_transform());
1991 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
1992 great_grand_child->draw_transform());
1993 }
1994
1995 TEST(LayerTreeHostCommonTest,
1996 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) {
1997 // This test checks for correct scroll compensation when the fixed-position
1998 // container contributes to a different render surface than the fixed-position
1999 // layer. In this case, the surface draw transforms also have to be accounted
2000 // for when checking the scroll delta.
2001 FakeImplProxy proxy;
2002 FakeLayerTreeHostImpl host_impl(&proxy);
2003 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
2004 LayerImpl* child = root->children()[0];
2005 LayerImpl* grand_child = child->children()[0];
2006 LayerImpl* great_grand_child = grand_child->children()[0];
2007
2008 child->SetIsContainerForFixedPositionLayers(true);
2009 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
2010 grand_child->SetForceRenderSurface(true);
2011 great_grand_child->SetFixedToContainerLayer(true);
2012 great_grand_child->SetDrawsContent(true);
2013
2014 gfx::Transform rotation_about_z;
2015 rotation_about_z.RotateAboutZAxis(90.0);
2016 grand_child->SetTransform(rotation_about_z);
2017
2018 // Case 1: scroll delta of 0, 0
2019 child->SetScrollDelta(gfx::Vector2d(0, 0));
2020 ExecuteCalculateDrawProperties(root.get());
2021
2022 gfx::Transform expected_child_transform;
2023 gfx::Transform expected_surface_draw_transform;
2024 expected_surface_draw_transform.Translate(8.0, 6.0);
2025 expected_surface_draw_transform.PreconcatTransform(rotation_about_z);
2026 gfx::Transform expected_grand_child_transform;
2027 gfx::Transform expected_great_grand_child_transform;
2028 ASSERT_TRUE(grand_child->render_surface());
2029 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2030 child->draw_transform());
2031 EXPECT_TRANSFORMATION_MATRIX_EQ(
2032 expected_surface_draw_transform,
2033 grand_child->render_surface()->draw_transform());
2034 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2035 grand_child->draw_transform());
2036 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
2037 great_grand_child->draw_transform());
2038
2039 // Case 2: scroll delta of 10, 30
2040 child->SetScrollDelta(gfx::Vector2d(10, 30));
2041 ExecuteCalculateDrawProperties(root.get());
2042
2043 // Here the grand_child remains unchanged, because it scrolls along with the
2044 // render surface, and the translation is actually in the render surface. But,
2045 // the fixed position great_grand_child is more awkward: its actually being
2046 // drawn with respect to the render surface, but it needs to remain fixed with
2047 // resepct to a container beyond that surface. So, the net result is that,
2048 // unlike previous tests where the fixed position layer's transform remains
2049 // unchanged, here the fixed position layer's transform explicitly contains
2050 // the translation that cancels out the scroll.
2051 expected_child_transform.MakeIdentity();
2052 expected_child_transform.Translate(-10.0, -30.0); // scroll delta
2053
2054 expected_surface_draw_transform.MakeIdentity();
2055 expected_surface_draw_transform.Translate(-10.0, -30.0); // scroll delta
2056 expected_surface_draw_transform.Translate(8.0, 6.0);
2057 expected_surface_draw_transform.PreconcatTransform(rotation_about_z);
2058
2059 // The rotation and its inverse are needed to place the scroll delta
2060 // compensation in the correct space. This test will fail if the
2061 // rotation/inverse are backwards, too, so it requires perfect order of
2062 // operations.
2063 expected_great_grand_child_transform.MakeIdentity();
2064 expected_great_grand_child_transform.PreconcatTransform(
2065 Inverse(rotation_about_z));
2066 // explicit canceling out the scroll delta that gets embedded in the fixed
2067 // position layer's surface.
2068 expected_great_grand_child_transform.Translate(10.0, 30.0);
2069 expected_great_grand_child_transform.PreconcatTransform(rotation_about_z);
2070
2071 ASSERT_TRUE(grand_child->render_surface());
2072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2073 child->draw_transform());
2074 EXPECT_TRANSFORMATION_MATRIX_EQ(
2075 expected_surface_draw_transform,
2076 grand_child->render_surface()->draw_transform());
2077 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2078 grand_child->draw_transform());
2079 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
2080 great_grand_child->draw_transform());
2081 }
2082
2083 TEST(LayerTreeHostCommonTest,
2084 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) {
2085 // This test checks for correct scroll compensation when the fixed-position
2086 // container contributes to a different render surface than the fixed-position
2087 // layer, with additional render surfaces in-between. This checks that the
2088 // conversion to ancestor surfaces is accumulated properly in the final matrix
2089 // transform.
2090 FakeImplProxy proxy;
2091 FakeLayerTreeHostImpl host_impl(&proxy);
2092 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
2093 LayerImpl* child = root->children()[0];
2094 LayerImpl* grand_child = child->children()[0];
2095 LayerImpl* great_grand_child = grand_child->children()[0];
2096
2097 // Add one more layer to the test tree for this scenario.
2098 {
2099 gfx::Transform identity;
2100 scoped_ptr<LayerImpl> fixed_position_child =
2101 LayerImpl::Create(host_impl.active_tree(), 5);
2102 SetLayerPropertiesForTesting(fixed_position_child.get(),
2103 identity,
2104 identity,
2105 gfx::PointF(),
2106 gfx::PointF(),
2107 gfx::Size(100, 100),
2108 false);
2109 great_grand_child->AddChild(fixed_position_child.Pass());
2110 }
2111 LayerImpl* fixed_position_child = great_grand_child->children()[0];
2112
2113 // Actually set up the scenario here.
2114 child->SetIsContainerForFixedPositionLayers(true);
2115 grand_child->SetPosition(gfx::PointF(8.f, 6.f));
2116 grand_child->SetForceRenderSurface(true);
2117 great_grand_child->SetPosition(gfx::PointF(40.f, 60.f));
2118 great_grand_child->SetForceRenderSurface(true);
2119 fixed_position_child->SetFixedToContainerLayer(true);
2120 fixed_position_child->SetDrawsContent(true);
2121
2122 // The additional rotations, which are non-commutative with translations, help
2123 // to verify that we have correct order-of-operations in the final scroll
2124 // compensation. Note that rotating about the center of the layer ensures we
2125 // do not accidentally clip away layers that we want to test.
2126 gfx::Transform rotation_about_z;
2127 rotation_about_z.Translate(50.0, 50.0);
2128 rotation_about_z.RotateAboutZAxis(90.0);
2129 rotation_about_z.Translate(-50.0, -50.0);
2130 grand_child->SetTransform(rotation_about_z);
2131 great_grand_child->SetTransform(rotation_about_z);
2132
2133 // Case 1: scroll delta of 0, 0
2134 child->SetScrollDelta(gfx::Vector2d(0, 0));
2135 ExecuteCalculateDrawProperties(root.get());
2136
2137 gfx::Transform expected_child_transform;
2138
2139 gfx::Transform expected_grand_child_surface_draw_transform;
2140 expected_grand_child_surface_draw_transform.Translate(8.0, 6.0);
2141 expected_grand_child_surface_draw_transform.PreconcatTransform(
2142 rotation_about_z);
2143
2144 gfx::Transform expected_grand_child_transform;
2145
2146 gfx::Transform expected_great_grand_child_surface_draw_transform;
2147 expected_great_grand_child_surface_draw_transform.Translate(40.0, 60.0);
2148 expected_great_grand_child_surface_draw_transform.PreconcatTransform(
2149 rotation_about_z);
2150
2151 gfx::Transform expected_great_grand_child_transform;
2152
2153 gfx::Transform expected_fixed_position_child_transform;
2154
2155 ASSERT_TRUE(grand_child->render_surface());
2156 ASSERT_TRUE(great_grand_child->render_surface());
2157 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2158 child->draw_transform());
2159 EXPECT_TRANSFORMATION_MATRIX_EQ(
2160 expected_grand_child_surface_draw_transform,
2161 grand_child->render_surface()->draw_transform());
2162 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2163 grand_child->draw_transform());
2164 EXPECT_TRANSFORMATION_MATRIX_EQ(
2165 expected_great_grand_child_surface_draw_transform,
2166 great_grand_child->render_surface()->draw_transform());
2167 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
2168 great_grand_child->draw_transform());
2169 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
2170 fixed_position_child->draw_transform());
2171
2172 // Case 2: scroll delta of 10, 30
2173 child->SetScrollDelta(gfx::Vector2d(10, 30));
2174 ExecuteCalculateDrawProperties(root.get());
2175
2176 expected_child_transform.MakeIdentity();
2177 expected_child_transform.Translate(-10.0, -30.0); // scroll delta
2178
2179 expected_grand_child_surface_draw_transform.MakeIdentity();
2180 expected_grand_child_surface_draw_transform.Translate(-10.0,
2181 -30.0); // scroll delta
2182 expected_grand_child_surface_draw_transform.Translate(8.0, 6.0);
2183 expected_grand_child_surface_draw_transform.PreconcatTransform(
2184 rotation_about_z);
2185
2186 // grand_child, great_grand_child, and great_grand_child's surface are not
2187 // expected to change, since they are all not fixed, and they are all drawn
2188 // with respect to grand_child's surface that already has the scroll delta
2189 // accounted for.
2190
2191 // But the great-great grandchild, "fixed_position_child", should have a
2192 // transform that explicitly cancels out the scroll delta. The expected
2193 // transform is: compound_draw_transform.Inverse() * translate(positive scroll
2194 // delta) * compound_origin_transform from great_grand_childSurface's origin
2195 // to the root surface.
2196 gfx::Transform compound_draw_transform;
2197 compound_draw_transform.Translate(8.0,
2198 6.0); // origin translation of grand_child
2199 compound_draw_transform.PreconcatTransform(
2200 rotation_about_z); // rotation of grand_child
2201 compound_draw_transform.Translate(
2202 40.0, 60.0); // origin translation of great_grand_child
2203 compound_draw_transform.PreconcatTransform(
2204 rotation_about_z); // rotation of great_grand_child
2205
2206 expected_fixed_position_child_transform.MakeIdentity();
2207 expected_fixed_position_child_transform.PreconcatTransform(
2208 Inverse(compound_draw_transform));
2209 // explicit canceling out the scroll delta that gets embedded in the fixed
2210 // position layer's surface.
2211 expected_fixed_position_child_transform.Translate(10.0, 30.0);
2212 expected_fixed_position_child_transform.PreconcatTransform(
2213 compound_draw_transform);
2214
2215 ASSERT_TRUE(grand_child->render_surface());
2216 ASSERT_TRUE(great_grand_child->render_surface());
2217 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2218 child->draw_transform());
2219 EXPECT_TRANSFORMATION_MATRIX_EQ(
2220 expected_grand_child_surface_draw_transform,
2221 grand_child->render_surface()->draw_transform());
2222 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2223 grand_child->draw_transform());
2224 EXPECT_TRANSFORMATION_MATRIX_EQ(
2225 expected_great_grand_child_surface_draw_transform,
2226 great_grand_child->render_surface()->draw_transform());
2227 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform,
2228 great_grand_child->draw_transform());
2229 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform,
2230 fixed_position_child->draw_transform());
2231 }
2232
2233 TEST(LayerTreeHostCommonTest,
2234 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) {
2235 // This test checks for correct scroll compensation when the fixed-position
2236 // container itself has a render surface. In this case, the container layer
2237 // should be treated like a layer that contributes to a render target, and
2238 // that render target is completely irrelevant; it should not affect the
2239 // scroll compensation.
2240 FakeImplProxy proxy;
2241 FakeLayerTreeHostImpl host_impl(&proxy);
2242 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
2243 LayerImpl* child = root->children()[0];
2244 LayerImpl* grand_child = child->children()[0];
2245
2246 child->SetIsContainerForFixedPositionLayers(true);
2247 child->SetForceRenderSurface(true);
2248 grand_child->SetFixedToContainerLayer(true);
2249 grand_child->SetDrawsContent(true);
2250
2251 // Case 1: scroll delta of 0, 0
2252 child->SetScrollDelta(gfx::Vector2d(0, 0));
2253 ExecuteCalculateDrawProperties(root.get());
2254
2255 gfx::Transform expected_surface_draw_transform;
2256 expected_surface_draw_transform.Translate(0.0, 0.0);
2257 gfx::Transform expected_child_transform;
2258 gfx::Transform expected_grand_child_transform;
2259 ASSERT_TRUE(child->render_surface());
2260 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
2261 child->render_surface()->draw_transform());
2262 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2263 child->draw_transform());
2264 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2265 grand_child->draw_transform());
2266
2267 // Case 2: scroll delta of 10, 10
2268 child->SetScrollDelta(gfx::Vector2d(10, 10));
2269 ExecuteCalculateDrawProperties(root.get());
2270
2271 // The surface is translated by scroll delta, the child transform doesn't
2272 // change because it scrolls along with the surface, but the fixed position
2273 // grand_child needs to compensate for the scroll translation.
2274 expected_surface_draw_transform.MakeIdentity();
2275 expected_surface_draw_transform.Translate(-10.0, -10.0);
2276 expected_grand_child_transform.MakeIdentity();
2277 expected_grand_child_transform.Translate(10.0, 10.0);
2278
2279 ASSERT_TRUE(child->render_surface());
2280 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
2281 child->render_surface()->draw_transform());
2282 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2283 child->draw_transform());
2284 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2285 grand_child->draw_transform());
2286 }
2287
2288 TEST(LayerTreeHostCommonTest,
2289 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) {
2290 // This test checks the scenario where a fixed-position layer also happens to
2291 // be a container itself for a descendant fixed position layer. In particular,
2292 // the layer should not accidentally be fixed to itself.
2293 FakeImplProxy proxy;
2294 FakeLayerTreeHostImpl host_impl(&proxy);
2295 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
2296 LayerImpl* child = root->children()[0];
2297 LayerImpl* grand_child = child->children()[0];
2298
2299 child->SetIsContainerForFixedPositionLayers(true);
2300 grand_child->SetFixedToContainerLayer(true);
2301
2302 // This should not confuse the grand_child. If correct, the grand_child would
2303 // still be considered fixed to its container (i.e. "child").
2304 grand_child->SetIsContainerForFixedPositionLayers(true);
2305
2306 // Case 1: scroll delta of 0, 0
2307 child->SetScrollDelta(gfx::Vector2d(0, 0));
2308 ExecuteCalculateDrawProperties(root.get());
2309
2310 gfx::Transform expected_child_transform;
2311 gfx::Transform expected_grand_child_transform;
2312 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2313 child->draw_transform());
2314 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2315 grand_child->draw_transform());
2316
2317 // Case 2: scroll delta of 10, 10
2318 child->SetScrollDelta(gfx::Vector2d(10, 10));
2319 ExecuteCalculateDrawProperties(root.get());
2320
2321 // Here the child is affected by scroll delta, but the fixed position
2322 // grand_child should not be affected.
2323 expected_child_transform.MakeIdentity();
2324 expected_child_transform.Translate(-10.0, -10.0);
2325 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
2326 child->draw_transform());
2327 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2328 grand_child->draw_transform());
2329 }
2330
2331 TEST(LayerTreeHostCommonTest,
2332 ScrollCompensationForFixedPositionLayerThatHasNoContainer) {
2333 // This test checks scroll compensation when a fixed-position layer does not
2334 // find any ancestor that is a "containerForFixedPositionLayers". In this
2335 // situation, the layer should be fixed to the viewport -- not the root_layer,
2336 // which may have transforms of its own.
2337 FakeImplProxy proxy;
2338 FakeLayerTreeHostImpl host_impl(&proxy);
2339 scoped_ptr<LayerImpl> root = CreateTreeForFixedPositionTests(&host_impl);
2340 LayerImpl* child = root->children()[0];
2341 LayerImpl* grand_child = child->children()[0];
2342
2343 gfx::Transform rotation_by_z;
2344 rotation_by_z.RotateAboutZAxis(90.0);
2345
2346 root->SetTransform(rotation_by_z);
2347 grand_child->SetFixedToContainerLayer(true);
2348
2349 // Case 1: root scroll delta of 0, 0
2350 root->SetScrollDelta(gfx::Vector2d(0, 0));
2351 ExecuteCalculateDrawProperties(root.get());
2352
2353 gfx::Transform identity_matrix;
2354
2355 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
2356 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
2357 grand_child->draw_transform());
2358
2359 // Case 2: root scroll delta of 10, 10
2360 root->SetScrollDelta(gfx::Vector2d(10, 20));
2361 ExecuteCalculateDrawProperties(root.get());
2362
2363 // The child is affected by scroll delta, but it is already implcitly
2364 // accounted for by the child's target surface (i.e. the root render surface).
2365 // The grand_child is not affected by the scroll delta, so its draw transform
2366 // needs to explicitly inverse-compensate for the scroll that's embedded in
2367 // the target surface.
2368 gfx::Transform expected_grand_child_transform;
2369 expected_grand_child_transform.PreconcatTransform(Inverse(rotation_by_z));
2370 // explicit cancelling out the scroll delta that gets embedded in the fixed
2371 // position layer's surface.
2372 expected_grand_child_transform.Translate(10.0, 20.0);
2373 expected_grand_child_transform.PreconcatTransform(rotation_by_z);
2374
2375 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
2376 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
2377 grand_child->draw_transform());
2378 }
2379
2380 TEST(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { 1638 TEST(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
2381 // The entire subtree of layers that are outside the clip rect should be 1639 // The entire subtree of layers that are outside the clip rect should be
2382 // culled away, and should not affect the render_surface_layer_list. 1640 // culled away, and should not affect the render_surface_layer_list.
2383 // 1641 //
2384 // The test tree is set up as follows: 1642 // The test tree is set up as follows:
2385 // - all layers except the leaf_nodes are forced to be a new render surface 1643 // - all layers except the leaf_nodes are forced to be a new render surface
2386 // that have something to draw. 1644 // that have something to draw.
2387 // - parent is a large container layer. 1645 // - parent is a large container layer.
2388 // - child has masksToBounds=true to cause clipping. 1646 // - child has masksToBounds=true to cause clipping.
2389 // - grand_child is positioned outside of the child's bounds 1647 // - grand_child is positioned outside of the child's bounds
(...skipping 5757 matching lines...) Expand 10 before | Expand all | Expand 10 after
8147 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 7405 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
8148 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 7406 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
8149 } 7407 }
8150 7408
8151 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 7409 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
8152 LCDTextTest, 7410 LCDTextTest,
8153 testing::Combine(testing::Bool(), testing::Bool())); 7411 testing::Combine(testing::Bool(), testing::Bool()));
8154 7412
8155 } // namespace 7413 } // namespace
8156 } // namespace cc 7414 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698