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

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

Issue 1387003002: cc: Make property trees support resourceless draw mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DontReparentUnclippedClipNodes
Patch Set: Rebased Created 5 years, 2 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/property_tree.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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "cc/animation/keyframed_animation_curve.h" 10 #include "cc/animation/keyframed_animation_curve.h"
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 surface_sublayer_composite_transform, 515 surface_sublayer_composite_transform,
516 child->render_target()->render_surface()->draw_transform()); 516 child->render_target()->render_surface()->draw_transform());
517 517
518 // The screen space is the same as the target since the child surface draws 518 // The screen space is the same as the target since the child surface draws
519 // into the root. 519 // into the root.
520 EXPECT_TRANSFORMATION_MATRIX_EQ( 520 EXPECT_TRANSFORMATION_MATRIX_EQ(
521 surface_sublayer_composite_transform, 521 surface_sublayer_composite_transform,
522 child->render_target()->render_surface()->screen_space_transform()); 522 child->render_target()->render_surface()->screen_space_transform());
523 } 523 }
524 524
525 TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
526 LayerImpl* root = root_layer();
527 LayerImpl* parent = AddChildToRoot<LayerImpl>();
528 LayerImpl* child = AddChild<LayerImpl>(parent);
529 LayerImpl* grand_child = AddChild<LayerImpl>(child);
530 grand_child->SetDrawsContent(true);
531
532 gfx::Transform identity_matrix;
533 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
534 gfx::PointF(), gfx::Size(100, 100), true, false,
535 true);
536
537 gfx::Transform parent_transform;
538 parent_transform.Translate(10.0, 10.0);
539
540 gfx::Transform child_transform;
541 child_transform.Rotate(45.0);
542
543 // child gets a render surface when surfaces are enabled.
544 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
545 gfx::PointF(), gfx::Size(10, 10), true, false,
546 false);
547 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
548 gfx::PointF(), gfx::Size(10, 10), true, false,
549 true);
550 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
551 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
552 false, false);
553
554 gfx::Transform expected_grand_child_screen_space_transform;
555 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
556 expected_grand_child_screen_space_transform.Rotate(45.0);
557 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
558
559 // First compute draw properties with separate surfaces enabled.
560 ExecuteCalculateDrawProperties(root);
561
562 // The grand child's draw transform should be its offset wrt the child.
563 gfx::Transform expected_grand_child_draw_transform;
564 expected_grand_child_draw_transform.Translate(2.0, 2.0);
565 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
566 grand_child->draw_transform());
567 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
568 grand_child->screen_space_transform());
569
570 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
571
572 // With separate surfaces disabled, the grand child's draw transform should be
573 // the same as its screen space transform.
574 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
575 grand_child->draw_transform());
576 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
577 grand_child->screen_space_transform());
578 }
579
525 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { 580 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
526 LayerImpl* root = root_layer(); 581 LayerImpl* root = root_layer();
527 LayerImpl* parent = AddChildToRoot<LayerImpl>(); 582 LayerImpl* parent = AddChildToRoot<LayerImpl>();
528 LayerImpl* child = AddChild<LayerImpl>(parent); 583 LayerImpl* child = AddChild<LayerImpl>(parent);
529 LayerImpl* grand_child = AddChild<LayerImpl>(child); 584 LayerImpl* grand_child = AddChild<LayerImpl>(child);
530 grand_child->SetDrawsContent(true); 585 grand_child->SetDrawsContent(true);
531 scoped_ptr<LayerImpl> child_replica = 586 scoped_ptr<LayerImpl> child_replica =
532 LayerImpl::Create(host_impl()->active_tree(), 100); 587 LayerImpl::Create(host_impl()->active_tree(), 100);
533 588
534 // One-time setup of root layer 589 // One-time setup of root layer
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 // Since the child layer has a blend mode other than normal, it should get 1280 // Since the child layer has a blend mode other than normal, it should get
1226 // its own render surface. Also, layer's draw_properties should contain the 1281 // its own render surface. Also, layer's draw_properties should contain the
1227 // default blend mode, since the render surface becomes responsible for 1282 // default blend mode, since the render surface becomes responsible for
1228 // applying the blend mode. 1283 // applying the blend mode.
1229 ASSERT_TRUE(child->render_surface()); 1284 ASSERT_TRUE(child->render_surface());
1230 EXPECT_EQ(1.0f, child->draw_opacity()); 1285 EXPECT_EQ(1.0f, child->draw_opacity());
1231 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); 1286 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
1232 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); 1287 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
1233 } 1288 }
1234 1289
1290 TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1291 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1292 // the product of all ancestor layer opacties and the layer's own opacity.
1293 // (Rendering will still be incorrect in situations where we really do need
1294 // surfaces to apply opacity, such as when we have overlapping layers with an
1295 // ancestor whose opacity is <1.)
1296 LayerImpl* root = root_layer();
1297 LayerImpl* parent = AddChild<LayerImpl>(root);
1298 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1299 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1300 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1301 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1302 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1303
1304 root->SetDrawsContent(true);
1305 parent->SetDrawsContent(true);
1306 child1->SetDrawsContent(true);
1307 child2->SetDrawsContent(true);
1308 grand_child->SetDrawsContent(true);
1309 leaf_node1->SetDrawsContent(true);
1310 leaf_node2->SetDrawsContent(true);
1311
1312 const gfx::Transform identity_matrix;
1313
1314 // child1 and grand_child get render surfaces when surfaces are enabled.
1315 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1316 gfx::PointF(), gfx::Size(100, 100), true, false,
1317 true);
1318 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1319 gfx::PointF(), gfx::Size(100, 100), true, false,
1320 false);
1321 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1322 gfx::PointF(), gfx::Size(100, 100), true, false,
1323 true);
1324 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1325 gfx::PointF(), gfx::Size(100, 100), true, false,
1326 false);
1327 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1328 gfx::PointF(), gfx::Size(100, 100), true, false,
1329 true);
1330 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1331 gfx::PointF(), gfx::Size(100, 100), true, false,
1332 false);
1333 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1334 gfx::PointF(), gfx::Size(100, 100), true, false,
1335 false);
1336
1337 child1->SetOpacity(0.5f);
1338 grand_child->SetOpacity(0.5f);
1339 leaf_node1->SetOpacity(0.5f);
1340 leaf_node2->SetOpacity(0.5f);
1341
1342 // With surfaces enabled, each layer's draw opacity is the product of layer
1343 // opacities on the path from the layer to its render target, not including
1344 // the opacity of the layer that owns the target surface (since that opacity
1345 // is applied by the surface).
1346 ExecuteCalculateDrawProperties(root);
1347 EXPECT_EQ(1.f, root->draw_opacity());
1348 EXPECT_EQ(1.f, parent->draw_opacity());
1349 EXPECT_EQ(1.f, child1->draw_opacity());
1350 EXPECT_EQ(1.f, child2->draw_opacity());
1351 EXPECT_EQ(1.f, grand_child->draw_opacity());
1352 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1353 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1354
1355 // With surfaces disabled, each layer's draw opacity is the product of layer
1356 // opacities on the path from the layer to the root.
1357 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1358 EXPECT_EQ(1.f, root->draw_opacity());
1359 EXPECT_EQ(1.f, parent->draw_opacity());
1360 EXPECT_EQ(0.5f, child1->draw_opacity());
1361 EXPECT_EQ(1.f, child2->draw_opacity());
1362 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1363 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1364 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1365 }
1366
1235 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { 1367 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
1236 scoped_refptr<Layer> parent = Layer::Create(layer_settings()); 1368 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1237 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); 1369 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
1238 scoped_refptr<LayerWithForcedDrawsContent> child = 1370 scoped_refptr<LayerWithForcedDrawsContent> child =
1239 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); 1371 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1240 render_surface1->SetForceRenderSurface(true); 1372 render_surface1->SetForceRenderSurface(true);
1241 1373
1242 host()->SetRootLayer(parent); 1374 host()->SetRootLayer(parent);
1243 1375
1244 const gfx::Transform identity_matrix; 1376 const gfx::Transform identity_matrix;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 EXPECT_FALSE(parent->is_clipped()); 1704 EXPECT_FALSE(parent->is_clipped());
1573 EXPECT_FALSE(child1->is_clipped()); 1705 EXPECT_FALSE(child1->is_clipped());
1574 EXPECT_TRUE(child2->is_clipped()); 1706 EXPECT_TRUE(child2->is_clipped());
1575 EXPECT_FALSE(child2->render_surface()->is_clipped()); 1707 EXPECT_FALSE(child2->render_surface()->is_clipped());
1576 EXPECT_FALSE(grand_child->is_clipped()); 1708 EXPECT_FALSE(grand_child->is_clipped());
1577 EXPECT_FALSE(leaf_node1->is_clipped()); 1709 EXPECT_FALSE(leaf_node1->is_clipped());
1578 EXPECT_TRUE(leaf_node2->is_clipped()); 1710 EXPECT_TRUE(leaf_node2->is_clipped());
1579 } 1711 }
1580 } 1712 }
1581 1713
1714 TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1715 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1716 // when a layer or its ancestor has a clip; in particular, if a layer
1717 // is_clipped, so is its entire subtree (since there are no render surfaces
1718 // that can reset is_clipped).
1719 LayerImpl* root = root_layer();
1720 LayerImpl* parent = AddChild<LayerImpl>(root);
1721 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1722 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1723 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1724 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1725 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1726
1727 root->SetDrawsContent(true);
1728 parent->SetDrawsContent(true);
1729 child1->SetDrawsContent(true);
1730 child2->SetDrawsContent(true);
1731 grand_child->SetDrawsContent(true);
1732 leaf_node1->SetDrawsContent(true);
1733 leaf_node2->SetDrawsContent(true);
1734
1735 const gfx::Transform identity_matrix;
1736
1737 // child1 and grand_child get render surfaces when surfaces are enabled.
1738 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1739 gfx::PointF(), gfx::Size(100, 100), true, false,
1740 true);
1741 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1742 gfx::PointF(), gfx::Size(100, 100), true, false,
1743 false);
1744 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1745 gfx::PointF(), gfx::Size(100, 100), true, false,
1746 true);
1747 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1748 gfx::PointF(), gfx::Size(100, 100), true, false,
1749 false);
1750 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1751 gfx::PointF(), gfx::Size(100, 100), true, false,
1752 true);
1753 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1754 gfx::PointF(), gfx::Size(100, 100), true, false,
1755 false);
1756 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1757 gfx::PointF(), gfx::Size(100, 100), true, false,
1758 false);
1759
1760 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1761 // or without surfaces.
1762 ExecuteCalculateDrawProperties(root);
1763 EXPECT_FALSE(root->is_clipped());
1764 EXPECT_FALSE(parent->is_clipped());
1765 EXPECT_FALSE(child1->is_clipped());
1766 EXPECT_FALSE(child2->is_clipped());
1767 EXPECT_FALSE(grand_child->is_clipped());
1768 EXPECT_FALSE(leaf_node1->is_clipped());
1769 EXPECT_FALSE(leaf_node2->is_clipped());
1770
1771 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1772 EXPECT_FALSE(root->is_clipped());
1773 EXPECT_FALSE(parent->is_clipped());
1774 EXPECT_FALSE(child1->is_clipped());
1775 EXPECT_FALSE(child2->is_clipped());
1776 EXPECT_FALSE(grand_child->is_clipped());
1777 EXPECT_FALSE(leaf_node1->is_clipped());
1778 EXPECT_FALSE(leaf_node2->is_clipped());
1779
1780 // Case 2: The root is clipped. With surfaces, this only persists until the
1781 // next render surface. Without surfaces, the entire tree is clipped.
1782 root->SetMasksToBounds(true);
1783 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1784 ExecuteCalculateDrawProperties(root);
1785 EXPECT_TRUE(root->is_clipped());
1786 EXPECT_TRUE(parent->is_clipped());
1787 EXPECT_FALSE(child1->is_clipped());
1788 EXPECT_TRUE(child2->is_clipped());
1789 EXPECT_FALSE(grand_child->is_clipped());
1790 EXPECT_FALSE(leaf_node1->is_clipped());
1791 EXPECT_TRUE(leaf_node2->is_clipped());
1792
1793 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1794 EXPECT_TRUE(root->is_clipped());
1795 EXPECT_TRUE(parent->is_clipped());
1796 EXPECT_TRUE(child1->is_clipped());
1797 EXPECT_TRUE(child2->is_clipped());
1798 EXPECT_TRUE(grand_child->is_clipped());
1799 EXPECT_TRUE(leaf_node1->is_clipped());
1800 EXPECT_TRUE(leaf_node2->is_clipped());
1801
1802 root->SetMasksToBounds(false);
1803
1804 // Case 3: The parent is clipped. Again, with surfaces, this only persists
1805 // until the next render surface. Without surfaces, parent's entire subtree is
1806 // clipped.
1807 parent->SetMasksToBounds(true);
1808 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1809 ExecuteCalculateDrawProperties(root);
1810 EXPECT_FALSE(root->is_clipped());
1811 EXPECT_TRUE(parent->is_clipped());
1812 EXPECT_FALSE(child1->is_clipped());
1813 EXPECT_TRUE(child2->is_clipped());
1814 EXPECT_FALSE(grand_child->is_clipped());
1815 EXPECT_FALSE(leaf_node1->is_clipped());
1816 EXPECT_TRUE(leaf_node2->is_clipped());
1817
1818 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1819 EXPECT_FALSE(root->is_clipped());
1820 EXPECT_TRUE(parent->is_clipped());
1821 EXPECT_TRUE(child1->is_clipped());
1822 EXPECT_TRUE(child2->is_clipped());
1823 EXPECT_TRUE(grand_child->is_clipped());
1824 EXPECT_TRUE(leaf_node1->is_clipped());
1825 EXPECT_TRUE(leaf_node2->is_clipped());
1826
1827 parent->SetMasksToBounds(false);
1828
1829 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
1830 // has no non-surface children. Without surfaces, child1's entire subtree is
1831 // clipped.
1832 child1->SetMasksToBounds(true);
1833 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1834 ExecuteCalculateDrawProperties(root);
1835 EXPECT_FALSE(root->is_clipped());
1836 EXPECT_FALSE(parent->is_clipped());
1837 EXPECT_TRUE(child1->is_clipped());
1838 EXPECT_FALSE(child2->is_clipped());
1839 EXPECT_FALSE(grand_child->is_clipped());
1840 EXPECT_FALSE(leaf_node1->is_clipped());
1841 EXPECT_FALSE(leaf_node2->is_clipped());
1842
1843 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1844 EXPECT_FALSE(root->is_clipped());
1845 EXPECT_FALSE(parent->is_clipped());
1846 EXPECT_TRUE(child1->is_clipped());
1847 EXPECT_FALSE(child2->is_clipped());
1848 EXPECT_TRUE(grand_child->is_clipped());
1849 EXPECT_TRUE(leaf_node1->is_clipped());
1850 EXPECT_FALSE(leaf_node2->is_clipped());
1851
1852 child1->SetMasksToBounds(false);
1853
1854 // Case 5: Only the leaf nodes are clipped. The behavior with and without
1855 // surfaces is the same.
1856 leaf_node1->SetMasksToBounds(true);
1857 leaf_node2->SetMasksToBounds(true);
1858 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1859 ExecuteCalculateDrawProperties(root);
1860 EXPECT_FALSE(root->is_clipped());
1861 EXPECT_FALSE(parent->is_clipped());
1862 EXPECT_FALSE(child1->is_clipped());
1863 EXPECT_FALSE(child2->is_clipped());
1864 EXPECT_FALSE(grand_child->is_clipped());
1865 EXPECT_TRUE(leaf_node1->is_clipped());
1866 EXPECT_TRUE(leaf_node2->is_clipped());
1867
1868 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1869 EXPECT_FALSE(root->is_clipped());
1870 EXPECT_FALSE(parent->is_clipped());
1871 EXPECT_FALSE(child1->is_clipped());
1872 EXPECT_FALSE(child2->is_clipped());
1873 EXPECT_FALSE(grand_child->is_clipped());
1874 EXPECT_TRUE(leaf_node1->is_clipped());
1875 EXPECT_TRUE(leaf_node2->is_clipped());
1876 }
1877
1582 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { 1878 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
1583 // Verify that layers get the appropriate DrawableContentRect when their 1879 // Verify that layers get the appropriate DrawableContentRect when their
1584 // parent masksToBounds is true. 1880 // parent masksToBounds is true.
1585 // 1881 //
1586 // grand_child1 - completely inside the region; DrawableContentRect should 1882 // grand_child1 - completely inside the region; DrawableContentRect should
1587 // be the layer rect expressed in target space. 1883 // be the layer rect expressed in target space.
1588 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect 1884 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1589 // will be the intersection of layer bounds and the mask region. 1885 // will be the intersection of layer bounds and the mask region.
1590 // grand_child3 - partially clipped and masksToBounds; the 1886 // grand_child3 - partially clipped and masksToBounds; the
1591 // DrawableContentRect will still be the intersection of layer bounds and 1887 // DrawableContentRect will still be the intersection of layer bounds and
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 // Surfaces are clipped by their parent, but un-affected by the owning layer's 2008 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1713 // masksToBounds. 2009 // masksToBounds.
1714 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2010 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1715 grand_child1->render_surface()->clip_rect()); 2011 grand_child1->render_surface()->clip_rect());
1716 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2012 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1717 grand_child2->render_surface()->clip_rect()); 2013 grand_child2->render_surface()->clip_rect());
1718 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), 2014 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1719 grand_child3->render_surface()->clip_rect()); 2015 grand_child3->render_surface()->clip_rect());
1720 } 2016 }
1721 2017
2018 TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2019 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2020 // intersection of all ancestor clips in screen space; in particular, if a
2021 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2022 // subtree (since there are no render surfaces that can reset the clip_rect).
2023 LayerImpl* root = root_layer();
2024 LayerImpl* parent = AddChild<LayerImpl>(root);
2025 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2026 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2027 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2028 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2029 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2030
2031 root->SetDrawsContent(true);
2032 parent->SetDrawsContent(true);
2033 child1->SetDrawsContent(true);
2034 child2->SetDrawsContent(true);
2035 grand_child->SetDrawsContent(true);
2036 leaf_node1->SetDrawsContent(true);
2037 leaf_node2->SetDrawsContent(true);
2038
2039 const gfx::Transform identity_matrix;
2040
2041 // child1 and grand_child get render surfaces when surfaces are enabled.
2042 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2043 gfx::PointF(), gfx::Size(100, 100), true, false,
2044 true);
2045 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2046 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2047 false, false);
2048 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2049 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2050 false, true);
2051 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2052 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
2053 false, false);
2054 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2055 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2056 true, false, true);
2057 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2058 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2059 true, false, false);
2060 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2061 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
2062 true, false, false);
2063
2064 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2065 // bounds in target space. The only thing that changes when surfaces are
2066 // disabled is that target space is always screen space.
2067 ExecuteCalculateDrawProperties(root);
2068 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2069 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2070 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2071 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2072 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2073 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2074 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2075
2076 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2077 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2078 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2079 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->clip_rect());
2080 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2081 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), grand_child->clip_rect());
2082 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->clip_rect());
2083 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2084
2085 // Case 2: The root is clipped. In this case, layers that draw into the root
2086 // render surface are clipped by the root's bounds.
2087 root->SetMasksToBounds(true);
2088 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2089 ExecuteCalculateDrawProperties(root);
2090 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2091 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2092 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2093 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2094 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2095 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2096 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2097
2098 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2099 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2100 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2101 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2102 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2103 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2104 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2105 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2106
2107 root->SetMasksToBounds(false);
2108
2109 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2110 // parent clip rect only contributes to the subtree rooted at child2, since
2111 // the subtree rooted at child1 renders into a separate surface. Similarly,
2112 // child1's clip rect doesn't contribute to its descendants, since its only
2113 // child is a render surface. However, without surfaces, these clip rects
2114 // contribute to all descendants.
2115 parent->SetMasksToBounds(true);
2116 child1->SetMasksToBounds(true);
2117 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2118 ExecuteCalculateDrawProperties(root);
2119 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2120 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2121 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2122 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2123 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2124 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2125 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2126
2127 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2128 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2129 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2130 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2131 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2132 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2133 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2134 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2135 }
2136
2137 TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2138 // Tests that draw properties are computed correctly when we disable and then
2139 // re-enable separate surfaces.
2140 LayerImpl* root = root_layer();
2141 LayerImpl* parent = AddChild<LayerImpl>(root);
2142 LayerImpl* child = AddChild<LayerImpl>(parent);
2143 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2144 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2145
2146 root->SetDrawsContent(true);
2147 parent->SetDrawsContent(true);
2148 child->SetDrawsContent(true);
2149 grand_child->SetDrawsContent(true);
2150 leaf_node->SetDrawsContent(true);
2151
2152 const gfx::Transform identity_matrix;
2153
2154 // child and grand_child get render surfaces when surfaces are enabled.
2155 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2156 gfx::PointF(), gfx::Size(100, 100), true, false,
2157 true);
2158 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2159 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2160 false, false);
2161 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2162 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2163 false, true);
2164 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2165 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2166 true, false, true);
2167 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2168 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2169 true, false, false);
2170
2171 parent->SetMasksToBounds(true);
2172 child->SetMasksToBounds(true);
2173
2174 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2175 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2176
2177 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2178 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2179
2180 ExecuteCalculateDrawProperties(root);
2181 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2182 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2183 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
2184 leaf_node->draw_transform());
2185
2186 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2187 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2188 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2189 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
2190 leaf_node->draw_transform());
2191
2192 ExecuteCalculateDrawProperties(root);
2193 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2194 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2195 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
2196 leaf_node->draw_transform());
2197 }
2198
1722 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { 2199 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
1723 LayerImpl* parent = root_layer(); 2200 LayerImpl* parent = root_layer();
1724 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); 2201 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1725 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); 2202 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
1726 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); 2203 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
1727 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); 2204 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
1728 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); 2205 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
1729 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); 2206 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
1730 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); 2207 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
1731 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); 2208 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); 2876 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2400 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); 2877 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2401 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); 2878 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2402 2879
2403 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); 2880 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2404 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); 2881 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2405 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); 2882 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2406 } 2883 }
2407 2884
2408 TEST_F(LayerTreeHostCommonTest, 2885 TEST_F(LayerTreeHostCommonTest,
2886 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
2887 LayerImpl* root = root_layer();
2888 LayerImpl* parent = AddChild<LayerImpl>(root);
2889 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2890 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2891 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
2892 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
2893 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2894 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2895
2896 root->SetDrawsContent(true);
2897 parent->SetDrawsContent(true);
2898 child1->SetDrawsContent(true);
2899 child2->SetDrawsContent(true);
2900 grand_child1->SetDrawsContent(true);
2901 grand_child2->SetDrawsContent(true);
2902 leaf_node1->SetDrawsContent(true);
2903 leaf_node2->SetDrawsContent(true);
2904
2905 const gfx::Transform identity_matrix;
2906
2907 // child1 and child2 get render surfaces when surfaces are enabled.
2908 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2909 gfx::PointF(), gfx::Size(100, 100), true, false,
2910 true);
2911 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2912 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2913 false, false);
2914 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2915 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2916 false, true);
2917 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2918 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
2919 false, true);
2920 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2921 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2922 true, false, false);
2923 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2924 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
2925 true, false, false);
2926 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2927 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2928 true, false, false);
2929 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2930 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
2931 true, false, false);
2932
2933 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
2934 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
2935 // Each layer's drawable content rect is its bounds in target space; the only
2936 // thing that changes with surfaces disabled is that target space is always
2937 // screen space.
2938 ExecuteCalculateDrawProperties(root);
2939 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
2940 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
2941 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
2942 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
2943 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
2944 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
2945 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
2946 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
2947
2948 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2949 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
2950 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
2951 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
2952 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
2953 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
2954 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
2955 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
2956
2957 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2958 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
2959 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
2960 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
2961 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
2962 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
2963 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
2964 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
2965 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
2966
2967 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2968 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
2969 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
2970 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
2971 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
2972 grand_child1->drawable_content_rect());
2973 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
2974 grand_child2->drawable_content_rect());
2975 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
2976 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
2977
2978 // Case 2: The parent clips. In this case, neither surface is unclipped, so
2979 // all visible layer rects are clipped by the intersection of all ancestor
2980 // clips, whether or not surfaces are disabled. However, drawable content
2981 // rects are clipped only until the next render surface is reached, so
2982 // descendants of parent have their drawable content rects clipped only when
2983 // surfaces are disabled.
2984 parent->SetMasksToBounds(true);
2985 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2986 ExecuteCalculateDrawProperties(root);
2987 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
2988 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
2989 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
2990 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
2991 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
2992 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
2993 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
2994 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
2995
2996 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2997 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
2998 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
2999 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3000 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3001 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3002 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3003 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3004
3005 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3006 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3007 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3008 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3009 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3010 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3011 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3012 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3013 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3014
3015 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3016 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3017 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3018 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3019 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3020 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3021 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3022 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3023
3024 parent->SetMasksToBounds(false);
3025
3026 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3027 // layers have their visible rects clipped by them; without surfaces, these
3028 // rects are also clipped by the viewport. Similarly, descendants of these
3029 // layers have their drawable content rects clipped by them.
3030 child1->SetMasksToBounds(true);
3031 grand_child2->SetMasksToBounds(true);
3032 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3033 ExecuteCalculateDrawProperties(root);
3034 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3035 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3036 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3037 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3038 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3039 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3040 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3041 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3042
3043 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3044 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3045 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3046 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3047 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3048 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3049 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3050 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3051
3052 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3053 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3054 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3055 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3056 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3057 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3058 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3059 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3060 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3061
3062 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3063 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3064 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3065 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3066 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3067 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3068 grand_child2->drawable_content_rect());
3069 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3070 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3071 }
3072
3073 TEST_F(LayerTreeHostCommonTest,
2409 VisibleContentRectsForClippedSurfaceWithEmptyClip) { 3074 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2410 LayerImpl* root = root_layer(); 3075 LayerImpl* root = root_layer();
2411 LayerImpl* child1 = AddChild<LayerImpl>(root); 3076 LayerImpl* child1 = AddChild<LayerImpl>(root);
2412 LayerImpl* child2 = AddChild<LayerImpl>(root); 3077 LayerImpl* child2 = AddChild<LayerImpl>(root);
2413 LayerImpl* child3 = AddChild<LayerImpl>(root); 3078 LayerImpl* child3 = AddChild<LayerImpl>(root);
2414 child1->SetDrawsContent(true); 3079 child1->SetDrawsContent(true);
2415 child2->SetDrawsContent(true); 3080 child2->SetDrawsContent(true);
2416 child3->SetDrawsContent(true); 3081 child3->SetDrawsContent(true);
2417 3082
2418 gfx::Transform identity_matrix; 3083 gfx::Transform identity_matrix;
(...skipping 5823 matching lines...) Expand 10 before | Expand all | Expand 10 after
8242 bool root_in_rsll = 8907 bool root_in_rsll =
8243 std::find(rsll->begin(), rsll->end(), root) != rsll->end(); 8908 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
8244 EXPECT_TRUE(root_in_rsll); 8909 EXPECT_TRUE(root_in_rsll);
8245 bool render_surface2_in_rsll = 8910 bool render_surface2_in_rsll =
8246 std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end(); 8911 std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end();
8247 EXPECT_FALSE(render_surface2_in_rsll); 8912 EXPECT_FALSE(render_surface2_in_rsll);
8248 } 8913 }
8249 8914
8250 } // namespace 8915 } // namespace
8251 } // namespace cc 8916 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/property_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698