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

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

Issue 23043011: cc: Use SkMScalar instead of doubles everywhere in cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: danakj review Created 7 years, 3 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
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/layers/content_layer.h" 9 #include "cc/layers/content_layer.h"
10 #include "cc/layers/content_layer_client.h" 10 #include "cc/layers/content_layer_client.h"
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 EXPECT_TRANSFORMATION_MATRIX_EQ( 1365 EXPECT_TRANSFORMATION_MATRIX_EQ(
1366 A * B * A * B * A * S2, 1366 A * B * A * B * A * S2,
1367 render_surface2->render_surface()->screen_space_transform()); 1367 render_surface2->render_surface()->screen_space_transform());
1368 EXPECT_TRANSFORMATION_MATRIX_EQ( 1368 EXPECT_TRANSFORMATION_MATRIX_EQ(
1369 A * B * A * B * R * S2, 1369 A * B * A * B * R * S2,
1370 render_surface2->render_surface()->replica_screen_space_transform()); 1370 render_surface2->render_surface()->replica_screen_space_transform());
1371 1371
1372 // Sanity check. If these fail there is probably a bug in the test itself. It 1372 // Sanity check. If these fail there is probably a bug in the test itself. It
1373 // is expected that we correctly set up transforms so that the y-component of 1373 // is expected that we correctly set up transforms so that the y-component of
1374 // the screen-space transform encodes the "depth" of the layer in the tree. 1374 // the screen-space transform encodes the "depth" of the layer in the tree.
1375 EXPECT_FLOAT_EQ(1.0, 1375 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1376 parent->screen_space_transform().matrix().getDouble(1, 3)); 1376 EXPECT_FLOAT_EQ(2.0,
1377 child_of_root->screen_space_transform().matrix().get(1, 3));
1377 EXPECT_FLOAT_EQ( 1378 EXPECT_FLOAT_EQ(
1378 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3)); 1379 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
1380
1381 EXPECT_FLOAT_EQ(2.0,
1382 render_surface1->screen_space_transform().matrix().get(1, 3));
1383 EXPECT_FLOAT_EQ(3.0,
1384 child_of_rs1->screen_space_transform().matrix().get(1, 3));
1379 EXPECT_FLOAT_EQ( 1385 EXPECT_FLOAT_EQ(
1380 3.0, 1386 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
1381 grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3));
1382 1387
1388 EXPECT_FLOAT_EQ(3.0,
1389 render_surface2->screen_space_transform().matrix().get(1, 3));
1390 EXPECT_FLOAT_EQ(4.0,
1391 child_of_rs2->screen_space_transform().matrix().get(1, 3));
1383 EXPECT_FLOAT_EQ( 1392 EXPECT_FLOAT_EQ(
1384 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3)); 1393 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
1385 EXPECT_FLOAT_EQ(
1386 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
1387 EXPECT_FLOAT_EQ(
1388 4.0,
1389 grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
1390
1391 EXPECT_FLOAT_EQ(
1392 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3));
1393 EXPECT_FLOAT_EQ(
1394 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
1395 EXPECT_FLOAT_EQ(
1396 5.0,
1397 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
1398 } 1394 }
1399 1395
1400 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { 1396 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
1401 // For layers that flatten their subtree, there should be an orthographic 1397 // For layers that flatten their subtree, there should be an orthographic
1402 // projection (for x and y values) in the middle of the transform sequence. 1398 // projection (for x and y values) in the middle of the transform sequence.
1403 // Note that the way the code is currently implemented, it is not expected to 1399 // Note that the way the code is currently implemented, it is not expected to
1404 // use a canonical orthographic projection. 1400 // use a canonical orthographic projection.
1405 1401
1406 scoped_refptr<Layer> root = Layer::Create(); 1402 scoped_refptr<Layer> root = Layer::Create();
1407 scoped_refptr<Layer> child = Layer::Create(); 1403 scoped_refptr<Layer> child = Layer::Create();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 { 1653 {
1658 RenderSurfaceLayerList render_surface_layer_list; 1654 RenderSurfaceLayerList render_surface_layer_list;
1659 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 1655 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1660 root.get(), root->bounds(), composite, &render_surface_layer_list); 1656 root.get(), root->bounds(), composite, &render_surface_layer_list);
1661 inputs.can_adjust_raster_scales = true; 1657 inputs.can_adjust_raster_scales = true;
1662 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 1658 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1663 gfx::Transform compositeSquared = composite; 1659 gfx::Transform compositeSquared = composite;
1664 compositeSquared.ConcatTransform(composite); 1660 compositeSquared.ConcatTransform(composite);
1665 gfx::Transform compositeCubed = compositeSquared; 1661 gfx::Transform compositeCubed = compositeSquared;
1666 compositeCubed.ConcatTransform(composite); 1662 compositeCubed.ConcatTransform(composite);
1667 EXPECT_EQ(compositeSquared, root->draw_properties().target_space_transform); 1663 EXPECT_TRANSFORMATION_MATRIX_EQ(
1668 EXPECT_EQ(compositeCubed, child->draw_properties().target_space_transform); 1664 compositeSquared, root->draw_properties().target_space_transform);
1665 EXPECT_TRANSFORMATION_MATRIX_EQ(
1666 compositeCubed, child->draw_properties().target_space_transform);
1669 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); 1667 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1670 } 1668 }
1671 } 1669 }
1672 1670
1673 TEST_F(LayerTreeHostCommonTest, 1671 TEST_F(LayerTreeHostCommonTest,
1674 RenderSurfaceListForRenderSurfaceWithClippedLayer) { 1672 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
1675 scoped_refptr<Layer> parent = Layer::Create(); 1673 scoped_refptr<Layer> parent = Layer::Create();
1676 scoped_refptr<Layer> render_surface1 = Layer::Create(); 1674 scoped_refptr<Layer> render_surface1 = Layer::Create();
1677 scoped_refptr<LayerWithForcedDrawsContent> child = 1675 scoped_refptr<LayerWithForcedDrawsContent> child =
1678 make_scoped_refptr(new LayerWithForcedDrawsContent()); 1676 make_scoped_refptr(new LayerWithForcedDrawsContent());
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
2631 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); 2629 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2632 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); 2630 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2633 EXPECT_TRUE(render_surface2->render_surface() 2631 EXPECT_TRUE(render_surface2->render_surface()
2634 ->screen_space_transforms_are_animating()); 2632 ->screen_space_transforms_are_animating());
2635 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); 2633 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2636 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); 2634 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2637 2635
2638 // Sanity check. If these fail there is probably a bug in the test itself. 2636 // Sanity check. If these fail there is probably a bug in the test itself.
2639 // It is expected that we correctly set up transforms so that the y-component 2637 // It is expected that we correctly set up transforms so that the y-component
2640 // of the screen-space transform encodes the "depth" of the layer in the tree. 2638 // of the screen-space transform encodes the "depth" of the layer in the tree.
2641 EXPECT_FLOAT_EQ(1.0, 2639 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2642 parent->screen_space_transform().matrix().getDouble(1, 3)); 2640 EXPECT_FLOAT_EQ(2.0,
2641 child_of_root->screen_space_transform().matrix().get(1, 3));
2643 EXPECT_FLOAT_EQ( 2642 EXPECT_FLOAT_EQ(
2644 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3)); 2643 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
2644
2645 EXPECT_FLOAT_EQ(2.0,
2646 render_surface1->screen_space_transform().matrix().get(1, 3));
2647 EXPECT_FLOAT_EQ(3.0,
2648 child_of_rs1->screen_space_transform().matrix().get(1, 3));
2645 EXPECT_FLOAT_EQ( 2649 EXPECT_FLOAT_EQ(
2646 3.0, 2650 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
2647 grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3));
2648 2651
2652 EXPECT_FLOAT_EQ(3.0,
2653 render_surface2->screen_space_transform().matrix().get(1, 3));
2654 EXPECT_FLOAT_EQ(4.0,
2655 child_of_rs2->screen_space_transform().matrix().get(1, 3));
2649 EXPECT_FLOAT_EQ( 2656 EXPECT_FLOAT_EQ(
2650 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3)); 2657 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
2651 EXPECT_FLOAT_EQ(
2652 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
2653 EXPECT_FLOAT_EQ(
2654 4.0,
2655 grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3));
2656
2657 EXPECT_FLOAT_EQ(
2658 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3));
2659 EXPECT_FLOAT_EQ(
2660 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
2661 EXPECT_FLOAT_EQ(
2662 5.0,
2663 grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3));
2664 } 2658 }
2665 2659
2666 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { 2660 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
2667 // Test the calculateVisibleRect() function works correctly for identity 2661 // Test the calculateVisibleRect() function works correctly for identity
2668 // transforms. 2662 // transforms.
2669 2663
2670 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); 2664 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2671 gfx::Transform layer_to_surface_transform; 2665 gfx::Transform layer_to_surface_transform;
2672 2666
2673 // Case 1: Layer is contained within the surface. 2667 // Case 1: Layer is contained within the surface.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 layer_to_surface_transform.RotateAboutYAxis(45.0); 2783 layer_to_surface_transform.RotateAboutYAxis(45.0);
2790 gfx::Rect expected = gfx::Rect(0, 0, 100, 100); 2784 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2791 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( 2785 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2792 target_surface_rect, layer_content_rect, layer_to_surface_transform); 2786 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2793 EXPECT_RECT_EQ(expected, actual); 2787 EXPECT_RECT_EQ(expected, actual);
2794 2788
2795 // Case 2: Orthographic projection of a layer rotated about y-axis by 45 2789 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2796 // degrees, but shifted to the side so only the right-half the layer would be 2790 // degrees, but shifted to the side so only the right-half the layer would be
2797 // visible on the surface. 2791 // visible on the surface.
2798 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. 2792 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2799 double half_width_of_rotated_layer = (100.0 / sqrt(2.0)) * 0.5; 2793 SkMScalar half_width_of_rotated_layer =
2794 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2800 layer_to_surface_transform.MakeIdentity(); 2795 layer_to_surface_transform.MakeIdentity();
2801 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); 2796 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
2802 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left 2797 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2803 // edge of the layer. 2798 // edge of the layer.
2804 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. 2799 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2805 actual = LayerTreeHostCommon::CalculateVisibleRect( 2800 actual = LayerTreeHostCommon::CalculateVisibleRect(
2806 target_surface_rect, layer_content_rect, layer_to_surface_transform); 2801 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2807 EXPECT_RECT_EQ(expected, actual); 2802 EXPECT_RECT_EQ(expected, actual);
2808 } 2803 }
2809 2804
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 ExecuteCalculateDrawProperties(root.get()); 3207 ExecuteCalculateDrawProperties(root.get());
3213 3208
3214 EXPECT_TRUE(child->visible_content_rect().IsEmpty()); 3209 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3215 EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); 3210 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
3216 3211
3217 // Case 2: a matrix with flattened z, technically uninvertible but still 3212 // Case 2: a matrix with flattened z, technically uninvertible but still
3218 // drawable and visible. In this case, we must assume that the entire layer 3213 // drawable and visible. In this case, we must assume that the entire layer
3219 // bounds are visible since there is no way to inverse-project the surface 3214 // bounds are visible since there is no way to inverse-project the surface
3220 // bounds to intersect. 3215 // bounds to intersect.
3221 uninvertible_matrix.MakeIdentity(); 3216 uninvertible_matrix.MakeIdentity();
3222 uninvertible_matrix.matrix().setDouble(2, 2, 0.0); 3217 uninvertible_matrix.matrix().set(2, 2, 0.0);
3223 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 3218 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3224 3219
3225 SetLayerPropertiesForTesting(child.get(), 3220 SetLayerPropertiesForTesting(child.get(),
3226 uninvertible_matrix, 3221 uninvertible_matrix,
3227 identity_matrix, 3222 identity_matrix,
3228 gfx::PointF(), 3223 gfx::PointF(),
3229 gfx::PointF(5.f, 5.f), 3224 gfx::PointF(5.f, 5.f),
3230 gfx::Size(50, 50), 3225 gfx::Size(50, 50),
3231 false); 3226 false);
3232 3227
3233 ExecuteCalculateDrawProperties(root.get()); 3228 ExecuteCalculateDrawProperties(root.get());
3234 3229
3235 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect()); 3230 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect());
3236 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect()); 3231 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect());
3237 3232
3238 // Case 3: a matrix with flattened z, technically uninvertible but still 3233 // Case 3: a matrix with flattened z, technically uninvertible but still
3239 // drawable, but not visible. In this case, we don't need to conservatively 3234 // drawable, but not visible. In this case, we don't need to conservatively
3240 // assume that the whole layer is visible. 3235 // assume that the whole layer is visible.
3241 uninvertible_matrix.MakeIdentity(); 3236 uninvertible_matrix.MakeIdentity();
3242 uninvertible_matrix.Translate(500.0, 0.0); 3237 uninvertible_matrix.Translate(500.0, 0.0);
3243 uninvertible_matrix.matrix().setDouble(2, 2, 0.0); 3238 uninvertible_matrix.matrix().set(2, 2, 0.0);
3244 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); 3239 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3245 3240
3246 SetLayerPropertiesForTesting(child.get(), 3241 SetLayerPropertiesForTesting(child.get(),
3247 uninvertible_matrix, 3242 uninvertible_matrix,
3248 identity_matrix, 3243 identity_matrix,
3249 gfx::PointF(), 3244 gfx::PointF(),
3250 gfx::PointF(5.f, 5.f), 3245 gfx::PointF(5.f, 5.f),
3251 gfx::Size(50, 50), 3246 gfx::Size(50, 50),
3252 false); 3247 false);
3253 3248
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3501 3496
3502 // Layers that do not draw content should have empty visible content rects. 3497 // Layers that do not draw content should have empty visible content rects.
3503 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); 3498 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3504 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), 3499 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3505 render_surface1->visible_content_rect()); 3500 render_surface1->visible_content_rect());
3506 3501
3507 // The unclipped surface grows its DrawableContentRect to include all drawable 3502 // The unclipped surface grows its DrawableContentRect to include all drawable
3508 // regions of the subtree. 3503 // regions of the subtree.
3509 int diagonal_radius = ceil(sqrt(2.0) * 25.0); 3504 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3510 gfx::Rect expected_surface_drawable_content = 3505 gfx::Rect expected_surface_drawable_content =
3511 gfx::Rect(50.0 - diagonal_radius, 3506 gfx::Rect(50 - diagonal_radius,
3512 50.0 - diagonal_radius, 3507 50 - diagonal_radius,
3513 diagonal_radius * 2.0, 3508 diagonal_radius * 2,
3514 diagonal_radius * 2.0); 3509 diagonal_radius * 2);
3515 EXPECT_RECT_EQ(expected_surface_drawable_content, 3510 EXPECT_RECT_EQ(expected_surface_drawable_content,
3516 render_surface1->render_surface()->DrawableContentRect()); 3511 render_surface1->render_surface()->DrawableContentRect());
3517 3512
3518 // All layers that draw content into the unclipped surface are also unclipped. 3513 // All layers that draw content into the unclipped surface are also unclipped.
3519 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); 3514 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3520 EXPECT_RECT_EQ(expected_surface_drawable_content, 3515 EXPECT_RECT_EQ(expected_surface_drawable_content,
3521 child1->drawable_content_rect()); 3516 child1->drawable_content_rect());
3522 } 3517 }
3523 3518
3524 TEST_F(LayerTreeHostCommonTest, 3519 TEST_F(LayerTreeHostCommonTest,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3563 3558
3564 root->SetMasksToBounds(true); 3559 root->SetMasksToBounds(true);
3565 render_surface1->SetForceRenderSurface(true); 3560 render_surface1->SetForceRenderSurface(true);
3566 ExecuteCalculateDrawProperties(root.get()); 3561 ExecuteCalculateDrawProperties(root.get());
3567 3562
3568 ASSERT_TRUE(render_surface1->render_surface()); 3563 ASSERT_TRUE(render_surface1->render_surface());
3569 3564
3570 // The clipped surface clamps the DrawableContentRect that encloses the 3565 // The clipped surface clamps the DrawableContentRect that encloses the
3571 // rotated layer. 3566 // rotated layer.
3572 int diagonal_radius = ceil(sqrt(2.0) * 25.0); 3567 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3573 gfx::Rect unclipped_surface_content = gfx::Rect(50.0 - diagonal_radius, 3568 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3574 50.0 - diagonal_radius, 3569 50 - diagonal_radius,
3575 diagonal_radius * 2.0, 3570 diagonal_radius * 2,
3576 diagonal_radius * 2.0); 3571 diagonal_radius * 2);
3577 gfx::Rect expected_surface_drawable_content = 3572 gfx::Rect expected_surface_drawable_content =
3578 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); 3573 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3579 EXPECT_RECT_EQ(expected_surface_drawable_content, 3574 EXPECT_RECT_EQ(expected_surface_drawable_content,
3580 render_surface1->render_surface()->DrawableContentRect()); 3575 render_surface1->render_surface()->DrawableContentRect());
3581 3576
3582 // On the clipped surface, only a quarter of the child1 is visible, but when 3577 // On the clipped surface, only a quarter of the child1 is visible, but when
3583 // rotating it back to child1's content space, the actual enclosing rect ends 3578 // rotating it back to child1's content space, the actual enclosing rect ends
3584 // up covering the full left half of child1. 3579 // up covering the full left half of child1.
3580 //
3581 // Given the floating point math, this number is a little bit fuzzy.
3585 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); 3582 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
3586 3583
3587 // The child's DrawableContentRect is unclipped. 3584 // The child's DrawableContentRect is unclipped.
3588 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); 3585 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3589 } 3586 }
3590 3587
3591 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { 3588 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
3592 MockContentLayerClient client; 3589 MockContentLayerClient client;
3593 3590
3594 scoped_refptr<Layer> root = Layer::Create(); 3591 scoped_refptr<Layer> root = Layer::Create();
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
4461 EXPECT_EQ(12345, result_layer->id()); 4458 EXPECT_EQ(12345, result_layer->id());
4462 } 4459 }
4463 4460
4464 TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) { 4461 TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) {
4465 FakeImplProxy proxy; 4462 FakeImplProxy proxy;
4466 FakeLayerTreeHostImpl host_impl(&proxy); 4463 FakeLayerTreeHostImpl host_impl(&proxy);
4467 scoped_ptr<LayerImpl> root = 4464 scoped_ptr<LayerImpl> root =
4468 LayerImpl::Create(host_impl.active_tree(), 12345); 4465 LayerImpl::Create(host_impl.active_tree(), 12345);
4469 4466
4470 gfx::Transform uninvertible_transform; 4467 gfx::Transform uninvertible_transform;
4471 uninvertible_transform.matrix().setDouble(0, 0, 0.0); 4468 uninvertible_transform.matrix().set(0, 0, 0.0);
4472 uninvertible_transform.matrix().setDouble(1, 1, 0.0); 4469 uninvertible_transform.matrix().set(1, 1, 0.0);
4473 uninvertible_transform.matrix().setDouble(2, 2, 0.0); 4470 uninvertible_transform.matrix().set(2, 2, 0.0);
4474 uninvertible_transform.matrix().setDouble(3, 3, 0.0); 4471 uninvertible_transform.matrix().set(3, 3, 0.0);
4475 ASSERT_FALSE(uninvertible_transform.IsInvertible()); 4472 ASSERT_FALSE(uninvertible_transform.IsInvertible());
4476 4473
4477 gfx::Transform identity_matrix; 4474 gfx::Transform identity_matrix;
4478 gfx::PointF anchor; 4475 gfx::PointF anchor;
4479 gfx::PointF position; 4476 gfx::PointF position;
4480 gfx::Size bounds(100, 100); 4477 gfx::Size bounds(100, 100);
4481 SetLayerPropertiesForTesting(root.get(), 4478 SetLayerPropertiesForTesting(root.get(),
4482 uninvertible_transform, 4479 uninvertible_transform,
4483 identity_matrix, 4480 identity_matrix,
4484 anchor, 4481 anchor,
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
5047 5044
5048 // (11, 50) is inside the layer and within the clipped area. 5045 // (11, 50) is inside the layer and within the clipped area.
5049 test_point = gfx::Point(11, 50); 5046 test_point = gfx::Point(11, 50);
5050 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5047 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5051 test_point, render_surface_layer_list); 5048 test_point, render_surface_layer_list);
5052 ASSERT_TRUE(result_layer); 5049 ASSERT_TRUE(result_layer);
5053 EXPECT_EQ(2468, result_layer->id()); 5050 EXPECT_EQ(2468, result_layer->id());
5054 5051
5055 // Around the middle, just to the right and up, would have hit the layer 5052 // Around the middle, just to the right and up, would have hit the layer
5056 // except that that area should be clipped away by the parent. 5053 // except that that area should be clipped away by the parent.
5057 test_point = gfx::Point(51, 51); 5054 test_point = gfx::Point(51, 49);
danakj 2013/09/11 18:53:46 This is my favorite part
enne (OOO) 2013/09/11 19:58:30 I have no idea how this worked before, but I love
5058 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5055 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5059 test_point, render_surface_layer_list); 5056 test_point, render_surface_layer_list);
5060 EXPECT_FALSE(result_layer); 5057 EXPECT_FALSE(result_layer);
5061 5058
5062 // Around the middle, just to the left and down, should successfully hit the 5059 // Around the middle, just to the left and down, should successfully hit the
5063 // layer. 5060 // layer.
5064 test_point = gfx::Point(49, 51); 5061 test_point = gfx::Point(49, 51);
5065 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( 5062 result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint(
5066 test_point, render_surface_layer_list); 5063 test_point, render_surface_layer_list);
5067 ASSERT_TRUE(result_layer); 5064 ASSERT_TRUE(result_layer);
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
5560 } 5557 }
5561 5558
5562 TEST_F(LayerTreeHostCommonTest, 5559 TEST_F(LayerTreeHostCommonTest,
5563 HitCheckingTouchHandlerRegionsForUninvertibleTransform) { 5560 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
5564 FakeImplProxy proxy; 5561 FakeImplProxy proxy;
5565 FakeLayerTreeHostImpl host_impl(&proxy); 5562 FakeLayerTreeHostImpl host_impl(&proxy);
5566 scoped_ptr<LayerImpl> root = 5563 scoped_ptr<LayerImpl> root =
5567 LayerImpl::Create(host_impl.active_tree(), 12345); 5564 LayerImpl::Create(host_impl.active_tree(), 12345);
5568 5565
5569 gfx::Transform uninvertible_transform; 5566 gfx::Transform uninvertible_transform;
5570 uninvertible_transform.matrix().setDouble(0, 0, 0.0); 5567 uninvertible_transform.matrix().set(0, 0, 0.0);
5571 uninvertible_transform.matrix().setDouble(1, 1, 0.0); 5568 uninvertible_transform.matrix().set(1, 1, 0.0);
5572 uninvertible_transform.matrix().setDouble(2, 2, 0.0); 5569 uninvertible_transform.matrix().set(2, 2, 0.0);
5573 uninvertible_transform.matrix().setDouble(3, 3, 0.0); 5570 uninvertible_transform.matrix().set(3, 3, 0.0);
5574 ASSERT_FALSE(uninvertible_transform.IsInvertible()); 5571 ASSERT_FALSE(uninvertible_transform.IsInvertible());
5575 5572
5576 gfx::Transform identity_matrix; 5573 gfx::Transform identity_matrix;
5577 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); 5574 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
5578 gfx::PointF anchor; 5575 gfx::PointF anchor;
5579 gfx::PointF position; 5576 gfx::PointF position;
5580 gfx::Size bounds(100, 100); 5577 gfx::Size bounds(100, 100);
5581 SetLayerPropertiesForTesting(root.get(), 5578 SetLayerPropertiesForTesting(root.get(),
5582 uninvertible_transform, 5579 uninvertible_transform,
5583 identity_matrix, 5580 identity_matrix,
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
6463 child_no_scale->draw_transform()); 6460 child_no_scale->draw_transform());
6464 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, 6461 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
6465 child_no_scale->screen_space_transform()); 6462 child_no_scale->screen_space_transform());
6466 } 6463 }
6467 6464
6468 TEST_F(LayerTreeHostCommonTest, ContentsScale) { 6465 TEST_F(LayerTreeHostCommonTest, ContentsScale) {
6469 MockContentLayerClient delegate; 6466 MockContentLayerClient delegate;
6470 gfx::Transform identity_matrix; 6467 gfx::Transform identity_matrix;
6471 6468
6472 gfx::Transform parent_scale_matrix; 6469 gfx::Transform parent_scale_matrix;
6473 double initial_parent_scale = 1.75; 6470 SkMScalar initial_parent_scale = 1.75;
6474 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 6471 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6475 6472
6476 gfx::Transform child_scale_matrix; 6473 gfx::Transform child_scale_matrix;
6477 double initial_child_scale = 1.25; 6474 SkMScalar initial_child_scale = 1.25;
6478 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 6475 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6479 6476
6480 scoped_refptr<Layer> root = Layer::Create(); 6477 scoped_refptr<Layer> root = Layer::Create();
6481 root->SetBounds(gfx::Size(100, 100)); 6478 root->SetBounds(gfx::Size(100, 100));
6482 6479
6483 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 6480 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6484 SetLayerPropertiesForTesting(parent.get(), 6481 SetLayerPropertiesForTesting(parent.get(),
6485 parent_scale_matrix, 6482 parent_scale_matrix,
6486 identity_matrix, 6483 identity_matrix,
6487 gfx::PointF(), 6484 gfx::PointF(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
6548 child_scale); 6545 child_scale);
6549 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6546 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6550 initial_parent_scale * initial_child_scale, 6547 initial_parent_scale * initial_child_scale,
6551 child_empty); 6548 child_empty);
6552 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); 6549 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6553 6550
6554 // The parent is scaled up and shouldn't need to scale during draw. The 6551 // The parent is scaled up and shouldn't need to scale during draw. The
6555 // child that can scale its contents should also not need to scale during 6552 // child that can scale its contents should also not need to scale during
6556 // draw. This shouldn't change if the child has empty bounds. The other 6553 // draw. This shouldn't change if the child has empty bounds. The other
6557 // children should. 6554 // children should.
6558 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0)); 6555 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6559 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1)); 6556 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6560 EXPECT_FLOAT_EQ(1.0, 6557 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
6561 child_scale->draw_transform().matrix().getDouble(0, 0)); 6558 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
6562 EXPECT_FLOAT_EQ(1.0, 6559 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
6563 child_scale->draw_transform().matrix().getDouble(1, 1)); 6560 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
6564 EXPECT_FLOAT_EQ(1.0,
6565 child_empty->draw_transform().matrix().getDouble(0, 0));
6566 EXPECT_FLOAT_EQ(1.0,
6567 child_empty->draw_transform().matrix().getDouble(1, 1));
6568 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 6561 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6569 initial_parent_scale * initial_child_scale, 6562 initial_parent_scale * initial_child_scale,
6570 child_no_scale->draw_transform().matrix().getDouble(0, 0)); 6563 child_no_scale->draw_transform().matrix().get(0, 0));
6571 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 6564 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6572 initial_parent_scale * initial_child_scale, 6565 initial_parent_scale * initial_child_scale,
6573 child_no_scale->draw_transform().matrix().getDouble(1, 1)); 6566 child_no_scale->draw_transform().matrix().get(1, 1));
6574 } 6567 }
6575 6568
6576 // If the device_scale_factor or page_scale_factor changes, then it should be 6569 // If the device_scale_factor or page_scale_factor changes, then it should be
6577 // updated using the initial transform as the raster scale. 6570 // updated using the initial transform as the raster scale.
6578 device_scale_factor = 2.25f; 6571 device_scale_factor = 2.25f;
6579 page_scale_factor = 1.25f; 6572 page_scale_factor = 1.25f;
6580 6573
6581 { 6574 {
6582 RenderSurfaceLayerList render_surface_layer_list; 6575 RenderSurfaceLayerList render_surface_layer_list;
6583 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 6576 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6584 root.get(), root->bounds(), &render_surface_layer_list); 6577 root.get(), root->bounds(), &render_surface_layer_list);
6585 inputs.device_scale_factor = device_scale_factor; 6578 inputs.device_scale_factor = device_scale_factor;
6586 inputs.page_scale_factor = page_scale_factor; 6579 inputs.page_scale_factor = page_scale_factor;
6587 inputs.page_scale_application_layer = root.get(); 6580 inputs.page_scale_application_layer = root.get();
6588 inputs.can_adjust_raster_scales = true; 6581 inputs.can_adjust_raster_scales = true;
6589 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 6582 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6590 6583
6591 EXPECT_CONTENTS_SCALE_EQ( 6584 EXPECT_CONTENTS_SCALE_EQ(
6592 device_scale_factor * page_scale_factor * initial_parent_scale, parent); 6585 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
6593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6586 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6594 initial_parent_scale * initial_child_scale, 6587 initial_parent_scale * initial_child_scale,
6595 child_scale); 6588 child_scale);
6596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6589 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6597 initial_parent_scale * initial_child_scale, 6590 initial_parent_scale * initial_child_scale,
6598 child_empty); 6591 child_empty);
6599 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); 6592 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6600 } 6593 }
6601 6594
6602 // If the transform changes, we expect the raster scale to be reset to 1.0. 6595 // If the transform changes, we expect the raster scale to be reset to 1.0.
6603 double second_child_scale = 1.75; 6596 SkMScalar second_child_scale = 1.75;
6604 child_scale_matrix.Scale(second_child_scale / initial_child_scale, 6597 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
6605 second_child_scale / initial_child_scale); 6598 second_child_scale / initial_child_scale);
6606 child_scale->SetTransform(child_scale_matrix); 6599 child_scale->SetTransform(child_scale_matrix);
6607 child_empty->SetTransform(child_scale_matrix); 6600 child_empty->SetTransform(child_scale_matrix);
6608 6601
6609 { 6602 {
6610 RenderSurfaceLayerList render_surface_layer_list; 6603 RenderSurfaceLayerList render_surface_layer_list;
6611 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 6604 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6612 root.get(), root->bounds(), &render_surface_layer_list); 6605 root.get(), root->bounds(), &render_surface_layer_list);
6613 inputs.device_scale_factor = device_scale_factor; 6606 inputs.device_scale_factor = device_scale_factor;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
6651 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); 6644 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6652 } 6645 }
6653 } 6646 }
6654 6647
6655 TEST_F(LayerTreeHostCommonTest, 6648 TEST_F(LayerTreeHostCommonTest,
6656 ContentsScale_LayerTransformsDontAffectContentsScale) { 6649 ContentsScale_LayerTransformsDontAffectContentsScale) {
6657 MockContentLayerClient delegate; 6650 MockContentLayerClient delegate;
6658 gfx::Transform identity_matrix; 6651 gfx::Transform identity_matrix;
6659 6652
6660 gfx::Transform parent_scale_matrix; 6653 gfx::Transform parent_scale_matrix;
6661 double initial_parent_scale = 1.75; 6654 SkMScalar initial_parent_scale = 1.75;
6662 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 6655 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6663 6656
6664 gfx::Transform child_scale_matrix; 6657 gfx::Transform child_scale_matrix;
6665 double initial_child_scale = 1.25; 6658 SkMScalar initial_child_scale = 1.25;
6666 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 6659 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6667 6660
6668 scoped_refptr<Layer> root = Layer::Create(); 6661 scoped_refptr<Layer> root = Layer::Create();
6669 root->SetBounds(gfx::Size(100, 100)); 6662 root->SetBounds(gfx::Size(100, 100));
6670 6663
6671 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 6664 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6672 SetLayerPropertiesForTesting(parent.get(), 6665 SetLayerPropertiesForTesting(parent.get(),
6673 parent_scale_matrix, 6666 parent_scale_matrix,
6674 identity_matrix, 6667 identity_matrix,
6675 gfx::PointF(), 6668 gfx::PointF(),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
6731 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); 6724 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
6732 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 6725 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6733 child_scale); 6726 child_scale);
6734 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 6727 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
6735 child_empty); 6728 child_empty);
6736 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); 6729 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
6737 6730
6738 // Since the transform scale does not affect contents scale, it should affect 6731 // Since the transform scale does not affect contents scale, it should affect
6739 // the draw transform instead. 6732 // the draw transform instead.
6740 EXPECT_FLOAT_EQ(initial_parent_scale, 6733 EXPECT_FLOAT_EQ(initial_parent_scale,
6741 parent->draw_transform().matrix().getDouble(0, 0)); 6734 parent->draw_transform().matrix().get(0, 0));
6742 EXPECT_FLOAT_EQ(initial_parent_scale, 6735 EXPECT_FLOAT_EQ(initial_parent_scale,
6743 parent->draw_transform().matrix().getDouble(1, 1)); 6736 parent->draw_transform().matrix().get(1, 1));
6744 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, 6737 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6745 child_scale->draw_transform().matrix().getDouble(0, 0)); 6738 child_scale->draw_transform().matrix().get(0, 0));
6746 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, 6739 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6747 child_scale->draw_transform().matrix().getDouble(1, 1)); 6740 child_scale->draw_transform().matrix().get(1, 1));
6748 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, 6741 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6749 child_empty->draw_transform().matrix().getDouble(0, 0)); 6742 child_empty->draw_transform().matrix().get(0, 0));
6750 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, 6743 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
6751 child_empty->draw_transform().matrix().getDouble(1, 1)); 6744 child_empty->draw_transform().matrix().get(1, 1));
6752 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 6745 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6753 initial_parent_scale * initial_child_scale, 6746 initial_parent_scale * initial_child_scale,
6754 child_no_scale->draw_transform().matrix().getDouble(0, 0)); 6747 child_no_scale->draw_transform().matrix().get(0, 0));
6755 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 6748 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
6756 initial_parent_scale * initial_child_scale, 6749 initial_parent_scale * initial_child_scale,
6757 child_no_scale->draw_transform().matrix().getDouble(1, 1)); 6750 child_no_scale->draw_transform().matrix().get(1, 1));
6758 } 6751 }
6759 6752
6760 TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { 6753 TEST_F(LayerTreeHostCommonTest, SmallContentsScale) {
6761 MockContentLayerClient delegate; 6754 MockContentLayerClient delegate;
6762 gfx::Transform identity_matrix; 6755 gfx::Transform identity_matrix;
6763 6756
6764 gfx::Transform parent_scale_matrix; 6757 gfx::Transform parent_scale_matrix;
6765 double initial_parent_scale = 1.75; 6758 SkMScalar initial_parent_scale = 1.75;
6766 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 6759 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6767 6760
6768 gfx::Transform child_scale_matrix; 6761 gfx::Transform child_scale_matrix;
6769 double initial_child_scale = 0.25; 6762 SkMScalar initial_child_scale = 0.25;
6770 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 6763 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6771 6764
6772 scoped_refptr<Layer> root = Layer::Create(); 6765 scoped_refptr<Layer> root = Layer::Create();
6773 root->SetBounds(gfx::Size(100, 100)); 6766 root->SetBounds(gfx::Size(100, 100));
6774 6767
6775 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 6768 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6776 SetLayerPropertiesForTesting(parent.get(), 6769 SetLayerPropertiesForTesting(parent.get(),
6777 parent_scale_matrix, 6770 parent_scale_matrix,
6778 identity_matrix, 6771 identity_matrix,
6779 gfx::PointF(), 6772 gfx::PointF(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6816 parent); 6809 parent);
6817 // The child's scale is < 1, so we should not save and use that scale 6810 // The child's scale is < 1, so we should not save and use that scale
6818 // factor. 6811 // factor.
6819 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, 6812 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1,
6820 child_scale); 6813 child_scale);
6821 } 6814 }
6822 6815
6823 // When chilld's total scale becomes >= 1, we should save and use that scale 6816 // When chilld's total scale becomes >= 1, we should save and use that scale
6824 // factor. 6817 // factor.
6825 child_scale_matrix.MakeIdentity(); 6818 child_scale_matrix.MakeIdentity();
6826 double final_child_scale = 0.75; 6819 SkMScalar final_child_scale = 0.75;
6827 child_scale_matrix.Scale(final_child_scale, final_child_scale); 6820 child_scale_matrix.Scale(final_child_scale, final_child_scale);
6828 child_scale->SetTransform(child_scale_matrix); 6821 child_scale->SetTransform(child_scale_matrix);
6829 6822
6830 { 6823 {
6831 RenderSurfaceLayerList render_surface_layer_list; 6824 RenderSurfaceLayerList render_surface_layer_list;
6832 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 6825 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6833 root.get(), root->bounds(), &render_surface_layer_list); 6826 root.get(), root->bounds(), &render_surface_layer_list);
6834 inputs.device_scale_factor = device_scale_factor; 6827 inputs.device_scale_factor = device_scale_factor;
6835 inputs.page_scale_factor = page_scale_factor; 6828 inputs.page_scale_factor = page_scale_factor;
6836 inputs.page_scale_application_layer = root.get(); 6829 inputs.page_scale_application_layer = root.get();
6837 inputs.can_adjust_raster_scales = true; 6830 inputs.can_adjust_raster_scales = true;
6838 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 6831 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6839 6832
6840 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6833 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6841 initial_parent_scale, 6834 initial_parent_scale,
6842 parent); 6835 parent);
6843 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6836 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6844 initial_parent_scale * final_child_scale, 6837 initial_parent_scale * final_child_scale,
6845 child_scale); 6838 child_scale);
6846 } 6839 }
6847 } 6840 }
6848 6841
6849 TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { 6842 TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
6850 MockContentLayerClient delegate; 6843 MockContentLayerClient delegate;
6851 gfx::Transform identity_matrix; 6844 gfx::Transform identity_matrix;
6852 6845
6853 gfx::Transform parent_scale_matrix; 6846 gfx::Transform parent_scale_matrix;
6854 double initial_parent_scale = 2.0; 6847 SkMScalar initial_parent_scale = 2.0;
6855 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 6848 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
6856 6849
6857 gfx::Transform child_scale_matrix; 6850 gfx::Transform child_scale_matrix;
6858 double initial_child_scale = 3.0; 6851 SkMScalar initial_child_scale = 3.0;
6859 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 6852 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
6860 6853
6861 scoped_refptr<Layer> root = Layer::Create(); 6854 scoped_refptr<Layer> root = Layer::Create();
6862 root->SetBounds(gfx::Size(100, 100)); 6855 root->SetBounds(gfx::Size(100, 100));
6863 6856
6864 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 6857 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
6865 SetLayerPropertiesForTesting(parent.get(), 6858 SetLayerPropertiesForTesting(parent.get(),
6866 parent_scale_matrix, 6859 parent_scale_matrix,
6867 identity_matrix, 6860 identity_matrix,
6868 gfx::PointF(), 6861 gfx::PointF(),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
6939 surface_scale->AddChild(surface_scale_child_scale); 6932 surface_scale->AddChild(surface_scale_child_scale);
6940 surface_scale->AddChild(surface_scale_child_no_scale); 6933 surface_scale->AddChild(surface_scale_child_no_scale);
6941 6934
6942 surface_no_scale->SetForceRenderSurface(true); 6935 surface_no_scale->SetForceRenderSurface(true);
6943 surface_no_scale->AddChild(surface_no_scale_child_scale); 6936 surface_no_scale->AddChild(surface_no_scale_child_scale);
6944 surface_no_scale->AddChild(surface_no_scale_child_no_scale); 6937 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
6945 6938
6946 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 6939 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
6947 host->SetRootLayer(root); 6940 host->SetRootLayer(root);
6948 6941
6949 double device_scale_factor = 5; 6942 SkMScalar device_scale_factor = 5;
6950 double page_scale_factor = 7; 6943 SkMScalar page_scale_factor = 7;
6951 6944
6952 RenderSurfaceLayerList render_surface_layer_list; 6945 RenderSurfaceLayerList render_surface_layer_list;
6953 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 6946 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
6954 root.get(), root->bounds(), &render_surface_layer_list); 6947 root.get(), root->bounds(), &render_surface_layer_list);
6955 inputs.device_scale_factor = device_scale_factor; 6948 inputs.device_scale_factor = device_scale_factor;
6956 inputs.page_scale_factor = page_scale_factor; 6949 inputs.page_scale_factor = page_scale_factor;
6957 inputs.page_scale_application_layer = root.get(); 6950 inputs.page_scale_application_layer = root.get();
6958 inputs.can_adjust_raster_scales = true; 6951 inputs.can_adjust_raster_scales = true;
6959 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 6952 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6960 6953
6961 EXPECT_CONTENTS_SCALE_EQ( 6954 EXPECT_CONTENTS_SCALE_EQ(
6962 device_scale_factor * page_scale_factor * initial_parent_scale, parent); 6955 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
6963 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 6956 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
6964 initial_parent_scale * initial_child_scale, 6957 initial_parent_scale * initial_child_scale,
6965 surface_scale); 6958 surface_scale);
6966 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); 6959 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
6967 EXPECT_CONTENTS_SCALE_EQ( 6960 EXPECT_CONTENTS_SCALE_EQ(
6968 device_scale_factor * page_scale_factor * initial_parent_scale * 6961 device_scale_factor * page_scale_factor * initial_parent_scale *
6969 initial_child_scale * initial_child_scale, 6962 initial_child_scale * initial_child_scale,
6970 surface_scale_child_scale); 6963 surface_scale_child_scale);
6971 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); 6964 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
6972 EXPECT_CONTENTS_SCALE_EQ( 6965 EXPECT_CONTENTS_SCALE_EQ(
6973 device_scale_factor * page_scale_factor * initial_parent_scale * 6966 device_scale_factor * page_scale_factor * initial_parent_scale *
6974 initial_child_scale * initial_child_scale, 6967 initial_child_scale * initial_child_scale,
6975 surface_no_scale_child_scale); 6968 surface_no_scale_child_scale);
6976 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); 6969 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
6977 6970
6978 // The parent is scaled up and shouldn't need to scale during draw. 6971 // The parent is scaled up and shouldn't need to scale during draw.
6979 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0)); 6972 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
6980 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1)); 6973 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
6981 6974
6982 // RenderSurfaces should always be 1:1 with their target. 6975 // RenderSurfaces should always be 1:1 with their target.
6983 EXPECT_FLOAT_EQ( 6976 EXPECT_FLOAT_EQ(
6984 1.0, 6977 1.0,
6985 surface_scale->render_surface()->draw_transform().matrix().getDouble(0, 6978 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
6986 0));
6987 EXPECT_FLOAT_EQ( 6979 EXPECT_FLOAT_EQ(
6988 1.0, 6980 1.0,
6989 surface_scale->render_surface()->draw_transform().matrix().getDouble(1, 6981 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
6990 1));
6991 6982
6992 // The surface_scale can apply contents scale so the layer shouldn't need to 6983 // The surface_scale can apply contents scale so the layer shouldn't need to
6993 // scale during draw. 6984 // scale during draw.
6994 EXPECT_FLOAT_EQ(1.0, 6985 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
6995 surface_scale->draw_transform().matrix().getDouble(0, 0)); 6986 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
6996 EXPECT_FLOAT_EQ(1.0,
6997 surface_scale->draw_transform().matrix().getDouble(1, 1));
6998 6987
6999 // The surface_scale_child_scale can apply contents scale so it shouldn't need 6988 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7000 // to scale during draw. 6989 // to scale during draw.
7001 EXPECT_FLOAT_EQ( 6990 EXPECT_FLOAT_EQ(
7002 1.0, 6991 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
7003 surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
7004 EXPECT_FLOAT_EQ( 6992 EXPECT_FLOAT_EQ(
7005 1.0, 6993 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
7006 surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
7007 6994
7008 // The surface_scale_child_no_scale can not apply contents scale, so it needs 6995 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7009 // to be scaled during draw. 6996 // to be scaled during draw.
7010 EXPECT_FLOAT_EQ( 6997 EXPECT_FLOAT_EQ(
7011 device_scale_factor * page_scale_factor * initial_parent_scale * 6998 device_scale_factor * page_scale_factor * initial_parent_scale *
7012 initial_child_scale * initial_child_scale, 6999 initial_child_scale * initial_child_scale,
7013 surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0)); 7000 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
7014 EXPECT_FLOAT_EQ( 7001 EXPECT_FLOAT_EQ(
7015 device_scale_factor * page_scale_factor * initial_parent_scale * 7002 device_scale_factor * page_scale_factor * initial_parent_scale *
7016 initial_child_scale * initial_child_scale, 7003 initial_child_scale * initial_child_scale,
7017 surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1)); 7004 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
7018 7005
7019 // RenderSurfaces should always be 1:1 with their target. 7006 // RenderSurfaces should always be 1:1 with their target.
7020 EXPECT_FLOAT_EQ( 7007 EXPECT_FLOAT_EQ(
7021 1.0, 7008 1.0,
7022 surface_no_scale->render_surface()->draw_transform().matrix().getDouble( 7009 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
7023 0, 0));
7024 EXPECT_FLOAT_EQ( 7010 EXPECT_FLOAT_EQ(
7025 1.0, 7011 1.0,
7026 surface_no_scale->render_surface()->draw_transform().matrix().getDouble( 7012 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
7027 1, 1));
7028 7013
7029 // The surface_no_scale layer can not apply contents scale, so it needs to be 7014 // The surface_no_scale layer can not apply contents scale, so it needs to be
7030 // scaled during draw. 7015 // scaled during draw.
7031 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 7016 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
7032 initial_parent_scale * initial_child_scale, 7017 initial_parent_scale * initial_child_scale,
7033 surface_no_scale->draw_transform().matrix().getDouble(0, 0)); 7018 surface_no_scale->draw_transform().matrix().get(0, 0));
7034 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * 7019 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
7035 initial_parent_scale * initial_child_scale, 7020 initial_parent_scale * initial_child_scale,
7036 surface_no_scale->draw_transform().matrix().getDouble(1, 1)); 7021 surface_no_scale->draw_transform().matrix().get(1, 1));
7037 7022
7038 // The surface_scale_child_scale can apply contents scale so it shouldn't need 7023 // The surface_scale_child_scale can apply contents scale so it shouldn't need
7039 // to scale during draw. 7024 // to scale during draw.
7040 EXPECT_FLOAT_EQ( 7025 EXPECT_FLOAT_EQ(
7041 1.0, 7026 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
7042 surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0));
7043 EXPECT_FLOAT_EQ( 7027 EXPECT_FLOAT_EQ(
7044 1.0, 7028 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
7045 surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1));
7046 7029
7047 // The surface_scale_child_no_scale can not apply contents scale, so it needs 7030 // The surface_scale_child_no_scale can not apply contents scale, so it needs
7048 // to be scaled during draw. 7031 // to be scaled during draw.
7049 EXPECT_FLOAT_EQ( 7032 EXPECT_FLOAT_EQ(
7050 device_scale_factor * page_scale_factor * initial_parent_scale * 7033 device_scale_factor * page_scale_factor * initial_parent_scale *
7051 initial_child_scale * initial_child_scale, 7034 initial_child_scale * initial_child_scale,
7052 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0, 7035 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
7053 0));
7054 EXPECT_FLOAT_EQ( 7036 EXPECT_FLOAT_EQ(
7055 device_scale_factor * page_scale_factor * initial_parent_scale * 7037 device_scale_factor * page_scale_factor * initial_parent_scale *
7056 initial_child_scale * initial_child_scale, 7038 initial_child_scale * initial_child_scale,
7057 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1, 7039 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
7058 1));
7059 } 7040 }
7060 7041
7061 TEST_F(LayerTreeHostCommonTest, 7042 TEST_F(LayerTreeHostCommonTest,
7062 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { 7043 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
7063 MockContentLayerClient delegate; 7044 MockContentLayerClient delegate;
7064 gfx::Transform identity_matrix; 7045 gfx::Transform identity_matrix;
7065 7046
7066 gfx::Transform parent_scale_matrix; 7047 gfx::Transform parent_scale_matrix;
7067 double initial_parent_scale = 2.0; 7048 SkMScalar initial_parent_scale = 2.0;
7068 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 7049 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7069 7050
7070 gfx::Transform child_scale_matrix; 7051 gfx::Transform child_scale_matrix;
7071 double initial_child_scale = 3.0; 7052 SkMScalar initial_child_scale = 3.0;
7072 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 7053 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7073 7054
7074 scoped_refptr<Layer> root = Layer::Create(); 7055 scoped_refptr<Layer> root = Layer::Create();
7075 root->SetBounds(gfx::Size(100, 100)); 7056 root->SetBounds(gfx::Size(100, 100));
7076 7057
7077 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 7058 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7078 SetLayerPropertiesForTesting(parent.get(), 7059 SetLayerPropertiesForTesting(parent.get(),
7079 parent_scale_matrix, 7060 parent_scale_matrix,
7080 identity_matrix, 7061 identity_matrix,
7081 gfx::PointF(), 7062 gfx::PointF(),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
7154 7135
7155 surface_no_scale->SetForceRenderSurface(true); 7136 surface_no_scale->SetForceRenderSurface(true);
7156 surface_no_scale->AddChild(surface_no_scale_child_scale); 7137 surface_no_scale->AddChild(surface_no_scale_child_scale);
7157 surface_no_scale->AddChild(surface_no_scale_child_no_scale); 7138 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
7158 7139
7159 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 7140 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
7160 host->SetRootLayer(root); 7141 host->SetRootLayer(root);
7161 7142
7162 RenderSurfaceLayerList render_surface_layer_list; 7143 RenderSurfaceLayerList render_surface_layer_list;
7163 7144
7164 double device_scale_factor = 5.0; 7145 SkMScalar device_scale_factor = 5.0;
7165 double page_scale_factor = 7.0; 7146 SkMScalar page_scale_factor = 7.0;
7166 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 7147 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7167 root.get(), root->bounds(), &render_surface_layer_list); 7148 root.get(), root->bounds(), &render_surface_layer_list);
7168 inputs.device_scale_factor = device_scale_factor; 7149 inputs.device_scale_factor = device_scale_factor;
7169 inputs.page_scale_factor = page_scale_factor; 7150 inputs.page_scale_factor = page_scale_factor;
7170 inputs.page_scale_application_layer = root.get(); 7151 inputs.page_scale_application_layer = root.get();
7171 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 7152 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7172 7153
7173 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 7154 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7174 parent); 7155 parent);
7175 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 7156 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7176 surface_scale); 7157 surface_scale);
7177 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); 7158 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
7178 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 7159 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7179 surface_scale_child_scale); 7160 surface_scale_child_scale);
7180 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); 7161 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
7181 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, 7162 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
7182 surface_no_scale_child_scale); 7163 surface_no_scale_child_scale);
7183 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); 7164 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
7184 7165
7185 // The parent is scaled up during draw, since its contents are not scaled by 7166 // The parent is scaled up during draw, since its contents are not scaled by
7186 // the transform hierarchy. 7167 // the transform hierarchy.
7187 EXPECT_FLOAT_EQ(initial_parent_scale, 7168 EXPECT_FLOAT_EQ(initial_parent_scale,
7188 parent->draw_transform().matrix().getDouble(0, 0)); 7169 parent->draw_transform().matrix().get(0, 0));
7189 EXPECT_FLOAT_EQ(initial_parent_scale, 7170 EXPECT_FLOAT_EQ(initial_parent_scale,
7190 parent->draw_transform().matrix().getDouble(1, 1)); 7171 parent->draw_transform().matrix().get(1, 1));
7191 7172
7192 // The child surface is scaled up during draw since its subtree is not scaled 7173 // The child surface is scaled up during draw since its subtree is not scaled
7193 // by the transform hierarchy. 7174 // by the transform hierarchy.
7194 EXPECT_FLOAT_EQ( 7175 EXPECT_FLOAT_EQ(
7195 initial_parent_scale * initial_child_scale, 7176 initial_parent_scale * initial_child_scale,
7196 surface_scale->render_surface()->draw_transform().matrix().getDouble(0, 7177 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
7197 0));
7198 EXPECT_FLOAT_EQ( 7178 EXPECT_FLOAT_EQ(
7199 initial_parent_scale * initial_child_scale, 7179 initial_parent_scale * initial_child_scale,
7200 surface_scale->render_surface()->draw_transform().matrix().getDouble(1, 7180 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
7201 1));
7202 7181
7203 // The surface_scale's RenderSurface is scaled during draw, so the layer does 7182 // The surface_scale's RenderSurface is scaled during draw, so the layer does
7204 // not need to be scaled when drawing into its surface. 7183 // not need to be scaled when drawing into its surface.
7205 EXPECT_FLOAT_EQ(1.0, 7184 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
7206 surface_scale->draw_transform().matrix().getDouble(0, 0)); 7185 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
7207 EXPECT_FLOAT_EQ(1.0,
7208 surface_scale->draw_transform().matrix().getDouble(1, 1));
7209 7186
7210 // The surface_scale_child_scale is scaled when drawing into its surface, 7187 // The surface_scale_child_scale is scaled when drawing into its surface,
7211 // since its content bounds are not scaled by the transform hierarchy. 7188 // since its content bounds are not scaled by the transform hierarchy.
7212 EXPECT_FLOAT_EQ( 7189 EXPECT_FLOAT_EQ(
7213 initial_child_scale, 7190 initial_child_scale,
7214 surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); 7191 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
7215 EXPECT_FLOAT_EQ( 7192 EXPECT_FLOAT_EQ(
7216 initial_child_scale, 7193 initial_child_scale,
7217 surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); 7194 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
7218 7195
7219 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it 7196 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
7220 // needs to be scaled by the device and page scale factors, along with the 7197 // needs to be scaled by the device and page scale factors, along with the
7221 // transform hierarchy. 7198 // transform hierarchy.
7222 EXPECT_FLOAT_EQ( 7199 EXPECT_FLOAT_EQ(
7223 device_scale_factor * page_scale_factor * initial_child_scale, 7200 device_scale_factor * page_scale_factor * initial_child_scale,
7224 surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0)); 7201 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
7225 EXPECT_FLOAT_EQ( 7202 EXPECT_FLOAT_EQ(
7226 device_scale_factor * page_scale_factor * initial_child_scale, 7203 device_scale_factor * page_scale_factor * initial_child_scale,
7227 surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1)); 7204 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
7228 7205
7229 // The child surface is scaled up during draw since its subtree is not scaled 7206 // The child surface is scaled up during draw since its subtree is not scaled
7230 // by the transform hierarchy. 7207 // by the transform hierarchy.
7231 EXPECT_FLOAT_EQ( 7208 EXPECT_FLOAT_EQ(
7232 initial_parent_scale * initial_child_scale, 7209 initial_parent_scale * initial_child_scale,
7233 surface_no_scale->render_surface()->draw_transform().matrix().getDouble( 7210 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
7234 0, 0));
7235 EXPECT_FLOAT_EQ( 7211 EXPECT_FLOAT_EQ(
7236 initial_parent_scale * initial_child_scale, 7212 initial_parent_scale * initial_child_scale,
7237 surface_no_scale->render_surface()->draw_transform().matrix().getDouble( 7213 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
7238 1, 1));
7239 7214
7240 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to 7215 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
7241 // be scaled by the device and page scale factors. Its surface is already 7216 // be scaled by the device and page scale factors. Its surface is already
7242 // scaled by the transform hierarchy so those don't need to scale the layer's 7217 // scaled by the transform hierarchy so those don't need to scale the layer's
7243 // drawing. 7218 // drawing.
7244 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, 7219 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
7245 surface_no_scale->draw_transform().matrix().getDouble(0, 0)); 7220 surface_no_scale->draw_transform().matrix().get(0, 0));
7246 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, 7221 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
7247 surface_no_scale->draw_transform().matrix().getDouble(1, 1)); 7222 surface_no_scale->draw_transform().matrix().get(1, 1));
7248 7223
7249 // The surface_no_scale_child_scale has its contents scaled by the page and 7224 // The surface_no_scale_child_scale has its contents scaled by the page and
7250 // device scale factors, but needs to be scaled by the transform hierarchy 7225 // device scale factors, but needs to be scaled by the transform hierarchy
7251 // when drawing. 7226 // when drawing.
7252 EXPECT_FLOAT_EQ( 7227 EXPECT_FLOAT_EQ(
7253 initial_child_scale, 7228 initial_child_scale,
7254 surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); 7229 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
7255 EXPECT_FLOAT_EQ( 7230 EXPECT_FLOAT_EQ(
7256 initial_child_scale, 7231 initial_child_scale,
7257 surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); 7232 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
7258 7233
7259 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it 7234 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
7260 // needs to be scaled by the device and page scale factors. It also needs to 7235 // needs to be scaled by the device and page scale factors. It also needs to
7261 // be scaled by any transform heirarchy below its target surface. 7236 // be scaled by any transform heirarchy below its target surface.
7262 EXPECT_FLOAT_EQ( 7237 EXPECT_FLOAT_EQ(
7263 device_scale_factor * page_scale_factor * initial_child_scale, 7238 device_scale_factor * page_scale_factor * initial_child_scale,
7264 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0, 7239 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
7265 0));
7266 EXPECT_FLOAT_EQ( 7240 EXPECT_FLOAT_EQ(
7267 device_scale_factor * page_scale_factor * initial_child_scale, 7241 device_scale_factor * page_scale_factor * initial_child_scale,
7268 surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1, 7242 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
7269 1));
7270 } 7243 }
7271 7244
7272 TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { 7245 TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) {
7273 MockContentLayerClient delegate; 7246 MockContentLayerClient delegate;
7274 gfx::Transform identity_matrix; 7247 gfx::Transform identity_matrix;
7275 7248
7276 gfx::Transform parent_scale_matrix; 7249 gfx::Transform parent_scale_matrix;
7277 double initial_parent_scale = 1.75; 7250 SkMScalar initial_parent_scale = 1.75;
7278 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); 7251 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
7279 7252
7280 gfx::Transform child_scale_matrix; 7253 gfx::Transform child_scale_matrix;
7281 double initial_child_scale = 1.25; 7254 SkMScalar initial_child_scale = 1.25;
7282 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); 7255 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
7283 7256
7284 scoped_refptr<Layer> root = Layer::Create(); 7257 scoped_refptr<Layer> root = Layer::Create();
7285 root->SetBounds(gfx::Size(100, 100)); 7258 root->SetBounds(gfx::Size(100, 100));
7286 7259
7287 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); 7260 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
7288 SetLayerPropertiesForTesting(parent.get(), 7261 SetLayerPropertiesForTesting(parent.get(),
7289 parent_scale_matrix, 7262 parent_scale_matrix,
7290 identity_matrix, 7263 identity_matrix,
7291 gfx::PointF(), 7264 gfx::PointF(),
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
7453 child->render_surface()->draw_transform()); 7426 child->render_surface()->draw_transform());
7454 7427
7455 gfx::Transform expected_surface_screen_space_transform; 7428 gfx::Transform expected_surface_screen_space_transform;
7456 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, 7429 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
7457 device_scale_factor * 2.f); 7430 device_scale_factor * 2.f);
7458 EXPECT_TRANSFORMATION_MATRIX_EQ( 7431 EXPECT_TRANSFORMATION_MATRIX_EQ(
7459 expected_surface_screen_space_transform, 7432 expected_surface_screen_space_transform,
7460 child->render_surface()->screen_space_transform()); 7433 child->render_surface()->screen_space_transform());
7461 7434
7462 gfx::Transform expected_replica_draw_transform; 7435 gfx::Transform expected_replica_draw_transform;
7463 expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0); 7436 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7464 expected_replica_draw_transform.matrix().setDouble(0, 3, 6.0); 7437 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
7465 expected_replica_draw_transform.matrix().setDouble(1, 3, 6.0); 7438 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
7466 EXPECT_TRANSFORMATION_MATRIX_EQ( 7439 EXPECT_TRANSFORMATION_MATRIX_EQ(
7467 expected_replica_draw_transform, 7440 expected_replica_draw_transform,
7468 child->render_surface()->replica_draw_transform()); 7441 child->render_surface()->replica_draw_transform());
7469 7442
7470 gfx::Transform expected_replica_screen_space_transform; 7443 gfx::Transform expected_replica_screen_space_transform;
7471 expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0); 7444 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7472 expected_replica_screen_space_transform.matrix().setDouble(0, 3, 6.0); 7445 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
7473 expected_replica_screen_space_transform.matrix().setDouble(1, 3, 6.0); 7446 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
7474 EXPECT_TRANSFORMATION_MATRIX_EQ( 7447 EXPECT_TRANSFORMATION_MATRIX_EQ(
7475 expected_replica_screen_space_transform, 7448 expected_replica_screen_space_transform,
7476 child->render_surface()->replica_screen_space_transform()); 7449 child->render_surface()->replica_screen_space_transform());
7477 EXPECT_TRANSFORMATION_MATRIX_EQ( 7450 EXPECT_TRANSFORMATION_MATRIX_EQ(
7478 expected_replica_screen_space_transform, 7451 expected_replica_screen_space_transform,
7479 child->render_surface()->replica_screen_space_transform()); 7452 child->render_surface()->replica_screen_space_transform());
7480 } 7453 }
7481 7454
7482 TEST_F(LayerTreeHostCommonTest, 7455 TEST_F(LayerTreeHostCommonTest,
7483 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { 7456 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
7563 duplicate_child_non_owner->content_bounds()); 7536 duplicate_child_non_owner->content_bounds());
7564 7537
7565 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, 7538 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7566 child->render_surface()->draw_transform()); 7539 child->render_surface()->draw_transform());
7567 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, 7540 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
7568 child->render_surface()->draw_transform()); 7541 child->render_surface()->draw_transform());
7569 EXPECT_TRANSFORMATION_MATRIX_EQ( 7542 EXPECT_TRANSFORMATION_MATRIX_EQ(
7570 identity_transform, child->render_surface()->screen_space_transform()); 7543 identity_transform, child->render_surface()->screen_space_transform());
7571 7544
7572 gfx::Transform expected_replica_draw_transform; 7545 gfx::Transform expected_replica_draw_transform;
7573 expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0); 7546 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
7574 EXPECT_TRANSFORMATION_MATRIX_EQ( 7547 EXPECT_TRANSFORMATION_MATRIX_EQ(
7575 expected_replica_draw_transform, 7548 expected_replica_draw_transform,
7576 child->render_surface()->replica_draw_transform()); 7549 child->render_surface()->replica_draw_transform());
7577 7550
7578 gfx::Transform expected_replica_screen_space_transform; 7551 gfx::Transform expected_replica_screen_space_transform;
7579 expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0); 7552 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
7580 EXPECT_TRANSFORMATION_MATRIX_EQ( 7553 EXPECT_TRANSFORMATION_MATRIX_EQ(
7581 expected_replica_screen_space_transform, 7554 expected_replica_screen_space_transform,
7582 child->render_surface()->replica_screen_space_transform()); 7555 child->render_surface()->replica_screen_space_transform());
7583 } 7556 }
7584 7557
7585 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { 7558 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
7586 scoped_refptr<Layer> root = Layer::Create(); 7559 scoped_refptr<Layer> root = Layer::Create();
7587 scoped_refptr<Layer> child = Layer::Create(); 7560 scoped_refptr<Layer> child = Layer::Create();
7588 scoped_refptr<Layer> grand_child = Layer::Create(); 7561 scoped_refptr<Layer> grand_child = Layer::Create();
7589 scoped_refptr<Layer> mask_layer = Layer::Create(); 7562 scoped_refptr<Layer> mask_layer = Layer::Create();
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
8967 ExecuteCalculateDrawProperties(root.get()); 8940 ExecuteCalculateDrawProperties(root.get());
8968 8941
8969 EXPECT_EQ(1u, render_surface_layer_list()->size()); 8942 EXPECT_EQ(1u, render_surface_layer_list()->size());
8970 EXPECT_EQ(0u, 8943 EXPECT_EQ(0u,
8971 render_surface_layer_list()->at(0) 8944 render_surface_layer_list()->at(0)
8972 ->render_surface()->layer_list().size()); 8945 ->render_surface()->layer_list().size());
8973 } 8946 }
8974 8947
8975 } // namespace 8948 } // namespace
8976 } // namespace cc 8949 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698