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

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

Issue 12967018: cc: Avoid pointless gfx::Point/Size contructors when making Rects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RectFs as well Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 std::vector<scoped_refptr<Layer> > render_surface_layer_list; 2825 std::vector<scoped_refptr<Layer> > render_surface_layer_list;
2826 int dummy_max_texture_size = 512; 2826 int dummy_max_texture_size = 512;
2827 LayerTreeHostCommon::CalculateDrawProperties(parent.get(), 2827 LayerTreeHostCommon::CalculateDrawProperties(parent.get(),
2828 parent->bounds(), 2828 parent->bounds(),
2829 1.f, 2829 1.f,
2830 1.f, 2830 1.f,
2831 dummy_max_texture_size, 2831 dummy_max_texture_size,
2832 false, 2832 false,
2833 &render_surface_layer_list); 2833 &render_surface_layer_list);
2834 2834
2835 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(5, 5), gfx::Size(10, 10)), 2835 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
2836 grand_child1->drawable_content_rect()); 2836 grand_child1->drawable_content_rect());
2837 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), 2837 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
2838 grand_child3->drawable_content_rect()); 2838 grand_child3->drawable_content_rect());
2839 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(15, 15), gfx::Size(5, 5)), 2839 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
2840 grand_child3->drawable_content_rect()); 2840 grand_child3->drawable_content_rect());
2841 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); 2841 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2842 } 2842 }
2843 2843
2844 TEST(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { 2844 TEST(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
2845 // Verify that render surfaces (and their layers) get the appropriate 2845 // Verify that render surfaces (and their layers) get the appropriate
2846 // clip rects when their parent masksToBounds is true. 2846 // clip rects when their parent masksToBounds is true.
2847 // 2847 //
2848 // Layers that own render surfaces (at least for now) do not inherit any 2848 // Layers that own render surfaces (at least for now) do not inherit any
2849 // clipping; instead the surface will enforce the clip for the entire subtree. 2849 // clipping; instead the surface will enforce the clip for the entire subtree.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 2977
2978 ASSERT_TRUE(grand_child1->render_surface()); 2978 ASSERT_TRUE(grand_child1->render_surface());
2979 ASSERT_TRUE(grand_child2->render_surface()); 2979 ASSERT_TRUE(grand_child2->render_surface());
2980 ASSERT_TRUE(grand_child3->render_surface()); 2980 ASSERT_TRUE(grand_child3->render_surface());
2981 // Because grand_child4 is entirely clipped, it is expected to not have a 2981 // Because grand_child4 is entirely clipped, it is expected to not have a
2982 // render surface. 2982 // render surface.
2983 EXPECT_FALSE(grand_child4->render_surface()); 2983 EXPECT_FALSE(grand_child4->render_surface());
2984 2984
2985 // Surfaces are clipped by their parent, but un-affected by the owning layer's 2985 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2986 // masksToBounds. 2986 // masksToBounds.
2987 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(20, 20)), 2987 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2988 grand_child1->render_surface()->clip_rect()); 2988 grand_child1->render_surface()->clip_rect());
2989 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(20, 20)), 2989 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2990 grand_child2->render_surface()->clip_rect()); 2990 grand_child2->render_surface()->clip_rect());
2991 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(20, 20)), 2991 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2992 grand_child3->render_surface()->clip_rect()); 2992 grand_child3->render_surface()->clip_rect());
2993 } 2993 }
2994 2994
2995 TEST(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { 2995 TEST(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
2996 scoped_refptr<Layer> parent = Layer::Create(); 2996 scoped_refptr<Layer> parent = Layer::Create();
2997 scoped_refptr<Layer> render_surface1 = Layer::Create(); 2997 scoped_refptr<Layer> render_surface1 = Layer::Create();
2998 scoped_refptr<Layer> render_surface2 = Layer::Create(); 2998 scoped_refptr<Layer> render_surface2 = Layer::Create();
2999 scoped_refptr<Layer> child_of_root = Layer::Create(); 2999 scoped_refptr<Layer> child_of_root = Layer::Create();
3000 scoped_refptr<Layer> child_of_rs1 = Layer::Create(); 3000 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
3001 scoped_refptr<Layer> child_of_rs2 = Layer::Create(); 3001 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); 3202 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
3203 EXPECT_FLOAT_EQ( 3203 EXPECT_FLOAT_EQ(
3204 5.0, 3204 5.0,
3205 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); 3205 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
3206 } 3206 }
3207 3207
3208 TEST(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { 3208 TEST(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
3209 // Test the calculateVisibleRect() function works correctly for identity 3209 // Test the calculateVisibleRect() function works correctly for identity
3210 // transforms. 3210 // transforms.
3211 3211
3212 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3212 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3213 gfx::Transform layer_to_surface_transform; 3213 gfx::Transform layer_to_surface_transform;
3214 3214
3215 // Case 1: Layer is contained within the surface. 3215 // Case 1: Layer is contained within the surface.
3216 gfx::Rect layer_content_rect = 3216 gfx::Rect layer_content_rect =
3217 gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30)); 3217 gfx::Rect(10, 10, 30, 30);
3218 gfx::Rect expected = gfx::Rect(gfx::Point(10, 10), gfx::Size(30, 30)); 3218 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
3219 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3219 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3220 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3220 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3221 EXPECT_RECT_EQ(expected, actual); 3221 EXPECT_RECT_EQ(expected, actual);
3222 3222
3223 // Case 2: Layer is outside the surface rect. 3223 // Case 2: Layer is outside the surface rect.
3224 layer_content_rect = gfx::Rect(gfx::Point(120, 120), gfx::Size(30, 30)); 3224 layer_content_rect = gfx::Rect(120, 120, 30, 30);
3225 actual = LayerTreeHostCommon::CalculateVisibleRect( 3225 actual = LayerTreeHostCommon::CalculateVisibleRect(
3226 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3226 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3227 EXPECT_TRUE(actual.IsEmpty()); 3227 EXPECT_TRUE(actual.IsEmpty());
3228 3228
3229 // Case 3: Layer is partially overlapping the surface rect. 3229 // Case 3: Layer is partially overlapping the surface rect.
3230 layer_content_rect = gfx::Rect(gfx::Point(80, 80), gfx::Size(30, 30)); 3230 layer_content_rect = gfx::Rect(80, 80, 30, 30);
3231 expected = gfx::Rect(gfx::Point(80, 80), gfx::Size(20, 20)); 3231 expected = gfx::Rect(80, 80, 20, 20);
3232 actual = LayerTreeHostCommon::CalculateVisibleRect( 3232 actual = LayerTreeHostCommon::CalculateVisibleRect(
3233 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3233 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3234 EXPECT_RECT_EQ(expected, actual); 3234 EXPECT_RECT_EQ(expected, actual);
3235 } 3235 }
3236 3236
3237 TEST(LayerTreeHostCommonTest, VisibleRectForTranslations) { 3237 TEST(LayerTreeHostCommonTest, VisibleRectForTranslations) {
3238 // Test the calculateVisibleRect() function works correctly for scaling 3238 // Test the calculateVisibleRect() function works correctly for scaling
3239 // transforms. 3239 // transforms.
3240 3240
3241 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3241 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3242 gfx::Rect layer_content_rect = gfx::Rect(gfx::Point(), gfx::Size(30, 30)); 3242 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
3243 gfx::Transform layer_to_surface_transform; 3243 gfx::Transform layer_to_surface_transform;
3244 3244
3245 // Case 1: Layer is contained within the surface. 3245 // Case 1: Layer is contained within the surface.
3246 layer_to_surface_transform.MakeIdentity(); 3246 layer_to_surface_transform.MakeIdentity();
3247 layer_to_surface_transform.Translate(10.0, 10.0); 3247 layer_to_surface_transform.Translate(10.0, 10.0);
3248 gfx::Rect expected = gfx::Rect(gfx::Point(), gfx::Size(30, 30)); 3248 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
3249 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3249 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3250 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3250 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3251 EXPECT_RECT_EQ(expected, actual); 3251 EXPECT_RECT_EQ(expected, actual);
3252 3252
3253 // Case 2: Layer is outside the surface rect. 3253 // Case 2: Layer is outside the surface rect.
3254 layer_to_surface_transform.MakeIdentity(); 3254 layer_to_surface_transform.MakeIdentity();
3255 layer_to_surface_transform.Translate(120.0, 120.0); 3255 layer_to_surface_transform.Translate(120.0, 120.0);
3256 actual = LayerTreeHostCommon::CalculateVisibleRect( 3256 actual = LayerTreeHostCommon::CalculateVisibleRect(
3257 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3257 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3258 EXPECT_TRUE(actual.IsEmpty()); 3258 EXPECT_TRUE(actual.IsEmpty());
3259 3259
3260 // Case 3: Layer is partially overlapping the surface rect. 3260 // Case 3: Layer is partially overlapping the surface rect.
3261 layer_to_surface_transform.MakeIdentity(); 3261 layer_to_surface_transform.MakeIdentity();
3262 layer_to_surface_transform.Translate(80.0, 80.0); 3262 layer_to_surface_transform.Translate(80.0, 80.0);
3263 expected = gfx::Rect(gfx::Point(), gfx::Size(20, 20)); 3263 expected = gfx::Rect(0, 0, 20, 20);
3264 actual = LayerTreeHostCommon::CalculateVisibleRect( 3264 actual = LayerTreeHostCommon::CalculateVisibleRect(
3265 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3265 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3266 EXPECT_RECT_EQ(expected, actual); 3266 EXPECT_RECT_EQ(expected, actual);
3267 } 3267 }
3268 3268
3269 TEST(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { 3269 TEST(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
3270 // Test the calculateVisibleRect() function works correctly for rotations 3270 // Test the calculateVisibleRect() function works correctly for rotations
3271 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() 3271 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
3272 // should return the g in the layer's space. 3272 // should return the g in the layer's space.
3273 3273
3274 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3274 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3275 gfx::Rect layer_content_rect = gfx::Rect(gfx::Point(), gfx::Size(30, 30)); 3275 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
3276 gfx::Transform layer_to_surface_transform; 3276 gfx::Transform layer_to_surface_transform;
3277 3277
3278 // Case 1: Layer is contained within the surface. 3278 // Case 1: Layer is contained within the surface.
3279 layer_to_surface_transform.MakeIdentity(); 3279 layer_to_surface_transform.MakeIdentity();
3280 layer_to_surface_transform.Translate(50.0, 50.0); 3280 layer_to_surface_transform.Translate(50.0, 50.0);
3281 layer_to_surface_transform.Rotate(45.0); 3281 layer_to_surface_transform.Rotate(45.0);
3282 gfx::Rect expected = gfx::Rect(gfx::Point(), gfx::Size(30, 30)); 3282 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
3283 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3283 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3284 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3284 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3285 EXPECT_RECT_EQ(expected, actual); 3285 EXPECT_RECT_EQ(expected, actual);
3286 3286
3287 // Case 2: Layer is outside the surface rect. 3287 // Case 2: Layer is outside the surface rect.
3288 layer_to_surface_transform.MakeIdentity(); 3288 layer_to_surface_transform.MakeIdentity();
3289 layer_to_surface_transform.Translate(-50.0, 0.0); 3289 layer_to_surface_transform.Translate(-50.0, 0.0);
3290 layer_to_surface_transform.Rotate(45.0); 3290 layer_to_surface_transform.Rotate(45.0);
3291 actual = LayerTreeHostCommon::CalculateVisibleRect( 3291 actual = LayerTreeHostCommon::CalculateVisibleRect(
3292 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3292 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3293 EXPECT_TRUE(actual.IsEmpty()); 3293 EXPECT_TRUE(actual.IsEmpty());
3294 3294
3295 // Case 3: The layer is rotated about its top-left corner. In surface space, 3295 // Case 3: The layer is rotated about its top-left corner. In surface space,
3296 // the layer is oriented diagonally, with the left half outside of the render 3296 // the layer is oriented diagonally, with the left half outside of the render
3297 // surface. In this case, the g should still be the entire layer 3297 // surface. In this case, the g should still be the entire layer
3298 // (remember the g is computed in layer space); both the top-left 3298 // (remember the g is computed in layer space); both the top-left
3299 // and bottom-right corners of the layer are still visible. 3299 // and bottom-right corners of the layer are still visible.
3300 layer_to_surface_transform.MakeIdentity(); 3300 layer_to_surface_transform.MakeIdentity();
3301 layer_to_surface_transform.Rotate(45.0); 3301 layer_to_surface_transform.Rotate(45.0);
3302 expected = gfx::Rect(gfx::Point(), gfx::Size(30, 30)); 3302 expected = gfx::Rect(0, 0, 30, 30);
3303 actual = LayerTreeHostCommon::CalculateVisibleRect( 3303 actual = LayerTreeHostCommon::CalculateVisibleRect(
3304 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3304 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3305 EXPECT_RECT_EQ(expected, actual); 3305 EXPECT_RECT_EQ(expected, actual);
3306 3306
3307 // Case 4: The layer is rotated about its top-left corner, and translated 3307 // Case 4: The layer is rotated about its top-left corner, and translated
3308 // upwards. In surface space, the layer is oriented diagonally, with only the 3308 // upwards. In surface space, the layer is oriented diagonally, with only the
3309 // top corner of the surface overlapping the layer. In layer space, the render 3309 // top corner of the surface overlapping the layer. In layer space, the render
3310 // surface overlaps the right side of the layer. The g should be 3310 // surface overlaps the right side of the layer. The g should be
3311 // the layer's right half. 3311 // the layer's right half.
3312 layer_to_surface_transform.MakeIdentity(); 3312 layer_to_surface_transform.MakeIdentity();
3313 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); 3313 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
3314 layer_to_surface_transform.Rotate(45.0); 3314 layer_to_surface_transform.Rotate(45.0);
3315 expected = gfx::Rect(gfx::Point(15, 0), 3315 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
3316 gfx::Size(15, 30)); // right half of layer bounds.
3317 actual = LayerTreeHostCommon::CalculateVisibleRect( 3316 actual = LayerTreeHostCommon::CalculateVisibleRect(
3318 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3317 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3319 EXPECT_RECT_EQ(expected, actual); 3318 EXPECT_RECT_EQ(expected, actual);
3320 } 3319 }
3321 3320
3322 TEST(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { 3321 TEST(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
3323 // Test that the calculateVisibleRect() function works correctly for 3d 3322 // Test that the calculateVisibleRect() function works correctly for 3d
3324 // transforms. 3323 // transforms.
3325 3324
3326 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3325 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3327 gfx::Rect layer_content_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3326 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
3328 gfx::Transform layer_to_surface_transform; 3327 gfx::Transform layer_to_surface_transform;
3329 3328
3330 // Case 1: Orthographic projection of a layer rotated about y-axis by 45 3329 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
3331 // degrees, should be fully contained in the render surface. 3330 // degrees, should be fully contained in the render surface.
3332 layer_to_surface_transform.MakeIdentity(); 3331 layer_to_surface_transform.MakeIdentity();
3333 layer_to_surface_transform.RotateAboutYAxis(45.0); 3332 layer_to_surface_transform.RotateAboutYAxis(45.0);
3334 gfx::Rect expected = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3333 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
3335 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3334 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3336 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3335 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3337 EXPECT_RECT_EQ(expected, actual); 3336 EXPECT_RECT_EQ(expected, actual);
3338 3337
3339 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 3338 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
3340 // degrees, but shifted to the side so only the right-half the layer would be 3339 // degrees, but shifted to the side so only the right-half the layer would be
3341 // visible on the surface. 3340 // visible on the surface.
3342 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. 3341 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
3343 double half_width_of_rotated_layer = (100.0 / sqrt(2.0)) * 0.5; 3342 double half_width_of_rotated_layer = (100.0 / sqrt(2.0)) * 0.5;
3344 layer_to_surface_transform.MakeIdentity(); 3343 layer_to_surface_transform.MakeIdentity();
3345 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); 3344 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
3346 layer_to_surface_transform.RotateAboutYAxis( 3345 layer_to_surface_transform.RotateAboutYAxis(
3347 45.0); // rotates about the left edge of the layer 3346 45.0); // Rotates about the left edge of the layer.
3348 expected = gfx::Rect(gfx::Point(50, 0), 3347 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
3349 gfx::Size(50, 100)); // right half of the layer.
3350 actual = LayerTreeHostCommon::CalculateVisibleRect( 3348 actual = LayerTreeHostCommon::CalculateVisibleRect(
3351 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3349 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3352 EXPECT_RECT_EQ(expected, actual); 3350 EXPECT_RECT_EQ(expected, actual);
3353 } 3351 }
3354 3352
3355 TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { 3353 TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
3356 // Test the calculateVisibleRect() function works correctly when the layer has 3354 // Test the calculateVisibleRect() function works correctly when the layer has
3357 // a perspective projection onto the target surface. 3355 // a perspective projection onto the target surface.
3358 3356
3359 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3357 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3360 gfx::Rect layer_content_rect = 3358 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
3361 gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200));
3362 gfx::Transform layer_to_surface_transform; 3359 gfx::Transform layer_to_surface_transform;
3363 3360
3364 // Case 1: Even though the layer is twice as large as the surface, due to 3361 // Case 1: Even though the layer is twice as large as the surface, due to
3365 // perspective foreshortening, the layer will fit fully in the surface when 3362 // perspective foreshortening, the layer will fit fully in the surface when
3366 // its translated more than the perspective amount. 3363 // its translated more than the perspective amount.
3367 layer_to_surface_transform.MakeIdentity(); 3364 layer_to_surface_transform.MakeIdentity();
3368 3365
3369 // The following sequence of transforms applies the perspective about the 3366 // The following sequence of transforms applies the perspective about the
3370 // center of the surface. 3367 // center of the surface.
3371 layer_to_surface_transform.Translate(50.0, 50.0); 3368 layer_to_surface_transform.Translate(50.0, 50.0);
3372 layer_to_surface_transform.ApplyPerspectiveDepth(9.0); 3369 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
3373 layer_to_surface_transform.Translate(-50.0, -50.0); 3370 layer_to_surface_transform.Translate(-50.0, -50.0);
3374 3371
3375 // This translate places the layer in front of the surface's projection plane. 3372 // This translate places the layer in front of the surface's projection plane.
3376 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); 3373 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
3377 3374
3378 gfx::Rect expected = gfx::Rect(gfx::Point(-50, -50), gfx::Size(200, 200)); 3375 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
3379 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3376 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3380 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3377 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3381 EXPECT_RECT_EQ(expected, actual); 3378 EXPECT_RECT_EQ(expected, actual);
3382 3379
3383 // Case 2: same projection as before, except that the layer is also translated 3380 // Case 2: same projection as before, except that the layer is also translated
3384 // to the side, so that only the right half of the layer should be visible. 3381 // to the side, so that only the right half of the layer should be visible.
3385 // 3382 //
3386 // Explanation of expected result: The perspective ratio is (z distance 3383 // Explanation of expected result: The perspective ratio is (z distance
3387 // between layer and camera origin) / (z distance between projection plane and 3384 // between layer and camera origin) / (z distance between projection plane and
3388 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to 3385 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
3389 // move a layer by translating -50 units in projected surface units (so that 3386 // move a layer by translating -50 units in projected surface units (so that
3390 // only half of it is visible), then we would need to translate by (-36 / 9) * 3387 // only half of it is visible), then we would need to translate by (-36 / 9) *
3391 // -50 == -200 in the layer's units. 3388 // -50 == -200 in the layer's units.
3392 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); 3389 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
3393 expected = gfx::Rect( 3390 expected = gfx::Rect(
3394 gfx::Point(50, -50), 3391 gfx::Point(50, -50),
3395 gfx::Size(100, 200)); // The right half of the layer's bounding rect. 3392 gfx::Size(100, 200)); // The right half of the layer's bounding rect.
3396 actual = LayerTreeHostCommon::CalculateVisibleRect( 3393 actual = LayerTreeHostCommon::CalculateVisibleRect(
3397 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3394 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3398 EXPECT_RECT_EQ(expected, actual); 3395 EXPECT_RECT_EQ(expected, actual);
3399 } 3396 }
3400 3397
3401 TEST(LayerTreeHostCommonTest, 3398 TEST(LayerTreeHostCommonTest,
3402 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { 3399 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
3403 // There is currently no explicit concept of an orthographic projection plane 3400 // There is currently no explicit concept of an orthographic projection plane
3404 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that 3401 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
3405 // are technically behind the surface in an orthographic world should not be 3402 // are technically behind the surface in an orthographic world should not be
3406 // clipped when they are flattened to the surface. 3403 // clipped when they are flattened to the surface.
3407 3404
3408 gfx::Rect target_surface_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3405 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3409 gfx::Rect layer_content_rect = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3406 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
3410 gfx::Transform layer_to_surface_transform; 3407 gfx::Transform layer_to_surface_transform;
3411 3408
3412 // This sequence of transforms effectively rotates the layer about the y-axis 3409 // This sequence of transforms effectively rotates the layer about the y-axis
3413 // at the center of the layer. 3410 // at the center of the layer.
3414 layer_to_surface_transform.MakeIdentity(); 3411 layer_to_surface_transform.MakeIdentity();
3415 layer_to_surface_transform.Translate(50.0, 0.0); 3412 layer_to_surface_transform.Translate(50.0, 0.0);
3416 layer_to_surface_transform.RotateAboutYAxis(45.0); 3413 layer_to_surface_transform.RotateAboutYAxis(45.0);
3417 layer_to_surface_transform.Translate(-50.0, 0.0); 3414 layer_to_surface_transform.Translate(-50.0, 0.0);
3418 3415
3419 gfx::Rect expected = gfx::Rect(gfx::Point(), gfx::Size(100, 100)); 3416 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
3420 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3417 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3421 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3418 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3422 EXPECT_RECT_EQ(expected, actual); 3419 EXPECT_RECT_EQ(expected, actual);
3423 } 3420 }
3424 3421
3425 TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { 3422 TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
3426 // Test the calculateVisibleRect() function works correctly when projecting a 3423 // Test the calculateVisibleRect() function works correctly when projecting a
3427 // surface onto a layer, but the layer is partially behind the camera (not 3424 // surface onto a layer, but the layer is partially behind the camera (not
3428 // just behind the projection plane). In this case, the cartesian coordinates 3425 // just behind the projection plane). In this case, the cartesian coordinates
3429 // may seem to be valid, but actually they are not. The visible rect needs to 3426 // may seem to be valid, but actually they are not. The visible rect needs to
3430 // be properly clipped by the w = 0 plane in homogeneous coordinates before 3427 // be properly clipped by the w = 0 plane in homogeneous coordinates before
3431 // converting to cartesian coordinates. 3428 // converting to cartesian coordinates.
3432 3429
3433 gfx::Rect target_surface_rect = 3430 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
3434 gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100));
3435 gfx::Rect layer_content_rect = 3431 gfx::Rect layer_content_rect =
3436 gfx::Rect(gfx::Point(-10, -1), gfx::Size(20, 2)); 3432 gfx::Rect(-10, -1, 20, 2);
3437 gfx::Transform layer_to_surface_transform; 3433 gfx::Transform layer_to_surface_transform;
3438 3434
3439 // The layer is positioned so that the right half of the layer should be in 3435 // The layer is positioned so that the right half of the layer should be in
3440 // front of the camera, while the other half is behind the surface's 3436 // front of the camera, while the other half is behind the surface's
3441 // projection plane. The following sequence of transforms applies the 3437 // projection plane. The following sequence of transforms applies the
3442 // perspective and rotation about the center of the layer. 3438 // perspective and rotation about the center of the layer.
3443 layer_to_surface_transform.MakeIdentity(); 3439 layer_to_surface_transform.MakeIdentity();
3444 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); 3440 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
3445 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); 3441 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
3446 layer_to_surface_transform.RotateAboutYAxis(45.0); 3442 layer_to_surface_transform.RotateAboutYAxis(45.0);
(...skipping 17 matching lines...) Expand all
3464 TEST(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { 3460 TEST(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
3465 // To determine visible rect in layer space, there needs to be an 3461 // To determine visible rect in layer space, there needs to be an
3466 // un-projection from surface space to layer space. When the original 3462 // un-projection from surface space to layer space. When the original
3467 // transform was a perspective projection that was clipped, it returns a rect 3463 // transform was a perspective projection that was clipped, it returns a rect
3468 // that encloses the clipped bounds. Un-projecting this new rect may require 3464 // that encloses the clipped bounds. Un-projecting this new rect may require
3469 // clipping again. 3465 // clipping again.
3470 3466
3471 // This sequence of transforms causes one corner of the layer to protrude 3467 // This sequence of transforms causes one corner of the layer to protrude
3472 // across the w = 0 plane, and should be clipped. 3468 // across the w = 0 plane, and should be clipped.
3473 gfx::Rect target_surface_rect = 3469 gfx::Rect target_surface_rect =
3474 gfx::Rect(gfx::Point(-50, -50), gfx::Size(100, 100)); 3470 gfx::Rect(-50, -50, 100, 100);
3475 gfx::Rect layer_content_rect = 3471 gfx::Rect layer_content_rect =
3476 gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20)); 3472 gfx::Rect(-10, -10, 20, 20);
3477 gfx::Transform layer_to_surface_transform; 3473 gfx::Transform layer_to_surface_transform;
3478 layer_to_surface_transform.MakeIdentity(); 3474 layer_to_surface_transform.MakeIdentity();
3479 layer_to_surface_transform.ApplyPerspectiveDepth(1.0); 3475 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
3480 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); 3476 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
3481 layer_to_surface_transform.RotateAboutYAxis(45.0); 3477 layer_to_surface_transform.RotateAboutYAxis(45.0);
3482 layer_to_surface_transform.RotateAboutXAxis(80.0); 3478 layer_to_surface_transform.RotateAboutXAxis(80.0);
3483 3479
3484 // Sanity check that un-projection does indeed cause w < 0, otherwise this 3480 // Sanity check that un-projection does indeed cause w < 0, otherwise this
3485 // code is not testing the intended scenario. 3481 // code is not testing the intended scenario.
3486 bool clipped; 3482 bool clipped;
3487 gfx::RectF clipped_rect = 3483 gfx::RectF clipped_rect =
3488 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); 3484 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
3489 MathUtil::ProjectQuad( 3485 MathUtil::ProjectQuad(
3490 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); 3486 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
3491 ASSERT_TRUE(clipped); 3487 ASSERT_TRUE(clipped);
3492 3488
3493 // Only the corner of the layer is not visible on the surface because of being 3489 // Only the corner of the layer is not visible on the surface because of being
3494 // clipped. But, the net result of rounding visible region to an axis-aligned 3490 // clipped. But, the net result of rounding visible region to an axis-aligned
3495 // rect is that the entire layer should still be considered visible. 3491 // rect is that the entire layer should still be considered visible.
3496 gfx::Rect expected = gfx::Rect(gfx::Point(-10, -10), gfx::Size(20, 20)); 3492 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
3497 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 3493 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3498 target_surface_rect, layer_content_rect, layer_to_surface_transform); 3494 target_surface_rect, layer_content_rect, layer_to_surface_transform);
3499 EXPECT_RECT_EQ(expected, actual); 3495 EXPECT_RECT_EQ(expected, actual);
3500 } 3496 }
3501 3497
3502 TEST(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { 3498 TEST(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
3503 scoped_refptr<Layer> root = Layer::Create(); 3499 scoped_refptr<Layer> root = Layer::Create();
3504 scoped_refptr<LayerWithForcedDrawsContent> child1 = 3500 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3505 make_scoped_refptr(new LayerWithForcedDrawsContent()); 3501 make_scoped_refptr(new LayerWithForcedDrawsContent());
3506 scoped_refptr<LayerWithForcedDrawsContent> child2 = 3502 scoped_refptr<LayerWithForcedDrawsContent> child2 =
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); 4635 render_surface_layer_list[1]->render_surface()->layer_list()[0]->id());
4640 EXPECT_EQ( 4636 EXPECT_EQ(
4641 child_of_animating_surface->id(), 4637 child_of_animating_surface->id(),
4642 render_surface_layer_list[1]->render_surface()->layer_list()[1]->id()); 4638 render_surface_layer_list[1]->render_surface()->layer_list()[1]->id());
4643 4639
4644 EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); 4640 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4645 4641
4646 // The animating layers should have a visible content rect that represents the 4642 // The animating layers should have a visible content rect that represents the
4647 // area of the front face that is within the viewport. 4643 // area of the front face that is within the viewport.
4648 EXPECT_EQ(animating_child->visible_content_rect(), 4644 EXPECT_EQ(animating_child->visible_content_rect(),
4649 gfx::Rect(gfx::Point(), animating_child->content_bounds())); 4645 gfx::Rect(animating_child->content_bounds()));
4650 EXPECT_EQ(animating_surface->visible_content_rect(), 4646 EXPECT_EQ(animating_surface->visible_content_rect(),
4651 gfx::Rect(gfx::Point(), animating_surface->content_bounds())); 4647 gfx::Rect(animating_surface->content_bounds()));
4652 // And layers in the subtree of the animating layer should have valid visible 4648 // And layers in the subtree of the animating layer should have valid visible
4653 // content rects also. 4649 // content rects also.
4654 EXPECT_EQ( 4650 EXPECT_EQ(
4655 child_of_animating_surface->visible_content_rect(), 4651 child_of_animating_surface->visible_content_rect(),
4656 gfx::Rect(gfx::Point(), child_of_animating_surface->content_bounds())); 4652 gfx::Rect(child_of_animating_surface->content_bounds()));
4657 } 4653 }
4658 4654
4659 TEST(LayerTreeHostCommonTest, 4655 TEST(LayerTreeHostCommonTest,
4660 BackFaceCullingWithPreserves3dForFlatteningSurface) { 4656 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4661 // Verify the behavior of back-face culling for a render surface that is 4657 // Verify the behavior of back-face culling for a render surface that is
4662 // created when it flattens its subtree, and its parent has preserves-3d. 4658 // created when it flattens its subtree, and its parent has preserves-3d.
4663 4659
4664 const gfx::Transform identity_matrix; 4660 const gfx::Transform identity_matrix;
4665 scoped_refptr<Layer> parent = Layer::Create(); 4661 scoped_refptr<Layer> parent = Layer::Create();
4666 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = 4662 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
5256 1.f, 5252 1.f,
5257 dummy_max_texture_size, 5253 dummy_max_texture_size,
5258 false, 5254 false,
5259 &render_surface_layer_list, 5255 &render_surface_layer_list,
5260 false); 5256 false);
5261 5257
5262 // Sanity check the scenario we just created. 5258 // Sanity check the scenario we just created.
5263 // The visible content rect for test_layer is actually 100x100, even though 5259 // The visible content rect for test_layer is actually 100x100, even though
5264 // its layout size is 50x50, positioned at 25x25. 5260 // its layout size is 50x50, positioned at 25x25.
5265 LayerImpl* test_layer = root->children()[0]; 5261 LayerImpl* test_layer = root->children()[0];
5266 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), 5262 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
5267 test_layer->visible_content_rect()); 5263 test_layer->visible_content_rect());
5268 ASSERT_EQ(1u, render_surface_layer_list.size()); 5264 ASSERT_EQ(1u, render_surface_layer_list.size());
5269 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); 5265 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5270 5266
5271 // Hit testing for a point outside the layer should return a null pointer (the 5267 // Hit testing for a point outside the layer should return a null pointer (the
5272 // root layer does not draw content, so it will not be hit tested either). 5268 // root layer does not draw content, so it will not be hit tested either).
5273 gfx::Point test_point(101, 101); 5269 gfx::Point test_point(101, 101);
5274 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5270 LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5275 test_point, render_surface_layer_list); 5271 test_point, render_surface_layer_list);
5276 EXPECT_FALSE(result_layer); 5272 EXPECT_FALSE(result_layer);
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
6291 1.f, 6287 1.f,
6292 dummy_max_texture_size, 6288 dummy_max_texture_size,
6293 false, 6289 false,
6294 &render_surface_layer_list, 6290 &render_surface_layer_list,
6295 false); 6291 false);
6296 6292
6297 // Sanity check the scenario we just created. 6293 // Sanity check the scenario we just created.
6298 // The visible content rect for test_layer is actually 100x100, even though 6294 // The visible content rect for test_layer is actually 100x100, even though
6299 // its layout size is 50x50, positioned at 25x25. 6295 // its layout size is 50x50, positioned at 25x25.
6300 LayerImpl* test_layer = root->children()[0]; 6296 LayerImpl* test_layer = root->children()[0];
6301 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), 6297 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect());
6302 test_layer->visible_content_rect());
6303 ASSERT_EQ(1u, render_surface_layer_list.size()); 6298 ASSERT_EQ(1u, render_surface_layer_list.size());
6304 ASSERT_EQ(1u, root->render_surface()->layer_list().size()); 6299 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
6305 6300
6306 // Hit checking for a point outside the layer should return a null pointer 6301 // Hit checking for a point outside the layer should return a null pointer
6307 // (the root layer does not draw content, so it will not be tested either). 6302 // (the root layer does not draw content, so it will not be tested either).
6308 gfx::Point test_point(76, 76); 6303 gfx::Point test_point(76, 76);
6309 LayerImpl* result_layer = 6304 LayerImpl* result_layer =
6310 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( 6305 LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion(
6311 test_point, render_surface_layer_list); 6306 test_point, render_surface_layer_list);
6312 EXPECT_FALSE(result_layer); 6307 EXPECT_FALSE(result_layer);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
6698 EXPECT_EQ(1u, render_surface_layer_list.size()); 6693 EXPECT_EQ(1u, render_surface_layer_list.size());
6699 6694
6700 // Verify parent transforms 6695 // Verify parent transforms
6701 gfx::Transform expected_parent_transform; 6696 gfx::Transform expected_parent_transform;
6702 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 6697 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6703 parent->screen_space_transform()); 6698 parent->screen_space_transform());
6704 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 6699 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6705 parent->draw_transform()); 6700 parent->draw_transform());
6706 6701
6707 // Verify results of transformed parent rects 6702 // Verify results of transformed parent rects
6708 gfx::RectF parent_content_bounds(gfx::PointF(), 6703 gfx::RectF parent_content_bounds(parent->content_bounds());
6709 gfx::SizeF(parent->content_bounds()));
6710 6704
6711 gfx::RectF parent_draw_rect = 6705 gfx::RectF parent_draw_rect =
6712 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); 6706 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6713 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( 6707 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6714 parent->screen_space_transform(), parent_content_bounds); 6708 parent->screen_space_transform(), parent_content_bounds);
6715 6709
6716 gfx::RectF expected_parent_draw_rect(gfx::PointF(), parent->bounds()); 6710 gfx::RectF expected_parent_draw_rect(parent->bounds());
6717 expected_parent_draw_rect.Scale(device_scale_factor); 6711 expected_parent_draw_rect.Scale(device_scale_factor);
6718 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); 6712 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6719 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); 6713 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
6720 6714
6721 // Verify child and child_empty transforms. They should match. 6715 // Verify child and child_empty transforms. They should match.
6722 gfx::Transform expected_child_transform; 6716 gfx::Transform expected_child_transform;
6723 expected_child_transform.Translate( 6717 expected_child_transform.Translate(
6724 device_scale_factor * child->position().x(), 6718 device_scale_factor * child->position().x(),
6725 device_scale_factor * child->position().y()); 6719 device_scale_factor * child->position().y());
6726 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6720 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6727 child->draw_transform()); 6721 child->draw_transform());
6728 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6722 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6729 child->screen_space_transform()); 6723 child->screen_space_transform());
6730 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6724 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6731 child_empty->draw_transform()); 6725 child_empty->draw_transform());
6732 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6726 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6733 child_empty->screen_space_transform()); 6727 child_empty->screen_space_transform());
6734 6728
6735 // Verify results of transformed child and child_empty rects. They should 6729 // Verify results of transformed child and child_empty rects. They should
6736 // match. 6730 // match.
6737 gfx::RectF child_content_bounds(gfx::PointF(), 6731 gfx::RectF child_content_bounds(child->content_bounds());
6738 gfx::SizeF(child->content_bounds()));
6739 6732
6740 gfx::RectF child_draw_rect = 6733 gfx::RectF child_draw_rect =
6741 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); 6734 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6742 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( 6735 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6743 child->screen_space_transform(), child_content_bounds); 6736 child->screen_space_transform(), child_content_bounds);
6744 6737
6745 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( 6738 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
6746 child_empty->draw_transform(), child_content_bounds); 6739 child_empty->draw_transform(), child_content_bounds);
6747 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( 6740 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
6748 child_empty->screen_space_transform(), child_content_bounds); 6741 child_empty->screen_space_transform(), child_content_bounds);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
6936 EXPECT_EQ(1u, render_surface_layer_list.size()); 6929 EXPECT_EQ(1u, render_surface_layer_list.size());
6937 6930
6938 // Verify parent transforms 6931 // Verify parent transforms
6939 gfx::Transform expected_parent_transform; 6932 gfx::Transform expected_parent_transform;
6940 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 6933 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6941 parent->screen_space_transform()); 6934 parent->screen_space_transform());
6942 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, 6935 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
6943 parent->draw_transform()); 6936 parent->draw_transform());
6944 6937
6945 // Verify results of transformed parent rects 6938 // Verify results of transformed parent rects
6946 gfx::RectF parent_content_bounds(gfx::PointF(), 6939 gfx::RectF parent_content_bounds(parent->content_bounds());
6947 gfx::SizeF(parent->content_bounds()));
6948 6940
6949 gfx::RectF parent_draw_rect = 6941 gfx::RectF parent_draw_rect =
6950 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); 6942 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
6951 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( 6943 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
6952 parent->screen_space_transform(), parent_content_bounds); 6944 parent->screen_space_transform(), parent_content_bounds);
6953 6945
6954 gfx::RectF expected_parent_draw_rect(gfx::PointF(), parent->bounds()); 6946 gfx::RectF expected_parent_draw_rect(parent->bounds());
6955 expected_parent_draw_rect.Scale(device_scale_factor); 6947 expected_parent_draw_rect.Scale(device_scale_factor);
6956 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); 6948 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
6957 expected_parent_draw_rect.set_height( 6949 expected_parent_draw_rect.set_height(
6958 ceil(expected_parent_draw_rect.height())); 6950 ceil(expected_parent_draw_rect.height()));
6959 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); 6951 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
6960 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); 6952 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
6961 6953
6962 // Verify child transforms 6954 // Verify child transforms
6963 gfx::Transform expected_child_transform; 6955 gfx::Transform expected_child_transform;
6964 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6956 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6965 child->draw_transform()); 6957 child->draw_transform());
6966 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, 6958 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
6967 child->screen_space_transform()); 6959 child->screen_space_transform());
6968 6960
6969 // Verify results of transformed child rects 6961 // Verify results of transformed child rects
6970 gfx::RectF child_content_bounds(gfx::PointF(), 6962 gfx::RectF child_content_bounds(child->content_bounds());
6971 gfx::SizeF(child->content_bounds()));
6972 6963
6973 gfx::RectF child_draw_rect = 6964 gfx::RectF child_draw_rect =
6974 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); 6965 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
6975 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( 6966 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
6976 child->screen_space_transform(), child_content_bounds); 6967 child->screen_space_transform(), child_content_bounds);
6977 6968
6978 gfx::RectF expected_child_draw_rect(gfx::PointF(), child->bounds()); 6969 gfx::RectF expected_child_draw_rect(child->bounds());
6979 expected_child_draw_rect.Scale(device_scale_factor); 6970 expected_child_draw_rect.Scale(device_scale_factor);
6980 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); 6971 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
6981 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); 6972 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
6982 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); 6973 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
6983 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); 6974 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
6984 6975
6985 // Verify child_no_scale transforms 6976 // Verify child_no_scale transforms
6986 gfx::Transform expected_child_no_scale_transform = child->draw_transform(); 6977 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
6987 // All transforms operate on content rects. The child's content rect 6978 // All transforms operate on content rects. The child's content rect
6988 // incorporates device scale, but the child_no_scale does not; add it here. 6979 // incorporates device scale, but the child_no_scale does not; add it here.
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
8104 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 8095 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text());
8105 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 8096 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text());
8106 } 8097 }
8107 8098
8108 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 8099 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
8109 LCDTextTest, 8100 LCDTextTest,
8110 testing::Combine(testing::Bool(), testing::Bool())); 8101 testing::Combine(testing::Bool(), testing::Bool()));
8111 8102
8112 } // namespace 8103 } // namespace
8113 } // namespace cc 8104 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common.cc ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698