| OLD | NEW |
| 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 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2300 gfx::Transform layer_to_surface_transform; | 2300 gfx::Transform layer_to_surface_transform; |
| 2301 layer_to_surface_transform.MakeIdentity(); | 2301 layer_to_surface_transform.MakeIdentity(); |
| 2302 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); | 2302 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2303 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); | 2303 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2304 layer_to_surface_transform.RotateAboutYAxis(45.0); | 2304 layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2305 layer_to_surface_transform.RotateAboutXAxis(80.0); | 2305 layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2306 | 2306 |
| 2307 // Sanity check that un-projection does indeed cause w < 0, otherwise this | 2307 // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2308 // code is not testing the intended scenario. | 2308 // code is not testing the intended scenario. |
| 2309 bool clipped; | 2309 bool clipped; |
| 2310 gfx::RectF clipped_rect = | 2310 gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2311 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); | 2311 layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
| 2312 MathUtil::ProjectQuad( | 2312 MathUtil::ProjectQuad( |
| 2313 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); | 2313 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2314 ASSERT_TRUE(clipped); | 2314 ASSERT_TRUE(clipped); |
| 2315 | 2315 |
| 2316 // Only the corner of the layer is not visible on the surface because of being | 2316 // Only the corner of the layer is not visible on the surface because of being |
| 2317 // clipped. But, the net result of rounding visible region to an axis-aligned | 2317 // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2318 // rect is that the entire layer should still be considered visible. | 2318 // rect is that the entire layer should still be considered visible. |
| 2319 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); | 2319 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
| 2320 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( | 2320 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2321 target_surface_rect, layer_content_rect, layer_to_surface_transform); | 2321 target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2322 EXPECT_EQ(expected, actual); | 2322 EXPECT_EQ(expected, actual); |
| 2323 } | 2323 } |
| 2324 | 2324 |
| 2325 TEST_F(LayerTreeHostCommonTest, | 2325 TEST_F(LayerTreeHostCommonTest, |
| 2326 VisibleRectsForPositionedRootLayerClippedByViewport) { | 2326 VisibleRectsForPositionedRootLayerClippedByViewport) { |
| 2327 LayerImpl* root = root_layer(); | 2327 LayerImpl* root = root_layer(); |
| 2328 root->SetDrawsContent(true); | 2328 root->SetDrawsContent(true); |
| 2329 | 2329 |
| 2330 gfx::Transform identity_matrix; | 2330 gfx::Transform identity_matrix; |
| 2331 // Root layer is positioned at (60, 70). The default device viewport size | 2331 // Root layer is positioned at (60, 70). The default device viewport size |
| 2332 // is (0, 0, 100x100) in target space. So the root layer's visible rect | 2332 // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 2333 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space. | 2333 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space. |
| 2334 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), | 2334 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2335 gfx::PointF(60, 70), gfx::Size(100, 100), true, | 2335 gfx::PointF(60, 70), gfx::Size(100, 100), true, |
| 2336 false, true); | 2336 false, true); |
| 2337 ExecuteCalculateDrawProperties(root); | 2337 ExecuteCalculateDrawProperties(root); |
| 2338 | 2338 |
| 2339 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2339 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2340 root->render_surface()->DrawableContentRect()); | 2340 root->render_surface()->DrawableContentRect()); |
| 2341 // In target space, not clipped. | 2341 // In target space, not clipped. |
| 2342 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); | 2342 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2343 // In layer space, clipped. | 2343 // In layer space, clipped. |
| 2344 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root->visible_layer_rect()); | 2344 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
| 2345 } | 2345 } |
| 2346 | 2346 |
| 2347 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { | 2347 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
| 2348 LayerImpl* root = root_layer(); | 2348 LayerImpl* root = root_layer(); |
| 2349 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); | 2349 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
| 2350 child1_layer->SetDrawsContent(true); | 2350 child1_layer->SetDrawsContent(true); |
| 2351 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); | 2351 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
| 2352 child2_layer->SetDrawsContent(true); | 2352 child2_layer->SetDrawsContent(true); |
| 2353 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); | 2353 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
| 2354 child3_layer->SetDrawsContent(true); | 2354 child3_layer->SetDrawsContent(true); |
| 2355 | 2355 |
| 2356 gfx::Transform identity_matrix; | 2356 gfx::Transform identity_matrix; |
| 2357 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), | 2357 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2358 gfx::PointF(), gfx::Size(100, 100), true, false, | 2358 gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2359 true); | 2359 true); |
| 2360 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), | 2360 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), |
| 2361 gfx::PointF(), gfx::Size(50, 50), true, false, | 2361 gfx::PointF(), gfx::Size(50, 50), true, false, |
| 2362 false); | 2362 false); |
| 2363 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), | 2363 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), |
| 2364 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, | 2364 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2365 false, false); | 2365 false, false); |
| 2366 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), | 2366 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), |
| 2367 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | 2367 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2368 true, false, false); | 2368 true, false, false); |
| 2369 | 2369 |
| 2370 ExecuteCalculateDrawProperties(root); | 2370 ExecuteCalculateDrawProperties(root); |
| 2371 | 2371 |
| 2372 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2372 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2373 root->render_surface()->DrawableContentRect()); | 2373 root->render_surface()->DrawableContentRect()); |
| 2374 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2374 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 2375 | 2375 |
| 2376 // Layers that do not draw content should have empty visible_layer_rects. | 2376 // Layers that do not draw content should have empty visible_layer_rects. |
| 2377 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2377 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2378 | 2378 |
| 2379 // layer visible_layer_rects are clipped by their target surface. | 2379 // layer visible_layer_rects are clipped by their target surface. |
| 2380 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); | 2380 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 2381 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); | 2381 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 2382 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); | 2382 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
| 2383 | 2383 |
| 2384 // layer drawable_content_rects are not clipped. | 2384 // layer drawable_content_rects are not clipped. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2411 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), | 2411 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2412 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, | 2412 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2413 false, false); | 2413 false, false); |
| 2414 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), | 2414 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2415 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | 2415 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2416 true, false, false); | 2416 true, false, false); |
| 2417 | 2417 |
| 2418 child->SetMasksToBounds(true); | 2418 child->SetMasksToBounds(true); |
| 2419 ExecuteCalculateDrawProperties(root); | 2419 ExecuteCalculateDrawProperties(root); |
| 2420 | 2420 |
| 2421 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2421 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2422 root->render_surface()->DrawableContentRect()); | 2422 root->render_surface()->DrawableContentRect()); |
| 2423 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2423 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 2424 | 2424 |
| 2425 // Layers that do not draw content should have empty visible content rects. | 2425 // Layers that do not draw content should have empty visible content rects. |
| 2426 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2426 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2427 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); | 2427 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
| 2428 | 2428 |
| 2429 // All grandchild visible content rects should be clipped by child. | 2429 // All grandchild visible content rects should be clipped by child. |
| 2430 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); | 2430 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 2431 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); | 2431 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 2432 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); | 2432 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
| 2433 | 2433 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2494 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, | 2494 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2495 false, false); | 2495 false, false); |
| 2496 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), | 2496 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 2497 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | 2497 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2498 true, false, false); | 2498 true, false, false); |
| 2499 | 2499 |
| 2500 ExecuteCalculateDrawProperties(root); | 2500 ExecuteCalculateDrawProperties(root); |
| 2501 | 2501 |
| 2502 ASSERT_TRUE(render_surface->render_surface()); | 2502 ASSERT_TRUE(render_surface->render_surface()); |
| 2503 | 2503 |
| 2504 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2504 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2505 root->render_surface()->DrawableContentRect()); | 2505 root->render_surface()->DrawableContentRect()); |
| 2506 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2506 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 2507 | 2507 |
| 2508 // Layers that do not draw content should have empty visible content rects. | 2508 // Layers that do not draw content should have empty visible content rects. |
| 2509 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2509 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2510 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); | 2510 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
| 2511 | 2511 |
| 2512 // An unclipped surface grows its DrawableContentRect to include all drawable | 2512 // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2513 // regions of the subtree. | 2513 // regions of the subtree. |
| 2514 EXPECT_EQ(gfx::Rect(5, 5, 170, 170), | 2514 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
| 2515 render_surface->render_surface()->DrawableContentRect()); | 2515 render_surface->render_surface()->DrawableContentRect()); |
| 2516 | 2516 |
| 2517 // All layers that draw content into the unclipped surface are also unclipped. | 2517 // All layers that draw content into the unclipped surface are also unclipped. |
| 2518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 2519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); | 2519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 2520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); | 2520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
| 2521 | 2521 |
| 2522 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | 2522 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2523 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | 2523 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2524 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); | 2524 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2830 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), | 2830 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 2831 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | 2831 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2832 true, false, false); | 2832 true, false, false); |
| 2833 | 2833 |
| 2834 root->SetMasksToBounds(true); | 2834 root->SetMasksToBounds(true); |
| 2835 | 2835 |
| 2836 ExecuteCalculateDrawProperties(root); | 2836 ExecuteCalculateDrawProperties(root); |
| 2837 | 2837 |
| 2838 ASSERT_TRUE(render_surface->render_surface()); | 2838 ASSERT_TRUE(render_surface->render_surface()); |
| 2839 | 2839 |
| 2840 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2840 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2841 root->render_surface()->DrawableContentRect()); | 2841 root->render_surface()->DrawableContentRect()); |
| 2842 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2842 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 2843 | 2843 |
| 2844 // Layers that do not draw content should have empty visible content rects. | 2844 // Layers that do not draw content should have empty visible content rects. |
| 2845 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2845 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2846 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); | 2846 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
| 2847 | 2847 |
| 2848 // A clipped surface grows its DrawableContentRect to include all drawable | 2848 // A clipped surface grows its DrawableContentRect to include all drawable |
| 2849 // regions of the subtree, but also gets clamped by the ancestor's clip. | 2849 // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 2850 EXPECT_EQ(gfx::Rect(5, 5, 95, 95), | 2850 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
| 2851 render_surface->render_surface()->DrawableContentRect()); | 2851 render_surface->render_surface()->DrawableContentRect()); |
| 2852 | 2852 |
| 2853 // All layers that draw content into the surface have their visible content | 2853 // All layers that draw content into the surface have their visible content |
| 2854 // rect clipped by the surface clip rect. | 2854 // rect clipped by the surface clip rect. |
| 2855 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2855 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 2856 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); | 2856 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 2857 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); | 2857 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
| 2858 | 2858 |
| 2859 // But the DrawableContentRects are unclipped. | 2859 // But the DrawableContentRects are unclipped. |
| 2860 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | 2860 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), | 2895 gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2896 true, false, false); | 2896 true, false, false); |
| 2897 | 2897 |
| 2898 root->SetMasksToBounds(true); | 2898 root->SetMasksToBounds(true); |
| 2899 | 2899 |
| 2900 ExecuteCalculateDrawProperties(root); | 2900 ExecuteCalculateDrawProperties(root); |
| 2901 | 2901 |
| 2902 ASSERT_TRUE(render_surface1->render_surface()); | 2902 ASSERT_TRUE(render_surface1->render_surface()); |
| 2903 ASSERT_TRUE(render_surface2->render_surface()); | 2903 ASSERT_TRUE(render_surface2->render_surface()); |
| 2904 | 2904 |
| 2905 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2905 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2906 root->render_surface()->DrawableContentRect()); | 2906 root->render_surface()->DrawableContentRect()); |
| 2907 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2907 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 2908 | 2908 |
| 2909 // Layers that do not draw content should have empty visible content rects. | 2909 // Layers that do not draw content should have empty visible content rects. |
| 2910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2911 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); | 2911 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 2912 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); | 2912 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
| 2913 | 2913 |
| 2914 // A clipped surface grows its DrawableContentRect to include all drawable | 2914 // A clipped surface grows its DrawableContentRect to include all drawable |
| 2915 // regions of the subtree, but also gets clamped by the ancestor's clip. | 2915 // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 2916 EXPECT_EQ(gfx::Rect(5, 5, 95, 95), | 2916 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
| 2917 render_surface1->render_surface()->DrawableContentRect()); | 2917 render_surface1->render_surface()->DrawableContentRect()); |
| 2918 | 2918 |
| 2919 // render_surface1 lives in the "unclipped universe" of render_surface1, and | 2919 // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 2920 // is only implicitly clipped by render_surface1's content rect. So, | 2920 // is only implicitly clipped by render_surface1's content rect. So, |
| 2921 // render_surface2 grows to enclose all drawable content of its subtree. | 2921 // render_surface2 grows to enclose all drawable content of its subtree. |
| 2922 EXPECT_EQ(gfx::Rect(5, 5, 170, 170), | 2922 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
| 2923 render_surface2->render_surface()->DrawableContentRect()); | 2923 render_surface2->render_surface()->DrawableContentRect()); |
| 2924 | 2924 |
| 2925 // All layers that draw content into render_surface2 think they are unclipped. | 2925 // All layers that draw content into render_surface2 think they are unclipped. |
| 2926 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2926 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 2927 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); | 2927 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 2928 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); | 2928 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
| 2929 | 2929 |
| 2930 // DrawableContentRects are also unclipped. | 2930 // DrawableContentRects are also unclipped. |
| 2931 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); | 2931 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2932 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); | 2932 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2952 gfx::PointF(), gfx::Size(3, 4), true, false, | 2952 gfx::PointF(), gfx::Size(3, 4), true, false, |
| 2953 true); | 2953 true); |
| 2954 SetLayerPropertiesForTesting( | 2954 SetLayerPropertiesForTesting( |
| 2955 child1, child_rotation, gfx::Point3F(25, 25, 0.f), | 2955 child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 2956 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); | 2956 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
| 2957 | 2957 |
| 2958 ExecuteCalculateDrawProperties(root); | 2958 ExecuteCalculateDrawProperties(root); |
| 2959 | 2959 |
| 2960 ASSERT_TRUE(render_surface->render_surface()); | 2960 ASSERT_TRUE(render_surface->render_surface()); |
| 2961 | 2961 |
| 2962 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), | 2962 EXPECT_EQ(gfx::RectF(100.f, 100.f), |
| 2963 root->render_surface()->DrawableContentRect()); | 2963 root->render_surface()->DrawableContentRect()); |
| 2964 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); | 2964 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2965 | 2965 |
| 2966 // Layers that do not draw content should have empty visible content rects. | 2966 // Layers that do not draw content should have empty visible content rects. |
| 2967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 2967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 2968 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); | 2968 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
| 2969 | 2969 |
| 2970 // The unclipped surface grows its DrawableContentRect to include all drawable | 2970 // The unclipped surface grows its DrawableContentRect to include all drawable |
| 2971 // regions of the subtree. | 2971 // regions of the subtree. |
| 2972 int diagonal_radius = ceil(sqrt(2.0) * 25.0); | 2972 int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 2973 gfx::Rect expected_surface_drawable_content = | 2973 gfx::Rect expected_surface_drawable_content = |
| 2974 gfx::Rect(50 - diagonal_radius, | 2974 gfx::Rect(50 - diagonal_radius, |
| 2975 50 - diagonal_radius, | 2975 50 - diagonal_radius, |
| 2976 diagonal_radius * 2, | 2976 diagonal_radius * 2, |
| 2977 diagonal_radius * 2); | 2977 diagonal_radius * 2); |
| 2978 EXPECT_EQ(expected_surface_drawable_content, | 2978 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
| 2979 render_surface->render_surface()->DrawableContentRect()); | 2979 render_surface->render_surface()->DrawableContentRect()); |
| 2980 | 2980 |
| 2981 // All layers that draw content into the unclipped surface are also unclipped. | 2981 // All layers that draw content into the unclipped surface are also unclipped. |
| 2982 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); | 2982 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 2983 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); | 2983 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
| 2984 } | 2984 } |
| 2985 | 2985 |
| 2986 TEST_F(LayerTreeHostCommonTest, | 2986 TEST_F(LayerTreeHostCommonTest, |
| 2987 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { | 2987 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
| 2988 // Layers that have non-axis aligned bounds (due to transforms) have an | 2988 // Layers that have non-axis aligned bounds (due to transforms) have an |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3012 | 3012 |
| 3013 ASSERT_TRUE(render_surface->render_surface()); | 3013 ASSERT_TRUE(render_surface->render_surface()); |
| 3014 | 3014 |
| 3015 // The clipped surface clamps the DrawableContentRect that encloses the | 3015 // The clipped surface clamps the DrawableContentRect that encloses the |
| 3016 // rotated layer. | 3016 // rotated layer. |
| 3017 int diagonal_radius = ceil(sqrt(2.0) * 25.0); | 3017 int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3018 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, | 3018 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3019 50 - diagonal_radius, | 3019 50 - diagonal_radius, |
| 3020 diagonal_radius * 2, | 3020 diagonal_radius * 2, |
| 3021 diagonal_radius * 2); | 3021 diagonal_radius * 2); |
| 3022 gfx::Rect expected_surface_drawable_content = | 3022 gfx::RectF expected_surface_drawable_content( |
| 3023 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); | 3023 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
| 3024 EXPECT_EQ(expected_surface_drawable_content, | 3024 EXPECT_EQ(expected_surface_drawable_content, |
| 3025 render_surface->render_surface()->DrawableContentRect()); | 3025 render_surface->render_surface()->DrawableContentRect()); |
| 3026 | 3026 |
| 3027 // On the clipped surface, only a quarter of the child1 is visible, but when | 3027 // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3028 // rotating it back to child1's content space, the actual enclosing rect ends | 3028 // rotating it back to child1's content space, the actual enclosing rect ends |
| 3029 // up covering the full left half of child1. | 3029 // up covering the full left half of child1. |
| 3030 // | 3030 // |
| 3031 // Given the floating point math, this number is a little bit fuzzy. | 3031 // Given the floating point math, this number is a little bit fuzzy. |
| 3032 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect()); | 3032 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect()); |
| 3033 | 3033 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3077 | 3077 |
| 3078 root->SetMasksToBounds(true); | 3078 root->SetMasksToBounds(true); |
| 3079 | 3079 |
| 3080 ExecuteCalculateDrawProperties(root, device_scale_factor); | 3080 ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 3081 | 3081 |
| 3082 ASSERT_TRUE(render_surface1->render_surface()); | 3082 ASSERT_TRUE(render_surface1->render_surface()); |
| 3083 ASSERT_TRUE(render_surface2->render_surface()); | 3083 ASSERT_TRUE(render_surface2->render_surface()); |
| 3084 | 3084 |
| 3085 // drawable_content_rects for all layers and surfaces are scaled by | 3085 // drawable_content_rects for all layers and surfaces are scaled by |
| 3086 // device_scale_factor. | 3086 // device_scale_factor. |
| 3087 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), | 3087 EXPECT_EQ(gfx::RectF(200.f, 200.f), |
| 3088 root->render_surface()->DrawableContentRect()); | 3088 root->render_surface()->DrawableContentRect()); |
| 3089 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); | 3089 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3090 EXPECT_EQ(gfx::Rect(10, 10, 190, 190), | 3090 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
| 3091 render_surface1->render_surface()->DrawableContentRect()); | 3091 render_surface1->render_surface()->DrawableContentRect()); |
| 3092 | 3092 |
| 3093 // render_surface2 lives in the "unclipped universe" of render_surface1, and | 3093 // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3094 // is only implicitly clipped by render_surface1. | 3094 // is only implicitly clipped by render_surface1. |
| 3095 EXPECT_EQ(gfx::Rect(10, 10, 350, 350), | 3095 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
| 3096 render_surface2->render_surface()->DrawableContentRect()); | 3096 render_surface2->render_surface()->DrawableContentRect()); |
| 3097 | 3097 |
| 3098 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); | 3098 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3099 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); | 3099 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3100 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); | 3100 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
| 3101 | 3101 |
| 3102 // The root layer does not actually draw content of its own. | 3102 // The root layer does not actually draw content of its own. |
| 3103 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); | 3103 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3104 | 3104 |
| 3105 // All layer visible content rects are not expressed in content space of each | 3105 // All layer visible content rects are not expressed in content space of each |
| (...skipping 4723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7829 | 7829 |
| 7830 TransformTree transform_tree = | 7830 TransformTree transform_tree = |
| 7831 root->layer_tree_impl()->property_trees()->transform_tree; | 7831 root->layer_tree_impl()->property_trees()->transform_tree; |
| 7832 TransformNode* transform_node = | 7832 TransformNode* transform_node = |
| 7833 transform_tree.Node(significant_transform->transform_tree_index()); | 7833 transform_tree.Node(significant_transform->transform_tree_index()); |
| 7834 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); | 7834 EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 7835 | 7835 |
| 7836 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; | 7836 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
| 7837 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); | 7837 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
| 7838 EXPECT_TRUE(clip_node->data.inherit_parent_target_space_clip); | 7838 EXPECT_TRUE(clip_node->data.inherit_parent_target_space_clip); |
| 7839 EXPECT_EQ(test_layer->visible_rect_from_property_trees(), gfx::RectF(30, 21)); | 7839 EXPECT_EQ(gfx::Rect(30, 21), test_layer->visible_rect_from_property_trees()); |
| 7840 } | 7840 } |
| 7841 | 7841 |
| 7842 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { | 7842 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 7843 // Ensure that when parent clip node's transform is an ancestor of current | 7843 // Ensure that when parent clip node's transform is an ancestor of current |
| 7844 // clip node's target, clip is 'projected' from parent space to current | 7844 // clip node's target, clip is 'projected' from parent space to current |
| 7845 // target space and visible rects are calculated correctly. | 7845 // target space and visible rects are calculated correctly. |
| 7846 LayerImpl* root = root_layer(); | 7846 LayerImpl* root = root_layer(); |
| 7847 LayerImpl* clip_layer = AddChild<LayerImpl>(root); | 7847 LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 7848 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); | 7848 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 7849 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); | 7849 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7864 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), | 7864 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), |
| 7865 gfx::PointF(), gfx::Size(30, 30), true, false, | 7865 gfx::PointF(), gfx::Size(30, 30), true, false, |
| 7866 true); | 7866 true); |
| 7867 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), | 7867 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 7868 gfx::PointF(), gfx::Size(30, 30), true, false, | 7868 gfx::PointF(), gfx::Size(30, 30), true, false, |
| 7869 false); | 7869 false); |
| 7870 ExecuteCalculateDrawProperties(root); | 7870 ExecuteCalculateDrawProperties(root); |
| 7871 | 7871 |
| 7872 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; | 7872 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
| 7873 ClipNode* clip_node = clip_tree.Node(target_layer->clip_tree_index()); | 7873 ClipNode* clip_node = clip_tree.Node(target_layer->clip_tree_index()); |
| 7874 EXPECT_EQ(clip_node->data.combined_clip, gfx::RectF(30, 30)); | 7874 EXPECT_EQ(gfx::RectF(30, 30), clip_node->data.combined_clip); |
| 7875 EXPECT_EQ(test_layer->visible_rect_from_property_trees(), gfx::RectF(30, 30)); | 7875 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees()); |
| 7876 } | 7876 } |
| 7877 | 7877 |
| 7878 TEST_F(LayerTreeHostCommonTest, | 7878 TEST_F(LayerTreeHostCommonTest, |
| 7879 RenderSurfaceWithUnclippedDescendantsClipsSubtree) { | 7879 RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 7880 // Ensure clip rect is calculated correctly when render surface has unclipped | 7880 // Ensure clip rect is calculated correctly when render surface has unclipped |
| 7881 // descendants. | 7881 // descendants. |
| 7882 LayerImpl* root = root_layer(); | 7882 LayerImpl* root = root_layer(); |
| 7883 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); | 7883 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 7884 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); | 7884 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 7885 LayerImpl* render_surface = | 7885 LayerImpl* render_surface = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 7903 true, false, false); | 7903 true, false, false); |
| 7904 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), | 7904 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 7905 gfx::PointF(), gfx::Size(30, 30), true, false, | 7905 gfx::PointF(), gfx::Size(30, 30), true, false, |
| 7906 true); | 7906 true); |
| 7907 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), | 7907 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 7908 gfx::PointF(), gfx::Size(30, 30), true, false, | 7908 gfx::PointF(), gfx::Size(30, 30), true, false, |
| 7909 false); | 7909 false); |
| 7910 | 7910 |
| 7911 ExecuteCalculateDrawProperties(root); | 7911 ExecuteCalculateDrawProperties(root); |
| 7912 | 7912 |
| 7913 EXPECT_EQ(test_layer->clip_rect(), gfx::RectF(-4, -4, 30, 30)); | 7913 EXPECT_EQ(gfx::Rect(-4, -4, 30, 30), test_layer->clip_rect()); |
| 7914 } | 7914 } |
| 7915 | 7915 |
| 7916 } // namespace | 7916 } // namespace |
| 7917 } // namespace cc | 7917 } // namespace cc |
| OLD | NEW |