Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "cc/animation/layer_animation_controller.h" | 9 #include "cc/animation/layer_animation_controller.h" |
| 10 #include "cc/animation/transform_operations.h" | 10 #include "cc/animation/transform_operations.h" |
| 11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
| 12 #include "cc/layers/content_layer.h" | 12 #include "cc/layers/content_layer.h" |
| 13 #include "cc/layers/content_layer_client.h" | 13 #include "cc/layers/content_layer_client.h" |
| 14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 15 #include "cc/layers/layer_client.h" | 15 #include "cc/layers/layer_client.h" |
| 16 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
| 17 #include "cc/layers/layer_iterator.h" | 17 #include "cc/layers/layer_iterator.h" |
| 18 #include "cc/layers/render_surface.h" | 18 #include "cc/layers/render_surface.h" |
| 19 #include "cc/layers/render_surface_impl.h" | 19 #include "cc/layers/render_surface_impl.h" |
| 20 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
| 21 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
| 22 #include "cc/test/animation_test_common.h" | 22 #include "cc/test/animation_test_common.h" |
| 23 #include "cc/test/fake_impl_proxy.h" | 23 #include "cc/test/fake_impl_proxy.h" |
| 24 #include "cc/test/fake_layer_tree_host.h" | 24 #include "cc/test/fake_layer_tree_host.h" |
| 25 #include "cc/test/fake_layer_tree_host_impl.h" | 25 #include "cc/test/fake_layer_tree_host_impl.h" |
| 26 #include "cc/test/fake_picture_layer.h" | |
| 27 #include "cc/test/fake_picture_layer_impl.h" | |
| 26 #include "cc/test/geometry_test_utils.h" | 28 #include "cc/test/geometry_test_utils.h" |
| 27 #include "cc/test/layer_tree_host_common_test.h" | 29 #include "cc/test/layer_tree_host_common_test.h" |
| 28 #include "cc/trees/layer_tree_impl.h" | 30 #include "cc/trees/layer_tree_impl.h" |
| 29 #include "cc/trees/proxy.h" | 31 #include "cc/trees/proxy.h" |
| 30 #include "cc/trees/single_thread_proxy.h" | 32 #include "cc/trees/single_thread_proxy.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/gfx/geometry/size_conversions.h" | 35 #include "ui/gfx/geometry/size_conversions.h" |
| 34 #include "ui/gfx/quad_f.h" | 36 #include "ui/gfx/quad_f.h" |
| 35 #include "ui/gfx/transform.h" | 37 #include "ui/gfx/transform.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 54 MockContentLayerClient() {} | 56 MockContentLayerClient() {} |
| 55 virtual ~MockContentLayerClient() {} | 57 virtual ~MockContentLayerClient() {} |
| 56 virtual void PaintContents( | 58 virtual void PaintContents( |
| 57 SkCanvas* canvas, | 59 SkCanvas* canvas, |
| 58 const gfx::Rect& clip, | 60 const gfx::Rect& clip, |
| 59 ContentLayerClient::GraphicsContextStatus gc_status) override {} | 61 ContentLayerClient::GraphicsContextStatus gc_status) override {} |
| 60 virtual void DidChangeLayerCanUseLCDText() override {} | 62 virtual void DidChangeLayerCanUseLCDText() override {} |
| 61 virtual bool FillsBoundsCompletely() const override { return false; } | 63 virtual bool FillsBoundsCompletely() const override { return false; } |
| 62 }; | 64 }; |
| 63 | 65 |
| 66 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( | |
| 67 ContentLayerClient* delegate) { | |
| 68 scoped_refptr<FakePictureLayer> to_return = | |
| 69 FakePictureLayer::Create(delegate); | |
| 70 to_return->SetIsDrawable(true); | |
| 71 return to_return; | |
| 72 } | |
| 73 | |
| 64 scoped_refptr<ContentLayer> CreateDrawableContentLayer( | 74 scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 65 ContentLayerClient* delegate) { | 75 ContentLayerClient* delegate) { |
| 66 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); | 76 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 67 to_return->SetIsDrawable(true); | 77 to_return->SetIsDrawable(true); |
| 68 return to_return; | 78 return to_return; |
| 69 } | 79 } |
| 70 | 80 |
| 71 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ | 81 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 72 do { \ | 82 do { \ |
| 73 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ | 83 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 74 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ | 84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
| 75 } while (false) | 85 } while (false) |
| 76 | 86 |
| 87 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ | |
| 88 do { \ | |
| 89 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ | |
| 90 } while (false) | |
| 91 | |
| 77 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { | 92 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
| 78 // Sanity check: For layers positioned at zero, with zero size, | 93 // Sanity check: For layers positioned at zero, with zero size, |
| 79 // and with identity transforms, then the draw transform, | 94 // and with identity transforms, then the draw transform, |
| 80 // screen space transform, and the hierarchy passed on to children | 95 // screen space transform, and the hierarchy passed on to children |
| 81 // layers should also be identity transforms. | 96 // layers should also be identity transforms. |
| 82 | 97 |
| 83 scoped_refptr<Layer> parent = Layer::Create(); | 98 scoped_refptr<Layer> parent = Layer::Create(); |
| 84 scoped_refptr<Layer> child = Layer::Create(); | 99 scoped_refptr<Layer> child = Layer::Create(); |
| 85 scoped_refptr<Layer> grand_child = Layer::Create(); | 100 scoped_refptr<Layer> grand_child = Layer::Create(); |
| 86 parent->AddChild(child); | 101 parent->AddChild(child); |
| (...skipping 3189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3276 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); | 3291 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3277 | 3292 |
| 3278 // The child's DrawableContentRect is unclipped. | 3293 // The child's DrawableContentRect is unclipped. |
| 3279 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); | 3294 EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3280 } | 3295 } |
| 3281 | 3296 |
| 3282 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { | 3297 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
| 3283 MockContentLayerClient client; | 3298 MockContentLayerClient client; |
| 3284 | 3299 |
| 3285 scoped_refptr<Layer> root = Layer::Create(); | 3300 scoped_refptr<Layer> root = Layer::Create(); |
| 3286 scoped_refptr<ContentLayer> render_surface1 = | 3301 scoped_refptr<FakePictureLayer> render_surface1 = |
| 3287 CreateDrawableContentLayer(&client); | 3302 CreateDrawablePictureLayer(&client); |
| 3288 scoped_refptr<ContentLayer> render_surface2 = | 3303 scoped_refptr<FakePictureLayer> render_surface2 = |
| 3289 CreateDrawableContentLayer(&client); | 3304 CreateDrawablePictureLayer(&client); |
| 3290 scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); | 3305 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); |
| 3291 scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); | 3306 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); |
| 3292 scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); | 3307 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); |
| 3293 root->AddChild(render_surface1); | 3308 root->AddChild(render_surface1); |
| 3294 render_surface1->AddChild(render_surface2); | 3309 render_surface1->AddChild(render_surface2); |
| 3295 render_surface2->AddChild(child1); | 3310 render_surface2->AddChild(child1); |
| 3296 render_surface2->AddChild(child2); | 3311 render_surface2->AddChild(child2); |
| 3297 render_surface2->AddChild(child3); | 3312 render_surface2->AddChild(child3); |
| 3298 | 3313 |
| 3299 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 3314 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 3300 host->SetRootLayer(root); | 3315 host->SetRootLayer(root); |
| 3301 | 3316 |
| 3302 gfx::Transform identity_matrix; | 3317 gfx::Transform identity_matrix; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3368 | 3383 |
| 3369 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); | 3384 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3370 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), | 3385 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3371 child2->drawable_content_rect()); | 3386 child2->drawable_content_rect()); |
| 3372 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), | 3387 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3373 child3->drawable_content_rect()); | 3388 child3->drawable_content_rect()); |
| 3374 | 3389 |
| 3375 // The root layer does not actually draw content of its own. | 3390 // The root layer does not actually draw content of its own. |
| 3376 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); | 3391 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3377 | 3392 |
| 3378 // All layer visible content rects are expressed in content space of each | 3393 // All layer visible content rects are not expressed in content space of each |
| 3379 // layer, so they are also scaled by the device_scale_factor. | 3394 // layer, so they are not scaled by the device_scale_factor. |
| 3380 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), | 3395 EXPECT_RECT_EQ(gfx::Rect(0, 0, 3, 4), |
| 3381 render_surface1->visible_content_rect()); | 3396 render_surface1->visible_content_rect()); |
| 3382 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), | 3397 EXPECT_RECT_EQ(gfx::Rect(0, 0, 7, 13), |
| 3383 render_surface2->visible_content_rect()); | 3398 render_surface2->visible_content_rect()); |
| 3384 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); | 3399 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3385 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); | 3400 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3386 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); | 3401 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3387 } | 3402 } |
| 3388 | 3403 |
| 3389 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { | 3404 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
| 3390 // Verify the behavior of back-face culling when there are no preserve-3d | 3405 // Verify the behavior of back-face culling when there are no preserve-3d |
| 3391 // layers. Note that 3d transforms still apply in this case, but they are | 3406 // layers. Note that 3d transforms still apply in this case, but they are |
| 3392 // "flattened" to each parent layer according to current W3C spec. | 3407 // "flattened" to each parent layer according to current W3C spec. |
| 3393 | 3408 |
| 3394 const gfx::Transform identity_matrix; | 3409 const gfx::Transform identity_matrix; |
| 3395 scoped_refptr<Layer> parent = Layer::Create(); | 3410 scoped_refptr<Layer> parent = Layer::Create(); |
| 3396 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = | 3411 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4060 NoScaleContentLayer::Create(delegate); | 4075 NoScaleContentLayer::Create(delegate); |
| 4061 to_return->SetIsDrawable(true); | 4076 to_return->SetIsDrawable(true); |
| 4062 return to_return; | 4077 return to_return; |
| 4063 } | 4078 } |
| 4064 | 4079 |
| 4065 TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { | 4080 TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
| 4066 // Verify draw and screen space transforms of layers not in a surface. | 4081 // Verify draw and screen space transforms of layers not in a surface. |
| 4067 MockContentLayerClient delegate; | 4082 MockContentLayerClient delegate; |
| 4068 gfx::Transform identity_matrix; | 4083 gfx::Transform identity_matrix; |
| 4069 | 4084 |
| 4070 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 4085 scoped_refptr<FakePictureLayer> parent = |
| 4086 CreateDrawablePictureLayer(&delegate); | |
| 4071 SetLayerPropertiesForTesting(parent.get(), | 4087 SetLayerPropertiesForTesting(parent.get(), |
| 4072 identity_matrix, | 4088 identity_matrix, |
| 4073 gfx::Point3F(), | 4089 gfx::Point3F(), |
| 4074 gfx::PointF(), | 4090 gfx::PointF(), |
| 4075 gfx::Size(100, 100), | 4091 gfx::Size(100, 100), |
| 4076 false, | 4092 false, |
| 4077 true); | 4093 true); |
| 4078 | 4094 |
| 4079 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); | 4095 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
| 4080 SetLayerPropertiesForTesting(child.get(), | 4096 SetLayerPropertiesForTesting(child.get(), |
| 4081 identity_matrix, | 4097 identity_matrix, |
| 4082 gfx::Point3F(), | 4098 gfx::Point3F(), |
| 4083 gfx::PointF(2.f, 2.f), | 4099 gfx::PointF(2.f, 2.f), |
| 4084 gfx::Size(10, 10), | 4100 gfx::Size(10, 10), |
| 4085 false, | 4101 false, |
| 4086 true); | 4102 true); |
| 4087 | 4103 |
| 4088 scoped_refptr<ContentLayer> child_empty = | 4104 scoped_refptr<FakePictureLayer> child_empty = |
| 4089 CreateDrawableContentLayer(&delegate); | 4105 CreateDrawablePictureLayer(&delegate); |
| 4090 SetLayerPropertiesForTesting(child_empty.get(), | 4106 SetLayerPropertiesForTesting(child_empty.get(), |
| 4091 identity_matrix, | 4107 identity_matrix, |
| 4092 gfx::Point3F(), | 4108 gfx::Point3F(), |
| 4093 gfx::PointF(2.f, 2.f), | 4109 gfx::PointF(2.f, 2.f), |
| 4094 gfx::Size(), | 4110 gfx::Size(), |
| 4095 false, | 4111 false, |
| 4096 true); | 4112 true); |
| 4097 | 4113 |
| 4098 scoped_refptr<NoScaleContentLayer> child_no_scale = | |
| 4099 CreateNoScaleDrawableContentLayer(&delegate); | |
| 4100 SetLayerPropertiesForTesting(child_no_scale.get(), | |
| 4101 identity_matrix, | |
| 4102 gfx::Point3F(), | |
| 4103 gfx::PointF(2.f, 2.f), | |
| 4104 gfx::Size(10, 10), | |
| 4105 false, | |
| 4106 true); | |
| 4107 | |
| 4108 parent->AddChild(child); | 4114 parent->AddChild(child); |
| 4109 parent->AddChild(child_empty); | 4115 parent->AddChild(child_empty); |
| 4110 parent->AddChild(child_no_scale); | |
| 4111 | 4116 |
| 4112 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 4117 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 4113 host->SetRootLayer(parent); | 4118 host->SetRootLayer(parent); |
| 4114 | 4119 |
| 4115 float device_scale_factor = 2.5f; | 4120 float device_scale_factor = 2.5f; |
| 4116 float page_scale_factor = 1.f; | 4121 float page_scale_factor = 1.f; |
| 4117 | 4122 |
| 4118 RenderSurfaceLayerList render_surface_layer_list; | 4123 RenderSurfaceLayerList render_surface_layer_list; |
| 4119 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 4124 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4120 parent.get(), parent->bounds(), &render_surface_layer_list); | 4125 parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4121 inputs.device_scale_factor = device_scale_factor; | 4126 inputs.device_scale_factor = device_scale_factor; |
| 4122 inputs.page_scale_factor = page_scale_factor; | 4127 inputs.page_scale_factor = page_scale_factor; |
| 4123 inputs.can_adjust_raster_scales = true; | 4128 inputs.can_adjust_raster_scales = true; |
| 4124 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 4129 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4125 | 4130 |
| 4126 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | 4131 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4127 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); | 4132 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4128 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | 4133 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
| 4129 child_empty); | |
| 4130 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | |
| 4131 | 4134 |
| 4132 EXPECT_EQ(1u, render_surface_layer_list.size()); | 4135 EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 4133 | 4136 |
| 4134 // Verify parent transforms | 4137 // Verify parent transforms |
| 4135 gfx::Transform expected_parent_transform; | 4138 gfx::Transform expected_parent_transform; |
| 4139 expected_parent_transform.Scale(device_scale_factor * page_scale_factor, | |
| 4140 device_scale_factor * page_scale_factor); | |
| 4136 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | 4141 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4137 parent->screen_space_transform()); | 4142 parent->screen_space_transform()); |
| 4138 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | 4143 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4139 parent->draw_transform()); | 4144 parent->draw_transform()); |
| 4140 | 4145 |
| 4141 // Verify results of transformed parent rects | 4146 // Verify results of transformed parent rects |
| 4142 gfx::RectF parent_content_bounds(parent->content_bounds()); | 4147 gfx::RectF parent_content_bounds(parent->content_bounds()); |
| 4143 | 4148 |
| 4144 gfx::RectF parent_draw_rect = | 4149 gfx::RectF parent_draw_rect = |
| 4145 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); | 4150 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4146 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( | 4151 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4147 parent->screen_space_transform(), parent_content_bounds); | 4152 parent->screen_space_transform(), parent_content_bounds); |
| 4148 | 4153 |
| 4149 gfx::RectF expected_parent_draw_rect(parent->bounds()); | 4154 gfx::RectF expected_parent_draw_rect(parent->bounds()); |
| 4150 expected_parent_draw_rect.Scale(device_scale_factor); | 4155 expected_parent_draw_rect.Scale(device_scale_factor); |
| 4151 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); | 4156 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4152 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); | 4157 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
| 4153 | 4158 |
| 4154 // Verify child and child_empty transforms. They should match. | 4159 // Verify child and child_empty transforms. They should match. |
| 4155 gfx::Transform expected_child_transform; | 4160 gfx::Transform expected_child_transform; |
| 4156 expected_child_transform.Translate( | 4161 expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4157 device_scale_factor * child->position().x(), | 4162 expected_child_transform.Translate(child->position().x(), |
| 4158 device_scale_factor * child->position().y()); | 4163 child->position().y()); |
| 4159 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 4164 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4160 child->draw_transform()); | 4165 child->draw_transform()); |
| 4161 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 4166 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4162 child->screen_space_transform()); | 4167 child->screen_space_transform()); |
| 4163 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 4168 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4164 child_empty->draw_transform()); | 4169 child_empty->draw_transform()); |
| 4165 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | 4170 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4166 child_empty->screen_space_transform()); | 4171 child_empty->screen_space_transform()); |
| 4167 | 4172 |
| 4168 // Verify results of transformed child and child_empty rects. They should | 4173 // Verify results of transformed child and child_empty rects. They should |
| 4169 // match. | 4174 // match. |
| 4170 gfx::RectF child_content_bounds(child->content_bounds()); | 4175 gfx::RectF child_content_bounds(child->content_bounds()); |
| 4171 | 4176 |
| 4172 gfx::RectF child_draw_rect = | 4177 gfx::RectF child_draw_rect = |
| 4173 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); | 4178 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4174 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( | 4179 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4175 child->screen_space_transform(), child_content_bounds); | 4180 child->screen_space_transform(), child_content_bounds); |
| 4176 | 4181 |
| 4177 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( | 4182 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4178 child_empty->draw_transform(), child_content_bounds); | 4183 child_empty->draw_transform(), child_content_bounds); |
| 4179 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( | 4184 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4180 child_empty->screen_space_transform(), child_content_bounds); | 4185 child_empty->screen_space_transform(), child_content_bounds); |
| 4181 | 4186 |
| 4182 gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); | 4187 gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4183 expected_child_draw_rect.Scale(device_scale_factor); | 4188 expected_child_draw_rect.Scale(device_scale_factor); |
| 4184 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); | 4189 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4185 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); | 4190 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4186 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); | 4191 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4187 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); | 4192 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
| 4188 | |
| 4189 // Verify child_no_scale transforms | |
| 4190 gfx::Transform expected_child_no_scale_transform = child->draw_transform(); | |
| 4191 // All transforms operate on content rects. The child's content rect | |
| 4192 // incorporates device scale, but the child_no_scale does not; add it here. | |
| 4193 expected_child_no_scale_transform.Scale(device_scale_factor, | |
| 4194 device_scale_factor); | |
| 4195 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | |
| 4196 child_no_scale->draw_transform()); | |
| 4197 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | |
| 4198 child_no_scale->screen_space_transform()); | |
| 4199 } | 4193 } |
| 4200 | 4194 |
| 4201 TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { | 4195 TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
| 4202 // Verify draw and screen space transforms of layers in a surface. | 4196 // Verify draw and screen space transforms of layers in a surface. |
| 4203 MockContentLayerClient delegate; | 4197 MockContentLayerClient delegate; |
| 4204 gfx::Transform identity_matrix; | 4198 gfx::Transform identity_matrix; |
| 4205 | 4199 |
| 4206 gfx::Transform perspective_matrix; | 4200 gfx::Transform perspective_matrix; |
| 4207 perspective_matrix.ApplyPerspectiveDepth(2.0); | 4201 perspective_matrix.ApplyPerspectiveDepth(2.0); |
| 4208 | 4202 |
| 4209 gfx::Transform scale_small_matrix; | 4203 gfx::Transform scale_small_matrix; |
| 4210 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); | 4204 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
| 4211 | 4205 |
| 4212 scoped_refptr<Layer> root = Layer::Create(); | 4206 scoped_refptr<Layer> root = Layer::Create(); |
| 4213 | 4207 |
| 4214 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 4208 scoped_refptr<FakePictureLayer> parent = |
| 4209 CreateDrawablePictureLayer(&delegate); | |
| 4215 SetLayerPropertiesForTesting(parent.get(), | 4210 SetLayerPropertiesForTesting(parent.get(), |
| 4216 identity_matrix, | 4211 identity_matrix, |
| 4217 gfx::Point3F(), | 4212 gfx::Point3F(), |
| 4218 gfx::PointF(), | 4213 gfx::PointF(), |
| 4219 gfx::Size(100, 100), | 4214 gfx::Size(100, 100), |
| 4220 false, | 4215 false, |
| 4221 true); | 4216 true); |
| 4222 | 4217 |
| 4223 scoped_refptr<ContentLayer> perspective_surface = | 4218 scoped_refptr<FakePictureLayer> perspective_surface = |
| 4224 CreateDrawableContentLayer(&delegate); | 4219 CreateDrawablePictureLayer(&delegate); |
| 4225 SetLayerPropertiesForTesting(perspective_surface.get(), | 4220 SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4226 perspective_matrix * scale_small_matrix, | 4221 perspective_matrix * scale_small_matrix, |
| 4227 gfx::Point3F(), | 4222 gfx::Point3F(), |
| 4228 gfx::PointF(2.f, 2.f), | 4223 gfx::PointF(2.f, 2.f), |
| 4229 gfx::Size(10, 10), | 4224 gfx::Size(10, 10), |
| 4230 false, | 4225 false, |
| 4231 true); | 4226 true); |
| 4232 | 4227 |
| 4233 scoped_refptr<ContentLayer> scale_surface = | 4228 scoped_refptr<FakePictureLayer> scale_surface = |
| 4234 CreateDrawableContentLayer(&delegate); | 4229 CreateDrawablePictureLayer(&delegate); |
| 4235 SetLayerPropertiesForTesting(scale_surface.get(), | 4230 SetLayerPropertiesForTesting(scale_surface.get(), |
| 4236 scale_small_matrix, | 4231 scale_small_matrix, |
| 4237 gfx::Point3F(), | 4232 gfx::Point3F(), |
| 4238 gfx::PointF(2.f, 2.f), | 4233 gfx::PointF(2.f, 2.f), |
| 4239 gfx::Size(10, 10), | 4234 gfx::Size(10, 10), |
| 4240 false, | 4235 false, |
| 4241 true); | 4236 true); |
| 4242 | 4237 |
| 4243 perspective_surface->SetForceRenderSurface(true); | 4238 perspective_surface->SetForceRenderSurface(true); |
| 4244 scale_surface->SetForceRenderSurface(true); | 4239 scale_surface->SetForceRenderSurface(true); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 4255 | 4250 |
| 4256 RenderSurfaceLayerList render_surface_layer_list; | 4251 RenderSurfaceLayerList render_surface_layer_list; |
| 4257 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 4252 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4258 root.get(), parent->bounds(), &render_surface_layer_list); | 4253 root.get(), parent->bounds(), &render_surface_layer_list); |
| 4259 inputs.device_scale_factor = device_scale_factor; | 4254 inputs.device_scale_factor = device_scale_factor; |
| 4260 inputs.page_scale_factor = page_scale_factor; | 4255 inputs.page_scale_factor = page_scale_factor; |
| 4261 inputs.page_scale_application_layer = root.get(); | 4256 inputs.page_scale_application_layer = root.get(); |
| 4262 inputs.can_adjust_raster_scales = true; | 4257 inputs.can_adjust_raster_scales = true; |
| 4263 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 4258 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4264 | 4259 |
| 4265 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); | 4260 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4266 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | 4261 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4267 perspective_surface); | 4262 perspective_surface); |
| 4268 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | 4263 // Ideal scale is the max 2d scale component of the combined transform up to |
| 4269 scale_surface); | 4264 // the nearest render target. Here this includes the layer transform as well |
| 4265 // as the device and page scale factors. | |
| 4266 gfx::Transform transform = scale_small_matrix; | |
| 4267 transform.Scale(device_scale_factor * page_scale_factor, | |
| 4268 device_scale_factor * page_scale_factor); | |
| 4269 gfx::Vector2dF scales = MathUtil::ComputeTransform2dScaleComponents( | |
| 4270 transform, device_scale_factor * page_scale_factor); | |
|
danakj
2014/10/08 21:13:52
pass 0.f as the 2nd parameter. we should always ge
sohanjg
2014/10/13 06:33:38
Done.
| |
| 4271 float max_2d_scale = std::max(scales.x(), scales.y()); | |
| 4272 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); | |
| 4273 | |
| 4274 // The ideal scale will draw 1:1 with its render target space along | |
| 4275 // the larger-scale axis. | |
| 4276 gfx::Vector2dF target_space_transform_scales = | |
| 4277 MathUtil::ComputeTransform2dScaleComponents( | |
| 4278 scale_surface->draw_properties().target_space_transform, 0.f); | |
| 4279 EXPECT_FLOAT_EQ(max_2d_scale, | |
| 4280 std::max(target_space_transform_scales.x(), | |
| 4281 target_space_transform_scales.y())); | |
| 4270 | 4282 |
| 4271 EXPECT_EQ(3u, render_surface_layer_list.size()); | 4283 EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 4272 | 4284 |
| 4273 gfx::Transform expected_parent_draw_transform; | 4285 gfx::Transform expected_parent_draw_transform; |
| 4286 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, | |
| 4287 device_scale_factor * page_scale_factor); | |
| 4274 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, | 4288 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4275 parent->draw_transform()); | 4289 parent->draw_transform()); |
| 4276 | 4290 |
| 4277 // The scaled surface is rendered at its appropriate scale, and drawn 1:1 | |
| 4278 // into its target. | |
| 4279 gfx::Transform expected_scale_surface_draw_transform; | |
| 4280 expected_scale_surface_draw_transform.Translate( | |
| 4281 device_scale_factor * page_scale_factor * scale_surface->position().x(), | |
| 4282 device_scale_factor * page_scale_factor * scale_surface->position().y()); | |
| 4283 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 4284 expected_scale_surface_draw_transform, | |
| 4285 scale_surface->render_surface()->draw_transform()); | |
| 4286 gfx::Transform expected_scale_surface_layer_draw_transform = | |
| 4287 scale_small_matrix; | |
| 4288 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, | |
| 4289 scale_surface->draw_transform()); | |
| 4290 | |
| 4291 // The scale for the perspective surface is not known, so it is rendered 1:1 | 4291 // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4292 // with the screen, and then scaled during drawing. | 4292 // with the screen, and then scaled during drawing. |
| 4293 gfx::Transform expected_perspective_surface_draw_transform; | 4293 gfx::Transform expected_perspective_surface_draw_transform; |
| 4294 expected_perspective_surface_draw_transform.Translate( | 4294 expected_perspective_surface_draw_transform.Translate( |
| 4295 device_scale_factor * page_scale_factor * | 4295 device_scale_factor * page_scale_factor * |
| 4296 perspective_surface->position().x(), | 4296 perspective_surface->position().x(), |
| 4297 device_scale_factor * page_scale_factor * | 4297 device_scale_factor * page_scale_factor * |
| 4298 perspective_surface->position().y()); | 4298 perspective_surface->position().y()); |
| 4299 expected_perspective_surface_draw_transform.PreconcatTransform( | 4299 expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4300 perspective_matrix); | 4300 perspective_matrix); |
| 4301 expected_perspective_surface_draw_transform.PreconcatTransform( | 4301 expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4302 scale_small_matrix); | 4302 scale_small_matrix); |
| 4303 gfx::Transform expected_perspective_surface_layer_draw_transform; | 4303 gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 4304 expected_perspective_surface_layer_draw_transform.Scale( | |
| 4305 device_scale_factor * page_scale_factor, | |
| 4306 device_scale_factor * page_scale_factor); | |
| 4304 EXPECT_TRANSFORMATION_MATRIX_EQ( | 4307 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4305 expected_perspective_surface_draw_transform, | 4308 expected_perspective_surface_draw_transform, |
| 4306 perspective_surface->render_surface()->draw_transform()); | 4309 perspective_surface->render_surface()->draw_transform()); |
| 4307 EXPECT_TRANSFORMATION_MATRIX_EQ( | 4310 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4308 expected_perspective_surface_layer_draw_transform, | 4311 expected_perspective_surface_layer_draw_transform, |
| 4309 perspective_surface->draw_transform()); | 4312 perspective_surface->draw_transform()); |
| 4310 } | 4313 } |
| 4311 | 4314 |
| 4315 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4312 TEST_F(LayerTreeHostCommonTest, | 4316 TEST_F(LayerTreeHostCommonTest, |
| 4313 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { | 4317 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4314 // Verify draw and screen space transforms of layers not in a surface. | 4318 // Verify draw and screen space transforms of layers not in a surface. |
| 4315 MockContentLayerClient delegate; | 4319 MockContentLayerClient delegate; |
| 4316 gfx::Transform identity_matrix; | 4320 gfx::Transform identity_matrix; |
| 4317 | 4321 |
| 4318 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 4322 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4319 SetLayerPropertiesForTesting(parent.get(), | 4323 SetLayerPropertiesForTesting(parent.get(), |
| 4320 identity_matrix, | 4324 identity_matrix, |
| 4321 gfx::Point3F(), | 4325 gfx::Point3F(), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4417 // All transforms operate on content rects. The child's content rect | 4421 // All transforms operate on content rects. The child's content rect |
| 4418 // incorporates device scale, but the child_no_scale does not; add it here. | 4422 // incorporates device scale, but the child_no_scale does not; add it here. |
| 4419 expected_child_no_scale_transform.Scale(device_scale_factor, | 4423 expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4420 device_scale_factor); | 4424 device_scale_factor); |
| 4421 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | 4425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4422 child_no_scale->draw_transform()); | 4426 child_no_scale->draw_transform()); |
| 4423 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, | 4427 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4424 child_no_scale->screen_space_transform()); | 4428 child_no_scale->screen_space_transform()); |
| 4425 } | 4429 } |
| 4426 | 4430 |
| 4431 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4427 TEST_F(LayerTreeHostCommonTest, ContentsScale) { | 4432 TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
| 4428 MockContentLayerClient delegate; | 4433 MockContentLayerClient delegate; |
| 4429 gfx::Transform identity_matrix; | 4434 gfx::Transform identity_matrix; |
| 4430 | 4435 |
| 4431 gfx::Transform parent_scale_matrix; | 4436 gfx::Transform parent_scale_matrix; |
| 4432 SkMScalar initial_parent_scale = 1.75; | 4437 SkMScalar initial_parent_scale = 1.75; |
| 4433 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 4438 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4434 | 4439 |
| 4435 gfx::Transform child_scale_matrix; | 4440 gfx::Transform child_scale_matrix; |
| 4436 SkMScalar initial_child_scale = 1.25; | 4441 SkMScalar initial_child_scale = 1.25; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4608 initial_parent_scale, | 4613 initial_parent_scale, |
| 4609 parent); | 4614 parent); |
| 4610 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | 4615 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4611 child_scale); | 4616 child_scale); |
| 4612 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, | 4617 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4613 child_empty); | 4618 child_empty); |
| 4614 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); | 4619 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4615 } | 4620 } |
| 4616 } | 4621 } |
| 4617 | 4622 |
| 4623 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 4618 TEST_F(LayerTreeHostCommonTest, | 4624 TEST_F(LayerTreeHostCommonTest, |
| 4619 ContentsScale_LayerTransformsDontAffectContentsScale) { | 4625 ContentsScale_LayerTransformsDontAffectContentsScale) { |
| 4620 MockContentLayerClient delegate; | 4626 MockContentLayerClient delegate; |
| 4621 gfx::Transform identity_matrix; | 4627 gfx::Transform identity_matrix; |
| 4622 | 4628 |
| 4623 gfx::Transform parent_scale_matrix; | 4629 gfx::Transform parent_scale_matrix; |
| 4624 SkMScalar initial_parent_scale = 1.75; | 4630 SkMScalar initial_parent_scale = 1.75; |
| 4625 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 4631 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4626 | 4632 |
| 4627 gfx::Transform child_scale_matrix; | 4633 gfx::Transform child_scale_matrix; |
| 4628 SkMScalar initial_child_scale = 1.25; | 4634 SkMScalar initial_child_scale = 1.25; |
| 4629 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | 4635 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4715 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, | 4721 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 4716 child_empty->draw_transform().matrix().get(1, 1)); | 4722 child_empty->draw_transform().matrix().get(1, 1)); |
| 4717 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | 4723 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4718 initial_parent_scale * initial_child_scale, | 4724 initial_parent_scale * initial_child_scale, |
| 4719 child_no_scale->draw_transform().matrix().get(0, 0)); | 4725 child_no_scale->draw_transform().matrix().get(0, 0)); |
| 4720 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * | 4726 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4721 initial_parent_scale * initial_child_scale, | 4727 initial_parent_scale * initial_child_scale, |
| 4722 child_no_scale->draw_transform().matrix().get(1, 1)); | 4728 child_no_scale->draw_transform().matrix().get(1, 1)); |
| 4723 } | 4729 } |
| 4724 | 4730 |
| 4725 TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { | 4731 TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
| 4726 MockContentLayerClient delegate; | 4732 MockContentLayerClient delegate; |
| 4727 gfx::Transform identity_matrix; | 4733 gfx::Transform identity_matrix; |
| 4728 | 4734 |
| 4729 gfx::Transform parent_scale_matrix; | 4735 gfx::Transform parent_scale_matrix; |
| 4730 SkMScalar initial_parent_scale = 1.75; | 4736 SkMScalar initial_parent_scale = 1.75; |
| 4731 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 4737 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4732 | 4738 |
| 4733 gfx::Transform child_scale_matrix; | 4739 gfx::Transform child_scale_matrix; |
| 4734 SkMScalar initial_child_scale = 0.25; | 4740 SkMScalar initial_child_scale = 0.25; |
| 4735 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | 4741 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4736 | 4742 |
| 4737 scoped_refptr<Layer> root = Layer::Create(); | 4743 scoped_refptr<Layer> root = Layer::Create(); |
| 4738 root->SetBounds(gfx::Size(100, 100)); | 4744 root->SetBounds(gfx::Size(100, 100)); |
| 4739 | 4745 |
| 4740 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 4746 scoped_refptr<FakePictureLayer> parent = |
| 4747 CreateDrawablePictureLayer(&delegate); | |
| 4741 SetLayerPropertiesForTesting(parent.get(), | 4748 SetLayerPropertiesForTesting(parent.get(), |
| 4742 parent_scale_matrix, | 4749 parent_scale_matrix, |
| 4743 gfx::Point3F(), | 4750 gfx::Point3F(), |
| 4744 gfx::PointF(), | 4751 gfx::PointF(), |
| 4745 gfx::Size(100, 100), | 4752 gfx::Size(100, 100), |
| 4746 false, | 4753 false, |
| 4747 true); | 4754 true); |
| 4748 | 4755 |
| 4749 scoped_refptr<ContentLayer> child_scale = | 4756 scoped_refptr<FakePictureLayer> child_scale = |
| 4750 CreateDrawableContentLayer(&delegate); | 4757 CreateDrawablePictureLayer(&delegate); |
| 4751 SetLayerPropertiesForTesting(child_scale.get(), | 4758 SetLayerPropertiesForTesting(child_scale.get(), |
| 4752 child_scale_matrix, | 4759 child_scale_matrix, |
| 4753 gfx::Point3F(), | 4760 gfx::Point3F(), |
| 4754 gfx::PointF(2.f, 2.f), | 4761 gfx::PointF(2.f, 2.f), |
| 4755 gfx::Size(10, 10), | 4762 gfx::Size(10, 10), |
| 4756 false, | 4763 false, |
| 4757 true); | 4764 true); |
| 4758 | 4765 |
| 4759 root->AddChild(parent); | 4766 root->AddChild(parent); |
| 4760 | 4767 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 4771 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 4778 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4772 root.get(), | 4779 root.get(), |
| 4773 gfx::ToCeiledSize(root->bounds()), | 4780 gfx::ToCeiledSize(root->bounds()), |
| 4774 &render_surface_layer_list); | 4781 &render_surface_layer_list); |
| 4775 inputs.device_scale_factor = device_scale_factor; | 4782 inputs.device_scale_factor = device_scale_factor; |
| 4776 inputs.page_scale_factor = page_scale_factor; | 4783 inputs.page_scale_factor = page_scale_factor; |
| 4777 inputs.page_scale_application_layer = root.get(); | 4784 inputs.page_scale_application_layer = root.get(); |
| 4778 inputs.can_adjust_raster_scales = true; | 4785 inputs.can_adjust_raster_scales = true; |
| 4779 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 4786 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4780 | 4787 |
| 4781 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | 4788 // The ideal scale is able to go below 1. |
| 4782 initial_parent_scale, | 4789 float expected_ideal_scale = |
| 4783 parent); | 4790 device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4784 // The child's scale is < 1, so we should not save and use that scale | 4791 EXPECT_LT(expected_ideal_scale, 1.f); |
| 4785 // factor. | 4792 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
| 4786 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, | |
| 4787 child_scale); | |
| 4788 } | |
| 4789 | 4793 |
| 4790 // When chilld's total scale becomes >= 1, we should save and use that scale | 4794 expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4791 // factor. | 4795 initial_parent_scale * initial_child_scale; |
| 4792 child_scale_matrix.MakeIdentity(); | 4796 EXPECT_LT(expected_ideal_scale, 1.f); |
| 4793 SkMScalar final_child_scale = 0.75; | 4797 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
| 4794 child_scale_matrix.Scale(final_child_scale, final_child_scale); | |
| 4795 child_scale->SetTransform(child_scale_matrix); | |
| 4796 | |
| 4797 { | |
| 4798 RenderSurfaceLayerList render_surface_layer_list; | |
| 4799 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | |
| 4800 root.get(), | |
| 4801 gfx::ToCeiledSize(root->bounds()), | |
| 4802 &render_surface_layer_list); | |
| 4803 inputs.device_scale_factor = device_scale_factor; | |
| 4804 inputs.page_scale_factor = page_scale_factor; | |
| 4805 inputs.page_scale_application_layer = root.get(); | |
| 4806 inputs.can_adjust_raster_scales = true; | |
| 4807 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 4808 | |
| 4809 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4810 initial_parent_scale, | |
| 4811 parent); | |
| 4812 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * | |
| 4813 initial_parent_scale * final_child_scale, | |
| 4814 child_scale); | |
| 4815 } | 4798 } |
| 4816 } | 4799 } |
| 4817 | 4800 |
| 4818 TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { | 4801 TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
| 4819 MockContentLayerClient delegate; | 4802 MockContentLayerClient delegate; |
| 4820 gfx::Transform identity_matrix; | 4803 gfx::Transform identity_matrix; |
| 4821 | 4804 |
| 4822 gfx::Transform parent_scale_matrix; | 4805 gfx::Transform parent_scale_matrix; |
| 4823 SkMScalar initial_parent_scale = 2.0; | 4806 SkMScalar initial_parent_scale = 2.0; |
| 4824 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 4807 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5010 EXPECT_FLOAT_EQ( | 4993 EXPECT_FLOAT_EQ( |
| 5011 device_scale_factor * page_scale_factor * initial_parent_scale * | 4994 device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5012 initial_child_scale * initial_child_scale, | 4995 initial_child_scale * initial_child_scale, |
| 5013 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | 4996 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
| 5014 EXPECT_FLOAT_EQ( | 4997 EXPECT_FLOAT_EQ( |
| 5015 device_scale_factor * page_scale_factor * initial_parent_scale * | 4998 device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5016 initial_child_scale * initial_child_scale, | 4999 initial_child_scale * initial_child_scale, |
| 5017 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | 5000 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
| 5018 } | 5001 } |
| 5019 | 5002 |
| 5003 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 5020 TEST_F(LayerTreeHostCommonTest, | 5004 TEST_F(LayerTreeHostCommonTest, |
| 5021 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { | 5005 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 5022 MockContentLayerClient delegate; | 5006 MockContentLayerClient delegate; |
| 5023 gfx::Transform identity_matrix; | 5007 gfx::Transform identity_matrix; |
| 5024 | 5008 |
| 5025 gfx::Transform parent_scale_matrix; | 5009 gfx::Transform parent_scale_matrix; |
| 5026 SkMScalar initial_parent_scale = 2.0; | 5010 SkMScalar initial_parent_scale = 2.0; |
| 5027 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 5011 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5028 | 5012 |
| 5029 gfx::Transform child_scale_matrix; | 5013 gfx::Transform child_scale_matrix; |
| 5030 SkMScalar initial_child_scale = 3.0; | 5014 SkMScalar initial_child_scale = 3.0; |
| 5031 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | 5015 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5215 // needs to be scaled by the device and page scale factors. It also needs to | 5199 // needs to be scaled by the device and page scale factors. It also needs to |
| 5216 // be scaled by any transform heirarchy below its target surface. | 5200 // be scaled by any transform heirarchy below its target surface. |
| 5217 EXPECT_FLOAT_EQ( | 5201 EXPECT_FLOAT_EQ( |
| 5218 device_scale_factor * page_scale_factor * initial_child_scale, | 5202 device_scale_factor * page_scale_factor * initial_child_scale, |
| 5219 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); | 5203 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
| 5220 EXPECT_FLOAT_EQ( | 5204 EXPECT_FLOAT_EQ( |
| 5221 device_scale_factor * page_scale_factor * initial_child_scale, | 5205 device_scale_factor * page_scale_factor * initial_child_scale, |
| 5222 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); | 5206 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
| 5223 } | 5207 } |
| 5224 | 5208 |
| 5225 TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { | 5209 TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
| 5226 MockContentLayerClient delegate; | 5210 MockContentLayerClient delegate; |
| 5227 gfx::Transform identity_matrix; | 5211 gfx::Transform identity_matrix; |
| 5228 | 5212 |
| 5229 gfx::Transform parent_scale_matrix; | 5213 gfx::Transform parent_scale_matrix; |
| 5230 SkMScalar initial_parent_scale = 1.75; | 5214 SkMScalar initial_parent_scale = 1.75; |
| 5231 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); | 5215 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5232 | 5216 |
| 5233 gfx::Transform child_scale_matrix; | 5217 gfx::Transform child_scale_matrix; |
| 5234 SkMScalar initial_child_scale = 1.25; | 5218 SkMScalar initial_child_scale = 1.25; |
| 5235 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); | 5219 child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5236 | 5220 |
| 5237 scoped_refptr<Layer> root = Layer::Create(); | 5221 scoped_refptr<Layer> root = Layer::Create(); |
| 5238 root->SetBounds(gfx::Size(100, 100)); | 5222 root->SetBounds(gfx::Size(100, 100)); |
| 5239 | 5223 |
| 5240 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 5224 scoped_refptr<FakePictureLayer> parent = |
| 5225 CreateDrawablePictureLayer(&delegate); | |
| 5241 SetLayerPropertiesForTesting(parent.get(), | 5226 SetLayerPropertiesForTesting(parent.get(), |
| 5242 parent_scale_matrix, | 5227 parent_scale_matrix, |
| 5243 gfx::Point3F(), | 5228 gfx::Point3F(), |
| 5244 gfx::PointF(), | 5229 gfx::PointF(), |
| 5245 gfx::Size(100, 100), | 5230 gfx::Size(100, 100), |
| 5246 false, | 5231 false, |
| 5247 true); | 5232 true); |
| 5248 | 5233 |
| 5249 scoped_refptr<ContentLayer> child_scale = | 5234 scoped_refptr<FakePictureLayer> child_scale = |
| 5250 CreateDrawableContentLayer(&delegate); | 5235 CreateDrawablePictureLayer(&delegate); |
| 5251 SetLayerPropertiesForTesting(child_scale.get(), | 5236 SetLayerPropertiesForTesting(child_scale.get(), |
| 5252 child_scale_matrix, | 5237 child_scale_matrix, |
| 5253 gfx::Point3F(), | 5238 gfx::Point3F(), |
| 5254 gfx::PointF(2.f, 2.f), | 5239 gfx::PointF(2.f, 2.f), |
| 5255 gfx::Size(10, 10), | 5240 gfx::Size(10, 10), |
| 5256 false, | 5241 false, |
| 5257 true); | 5242 true); |
| 5258 | 5243 |
| 5259 root->AddChild(parent); | 5244 root->AddChild(parent); |
| 5260 | 5245 |
| 5261 parent->AddChild(child_scale); | 5246 parent->AddChild(child_scale); |
| 5262 | 5247 |
| 5263 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 5248 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 5264 host->SetRootLayer(root); | 5249 host->SetRootLayer(root); |
| 5265 | 5250 |
| 5266 // Now put an animating transform on child. | 5251 // Now put an animating transform on child. |
| 5267 int animation_id = AddAnimatedTransformToController( | 5252 int animation_id = AddAnimatedTransformToController( |
| 5268 child_scale->layer_animation_controller(), 10.0, 30, 0); | 5253 child_scale->layer_animation_controller(), 10.0, 30, 0); |
| 5269 | 5254 |
| 5270 { | 5255 { |
| 5271 RenderSurfaceLayerList render_surface_layer_list; | 5256 RenderSurfaceLayerList render_surface_layer_list; |
| 5272 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 5257 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5273 root.get(), | 5258 root.get(), |
| 5274 gfx::ToCeiledSize(root->bounds()), | 5259 gfx::ToCeiledSize(root->bounds()), |
| 5275 &render_surface_layer_list); | 5260 &render_surface_layer_list); |
| 5276 inputs.can_adjust_raster_scales = true; | 5261 inputs.can_adjust_raster_scales = true; |
| 5277 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 5262 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5278 | 5263 |
| 5279 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); | 5264 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5280 // The layers with animating transforms should not compute a contents scale | 5265 // Animating layers compute ideal scale in the same way as when |
| 5281 // other than 1 until they finish animating. | 5266 // they are static. |
| 5282 EXPECT_CONTENTS_SCALE_EQ(1, child_scale); | 5267 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5268 child_scale); | |
| 5283 } | 5269 } |
| 5284 | 5270 |
| 5285 // Remove the animation, now it can save a raster scale. | 5271 // Remove the animation, now it can save a raster scale. |
|
danakj
2014/10/08 21:13:52
remove from here to the end of this test, it's not
sohanjg
2014/10/13 06:33:38
Done.
| |
| 5286 child_scale->layer_animation_controller()->RemoveAnimation(animation_id); | 5272 child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
| 5287 | 5273 |
| 5288 { | 5274 { |
| 5289 RenderSurfaceLayerList render_surface_layer_list; | 5275 RenderSurfaceLayerList render_surface_layer_list; |
| 5290 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 5276 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5291 root.get(), | 5277 root.get(), |
| 5292 gfx::ToCeiledSize(root->bounds()), | 5278 gfx::ToCeiledSize(root->bounds()), |
| 5293 &render_surface_layer_list); | 5279 &render_surface_layer_list); |
| 5294 inputs.can_adjust_raster_scales = true; | 5280 inputs.can_adjust_raster_scales = true; |
| 5295 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 5281 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5296 | 5282 |
| 5297 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); | 5283 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5298 // The layers with animating transforms should not compute a contents scale | 5284 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5299 // other than 1 until they finish animating. | 5285 child_scale); |
| 5300 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, | |
| 5301 child_scale); | |
| 5302 } | 5286 } |
| 5303 } | 5287 } |
| 5304 | 5288 |
| 5289 // TODO(sohanjg): Remove this test when ContentLayer is removed. | |
| 5305 TEST_F(LayerTreeHostCommonTest, | 5290 TEST_F(LayerTreeHostCommonTest, |
| 5306 ChangeInContentBoundsOrScaleTriggersPushProperties) { | 5291 ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5307 MockContentLayerClient delegate; | 5292 MockContentLayerClient delegate; |
| 5308 scoped_refptr<Layer> root = Layer::Create(); | 5293 scoped_refptr<Layer> root = Layer::Create(); |
| 5309 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); | 5294 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5310 root->AddChild(child); | 5295 root->AddChild(child); |
| 5311 | 5296 |
| 5312 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 5297 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 5313 host->SetRootLayer(root); | 5298 host->SetRootLayer(root); |
| 5314 | 5299 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5351 // This will not change either layer's contents scale or content bounds. | 5336 // This will not change either layer's contents scale or content bounds. |
| 5352 ExecuteCalculateDrawProperties(root.get(), 2.f); | 5337 ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5353 EXPECT_FALSE(root->needs_push_properties()); | 5338 EXPECT_FALSE(root->needs_push_properties()); |
| 5354 EXPECT_FALSE(child->needs_push_properties()); | 5339 EXPECT_FALSE(child->needs_push_properties()); |
| 5355 } | 5340 } |
| 5356 | 5341 |
| 5357 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { | 5342 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
| 5358 MockContentLayerClient delegate; | 5343 MockContentLayerClient delegate; |
| 5359 gfx::Transform identity_matrix; | 5344 gfx::Transform identity_matrix; |
| 5360 | 5345 |
| 5361 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 5346 scoped_refptr<FakePictureLayer> parent = |
| 5347 CreateDrawablePictureLayer(&delegate); | |
| 5362 SetLayerPropertiesForTesting(parent.get(), | 5348 SetLayerPropertiesForTesting(parent.get(), |
| 5363 identity_matrix, | 5349 identity_matrix, |
| 5364 gfx::Point3F(), | 5350 gfx::Point3F(), |
| 5365 gfx::PointF(), | 5351 gfx::PointF(), |
| 5366 gfx::Size(30, 30), | 5352 gfx::Size(30, 30), |
| 5367 false, | 5353 false, |
| 5368 true); | 5354 true); |
| 5369 | 5355 |
| 5370 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); | 5356 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
| 5371 SetLayerPropertiesForTesting(child.get(), | 5357 SetLayerPropertiesForTesting(child.get(), |
| 5372 identity_matrix, | 5358 identity_matrix, |
| 5373 gfx::Point3F(), | 5359 gfx::Point3F(), |
| 5374 gfx::PointF(2.f, 2.f), | 5360 gfx::PointF(2.f, 2.f), |
| 5375 gfx::Size(10, 10), | 5361 gfx::Size(10, 10), |
| 5376 false, | 5362 false, |
| 5377 true); | 5363 true); |
| 5378 | 5364 |
| 5379 gfx::Transform replica_transform; | 5365 gfx::Transform replica_transform; |
| 5380 replica_transform.Scale(1.0, -1.0); | 5366 replica_transform.Scale(1.0, -1.0); |
| 5381 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); | 5367 scoped_refptr<FakePictureLayer> replica = |
| 5368 CreateDrawablePictureLayer(&delegate); | |
| 5382 SetLayerPropertiesForTesting(replica.get(), | 5369 SetLayerPropertiesForTesting(replica.get(), |
| 5383 replica_transform, | 5370 replica_transform, |
| 5384 gfx::Point3F(), | 5371 gfx::Point3F(), |
| 5385 gfx::PointF(2.f, 2.f), | 5372 gfx::PointF(2.f, 2.f), |
| 5386 gfx::Size(10, 10), | 5373 gfx::Size(10, 10), |
| 5387 false, | 5374 false, |
| 5388 true); | 5375 true); |
| 5389 | 5376 |
| 5390 // This layer should end up in the same surface as child, with the same draw | 5377 // This layer should end up in the same surface as child, with the same draw |
| 5391 // and screen space transforms. | 5378 // and screen space transforms. |
| 5392 scoped_refptr<ContentLayer> duplicate_child_non_owner = | 5379 scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
| 5393 CreateDrawableContentLayer(&delegate); | 5380 CreateDrawablePictureLayer(&delegate); |
| 5394 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), | 5381 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5395 identity_matrix, | 5382 identity_matrix, |
| 5396 gfx::Point3F(), | 5383 gfx::Point3F(), |
| 5397 gfx::PointF(), | 5384 gfx::PointF(), |
| 5398 gfx::Size(10, 10), | 5385 gfx::Size(10, 10), |
| 5399 false, | 5386 false, |
| 5400 true); | 5387 true); |
| 5401 | 5388 |
| 5402 parent->AddChild(child); | 5389 parent->AddChild(child); |
| 5403 child->AddChild(duplicate_child_non_owner); | 5390 child->AddChild(duplicate_child_non_owner); |
| 5404 child->SetReplicaLayer(replica.get()); | 5391 child->SetReplicaLayer(replica.get()); |
| 5405 | 5392 |
| 5406 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 5393 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 5407 host->SetRootLayer(parent); | 5394 host->SetRootLayer(parent); |
| 5408 | 5395 |
| 5409 RenderSurfaceLayerList render_surface_layer_list; | 5396 RenderSurfaceLayerList render_surface_layer_list; |
| 5410 | 5397 |
| 5411 float device_scale_factor = 1.5f; | 5398 float device_scale_factor = 1.5f; |
| 5412 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 5399 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5413 parent.get(), parent->bounds(), &render_surface_layer_list); | 5400 parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5414 inputs.device_scale_factor = device_scale_factor; | 5401 inputs.device_scale_factor = device_scale_factor; |
| 5415 inputs.can_adjust_raster_scales = true; | 5402 inputs.can_adjust_raster_scales = true; |
| 5416 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 5403 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5417 | 5404 |
| 5418 // We should have two render surfaces. The root's render surface and child's | 5405 // We should have two render surfaces. The root's render surface and child's |
| 5419 // render surface (it needs one because it has a replica layer). | 5406 // render surface (it needs one because it has a replica layer). |
| 5420 EXPECT_EQ(2u, render_surface_layer_list.size()); | 5407 EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 5421 | 5408 |
| 5422 gfx::Transform expected_parent_transform; | 5409 gfx::Transform expected_parent_transform; |
| 5410 expected_parent_transform.Scale(device_scale_factor, device_scale_factor); | |
| 5423 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | 5411 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5424 parent->screen_space_transform()); | 5412 parent->screen_space_transform()); |
| 5425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, | 5413 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5426 parent->draw_transform()); | 5414 parent->draw_transform()); |
| 5427 | 5415 |
| 5428 gfx::Transform expected_draw_transform; | 5416 gfx::Transform expected_draw_transform; |
| 5417 expected_draw_transform.Scale(device_scale_factor, device_scale_factor); | |
| 5429 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, | 5418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5430 child->draw_transform()); | 5419 child->draw_transform()); |
| 5431 | 5420 |
| 5432 gfx::Transform expected_screen_space_transform; | 5421 gfx::Transform expected_screen_space_transform; |
| 5433 expected_screen_space_transform.Translate( | 5422 expected_screen_space_transform.Scale(device_scale_factor, |
| 5434 device_scale_factor * child->position().x(), | 5423 device_scale_factor); |
| 5435 device_scale_factor * child->position().y()); | 5424 expected_screen_space_transform.Translate(child->position().x(), |
| 5425 child->position().y()); | |
| 5436 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, | 5426 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5437 child->screen_space_transform()); | 5427 child->screen_space_transform()); |
| 5438 | 5428 |
| 5439 gfx::Transform expected_duplicate_child_draw_transform = | 5429 gfx::Transform expected_duplicate_child_draw_transform = |
| 5440 child->draw_transform(); | 5430 child->draw_transform(); |
| 5441 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), | 5431 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5442 duplicate_child_non_owner->draw_transform()); | 5432 duplicate_child_non_owner->draw_transform()); |
| 5443 EXPECT_TRANSFORMATION_MATRIX_EQ( | 5433 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5444 child->screen_space_transform(), | 5434 child->screen_space_transform(), |
| 5445 duplicate_child_non_owner->screen_space_transform()); | 5435 duplicate_child_non_owner->screen_space_transform()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5486 EXPECT_TRANSFORMATION_MATRIX_EQ( | 5476 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5487 expected_replica_screen_space_transform, | 5477 expected_replica_screen_space_transform, |
| 5488 child->render_surface()->replica_screen_space_transform()); | 5478 child->render_surface()->replica_screen_space_transform()); |
| 5489 } | 5479 } |
| 5490 | 5480 |
| 5491 TEST_F(LayerTreeHostCommonTest, | 5481 TEST_F(LayerTreeHostCommonTest, |
| 5492 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { | 5482 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5493 MockContentLayerClient delegate; | 5483 MockContentLayerClient delegate; |
| 5494 gfx::Transform identity_matrix; | 5484 gfx::Transform identity_matrix; |
| 5495 | 5485 |
| 5496 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); | 5486 scoped_refptr<FakePictureLayer> parent = |
| 5487 CreateDrawablePictureLayer(&delegate); | |
| 5497 SetLayerPropertiesForTesting(parent.get(), | 5488 SetLayerPropertiesForTesting(parent.get(), |
| 5498 identity_matrix, | 5489 identity_matrix, |
| 5499 gfx::Point3F(), | 5490 gfx::Point3F(), |
| 5500 gfx::PointF(), | 5491 gfx::PointF(), |
| 5501 gfx::Size(33, 31), | 5492 gfx::Size(33, 31), |
| 5502 false, | 5493 false, |
| 5503 true); | 5494 true); |
| 5504 | 5495 |
| 5505 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); | 5496 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
| 5506 SetLayerPropertiesForTesting(child.get(), | 5497 SetLayerPropertiesForTesting(child.get(), |
| 5507 identity_matrix, | 5498 identity_matrix, |
| 5508 gfx::Point3F(), | 5499 gfx::Point3F(), |
| 5509 gfx::PointF(), | 5500 gfx::PointF(), |
| 5510 gfx::Size(13, 11), | 5501 gfx::Size(13, 11), |
| 5511 false, | 5502 false, |
| 5512 true); | 5503 true); |
| 5513 | 5504 |
| 5514 gfx::Transform replica_transform; | 5505 gfx::Transform replica_transform; |
| 5515 replica_transform.Scale(1.0, -1.0); | 5506 replica_transform.Scale(1.0, -1.0); |
| 5516 scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); | 5507 scoped_refptr<FakePictureLayer> replica = |
| 5508 CreateDrawablePictureLayer(&delegate); | |
| 5517 SetLayerPropertiesForTesting(replica.get(), | 5509 SetLayerPropertiesForTesting(replica.get(), |
| 5518 replica_transform, | 5510 replica_transform, |
| 5519 gfx::Point3F(), | 5511 gfx::Point3F(), |
| 5520 gfx::PointF(), | 5512 gfx::PointF(), |
| 5521 gfx::Size(13, 11), | 5513 gfx::Size(13, 11), |
| 5522 false, | 5514 false, |
| 5523 true); | 5515 true); |
| 5524 | 5516 |
| 5525 // This layer should end up in the same surface as child, with the same draw | |
| 5526 // and screen space transforms. | |
| 5527 scoped_refptr<ContentLayer> duplicate_child_non_owner = | |
| 5528 CreateDrawableContentLayer(&delegate); | |
| 5529 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), | |
| 5530 identity_matrix, | |
| 5531 gfx::Point3F(), | |
| 5532 gfx::PointF(), | |
| 5533 gfx::Size(13, 11), | |
| 5534 false, | |
| 5535 true); | |
| 5536 | |
| 5537 parent->AddChild(child); | 5517 parent->AddChild(child); |
| 5538 child->AddChild(duplicate_child_non_owner); | |
| 5539 child->SetReplicaLayer(replica.get()); | 5518 child->SetReplicaLayer(replica.get()); |
| 5540 | 5519 |
| 5541 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 5520 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 5542 host->SetRootLayer(parent); | 5521 host->SetRootLayer(parent); |
| 5543 | 5522 |
| 5544 float device_scale_factor = 1.7f; | 5523 float device_scale_factor = 1.7f; |
| 5545 | 5524 |
| 5546 RenderSurfaceLayerList render_surface_layer_list; | 5525 RenderSurfaceLayerList render_surface_layer_list; |
| 5547 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( | 5526 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5548 parent.get(), parent->bounds(), &render_surface_layer_list); | 5527 parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5549 inputs.device_scale_factor = device_scale_factor; | 5528 inputs.device_scale_factor = device_scale_factor; |
| 5550 inputs.can_adjust_raster_scales = true; | 5529 inputs.can_adjust_raster_scales = true; |
| 5551 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 5530 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5552 | 5531 |
| 5553 // We should have two render surfaces. The root's render surface and child's | 5532 // We should have two render surfaces. The root's render surface and child's |
| 5554 // render surface (it needs one because it has a replica layer). | 5533 // render surface (it needs one because it has a replica layer). |
| 5555 EXPECT_EQ(2u, render_surface_layer_list.size()); | 5534 EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 5556 | 5535 |
| 5557 gfx::Transform identity_transform; | 5536 gfx::Transform identity_transform; |
| 5558 | |
| 5559 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | |
| 5560 parent->screen_space_transform()); | |
| 5561 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); | |
| 5562 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); | |
| 5563 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | |
| 5564 child->screen_space_transform()); | |
| 5565 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | |
| 5566 duplicate_child_non_owner->draw_transform()); | |
| 5567 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 5568 identity_transform, duplicate_child_non_owner->screen_space_transform()); | |
| 5569 EXPECT_RECT_EQ(child->drawable_content_rect(), | |
| 5570 duplicate_child_non_owner->drawable_content_rect()); | |
| 5571 EXPECT_EQ(child->content_bounds(), | |
| 5572 duplicate_child_non_owner->content_bounds()); | |
| 5573 | |
| 5574 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | 5537 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5575 child->render_surface()->draw_transform()); | 5538 child->render_surface()->draw_transform()); |
| 5576 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, | 5539 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5577 child->render_surface()->draw_transform()); | 5540 child->render_surface()->draw_transform()); |
| 5578 EXPECT_TRANSFORMATION_MATRIX_EQ( | 5541 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5579 identity_transform, child->render_surface()->screen_space_transform()); | 5542 identity_transform, child->render_surface()->screen_space_transform()); |
| 5580 | 5543 |
| 5581 gfx::Transform expected_replica_draw_transform; | 5544 gfx::Transform expected_replica_draw_transform; |
| 5582 expected_replica_draw_transform.matrix().set(1, 1, -1.0); | 5545 expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5583 EXPECT_TRANSFORMATION_MATRIX_EQ( | 5546 EXPECT_TRANSFORMATION_MATRIX_EQ( |
| (...skipping 3100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8684 // by the viewport. | 8647 // by the viewport. |
| 8685 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); | 8648 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8686 | 8649 |
| 8687 // Layers drawing to a child render surface should still have their visible | 8650 // Layers drawing to a child render surface should still have their visible |
| 8688 // content rect clipped by the viewport. | 8651 // content rect clipped by the viewport. |
| 8689 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); | 8652 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8690 } | 8653 } |
| 8691 | 8654 |
| 8692 } // namespace | 8655 } // namespace |
| 8693 } // namespace cc | 8656 } // namespace cc |
| OLD | NEW |