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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 2948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2959 | 2959 |
2960 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); | 2960 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
2961 gfx::Rect expected_drawable_content_rect = target_surface_rect; | 2961 gfx::Rect expected_drawable_content_rect = target_surface_rect; |
2962 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( | 2962 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
2963 target_surface_rect, layer_to_surface_transform, layer_content_rect); | 2963 target_surface_rect, layer_to_surface_transform, layer_content_rect); |
2964 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); | 2964 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
2965 EXPECT_EQ(expected_drawable_content_rect, | 2965 EXPECT_EQ(expected_drawable_content_rect, |
2966 drawing_layer->drawable_content_rect()); | 2966 drawing_layer->drawable_content_rect()); |
2967 } | 2967 } |
2968 | 2968 |
2969 static bool projection_clips(const gfx::Transform& t, const gfx::RectF& r) { | |
danakj
2017/03/14 20:14:11
nit: ProjectionClips
Peter Mayo
2017/03/17 00:35:54
Done.
| |
2970 gfx::Transform inv_t(Inverse(t)); | |
danakj
2017/03/14 20:14:11
nit: inverted (or some not-shortened word/s)
Peter Mayo
2017/03/17 00:35:54
Done.
| |
2971 bool clipped = false; | |
2972 if (!clipped) | |
2973 MathUtil::ProjectPoint(inv_t, r.top_right(), &clipped); | |
2974 if (!clipped) | |
2975 MathUtil::ProjectPoint(inv_t, r.origin(), &clipped); | |
2976 if (!clipped) | |
2977 MathUtil::ProjectPoint(inv_t, r.bottom_right(), &clipped); | |
2978 if (!clipped) | |
2979 MathUtil::ProjectPoint(inv_t, r.bottom_left(), &clipped); | |
2980 return clipped; | |
2981 } | |
2982 | |
2969 TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { | 2983 TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
2970 // To determine visible rect in layer space, there needs to be an | 2984 // To determine visible rect in layer space, there needs to be an |
2971 // un-projection from surface space to layer space. When the original | 2985 // un-projection from surface space to layer space. When the original |
2972 // transform was a perspective projection that was clipped, it returns a rect | 2986 // transform was a perspective projection that was clipped, it returns a rect |
2973 // that encloses the clipped bounds. Un-projecting this new rect may require | 2987 // that encloses the clipped bounds. Un-projecting this new rect may require |
2974 // clipping again. | 2988 // clipping again. |
2975 | 2989 |
2976 // This sequence of transforms causes one corner of the layer to protrude | 2990 // This sequence of transforms causes one corner of the layer to protrude |
2977 // across the w = 0 plane, and should be clipped. | 2991 // across the w = 0 plane, and should be clipped. |
2978 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); | 2992 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
2979 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); | 2993 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
2980 gfx::Transform layer_to_surface_transform; | 2994 gfx::Transform layer_to_surface_transform; |
2981 layer_to_surface_transform.MakeIdentity(); | 2995 layer_to_surface_transform.MakeIdentity(); |
2982 layer_to_surface_transform.Translate(10, 10); | 2996 layer_to_surface_transform.Translate(10, 10); |
2983 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); | 2997 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
2984 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); | 2998 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
2985 layer_to_surface_transform.RotateAboutYAxis(45.0); | 2999 layer_to_surface_transform.RotateAboutYAxis(45.0); |
2986 layer_to_surface_transform.RotateAboutXAxis(80.0); | 3000 layer_to_surface_transform.RotateAboutXAxis(80.0); |
2987 layer_to_surface_transform.Translate(-10, -10); | 3001 layer_to_surface_transform.Translate(-10, -10); |
2988 | 3002 |
2989 // Sanity check that un-projection does indeed cause w < 0, otherwise this | 3003 // Sanity check that un-projection does indeed cause w < 0, otherwise this |
2990 // code is not testing the intended scenario. | 3004 // code is not testing the intended scenario. |
2991 bool clipped; | |
2992 gfx::RectF clipped_rect = MathUtil::MapClippedRect( | 3005 gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
2993 layer_to_surface_transform, gfx::RectF(layer_content_rect)); | 3006 layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
2994 MathUtil::ProjectQuad( | 3007 ASSERT_TRUE(projection_clips(layer_to_surface_transform, clipped_rect)); |
2995 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); | |
2996 ASSERT_TRUE(clipped); | |
2997 | 3008 |
2998 // Only the corner of the layer is not visible on the surface because of being | 3009 // Only the corner of the layer is not visible on the surface because of being |
2999 // clipped. But, the net result of rounding visible region to an axis-aligned | 3010 // clipped. But, the net result of rounding visible region to an axis-aligned |
3000 // rect is that the entire layer should still be considered visible. | 3011 // rect is that the entire layer should still be considered visible. |
3001 gfx::Rect expected_visible_layer_rect = layer_content_rect; | 3012 gfx::Rect expected_visible_layer_rect = layer_content_rect; |
3002 gfx::Rect expected_drawable_content_rect = target_surface_rect; | 3013 gfx::Rect expected_drawable_content_rect = target_surface_rect; |
3003 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( | 3014 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
3004 target_surface_rect, layer_to_surface_transform, layer_content_rect); | 3015 target_surface_rect, layer_to_surface_transform, layer_content_rect); |
3005 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); | 3016 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
3006 EXPECT_EQ(expected_drawable_content_rect, | 3017 EXPECT_EQ(expected_drawable_content_rect, |
(...skipping 7754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10761 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10772 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
10762 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10773 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
10763 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10774 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
10764 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10775 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
10765 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10776 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
10766 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10777 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
10767 } | 10778 } |
10768 | 10779 |
10769 } // namespace | 10780 } // namespace |
10770 } // namespace cc | 10781 } // namespace cc |
OLD | NEW |