ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 10 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 12 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 13 | #include "cc/animation/animation_host.h" |
| 14 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 15 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 16 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 17 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 18 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 19 | #include "cc/base/math_util.h" |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 20 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 21 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 23 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 24 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 25 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 26 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 27 | #include "cc/output/copy_output_request.h" |
| 28 | #include "cc/output/copy_output_result.h" |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 29 | #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 30 | #include "cc/proto/gfx_conversions.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 31 | #include "cc/test/animation_test_common.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 32 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 33 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 34 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 35 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 36 | #include "cc/test/fake_output_surface.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 37 | #include "cc/test/fake_picture_layer.h" |
| 38 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 39 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 40 | #include "cc/test/layer_tree_host_common_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 41 | #include "cc/test/test_task_graph_runner.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 42 | #include "cc/trees/draw_property_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 43 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 44 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 45 | #include "cc/trees/task_runner_provider.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 46 | #include "testing/gmock/include/gmock/gmock.h" |
| 47 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 48 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 49 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 50 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 52 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | namespace { |
| 54 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 55 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 56 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 57 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 59 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 60 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 61 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 62 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 63 | }; |
| 64 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 65 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 66 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 67 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 68 | public: |
| 69 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 70 | ~MockContentLayerClient() override {} |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 71 | gfx::Rect PaintableRegion() override { return gfx::Rect(); } |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 72 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 73 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 74 | NOTIMPLEMENTED(); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 75 | return nullptr; |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 76 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 77 | bool FillsBoundsCompletely() const override { return false; } |
jbroman | 9f60f1a | 2015-07-16 21:40:32 | [diff] [blame] | 78 | size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 79 | }; |
| 80 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 81 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 82 | do { \ |
| 83 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 84 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 85 | } while (false) |
| 86 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 87 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 88 | do { \ |
| 89 | EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \ |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 90 | } while (false) |
| 91 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 92 | class LayerTreeSettingsScaleContent : public LayerTreeSettings { |
| 93 | public: |
| 94 | LayerTreeSettingsScaleContent() { |
| 95 | layer_transforms_should_scale_layer_contents = true; |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest { |
| 100 | public: |
| 101 | LayerTreeHostCommonScalingTest() |
| 102 | : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {} |
| 103 | }; |
| 104 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 105 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 106 | // Sanity check: For layers positioned at zero, with zero size, |
| 107 | // and with identity transforms, then the draw transform, |
| 108 | // screen space transform, and the hierarchy passed on to children |
| 109 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 111 | LayerImpl* parent = root_layer(); |
| 112 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 113 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 114 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 115 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 116 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 117 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 118 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 119 | gfx::PointF(), gfx::Size(), true, false); |
| 120 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 121 | gfx::PointF(), gfx::Size(), true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 122 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 123 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 124 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 125 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 126 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 127 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 128 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 129 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 130 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 131 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 132 | } |
| 133 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 134 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 135 | // Tests that effect tree node gets a valid transform id when a layer |
| 136 | // has opacity but doesn't create a render surface. |
| 137 | LayerImpl* parent = root_layer(); |
| 138 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 139 | child->SetDrawsContent(true); |
| 140 | |
| 141 | gfx::Transform identity_matrix; |
| 142 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 143 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 144 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 145 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
| 146 | false); |
| 147 | child->SetOpacity(0.f); |
| 148 | ExecuteCalculateDrawProperties(parent); |
| 149 | EffectTree effect_tree = |
| 150 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 151 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 152 | const int transform_tree_size = parent->layer_tree_impl() |
| 153 | ->property_trees() |
| 154 | ->transform_tree.next_available_id(); |
| 155 | EXPECT_LT(node->data.transform_id, transform_tree_size); |
| 156 | } |
| 157 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 158 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 159 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 160 | LayerImpl* root = root_layer(); |
| 161 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 162 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 163 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 164 | gfx::PointF(), gfx::Size(1, 2), true, false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 165 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 166 | TransformTree& tree = |
| 167 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 168 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 169 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 170 | // transform or the screenspace transform. |
| 171 | gfx::Transform translation_to_center; |
| 172 | translation_to_center.Translate(5.0, 6.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 173 | SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 174 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 175 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 176 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 177 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 178 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 179 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 180 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 181 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 182 | // no effect on the transforms. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 183 | SetLayerPropertiesForTesting(layer, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 184 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 185 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 186 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 187 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 188 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 189 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 190 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 191 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 192 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 193 | // Case 4: A change in actual position affects both the draw transform and |
| 194 | // screen space transform. |
| 195 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 196 | position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 197 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 198 | layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 199 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 200 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 201 | ExecuteCalculateDrawProperties(root); |
| 202 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 203 | position_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 204 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 205 | position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 206 | draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 207 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 208 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 209 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 210 | // scale transform, because scale and translation are not commutative. |
| 211 | gfx::Transform layer_transform; |
| 212 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 213 | SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 214 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 215 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 216 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 217 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 218 | layer_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 219 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 220 | layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 222 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 223 | gfx::Transform translation_to_anchor; |
| 224 | translation_to_anchor.Translate(5.0, 0.0); |
| 225 | gfx::Transform expected_result = |
| 226 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 227 | SetLayerPropertiesForTesting(layer, layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 228 | gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(), |
| 229 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 230 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 231 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 232 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 233 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 234 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 235 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 237 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 238 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 239 | // it is still worth testing to detect accidental regressions. |
| 240 | expected_result = position_transform * translation_to_anchor * |
| 241 | layer_transform * Inverse(translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 242 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 243 | layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 244 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 245 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 246 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 247 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 248 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 249 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 250 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 253 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 254 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 255 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 256 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 257 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 258 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 259 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 260 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 261 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 262 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 263 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 264 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 265 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 266 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 267 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 268 | gfx::Transform identity_matrix; |
| 269 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 270 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 271 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 272 | sublayer->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 273 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 274 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 275 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 276 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 277 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 278 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 279 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 280 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 281 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 282 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 283 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 284 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 285 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 286 | |
| 287 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 288 | clip_layer->SetBounds( |
| 289 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 290 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 291 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 292 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 293 | gfx::Transform impl_transform; |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 294 | scroll_layer->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 295 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 296 | clip_layer->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 297 | scroll_layer_raw_ptr->layer_tree_impl() |
| 298 | ->property_trees() |
| 299 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 300 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 301 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 302 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 303 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 304 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 305 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 306 | root->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 307 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 308 | LayerImpl* root_layer = root.get(); |
| 309 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 310 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 311 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 312 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 313 | gfx::Transform expected_transform = identity_matrix; |
| 314 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 315 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 316 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 317 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 318 | page_scale * kDeviceScale)); |
| 319 | expected_transform.Scale(page_scale * kDeviceScale, |
| 320 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 321 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 322 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 323 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 324 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 325 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 326 | gfx::Transform arbitrary_translate; |
| 327 | const float kTranslateX = 10.6f; |
| 328 | const float kTranslateY = 20.6f; |
| 329 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 330 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 331 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 332 | true, false, false); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 333 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 334 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 335 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 336 | expected_transform.MakeIdentity(); |
| 337 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 338 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 339 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 340 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 341 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 342 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 343 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 344 | expected_transform.Scale(page_scale * kDeviceScale, |
| 345 | page_scale * kDeviceScale); |
| 346 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 347 | sublayer->DrawTransform()); |
| 348 | |
| 349 | // Test that page scale is updated even when we don't rebuild property trees. |
| 350 | page_scale = 1.888f; |
| 351 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 352 | Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID, |
| 353 | Layer::INVALID_ID); |
| 354 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 355 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 356 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 357 | scroll_layer->parent()); |
| 358 | |
| 359 | expected_transform.MakeIdentity(); |
| 360 | expected_transform.Translate( |
| 361 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 362 | sub_layer_screen_position.x() * page_scale * |
| 363 | kDeviceScale), |
| 364 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 365 | sub_layer_screen_position.y() * page_scale * |
| 366 | kDeviceScale)); |
| 367 | expected_transform.Scale(page_scale * kDeviceScale, |
| 368 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 369 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 370 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 373 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 374 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 375 | LayerImpl* root = root_layer(); |
| 376 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 377 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 378 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 379 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 380 | // One-time setup of root layer |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 381 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 382 | gfx::PointF(), gfx::Size(1, 2), true, false); |
| 383 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 384 | TransformTree& tree = |
| 385 | host_impl()->active_tree()->property_trees()->transform_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 386 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 387 | // Case 1: parent's anchor point should not affect child or grand_child. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 388 | SetLayerPropertiesForTesting(parent, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 389 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 390 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 391 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 392 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 393 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 394 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 395 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 396 | |
| 397 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 398 | identity_matrix, draw_property_utils::DrawTransform(child, tree)); |
| 399 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 400 | identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree)); |
| 401 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 402 | identity_matrix, draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 403 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 404 | identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 405 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 407 | // Case 2: parent's position affects child and grand_child. |
| 408 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 409 | parent_position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 410 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 411 | parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 412 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 413 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 414 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 415 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 416 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 417 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 418 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 419 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 420 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 421 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 422 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 423 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 424 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 425 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 426 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 427 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 428 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 429 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 430 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 431 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 432 | // Case 3: parent's local transform affects child and grandchild |
| 433 | gfx::Transform parent_layer_transform; |
| 434 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 435 | gfx::Transform parent_translation_to_anchor; |
| 436 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 437 | gfx::Transform parent_composite_transform = |
| 438 | parent_translation_to_anchor * parent_layer_transform * |
| 439 | Inverse(parent_translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 440 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 441 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 442 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 443 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 444 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 445 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 446 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 447 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 448 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 449 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 450 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 451 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 452 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 453 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 454 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 455 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 456 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 457 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 458 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 459 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 460 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 461 | } |
| 462 | |
jaydasika | 5f7a7b8 | 2016-04-05 20:24:29 | [diff] [blame] | 463 | // Render target should get cleared when subtree is skipped. |
| 464 | TEST_F(LayerTreeHostCommonTest, ClearRenderTargetForSkippedLayers) { |
| 465 | LayerImpl* root = root_layer(); |
| 466 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 467 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 468 | child->SetDrawsContent(true); |
| 469 | |
| 470 | gfx::Transform identity_matrix; |
| 471 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 472 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 473 | true); |
| 474 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 475 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 476 | true); |
| 477 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 478 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 479 | false); |
| 480 | |
| 481 | ExecuteCalculateDrawProperties(root); |
| 482 | ASSERT_TRUE(parent->render_surface()); |
| 483 | EXPECT_EQ(parent, child->render_target()); |
| 484 | |
| 485 | // child is skipped when root's opacity is set to 0. So, its render target |
| 486 | // should be reset. |
| 487 | root->OnOpacityAnimated(0.0f); |
| 488 | ExecuteCalculateDrawProperties(root); |
| 489 | EXPECT_FALSE(child->render_target()); |
| 490 | } |
| 491 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 492 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 493 | LayerImpl* root = root_layer(); |
| 494 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 495 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 496 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 497 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 498 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 500 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 501 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 502 | true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 503 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 504 | // Child is set up so that a new render surface should be created. |
| 505 | child->SetOpacity(0.5f); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 506 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 508 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 509 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 510 | gfx::Transform parent_translation_to_anchor; |
| 511 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 513 | gfx::Transform parent_composite_transform = |
| 514 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 515 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 516 | gfx::Vector2dF parent_composite_scale = |
| 517 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 518 | 1.f); |
| 519 | gfx::Transform surface_sublayer_transform; |
| 520 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 521 | parent_composite_scale.y()); |
| 522 | gfx::Transform surface_sublayer_composite_transform = |
| 523 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 524 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 525 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 526 | gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(), |
| 527 | gfx::Size(100, 120), true, false, false); |
| 528 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 529 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 530 | true); |
| 531 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 532 | gfx::PointF(), gfx::Size(8, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 533 | false); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 534 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 535 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 536 | // Render surface should have been created now. |
| 537 | ASSERT_TRUE(child->render_surface()); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 538 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 540 | // The child layer's draw transform should refer to its new render surface. |
| 541 | // The screen-space transform, however, should still refer to the root. |
| 542 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 543 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 544 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 545 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 546 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 547 | // Because the grand_child is the only drawable content, the child's render |
| 548 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 549 | // surface's subtree is drawn must be removed from the composite transform. |
| 550 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 551 | surface_sublayer_composite_transform, |
| 552 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 553 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 554 | // The screen space is the same as the target since the child surface draws |
| 555 | // into the root. |
| 556 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 557 | surface_sublayer_composite_transform, |
| 558 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 559 | } |
| 560 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 561 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
| 562 | LayerImpl* root = root_layer(); |
| 563 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 564 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 565 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 566 | grand_child->SetDrawsContent(true); |
| 567 | |
| 568 | gfx::Transform identity_matrix; |
| 569 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 570 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 571 | true); |
| 572 | |
| 573 | gfx::Transform parent_transform; |
| 574 | parent_transform.Translate(10.0, 10.0); |
| 575 | |
| 576 | gfx::Transform child_transform; |
| 577 | child_transform.Rotate(45.0); |
| 578 | |
| 579 | // child gets a render surface when surfaces are enabled. |
| 580 | SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(), |
| 581 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 582 | false); |
| 583 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 584 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 585 | true); |
| 586 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 587 | gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true, |
| 588 | false, false); |
| 589 | |
| 590 | gfx::Transform expected_grand_child_screen_space_transform; |
| 591 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 592 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 593 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 594 | |
| 595 | // First compute draw properties with separate surfaces enabled. |
| 596 | ExecuteCalculateDrawProperties(root); |
| 597 | |
| 598 | // The grand child's draw transform should be its offset wrt the child. |
| 599 | gfx::Transform expected_grand_child_draw_transform; |
| 600 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 601 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 602 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 603 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 604 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 605 | |
| 606 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 607 | |
| 608 | // With separate surfaces disabled, the grand child's draw transform should be |
| 609 | // the same as its screen space transform. |
| 610 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 611 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 612 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 613 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 614 | } |
| 615 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 616 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 617 | LayerImpl* root = root_layer(); |
| 618 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 619 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 620 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 621 | grand_child->SetDrawsContent(true); |
| 622 | scoped_ptr<LayerImpl> child_replica = |
| 623 | LayerImpl::Create(host_impl()->active_tree(), 100); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 624 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 625 | // One-time setup of root layer |
| 626 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 627 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 628 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 629 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 630 | |
| 631 | // Child is set up so that a new render surface should be created. |
| 632 | child->SetOpacity(0.5f); |
| 633 | |
| 634 | gfx::Transform parent_layer_transform; |
| 635 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 636 | gfx::Transform parent_translation_to_anchor; |
| 637 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 638 | gfx::Transform parent_composite_transform = |
| 639 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 640 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 641 | gfx::Transform replica_layer_transform; |
| 642 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 643 | gfx::Vector2dF parent_composite_scale = |
| 644 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 645 | 1.f); |
| 646 | gfx::Transform surface_sublayer_transform; |
| 647 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 648 | parent_composite_scale.y()); |
| 649 | gfx::Transform replica_composite_transform = |
| 650 | parent_composite_transform * replica_layer_transform * |
| 651 | Inverse(surface_sublayer_transform); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 652 | child_replica->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 653 | // Child's render surface should not exist yet. |
| 654 | ASSERT_FALSE(child->render_surface()); |
| 655 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 656 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 657 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 658 | gfx::Size(10, 12), true, false, false); |
| 659 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 660 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 661 | true); |
| 662 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 663 | gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true, |
| 664 | false, false); |
| 665 | SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform, |
| 666 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 667 | false, false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 668 | child->SetReplicaLayer(std::move(child_replica)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 669 | |
| 670 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 671 | |
| 672 | // Render surface should have been created now. |
| 673 | ASSERT_TRUE(child->render_surface()); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 674 | ASSERT_EQ(child, child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 675 | |
| 676 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 677 | replica_composite_transform, |
| 678 | child->render_target()->render_surface()->replica_draw_transform()); |
| 679 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 680 | child->render_target() |
| 681 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 682 | ->replica_screen_space_transform()); |
| 683 | } |
| 684 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 685 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | // This test creates a more complex tree and verifies it all at once. This |
| 687 | // covers the following cases: |
| 688 | // - layers that are described w.r.t. a render surface: should have draw |
| 689 | // transforms described w.r.t. that surface |
| 690 | // - A render surface described w.r.t. an ancestor render surface: should |
| 691 | // have a draw transform described w.r.t. that ancestor surface |
| 692 | // - Replicas of a render surface are described w.r.t. the replica's |
| 693 | // transform around its anchor, along with the surface itself. |
| 694 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 695 | // a render surface that is described w.r.t. an ancestor render surface. |
| 696 | // - verifying that each layer has a reference to the correct render surface |
| 697 | // and render target values. |
| 698 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 699 | LayerImpl* root = root_layer(); |
| 700 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 701 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 702 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 703 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 704 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 705 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 706 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 707 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 708 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 709 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 710 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 711 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 712 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 713 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 714 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 715 | grand_child_of_rs1->SetDrawsContent(true); |
| 716 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 717 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 718 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 719 | scoped_ptr<LayerImpl> replica_of_rs1 = |
| 720 | LayerImpl::Create(host_impl()->active_tree(), 101); |
| 721 | scoped_ptr<LayerImpl> replica_of_rs2 = |
| 722 | LayerImpl::Create(host_impl()->active_tree(), 102); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 723 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 724 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 725 | // to have a new render surface. |
| 726 | render_surface1->SetOpacity(0.5f); |
| 727 | render_surface2->SetOpacity(0.33f); |
| 728 | |
| 729 | // One-time setup of root layer |
| 730 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 731 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 732 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 733 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 734 | |
| 735 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 736 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 737 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 738 | gfx::Transform translation_to_anchor; |
| 739 | translation_to_anchor.Translate(2.5, 0.0); |
| 740 | gfx::Transform layer_transform; |
| 741 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 742 | gfx::Transform replica_layer_transform; |
| 743 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 744 | |
| 745 | gfx::Transform A = |
| 746 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 747 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 748 | Inverse(translation_to_anchor); |
| 749 | |
| 750 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 751 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 752 | gfx::Transform surface1_sublayer_transform; |
| 753 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 754 | surface1_parent_transform_scale.y()); |
| 755 | |
| 756 | // SS1 = transform given to the subtree of render_surface1 |
| 757 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 758 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 759 | // the owning layer |
| 760 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 761 | |
| 762 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 763 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 764 | gfx::Transform surface2_sublayer_transform; |
| 765 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 766 | surface2_parent_transform_scale.y()); |
| 767 | |
| 768 | // SS2 = transform given to the subtree of render_surface2 |
| 769 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 770 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 771 | // the owning layer |
| 772 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 773 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 774 | SetLayerPropertiesForTesting(parent, layer_transform, |
| 775 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 776 | gfx::Size(10, 10), true, false, false); |
| 777 | SetLayerPropertiesForTesting(render_surface1, layer_transform, |
| 778 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 779 | gfx::Size(10, 10), true, false, true); |
| 780 | SetLayerPropertiesForTesting(render_surface2, layer_transform, |
| 781 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 782 | gfx::Size(10, 10), true, false, true); |
| 783 | SetLayerPropertiesForTesting(child_of_root, layer_transform, |
| 784 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 785 | gfx::Size(10, 10), true, false, false); |
| 786 | SetLayerPropertiesForTesting(child_of_rs1, layer_transform, |
| 787 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 788 | gfx::Size(10, 10), true, false, false); |
| 789 | SetLayerPropertiesForTesting(child_of_rs2, layer_transform, |
| 790 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 791 | gfx::Size(10, 10), true, false, false); |
| 792 | SetLayerPropertiesForTesting(grand_child_of_root, layer_transform, |
| 793 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 794 | gfx::Size(10, 10), true, false, false); |
| 795 | SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform, |
| 796 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 797 | gfx::Size(10, 10), true, false, false); |
| 798 | SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform, |
| 799 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 800 | gfx::Size(10, 10), true, false, false); |
| 801 | SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform, |
| 802 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 803 | gfx::Size(), true, false, false); |
| 804 | SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform, |
| 805 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 806 | gfx::Size(), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 807 | |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 808 | // We need to set parent on replica layers for property tree building. |
| 809 | replica_of_rs1->SetParent(render_surface1); |
| 810 | replica_of_rs2->SetParent(render_surface2); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 811 | render_surface1->SetReplicaLayer(std::move(replica_of_rs1)); |
| 812 | render_surface2->SetReplicaLayer(std::move(replica_of_rs2)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 813 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 814 | |
| 815 | // Only layers that are associated with render surfaces should have an actual |
| 816 | // RenderSurface() value. |
| 817 | ASSERT_TRUE(root->render_surface()); |
| 818 | ASSERT_FALSE(child_of_root->render_surface()); |
| 819 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 820 | |
| 821 | ASSERT_TRUE(render_surface1->render_surface()); |
| 822 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 823 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 824 | |
| 825 | ASSERT_TRUE(render_surface2->render_surface()); |
| 826 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 827 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 828 | |
| 829 | // Verify all render target accessors |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 830 | EXPECT_EQ(root, parent->render_target()); |
| 831 | EXPECT_EQ(root, child_of_root->render_target()); |
| 832 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 833 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 834 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 835 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 836 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 837 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 838 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 839 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 840 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 841 | |
| 842 | // Verify layer draw transforms note that draw transforms are described with |
| 843 | // respect to the nearest ancestor render surface but screen space transforms |
| 844 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 845 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 846 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 847 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 848 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 849 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 850 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 851 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 852 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 853 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 855 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 856 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 857 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 858 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 859 | |
| 860 | // Verify layer screen-space transforms |
| 861 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 862 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 863 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 864 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 865 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 866 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 867 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 868 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 869 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 870 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 871 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 872 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 873 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 874 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 875 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 876 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 877 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 878 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 879 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 880 | |
| 881 | // Verify render surface transforms. |
| 882 | // |
| 883 | // Draw transform of render surface 1 is described with respect to root. |
| 884 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 885 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 886 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 887 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 888 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 889 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 890 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 891 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 892 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 893 | // Draw transform of render surface 2 is described with respect to render |
| 894 | // surface 1. |
| 895 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 896 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 897 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 898 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 899 | render_surface2->render_surface()->replica_draw_transform()); |
| 900 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 901 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 902 | render_surface2->render_surface()->screen_space_transform()); |
| 903 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 904 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 905 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 906 | |
| 907 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 908 | // is expected that we correctly set up transforms so that the y-component of |
| 909 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 910 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 911 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 912 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 913 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 914 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 915 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 916 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 917 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 918 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 919 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 920 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 921 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 922 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 923 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 924 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 925 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 926 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 929 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 930 | // For layers that flatten their subtree, there should be an orthographic |
| 931 | // projection (for x and y values) in the middle of the transform sequence. |
| 932 | // Note that the way the code is currently implemented, it is not expected to |
| 933 | // use a canonical orthographic projection. |
| 934 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 935 | LayerImpl* root = root_layer(); |
| 936 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 937 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 938 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 939 | grand_child->SetDrawsContent(true); |
| 940 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 941 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 942 | |
| 943 | gfx::Transform rotation_about_y_axis; |
| 944 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 945 | |
| 946 | const gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 947 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 948 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 949 | true); |
| 950 | SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(), |
| 951 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 952 | true); |
| 953 | SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis, |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 954 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 955 | true, false, false); |
| 956 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 957 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 958 | true, false, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 959 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 961 | ASSERT_TRUE(root->should_flatten_transform()); |
| 962 | ASSERT_TRUE(child->should_flatten_transform()); |
| 963 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 964 | ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 965 | |
| 966 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 967 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 968 | gfx::Transform expected_grand_child_draw_transform = |
| 969 | rotation_about_y_axis; // draws onto child's render surface |
| 970 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 971 | flattened_rotation_about_y.FlattenTo2d(); |
| 972 | gfx::Transform expected_grand_child_screen_space_transform = |
| 973 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 974 | gfx::Transform expected_great_grand_child_draw_transform = |
| 975 | flattened_rotation_about_y; |
| 976 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 977 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 978 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 979 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 980 | |
| 981 | // The child's draw transform should have been taken by its surface. |
| 982 | ASSERT_TRUE(child->render_surface()); |
| 983 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 984 | child->render_surface()->draw_transform()); |
| 985 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 986 | expected_child_screen_space_transform, |
| 987 | child->render_surface()->screen_space_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 988 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 989 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 990 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 992 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 993 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 994 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 995 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 996 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 997 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 998 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 999 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | } |
| 1001 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1002 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 1003 | scoped_refptr<Layer> root = Layer::Create(); |
| 1004 | scoped_refptr<Layer> child = Layer::Create(); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1005 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 1006 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1007 | |
| 1008 | gfx::Transform child_transform; |
| 1009 | child_transform.Translate(50.0, 50.0); |
| 1010 | child_transform.RotateAboutZAxis(30.0); |
| 1011 | |
| 1012 | gfx::Transform grand_child_transform; |
| 1013 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1014 | |
| 1015 | const gfx::Transform identity_matrix; |
| 1016 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 1017 | gfx::PointF(), gfx::Size(200, 200), true, false); |
| 1018 | SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(), |
| 1019 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1020 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform, |
| 1021 | gfx::Point3F(), gfx::PointF(), |
| 1022 | gfx::Size(100, 100), true, false); |
| 1023 | |
| 1024 | root->AddChild(child); |
| 1025 | child->AddChild(grand_child); |
| 1026 | grand_child->SetShouldFlattenTransform(false); |
| 1027 | |
| 1028 | host()->SetRootLayer(root); |
| 1029 | |
| 1030 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 1031 | |
| 1032 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1033 | // that is fully contained within the target's bounds, so grand_child should |
| 1034 | // be considered fully visible. |
| 1035 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 1036 | grand_child->visible_layer_rect_for_testing()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1037 | } |
| 1038 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1039 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1040 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1041 | // skipping a necessary translation. Without that translation, the coordinate |
| 1042 | // space of the layer's draw transform is incorrect. |
| 1043 | // |
| 1044 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1045 | // but if that layer becomes a render surface, then its draw transform is |
| 1046 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1047 | // incorrectly as a result. |
| 1048 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1049 | LayerImpl* root = root_layer(); |
| 1050 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1051 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1052 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1053 | |
| 1054 | // The child height is zero, but has non-zero width that should be accounted |
| 1055 | // for while computing draw transforms. |
| 1056 | const gfx::Transform identity_matrix; |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1057 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1058 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1059 | true); |
| 1060 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1061 | gfx::PointF(), gfx::Size(10, 0), true, false, |
| 1062 | true); |
| 1063 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1064 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1065 | false); |
| 1066 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1067 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1068 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1069 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1070 | // This is the real test, the rest are sanity checks. |
| 1071 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1072 | child->render_surface()->draw_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1073 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1074 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1075 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | } |
| 1077 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1078 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
| 1079 | const gfx::Transform identity_matrix; |
| 1080 | LayerImpl* root = root_layer(); |
| 1081 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1082 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1083 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1084 | |
| 1085 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1086 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1087 | true); |
| 1088 | gfx::Transform translate; |
| 1089 | translate.Translate3d(5, 5, 5); |
| 1090 | SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(), |
| 1091 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1092 | true); |
| 1093 | SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(), |
| 1094 | gfx::Size(100, 100), true, false, false); |
| 1095 | SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(), |
| 1096 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1097 | false); |
| 1098 | grand_child->SetDrawsContent(true); |
| 1099 | |
| 1100 | // render_surface will have a sublayer scale because of device scale factor. |
| 1101 | float device_scale_factor = 2.0f; |
| 1102 | LayerImplList render_surface_layer_list_impl; |
| 1103 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1104 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1105 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1106 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 1107 | inputs.device_scale_factor = device_scale_factor; |
| 1108 | inputs.property_trees->needs_rebuild = true; |
| 1109 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1110 | |
| 1111 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1112 | // by a factor of 2. |
| 1113 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1114 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1115 | expected_translation); |
| 1116 | } |
| 1117 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1118 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1119 | // Transformations applied at the root of the tree should be forwarded |
| 1120 | // to child layers instead of applied to the root RenderSurface. |
| 1121 | const gfx::Transform identity_matrix; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1122 | LayerImpl* root = root_layer(); |
| 1123 | root->SetDrawsContent(true); |
| 1124 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1125 | child->SetDrawsContent(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1126 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1127 | child->SetScrollClipLayer(root->id()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1128 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1129 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1130 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1131 | true); |
| 1132 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1133 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1134 | false); |
| 1135 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1136 | gfx::Transform translate; |
| 1137 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1138 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1139 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1140 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1141 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1142 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1143 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1144 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1145 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1146 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1147 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1148 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1149 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1150 | |
| 1151 | gfx::Transform scale; |
| 1152 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1153 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1154 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1155 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1156 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1157 | root, root->bounds(), scale, &render_surface_layer_list_impl, |
| 1158 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1159 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1160 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1161 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1162 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1163 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1164 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1165 | |
| 1166 | gfx::Transform rotate; |
| 1167 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1168 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1169 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1170 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1171 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1172 | root, root->bounds(), rotate, &render_surface_layer_list_impl, |
| 1173 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1174 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1175 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1176 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1177 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1178 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1179 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1180 | |
| 1181 | gfx::Transform composite; |
| 1182 | composite.ConcatTransform(translate); |
| 1183 | composite.ConcatTransform(scale); |
| 1184 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1185 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1186 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1187 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1188 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1189 | root, root->bounds(), composite, &render_surface_layer_list_impl, |
| 1190 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1191 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1192 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1193 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1194 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1195 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1196 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1197 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1198 | // Verify it composes correctly with device scale. |
| 1199 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1200 | |
| 1201 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1202 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1203 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1204 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1205 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1206 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1207 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1208 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1209 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1210 | gfx::Transform device_scaled_translate = translate; |
| 1211 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1212 | EXPECT_EQ(device_scaled_translate, |
| 1213 | root->draw_properties().target_space_transform); |
| 1214 | EXPECT_EQ(device_scaled_translate, |
| 1215 | child->draw_properties().target_space_transform); |
| 1216 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1217 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1218 | |
| 1219 | // Verify it composes correctly with page scale. |
| 1220 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1221 | |
| 1222 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1223 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1224 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1225 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1226 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1227 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1228 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1229 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1230 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1231 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1232 | gfx::Transform page_scaled_translate = translate; |
| 1233 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1234 | EXPECT_EQ(page_scaled_translate, |
| 1235 | root->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1236 | EXPECT_EQ(page_scaled_translate, |
| 1237 | child->draw_properties().target_space_transform); |
| 1238 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1239 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1240 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1241 | // Verify that it composes correctly with transforms directly on root layer. |
| 1242 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1243 | |
| 1244 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1245 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1246 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1247 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1248 | root, root->bounds(), composite, &render_surface_layer_list_impl, |
| 1249 | root->layer_tree_impl()->current_render_surface_list_id()); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1250 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1251 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1252 | gfx::Transform compositeSquared = composite; |
| 1253 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1254 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1255 | compositeSquared, root->draw_properties().target_space_transform); |
| 1256 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1257 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1258 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1259 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1260 | } |
| 1261 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1262 | TEST_F(LayerTreeHostCommonTest, |
| 1263 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1264 | LayerImpl* parent = root_layer(); |
| 1265 | parent->SetMasksToBounds(true); |
| 1266 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1267 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1268 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1269 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1270 | const gfx::Transform identity_matrix; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1271 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1272 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1273 | true); |
| 1274 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1275 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1276 | true); |
| 1277 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1278 | gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true, |
| 1279 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1280 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1281 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1282 | |
| 1283 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1284 | // the intermediate render surface should not be listed here, even if it was |
| 1285 | // forced to be created. Render surfaces without children or visible content |
| 1286 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1287 | // of size 0). |
| 1288 | ASSERT_TRUE(parent->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1289 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1290 | } |
| 1291 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1292 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1293 | LayerImpl* parent = root_layer(); |
| 1294 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1295 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1296 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1297 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1298 | const gfx::Transform identity_matrix; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1299 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1300 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1301 | true); |
| 1302 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1303 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1304 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1305 | render_surface1->SetOpacity(0.f); |
| 1306 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1307 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1308 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1309 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1310 | parent, parent->bounds(), &render_surface_layer_list, |
| 1311 | parent->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1312 | inputs.can_adjust_raster_scales = true; |
| 1313 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1314 | |
| 1315 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1316 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1317 | // have been extended by the children. |
| 1318 | ASSERT_TRUE(parent->render_surface()); |
| 1319 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1320 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1321 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1322 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1323 | } |
| 1324 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1325 | TEST_F(LayerTreeHostCommonTest, |
| 1326 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
| 1327 | LayerImpl* parent = root_layer(); |
| 1328 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1329 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1330 | child->SetDrawsContent(true); |
| 1331 | |
| 1332 | const gfx::Transform identity_matrix; |
| 1333 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1334 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1335 | true); |
| 1336 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1337 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1338 | true); |
| 1339 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1340 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1341 | false); |
| 1342 | render_surface1->SetOpacity(0.f); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1343 | render_surface1->SetDrawsContent(true); |
| 1344 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1345 | FilterOperations filters; |
| 1346 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
| 1347 | render_surface1->SetBackgroundFilters(filters); |
| 1348 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame^] | 1349 | { |
| 1350 | LayerImplList render_surface_layer_list; |
| 1351 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1352 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1353 | parent, parent->bounds(), &render_surface_layer_list, |
| 1354 | parent->layer_tree_impl()->current_render_surface_list_id()); |
| 1355 | inputs.can_adjust_raster_scales = true; |
| 1356 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1357 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1358 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1359 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame^] | 1360 | // shouldn't be skipped and should be drawn. |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1361 | ASSERT_TRUE(parent->render_surface()); |
| 1362 | EXPECT_EQ(1U, parent->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1363 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
| 1364 | parent->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame^] | 1365 | EffectTree& effect_tree = |
| 1366 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 1367 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1368 | EXPECT_TRUE(node->data.is_drawn); |
| 1369 | |
| 1370 | // When parent is transparent, the layer should not be drawn. |
| 1371 | parent->OnOpacityAnimated(0.f); |
| 1372 | render_surface1->OnOpacityAnimated(1.f); |
| 1373 | { |
| 1374 | LayerImplList render_surface_layer_list; |
| 1375 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1376 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1377 | parent, parent->bounds(), &render_surface_layer_list, |
| 1378 | parent->layer_tree_impl()->current_render_surface_list_id()); |
| 1379 | inputs.can_adjust_raster_scales = true; |
| 1380 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1381 | } |
| 1382 | |
| 1383 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1384 | EXPECT_FALSE(node->data.is_drawn); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1385 | } |
| 1386 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1387 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
| 1388 | LayerImpl* root = root_layer(); |
| 1389 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1390 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1391 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1392 | child1->SetDrawsContent(true); |
| 1393 | child2->SetDrawsContent(true); |
| 1394 | |
| 1395 | const gfx::Transform identity_matrix; |
| 1396 | gfx::Transform scale_matrix; |
| 1397 | scale_matrix.Scale(2.0f, 2.0f); |
| 1398 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1399 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1400 | true); |
| 1401 | SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(), |
| 1402 | gfx::PointF(), gfx::Size(), true, false, true); |
| 1403 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1404 | gfx::PointF(0, 0), gfx::Size(25, 25), true, |
| 1405 | false, true); |
| 1406 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1407 | gfx::PointF(25, 25), gfx::Size(25, 25), true, |
| 1408 | false, true); |
| 1409 | FilterOperations filters; |
| 1410 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
| 1411 | parent->SetFilters(filters); |
| 1412 | |
| 1413 | LayerImplList render_surface_layer_list; |
| 1414 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1415 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1416 | root, root->bounds(), &render_surface_layer_list, |
| 1417 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 1418 | inputs.can_adjust_raster_scales = true; |
| 1419 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1420 | |
| 1421 | ASSERT_TRUE(parent->render_surface()); |
| 1422 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1423 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
| 1424 | EXPECT_EQ(gfx::RectF(-29, -29, 158, 158), |
| 1425 | parent->render_surface()->DrawableContentRect()); |
| 1426 | } |
| 1427 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1428 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1429 | LayerImpl* parent = root_layer(); |
| 1430 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1431 | child->SetDrawsContent(true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1432 | |
| 1433 | const gfx::Transform identity_matrix; |
| 1434 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1435 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1436 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1437 | true); |
| 1438 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1439 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1440 | true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1441 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1442 | child->SetBlendMode(blend_mode); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1443 | child->SetOpacity(0.5f); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1444 | |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1445 | ExecuteCalculateDrawProperties(parent); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1446 | |
| 1447 | // Since the child layer has a blend mode other than normal, it should get |
| 1448 | // its own render surface. Also, layer's draw_properties should contain the |
| 1449 | // default blend mode, since the render surface becomes responsible for |
| 1450 | // applying the blend mode. |
| 1451 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1452 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1453 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1454 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1455 | } |
| 1456 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1457 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
| 1458 | LayerImpl* root = root_layer(); |
| 1459 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1460 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1461 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1462 | |
| 1463 | const gfx::Transform identity_matrix; |
| 1464 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1465 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1466 | true); |
| 1467 | SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(), |
| 1468 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1469 | true); |
| 1470 | SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(), |
| 1471 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1472 | false); |
| 1473 | SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(), |
| 1474 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1475 | true); |
| 1476 | surface1->SetDrawsContent(true); |
| 1477 | surface2->SetDrawsContent(true); |
| 1478 | |
| 1479 | surface1->SetOpacity(0.5f); |
| 1480 | not_surface->SetOpacity(0.5f); |
| 1481 | surface2->SetOpacity(0.5f); |
| 1482 | |
| 1483 | ExecuteCalculateDrawProperties(root); |
| 1484 | |
| 1485 | ASSERT_TRUE(surface1->render_surface()); |
| 1486 | ASSERT_FALSE(not_surface->render_surface()); |
| 1487 | ASSERT_TRUE(surface2->render_surface()); |
| 1488 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1489 | // surface2's draw opacity should include the opacity of not-surface and |
| 1490 | // itself, but not the opacity of surface1. |
| 1491 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1492 | } |
| 1493 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1494 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1495 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1496 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1497 | // (Rendering will still be incorrect in situations where we really do need |
| 1498 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1499 | // ancestor whose opacity is <1.) |
| 1500 | LayerImpl* root = root_layer(); |
| 1501 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1502 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1503 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1504 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1505 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1506 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1507 | |
| 1508 | root->SetDrawsContent(true); |
| 1509 | parent->SetDrawsContent(true); |
| 1510 | child1->SetDrawsContent(true); |
| 1511 | child2->SetDrawsContent(true); |
| 1512 | grand_child->SetDrawsContent(true); |
| 1513 | leaf_node1->SetDrawsContent(true); |
| 1514 | leaf_node2->SetDrawsContent(true); |
| 1515 | |
| 1516 | const gfx::Transform identity_matrix; |
| 1517 | |
| 1518 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1519 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1520 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1521 | true); |
| 1522 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1523 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1524 | false); |
| 1525 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1526 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1527 | true); |
| 1528 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1529 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1530 | false); |
| 1531 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1532 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1533 | true); |
| 1534 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1535 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1536 | false); |
| 1537 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1538 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1539 | false); |
| 1540 | |
| 1541 | child1->SetOpacity(0.5f); |
| 1542 | grand_child->SetOpacity(0.5f); |
| 1543 | leaf_node1->SetOpacity(0.5f); |
| 1544 | leaf_node2->SetOpacity(0.5f); |
| 1545 | |
| 1546 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1547 | // opacities on the path from the layer to its render target, not including |
| 1548 | // the opacity of the layer that owns the target surface (since that opacity |
| 1549 | // is applied by the surface). |
| 1550 | ExecuteCalculateDrawProperties(root); |
| 1551 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1552 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1553 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1554 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1555 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1556 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1557 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1558 | |
| 1559 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1560 | // opacities on the path from the layer to the root. |
| 1561 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1562 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1563 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1564 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1565 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1566 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1567 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1568 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1569 | } |
| 1570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1571 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1572 | LayerImpl* parent = root_layer(); |
| 1573 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1574 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1575 | |
| 1576 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1577 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1578 | gfx::PointF(), gfx::Size(10, 10), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1579 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1580 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1581 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1582 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1583 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1584 | child->SetDrawsContent(true); |
| 1585 | render_surface1->SetForceRenderSurface(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1586 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1587 | { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1588 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1589 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1590 | // The root layer always creates a render surface |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1591 | EXPECT_TRUE(parent->has_render_surface()); |
| 1592 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1593 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1594 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1595 | { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1596 | render_surface1->SetForceRenderSurface(false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1597 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1598 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1599 | EXPECT_TRUE(parent->has_render_surface()); |
| 1600 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1601 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1602 | } |
| 1603 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1604 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1605 | // Render surfaces act as a flattening point for their subtree, so should |
| 1606 | // always flatten the target-to-screen space transform seen by descendants. |
| 1607 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1608 | LayerImpl* root = root_layer(); |
| 1609 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1610 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1611 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1612 | |
| 1613 | child->SetDrawsContent(true); |
| 1614 | grand_child->SetDrawsContent(true); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1615 | |
| 1616 | gfx::Transform rotation_about_y_axis; |
| 1617 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1618 | // Make |parent| have a render surface. |
| 1619 | parent->SetOpacity(0.9f); |
| 1620 | |
| 1621 | const gfx::Transform identity_matrix; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1622 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1623 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1624 | true); |
| 1625 | SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(), |
| 1626 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1627 | true); |
| 1628 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1629 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1630 | false); |
| 1631 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1632 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1633 | false); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1634 | |
| 1635 | grand_child->SetShouldFlattenTransform(false); |
| 1636 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1637 | // Only grand_child should preserve 3d. |
| 1638 | EXPECT_TRUE(root->should_flatten_transform()); |
| 1639 | EXPECT_TRUE(parent->should_flatten_transform()); |
| 1640 | EXPECT_TRUE(child->should_flatten_transform()); |
| 1641 | EXPECT_FALSE(grand_child->should_flatten_transform()); |
| 1642 | |
| 1643 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1644 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1645 | |
| 1646 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1647 | flattened_rotation_about_y.FlattenTo2d(); |
| 1648 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1649 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1650 | |
| 1651 | EXPECT_TRUE(parent->render_surface()); |
| 1652 | EXPECT_FALSE(child->render_surface()); |
| 1653 | EXPECT_FALSE(grand_child->render_surface()); |
| 1654 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1655 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1656 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1657 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1658 | |
| 1659 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1660 | // have been flattened at their render target. In particular, the fact that |
| 1661 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1662 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1663 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1664 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1665 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1668 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1669 | // The entire subtree of layers that are outside the clip rect should be |
| 1670 | // culled away, and should not affect the render_surface_layer_list. |
| 1671 | // |
| 1672 | // The test tree is set up as follows: |
| 1673 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1674 | // that have something to draw. |
| 1675 | // - parent is a large container layer. |
| 1676 | // - child has masksToBounds=true to cause clipping. |
| 1677 | // - grand_child is positioned outside of the child's bounds |
| 1678 | // - great_grand_child is also kept outside child's bounds. |
| 1679 | // |
| 1680 | // In this configuration, grand_child and great_grand_child are completely |
| 1681 | // outside the clip rect, and they should never get scheduled on the list of |
| 1682 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1683 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1684 | LayerImpl* parent = root_layer(); |
| 1685 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1686 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1687 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1688 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1689 | // leaf_node1 ensures that parent and child are kept on the |
| 1690 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1691 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1692 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
| 1693 | leaf_node1->SetDrawsContent(true); |
| 1694 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
| 1695 | leaf_node2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1696 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1697 | const gfx::Transform identity_matrix; |
| 1698 | |
| 1699 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1700 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 1701 | true); |
| 1702 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1703 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1704 | true); |
| 1705 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1706 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 1707 | false, false); |
| 1708 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 1709 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1710 | true, false, false); |
| 1711 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1712 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1713 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1714 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1715 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1716 | false); |
| 1717 | |
| 1718 | child->SetMasksToBounds(true); |
| 1719 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | grand_child->SetOpacity(0.5f); |
| 1721 | great_grand_child->SetOpacity(0.4f); |
| 1722 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1723 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1724 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1725 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
| 1726 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
| 1727 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1728 | } |
| 1729 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1730 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1731 | // When a render surface has a clip rect, it is used to clip the content rect |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1732 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1733 | |
| 1734 | // The test tree is set up as follows: |
| 1735 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1736 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1737 | // the parent. |
| 1738 | // - grand_child is a render surface, and the only visible content in child. |
| 1739 | // It is positioned outside of the clip rect from parent. |
| 1740 | |
| 1741 | // In this configuration, grand_child should be outside the clipped |
| 1742 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1743 | // render_surface_layer_list. |
| 1744 | |
| 1745 | LayerImpl* parent = root_layer(); |
| 1746 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1747 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1748 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 1749 | leaf_node->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1750 | |
| 1751 | const gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1752 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1753 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1754 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1755 | true); |
| 1756 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1757 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1758 | true); |
| 1759 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1760 | gfx::PointF(200.f, 200.f), gfx::Size(10, 10), |
| 1761 | true, false, true); |
| 1762 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 1763 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1764 | false); |
| 1765 | |
| 1766 | parent->SetMasksToBounds(true); |
| 1767 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1768 | grand_child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1769 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1770 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1771 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1772 | // We should cull child and grand_child from the |
| 1773 | // render_surface_layer_list. |
| 1774 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
| 1775 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1776 | } |
| 1777 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1778 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1779 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1780 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1781 | // - the layer is clipped by an ancestor that contributes to the same |
| 1782 | // render target, |
| 1783 | // - a surface is clipped by an ancestor that contributes to the same |
| 1784 | // render target. |
| 1785 | // |
| 1786 | // In particular, for a layer that owns a render surface: |
| 1787 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1788 | // pass that clipped status to the layer itself. |
| 1789 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1790 | // and propagates the clip to the subtree. |
| 1791 | |
| 1792 | const gfx::Transform identity_matrix; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1793 | LayerImpl* root = root_layer(); |
| 1794 | LayerImpl* parent = AddChild<LayerImpl>(root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1795 | parent->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1796 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1797 | child1->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1798 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1799 | child2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1800 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1801 | grand_child->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1802 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1803 | leaf_node1->SetDrawsContent(true); |
| 1804 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1805 | leaf_node2->SetDrawsContent(true); |
| 1806 | |
| 1807 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1808 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1809 | true); |
| 1810 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1811 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1812 | false); |
| 1813 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1814 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1815 | false); |
| 1816 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1817 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1818 | true); |
| 1819 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1820 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1821 | false); |
| 1822 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1823 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1824 | false); |
| 1825 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1826 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1827 | false); |
| 1828 | |
| 1829 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1830 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1831 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1832 | ASSERT_TRUE(root->render_surface()); |
| 1833 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1834 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1835 | EXPECT_FALSE(root->is_clipped()); |
| 1836 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1837 | EXPECT_FALSE(parent->is_clipped()); |
| 1838 | EXPECT_FALSE(child1->is_clipped()); |
| 1839 | EXPECT_FALSE(child2->is_clipped()); |
| 1840 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1841 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1842 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1843 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1844 | |
| 1845 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1846 | // surface are clipped. But layers that contribute to child2's surface are |
| 1847 | // not clipped explicitly because child2's surface already accounts for |
| 1848 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1849 | parent->SetMasksToBounds(true); |
| 1850 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1851 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1852 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1853 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1854 | ASSERT_TRUE(root->render_surface()); |
| 1855 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1856 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1857 | EXPECT_FALSE(root->is_clipped()); |
| 1858 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1859 | EXPECT_TRUE(parent->is_clipped()); |
| 1860 | EXPECT_TRUE(child1->is_clipped()); |
| 1861 | EXPECT_FALSE(child2->is_clipped()); |
| 1862 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1863 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1864 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1865 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1866 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1867 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1868 | |
| 1869 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1870 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1871 | child2->SetMasksToBounds(true); |
| 1872 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1873 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1874 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1875 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1876 | ASSERT_TRUE(root->render_surface()); |
| 1877 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1878 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1879 | EXPECT_FALSE(root->is_clipped()); |
| 1880 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1881 | EXPECT_FALSE(parent->is_clipped()); |
| 1882 | EXPECT_FALSE(child1->is_clipped()); |
| 1883 | EXPECT_TRUE(child2->is_clipped()); |
| 1884 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1885 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1886 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1887 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1888 | } |
| 1889 | |
| 1890 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1891 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1892 | // correct value. |
| 1893 | LayerImpl* root = root_layer(); |
| 1894 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1895 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1896 | |
| 1897 | root->SetDrawsContent(true); |
| 1898 | parent->SetDrawsContent(true); |
| 1899 | child->SetDrawsContent(true); |
| 1900 | |
| 1901 | const gfx::Transform identity_matrix; |
| 1902 | |
| 1903 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1904 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1905 | true); |
| 1906 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1907 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1908 | false); |
| 1909 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1910 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1911 | false); |
| 1912 | child->SetMasksToBounds(true); |
| 1913 | |
| 1914 | ExecuteCalculateDrawProperties(root); |
| 1915 | |
| 1916 | EXPECT_FALSE(root->is_clipped()); |
| 1917 | EXPECT_FALSE(parent->is_clipped()); |
| 1918 | EXPECT_TRUE(child->is_clipped()); |
| 1919 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1920 | |
| 1921 | parent->SetMasksToBounds(true); |
| 1922 | child->SetPosition(gfx::PointF(100, 100)); |
| 1923 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1924 | |
| 1925 | ExecuteCalculateDrawProperties(root); |
| 1926 | |
| 1927 | EXPECT_FALSE(root->is_clipped()); |
| 1928 | EXPECT_TRUE(parent->is_clipped()); |
| 1929 | EXPECT_TRUE(child->is_clipped()); |
| 1930 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | } |
| 1932 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1933 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1934 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1935 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1936 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1937 | // that can reset is_clipped). |
| 1938 | LayerImpl* root = root_layer(); |
| 1939 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1940 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1941 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1942 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1943 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1944 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1945 | |
| 1946 | root->SetDrawsContent(true); |
| 1947 | parent->SetDrawsContent(true); |
| 1948 | child1->SetDrawsContent(true); |
| 1949 | child2->SetDrawsContent(true); |
| 1950 | grand_child->SetDrawsContent(true); |
| 1951 | leaf_node1->SetDrawsContent(true); |
| 1952 | leaf_node2->SetDrawsContent(true); |
| 1953 | |
| 1954 | const gfx::Transform identity_matrix; |
| 1955 | |
| 1956 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1957 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1958 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1959 | true); |
| 1960 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1961 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1962 | false); |
| 1963 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1964 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1965 | true); |
| 1966 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1967 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1968 | false); |
| 1969 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1970 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1971 | true); |
| 1972 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1973 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1974 | false); |
| 1975 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1976 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1977 | false); |
| 1978 | |
| 1979 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1980 | // or without surfaces. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1981 | root->SetHasRenderSurface(true); |
| 1982 | child1->SetHasRenderSurface(true); |
| 1983 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1984 | ExecuteCalculateDrawProperties(root); |
| 1985 | EXPECT_FALSE(root->is_clipped()); |
| 1986 | EXPECT_FALSE(parent->is_clipped()); |
| 1987 | EXPECT_FALSE(child1->is_clipped()); |
| 1988 | EXPECT_FALSE(child2->is_clipped()); |
| 1989 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1990 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1991 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1992 | |
| 1993 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1994 | EXPECT_FALSE(root->is_clipped()); |
| 1995 | EXPECT_FALSE(parent->is_clipped()); |
| 1996 | EXPECT_FALSE(child1->is_clipped()); |
| 1997 | EXPECT_FALSE(child2->is_clipped()); |
| 1998 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1999 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2000 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2001 | |
| 2002 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 2003 | // next render surface. Without surfaces, the entire tree is clipped. |
| 2004 | root->SetMasksToBounds(true); |
| 2005 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2006 | root->SetHasRenderSurface(true); |
| 2007 | child1->SetHasRenderSurface(true); |
| 2008 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2009 | ExecuteCalculateDrawProperties(root); |
| 2010 | EXPECT_TRUE(root->is_clipped()); |
| 2011 | EXPECT_TRUE(parent->is_clipped()); |
| 2012 | EXPECT_FALSE(child1->is_clipped()); |
| 2013 | EXPECT_TRUE(child2->is_clipped()); |
| 2014 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2015 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2016 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2017 | |
| 2018 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2019 | EXPECT_TRUE(root->is_clipped()); |
| 2020 | EXPECT_TRUE(parent->is_clipped()); |
| 2021 | EXPECT_TRUE(child1->is_clipped()); |
| 2022 | EXPECT_TRUE(child2->is_clipped()); |
| 2023 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2024 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2025 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2026 | |
| 2027 | root->SetMasksToBounds(false); |
| 2028 | |
| 2029 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2030 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2031 | // clipped. |
| 2032 | parent->SetMasksToBounds(true); |
| 2033 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2034 | root->SetHasRenderSurface(true); |
| 2035 | child1->SetHasRenderSurface(true); |
| 2036 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2037 | ExecuteCalculateDrawProperties(root); |
| 2038 | EXPECT_FALSE(root->is_clipped()); |
| 2039 | EXPECT_TRUE(parent->is_clipped()); |
| 2040 | EXPECT_FALSE(child1->is_clipped()); |
| 2041 | EXPECT_TRUE(child2->is_clipped()); |
| 2042 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2043 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2044 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2045 | |
| 2046 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2047 | EXPECT_FALSE(root->is_clipped()); |
| 2048 | EXPECT_TRUE(parent->is_clipped()); |
| 2049 | EXPECT_TRUE(child1->is_clipped()); |
| 2050 | EXPECT_TRUE(child2->is_clipped()); |
| 2051 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2052 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2053 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2054 | |
| 2055 | parent->SetMasksToBounds(false); |
| 2056 | |
| 2057 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2058 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2059 | // clipped. |
| 2060 | child1->SetMasksToBounds(true); |
| 2061 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2062 | root->SetHasRenderSurface(true); |
| 2063 | child1->SetHasRenderSurface(true); |
| 2064 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2065 | ExecuteCalculateDrawProperties(root); |
| 2066 | EXPECT_FALSE(root->is_clipped()); |
| 2067 | EXPECT_FALSE(parent->is_clipped()); |
| 2068 | EXPECT_TRUE(child1->is_clipped()); |
| 2069 | EXPECT_FALSE(child2->is_clipped()); |
| 2070 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2071 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2072 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2073 | |
| 2074 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2075 | EXPECT_FALSE(root->is_clipped()); |
| 2076 | EXPECT_FALSE(parent->is_clipped()); |
| 2077 | EXPECT_TRUE(child1->is_clipped()); |
| 2078 | EXPECT_FALSE(child2->is_clipped()); |
| 2079 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2080 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2081 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2082 | |
| 2083 | child1->SetMasksToBounds(false); |
| 2084 | |
| 2085 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2086 | // surfaces is the same. |
| 2087 | leaf_node1->SetMasksToBounds(true); |
| 2088 | leaf_node2->SetMasksToBounds(true); |
| 2089 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2090 | root->SetHasRenderSurface(true); |
| 2091 | child1->SetHasRenderSurface(true); |
| 2092 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2093 | ExecuteCalculateDrawProperties(root); |
| 2094 | EXPECT_FALSE(root->is_clipped()); |
| 2095 | EXPECT_FALSE(parent->is_clipped()); |
| 2096 | EXPECT_FALSE(child1->is_clipped()); |
| 2097 | EXPECT_FALSE(child2->is_clipped()); |
| 2098 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2099 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2100 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2101 | |
| 2102 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2103 | EXPECT_FALSE(root->is_clipped()); |
| 2104 | EXPECT_FALSE(parent->is_clipped()); |
| 2105 | EXPECT_FALSE(child1->is_clipped()); |
| 2106 | EXPECT_FALSE(child2->is_clipped()); |
| 2107 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2108 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2109 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2110 | } |
| 2111 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2112 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2113 | // Verify that layers get the appropriate DrawableContentRect when their |
| 2114 | // parent masksToBounds is true. |
| 2115 | // |
| 2116 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2117 | // be the layer rect expressed in target space. |
| 2118 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 2119 | // will be the intersection of layer bounds and the mask region. |
| 2120 | // grand_child3 - partially clipped and masksToBounds; the |
| 2121 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2122 | // the mask region. |
| 2123 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2124 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2125 | |
| 2126 | const gfx::Transform identity_matrix; |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2127 | LayerImpl* parent = root_layer(); |
| 2128 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2129 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2130 | grand_child1->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2131 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2132 | grand_child2->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2133 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2134 | grand_child3->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2135 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2136 | grand_child4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2137 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2138 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2139 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2140 | true); |
| 2141 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2142 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2143 | true); |
| 2144 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2145 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2146 | false, false); |
| 2147 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2148 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2149 | false, false); |
| 2150 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2151 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2152 | false, false); |
| 2153 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2154 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2155 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2156 | |
| 2157 | child->SetMasksToBounds(true); |
| 2158 | grand_child3->SetMasksToBounds(true); |
| 2159 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2160 | // Force child to be a render surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2161 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2162 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2163 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2164 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2165 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2166 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2167 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2168 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2169 | } |
| 2170 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2171 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2172 | // Verify that render surfaces (and their layers) get the appropriate |
| 2173 | // clip rects when their parent masksToBounds is true. |
| 2174 | // |
| 2175 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2176 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2177 | // They may still have a clip rect of their own layer bounds, however, if |
| 2178 | // masksToBounds was true. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2179 | LayerImpl* parent = root_layer(); |
| 2180 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2181 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2182 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2183 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2184 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2185 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2186 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2187 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 2188 | leaf_node1->SetDrawsContent(true); |
| 2189 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 2190 | leaf_node2->SetDrawsContent(true); |
| 2191 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
| 2192 | leaf_node3->SetDrawsContent(true); |
| 2193 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
| 2194 | leaf_node4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2195 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2196 | const gfx::Transform identity_matrix; |
| 2197 | |
| 2198 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2199 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2200 | true); |
| 2201 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2202 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2203 | true); |
| 2204 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2205 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2206 | false, true); |
| 2207 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2208 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2209 | false, true); |
| 2210 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2211 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2212 | false, true); |
| 2213 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2214 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2215 | false, true); |
| 2216 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2217 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2218 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2219 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2220 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2221 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2222 | SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(), |
| 2223 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2224 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2225 | SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(), |
| 2226 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2227 | false); |
| 2228 | |
| 2229 | child->SetMasksToBounds(true); |
| 2230 | grand_child3->SetMasksToBounds(true); |
| 2231 | grand_child4->SetMasksToBounds(true); |
| 2232 | |
| 2233 | // Force everyone to be a render surface. |
| 2234 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2235 | grand_child1->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2236 | grand_child2->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2237 | grand_child3->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2238 | grand_child4->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2239 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2240 | ExecuteCalculateDrawProperties(parent); |
| 2241 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2242 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2243 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2244 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2245 | |
| 2246 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2247 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2248 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2249 | grand_child1->render_surface()->clip_rect()); |
| 2250 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2251 | grand_child2->render_surface()->clip_rect()); |
| 2252 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2253 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | } |
| 2255 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2256 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2257 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2258 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2259 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2260 | // subtree (since there are no render surfaces that can reset the clip_rect). |
| 2261 | LayerImpl* root = root_layer(); |
| 2262 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2263 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2264 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2265 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2266 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2267 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2268 | |
| 2269 | root->SetDrawsContent(true); |
| 2270 | parent->SetDrawsContent(true); |
| 2271 | child1->SetDrawsContent(true); |
| 2272 | child2->SetDrawsContent(true); |
| 2273 | grand_child->SetDrawsContent(true); |
| 2274 | leaf_node1->SetDrawsContent(true); |
| 2275 | leaf_node2->SetDrawsContent(true); |
| 2276 | |
| 2277 | const gfx::Transform identity_matrix; |
| 2278 | |
| 2279 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 2280 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2281 | gfx::PointF(), gfx::Size(100, 100), true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2282 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2283 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2284 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2285 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 2286 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2287 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2288 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 2289 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2290 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2291 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2292 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2293 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2294 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2295 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2296 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2297 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2298 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2299 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2300 | |
| 2301 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2302 | // bounds in target space. The only thing that changes when surfaces are |
| 2303 | // disabled is that target space is always screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2304 | root->SetForceRenderSurface(true); |
| 2305 | child1->SetForceRenderSurface(true); |
| 2306 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2307 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2308 | EXPECT_TRUE(root->has_render_surface()); |
| 2309 | EXPECT_FALSE(parent->has_render_surface()); |
| 2310 | EXPECT_TRUE(child1->has_render_surface()); |
| 2311 | EXPECT_FALSE(child2->has_render_surface()); |
| 2312 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2313 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2314 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2315 | EXPECT_FALSE(root->is_clipped()); |
| 2316 | EXPECT_FALSE(parent->is_clipped()); |
| 2317 | EXPECT_FALSE(child1->is_clipped()); |
| 2318 | EXPECT_FALSE(child2->is_clipped()); |
| 2319 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2320 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2321 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2322 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2323 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2324 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2325 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2326 | |
| 2327 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2328 | EXPECT_FALSE(root->is_clipped()); |
| 2329 | EXPECT_FALSE(parent->is_clipped()); |
| 2330 | EXPECT_FALSE(child1->is_clipped()); |
| 2331 | EXPECT_FALSE(child2->is_clipped()); |
| 2332 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2333 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2334 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2335 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2336 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2337 | |
| 2338 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2339 | // render surface are clipped by the root's bounds. |
| 2340 | root->SetMasksToBounds(true); |
| 2341 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2342 | root->SetForceRenderSurface(true); |
| 2343 | child1->SetForceRenderSurface(true); |
| 2344 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2345 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2346 | EXPECT_TRUE(root->has_render_surface()); |
| 2347 | EXPECT_FALSE(parent->has_render_surface()); |
| 2348 | EXPECT_TRUE(child1->has_render_surface()); |
| 2349 | EXPECT_FALSE(child2->has_render_surface()); |
| 2350 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2351 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2352 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2353 | EXPECT_TRUE(root->is_clipped()); |
| 2354 | EXPECT_TRUE(parent->is_clipped()); |
| 2355 | EXPECT_FALSE(child1->is_clipped()); |
| 2356 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2357 | EXPECT_TRUE(child2->is_clipped()); |
| 2358 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2359 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2360 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2361 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2362 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2363 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2364 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2365 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2366 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2367 | |
| 2368 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2369 | EXPECT_TRUE(root->is_clipped()); |
| 2370 | EXPECT_TRUE(parent->is_clipped()); |
| 2371 | EXPECT_TRUE(child1->is_clipped()); |
| 2372 | EXPECT_TRUE(child2->is_clipped()); |
| 2373 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2374 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2375 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2376 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2377 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2378 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2379 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2380 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2381 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2382 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2383 | |
| 2384 | root->SetMasksToBounds(false); |
| 2385 | |
| 2386 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2387 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2388 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2389 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2390 | // child is a render surface. However, without surfaces, these clip rects |
| 2391 | // contribute to all descendants. |
| 2392 | parent->SetMasksToBounds(true); |
| 2393 | child1->SetMasksToBounds(true); |
| 2394 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2395 | root->SetForceRenderSurface(true); |
| 2396 | child1->SetForceRenderSurface(true); |
| 2397 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2398 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2399 | EXPECT_TRUE(root->has_render_surface()); |
| 2400 | EXPECT_FALSE(parent->has_render_surface()); |
| 2401 | EXPECT_TRUE(child1->has_render_surface()); |
| 2402 | EXPECT_FALSE(child2->has_render_surface()); |
| 2403 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2404 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2405 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2406 | EXPECT_FALSE(root->is_clipped()); |
| 2407 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2408 | EXPECT_TRUE(parent->is_clipped()); |
| 2409 | EXPECT_TRUE(child1->is_clipped()); |
| 2410 | EXPECT_TRUE(child2->is_clipped()); |
| 2411 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2412 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2413 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2414 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2415 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2416 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2417 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2418 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2419 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2420 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2421 | |
| 2422 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2423 | EXPECT_FALSE(root->is_clipped()); |
| 2424 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2425 | EXPECT_TRUE(parent->is_clipped()); |
| 2426 | EXPECT_TRUE(child1->is_clipped()); |
| 2427 | EXPECT_TRUE(child2->is_clipped()); |
| 2428 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2429 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2430 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2431 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2432 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2433 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2434 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2435 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2436 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2437 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2438 | } |
| 2439 | |
| 2440 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2441 | // Tests that draw properties are computed correctly when we disable and then |
| 2442 | // re-enable separate surfaces. |
| 2443 | LayerImpl* root = root_layer(); |
| 2444 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2445 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2446 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2447 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2448 | |
| 2449 | root->SetDrawsContent(true); |
| 2450 | parent->SetDrawsContent(true); |
| 2451 | child->SetDrawsContent(true); |
| 2452 | grand_child->SetDrawsContent(true); |
| 2453 | leaf_node->SetDrawsContent(true); |
| 2454 | |
| 2455 | const gfx::Transform identity_matrix; |
| 2456 | |
| 2457 | // child and grand_child get render surfaces when surfaces are enabled. |
| 2458 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2459 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2460 | true); |
| 2461 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2462 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 2463 | false, false); |
| 2464 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2465 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 2466 | false, true); |
| 2467 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2468 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 2469 | true, false, true); |
| 2470 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 2471 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 2472 | true, false, false); |
| 2473 | |
| 2474 | parent->SetMasksToBounds(true); |
| 2475 | child->SetMasksToBounds(true); |
| 2476 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2477 | root->SetHasRenderSurface(true); |
| 2478 | child->SetHasRenderSurface(true); |
| 2479 | grand_child->SetHasRenderSurface(true); |
| 2480 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2481 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2482 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2483 | |
| 2484 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2485 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2486 | |
| 2487 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2488 | EXPECT_FALSE(leaf_node->is_clipped()); |
| 2489 | EXPECT_TRUE(leaf_node->render_target()->render_surface()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2490 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2491 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2492 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2493 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2494 | root->SetHasRenderSurface(true); |
| 2495 | child->SetHasRenderSurface(true); |
| 2496 | grand_child->SetHasRenderSurface(true); |
| 2497 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2498 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2499 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2500 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2501 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
| 2502 | EXPECT_EQ(expected_leaf_draw_transform_without_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2503 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2504 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2505 | root->SetHasRenderSurface(true); |
| 2506 | child->SetHasRenderSurface(true); |
| 2507 | grand_child->SetHasRenderSurface(true); |
| 2508 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2509 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2510 | EXPECT_FALSE(leaf_node->is_clipped()); |
| 2511 | EXPECT_TRUE(leaf_node->render_target()->render_surface()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2512 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2513 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2514 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2515 | } |
| 2516 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2517 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2518 | LayerImpl* parent = root_layer(); |
| 2519 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2520 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2521 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2522 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2523 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2524 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2525 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2526 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2527 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2528 | parent->SetDrawsContent(true); |
| 2529 | render_surface1->SetDrawsContent(true); |
| 2530 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2531 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2532 | render_surface2->SetDrawsContent(true); |
| 2533 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2534 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2535 | child_of_root->SetDrawsContent(true); |
| 2536 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2537 | |
| 2538 | gfx::Transform layer_transform; |
| 2539 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2540 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2541 | SetLayerPropertiesForTesting( |
| 2542 | parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2543 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2544 | SetLayerPropertiesForTesting( |
| 2545 | render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2546 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2547 | SetLayerPropertiesForTesting( |
| 2548 | render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2549 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2550 | SetLayerPropertiesForTesting( |
| 2551 | child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2552 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2553 | SetLayerPropertiesForTesting( |
| 2554 | child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2555 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2556 | SetLayerPropertiesForTesting( |
| 2557 | child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2558 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2559 | SetLayerPropertiesForTesting( |
| 2560 | grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2561 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2562 | SetLayerPropertiesForTesting( |
| 2563 | grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2564 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2565 | SetLayerPropertiesForTesting( |
| 2566 | grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2567 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2568 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2569 | // Put an animated opacity on the render surface. |
| 2570 | AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(), |
| 2571 | 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2572 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2573 | // Also put an animated opacity on a layer without descendants. |
| 2574 | AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(), |
| 2575 | timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2577 | // Put a transform animation on the render surface. |
| 2578 | AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(), |
| 2579 | 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2580 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2581 | // Also put transform animations on grand_child_of_root, and |
| 2582 | // grand_child_of_rs2 |
| 2583 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), |
| 2584 | timeline_impl(), 10.0, 30, 0); |
| 2585 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), |
| 2586 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2587 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2588 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2589 | |
| 2590 | // Only layers that are associated with render surfaces should have an actual |
| 2591 | // RenderSurface() value. |
| 2592 | ASSERT_TRUE(parent->render_surface()); |
| 2593 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2594 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2595 | |
| 2596 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2597 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2598 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2599 | |
| 2600 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2601 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2602 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2603 | |
| 2604 | // Verify all render target accessors |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2605 | EXPECT_EQ(parent, parent->render_target()); |
| 2606 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2607 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2608 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2609 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2610 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2611 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2612 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2613 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2614 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2615 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2617 | // Verify screen_space_transform_is_animating values |
| 2618 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2619 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2620 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2621 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2622 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2623 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2624 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2625 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2626 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2627 | |
| 2628 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2629 | // It is expected that we correctly set up transforms so that the y-component |
| 2630 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2631 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2632 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2633 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2634 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2635 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2636 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2637 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2638 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2639 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2640 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2641 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2642 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2643 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2644 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2645 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2646 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2647 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2648 | } |
| 2649 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2650 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
| 2651 | LayerImpl* parent = root_layer(); |
| 2652 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2653 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2654 | |
| 2655 | grand_child->SetDrawsContent(true); |
| 2656 | |
| 2657 | gfx::Transform large_transform; |
| 2658 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2659 | |
| 2660 | gfx::Transform identity; |
| 2661 | |
| 2662 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2663 | gfx::Size(10, 10), true, false, true); |
| 2664 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
| 2665 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2666 | false); |
| 2667 | SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(), |
| 2668 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2669 | false); |
| 2670 | ExecuteCalculateDrawProperties(parent); |
| 2671 | |
| 2672 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2673 | } |
| 2674 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2675 | TEST_F(LayerTreeHostCommonTest, |
| 2676 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
| 2677 | LayerImpl* parent = root_layer(); |
| 2678 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2679 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2680 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2681 | |
| 2682 | parent->SetDrawsContent(true); |
| 2683 | child->SetDrawsContent(true); |
| 2684 | grand_child->SetDrawsContent(true); |
| 2685 | great_grand_child->SetDrawsContent(true); |
| 2686 | |
| 2687 | gfx::Transform identity; |
| 2688 | |
| 2689 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2690 | gfx::Size(10, 10), true, false, true); |
| 2691 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 2692 | gfx::Size(10, 10), true, false, false); |
| 2693 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 2694 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2695 | false); |
| 2696 | SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(), |
| 2697 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2698 | false); |
| 2699 | |
| 2700 | // Add a transform animation with a start delay to |grand_child|. |
| 2701 | scoped_ptr<Animation> animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 2702 | scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2703 | TargetProperty::TRANSFORM); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2704 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 2705 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2706 | AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(), |
| 2707 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2708 | ExecuteCalculateDrawProperties(parent); |
| 2709 | |
| 2710 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2711 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2712 | |
| 2713 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2714 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2715 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2716 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2717 | } |
| 2718 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2719 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2720 | // Test the calculateVisibleRect() function works correctly for identity |
| 2721 | // transforms. |
| 2722 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2723 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2724 | gfx::Transform layer_to_surface_transform; |
| 2725 | |
| 2726 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2727 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2728 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2729 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2730 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2731 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2732 | |
| 2733 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2734 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2735 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2736 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2737 | EXPECT_TRUE(actual.IsEmpty()); |
| 2738 | |
| 2739 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2740 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2741 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2742 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2743 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2744 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2745 | } |
| 2746 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2747 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2748 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2749 | // transforms. |
| 2750 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2751 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2752 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2753 | gfx::Transform layer_to_surface_transform; |
| 2754 | |
| 2755 | // Case 1: Layer is contained within the surface. |
| 2756 | layer_to_surface_transform.MakeIdentity(); |
| 2757 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2758 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2759 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2760 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2761 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2762 | |
| 2763 | // Case 2: Layer is outside the surface rect. |
| 2764 | layer_to_surface_transform.MakeIdentity(); |
| 2765 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2766 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2767 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2768 | EXPECT_TRUE(actual.IsEmpty()); |
| 2769 | |
| 2770 | // Case 3: Layer is partially overlapping the surface rect. |
| 2771 | layer_to_surface_transform.MakeIdentity(); |
| 2772 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2773 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2774 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2775 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2776 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2777 | } |
| 2778 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2779 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2780 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2781 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2782 | // should return the g in the layer's space. |
| 2783 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2784 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2785 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2786 | gfx::Transform layer_to_surface_transform; |
| 2787 | |
| 2788 | // Case 1: Layer is contained within the surface. |
| 2789 | layer_to_surface_transform.MakeIdentity(); |
| 2790 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2791 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2792 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2793 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2794 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2795 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | |
| 2797 | // Case 2: Layer is outside the surface rect. |
| 2798 | layer_to_surface_transform.MakeIdentity(); |
| 2799 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2800 | layer_to_surface_transform.Rotate(45.0); |
| 2801 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2802 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2803 | EXPECT_TRUE(actual.IsEmpty()); |
| 2804 | |
| 2805 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2806 | // the layer is oriented diagonally, with the left half outside of the render |
| 2807 | // surface. In this case, the g should still be the entire layer |
| 2808 | // (remember the g is computed in layer space); both the top-left |
| 2809 | // and bottom-right corners of the layer are still visible. |
| 2810 | layer_to_surface_transform.MakeIdentity(); |
| 2811 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2812 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2813 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2814 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2815 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2816 | |
| 2817 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2818 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2819 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2820 | // surface overlaps the right side of the layer. The g should be |
| 2821 | // the layer's right half. |
| 2822 | layer_to_surface_transform.MakeIdentity(); |
| 2823 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2824 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2825 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2826 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2827 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2828 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2829 | } |
| 2830 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2831 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2832 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2833 | // transforms. |
| 2834 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2835 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2836 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2837 | gfx::Transform layer_to_surface_transform; |
| 2838 | |
| 2839 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2840 | // degrees, should be fully contained in the render surface. |
| 2841 | layer_to_surface_transform.MakeIdentity(); |
| 2842 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2843 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2844 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2845 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2846 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | |
| 2848 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2849 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2850 | // visible on the surface. |
| 2851 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2852 | SkMScalar half_width_of_rotated_layer = |
| 2853 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | layer_to_surface_transform.MakeIdentity(); |
| 2855 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2856 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2857 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2858 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2859 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2860 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2861 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2862 | } |
| 2863 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2864 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2865 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2866 | // a perspective projection onto the target surface. |
| 2867 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2868 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2869 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2870 | gfx::Transform layer_to_surface_transform; |
| 2871 | |
| 2872 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2873 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2874 | // its translated more than the perspective amount. |
| 2875 | layer_to_surface_transform.MakeIdentity(); |
| 2876 | |
| 2877 | // The following sequence of transforms applies the perspective about the |
| 2878 | // center of the surface. |
| 2879 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2880 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2881 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2882 | |
| 2883 | // This translate places the layer in front of the surface's projection plane. |
| 2884 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2885 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2886 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2887 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2888 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2889 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2890 | |
| 2891 | // Case 2: same projection as before, except that the layer is also translated |
| 2892 | // to the side, so that only the right half of the layer should be visible. |
| 2893 | // |
| 2894 | // Explanation of expected result: The perspective ratio is (z distance |
| 2895 | // between layer and camera origin) / (z distance between projection plane and |
| 2896 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2897 | // move a layer by translating -50 units in projected surface units (so that |
| 2898 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2899 | // -50 == -200 in the layer's units. |
| 2900 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2901 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2902 | gfx::Size(100, 200)); // The right half of the layer's |
| 2903 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2904 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2905 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2906 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2907 | } |
| 2908 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2909 | TEST_F(LayerTreeHostCommonTest, |
| 2910 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2911 | // There is currently no explicit concept of an orthographic projection plane |
| 2912 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2913 | // are technically behind the surface in an orthographic world should not be |
| 2914 | // clipped when they are flattened to the surface. |
| 2915 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2916 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2917 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2918 | gfx::Transform layer_to_surface_transform; |
| 2919 | |
| 2920 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2921 | // at the center of the layer. |
| 2922 | layer_to_surface_transform.MakeIdentity(); |
| 2923 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2924 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2925 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2926 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2927 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2928 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2929 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2930 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2931 | } |
| 2932 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2933 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2934 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2935 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2936 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2937 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2938 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2939 | // converting to cartesian coordinates. |
| 2940 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2941 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2942 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2943 | gfx::Transform layer_to_surface_transform; |
| 2944 | |
| 2945 | // The layer is positioned so that the right half of the layer should be in |
| 2946 | // front of the camera, while the other half is behind the surface's |
| 2947 | // projection plane. The following sequence of transforms applies the |
| 2948 | // perspective and rotation about the center of the layer. |
| 2949 | layer_to_surface_transform.MakeIdentity(); |
| 2950 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2951 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2952 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2953 | |
| 2954 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2955 | // transform, otherwise this code is not testing the intended scenario. |
| 2956 | bool clipped; |
| 2957 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2958 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2959 | &clipped); |
| 2960 | ASSERT_TRUE(clipped); |
| 2961 | |
| 2962 | int expected_x_position = 0; |
| 2963 | int expected_width = 10; |
| 2964 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2965 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2966 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2967 | EXPECT_EQ(expected_width, actual.width()); |
| 2968 | } |
| 2969 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2970 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2971 | // To determine visible rect in layer space, there needs to be an |
| 2972 | // un-projection from surface space to layer space. When the original |
| 2973 | // transform was a perspective projection that was clipped, it returns a rect |
| 2974 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2975 | // clipping again. |
| 2976 | |
| 2977 | // This sequence of transforms causes one corner of the layer to protrude |
| 2978 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2979 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2980 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2981 | gfx::Transform layer_to_surface_transform; |
| 2982 | layer_to_surface_transform.MakeIdentity(); |
| 2983 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2984 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2985 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2986 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2987 | |
| 2988 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2989 | // code is not testing the intended scenario. |
| 2990 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2991 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2992 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2993 | MathUtil::ProjectQuad( |
| 2994 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2995 | ASSERT_TRUE(clipped); |
| 2996 | |
| 2997 | // Only the corner of the layer is not visible on the surface because of being |
| 2998 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2999 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3000 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3001 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 3002 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3003 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3004 | } |
| 3005 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3006 | TEST_F(LayerTreeHostCommonTest, |
| 3007 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3008 | LayerImpl* root = root_layer(); |
| 3009 | root->SetDrawsContent(true); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3010 | |
| 3011 | gfx::Transform identity_matrix; |
| 3012 | // Root layer is positioned at (60, 70). The default device viewport size |
| 3013 | // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 3014 | // will be clipped by the viewport to be (0, 0, 40x30) in layer's space. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3015 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3016 | gfx::PointF(60, 70), gfx::Size(100, 100), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3017 | false, true); |
| 3018 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3019 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3020 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3021 | root->render_surface()->DrawableContentRect()); |
| 3022 | // In target space, not clipped. |
| 3023 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3024 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3025 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3026 | } |
| 3027 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3028 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3029 | LayerImpl* root = root_layer(); |
| 3030 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
| 3031 | child1_layer->SetDrawsContent(true); |
| 3032 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
| 3033 | child2_layer->SetDrawsContent(true); |
| 3034 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
| 3035 | child3_layer->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3036 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3037 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3038 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3039 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3040 | true); |
| 3041 | SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), |
| 3042 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3043 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3044 | SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), |
| 3045 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3046 | false, false); |
| 3047 | SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), |
| 3048 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3049 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3050 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3051 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3052 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3053 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3054 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3055 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3056 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3057 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3058 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3059 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3060 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3061 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3062 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3063 | |
| 3064 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3065 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3066 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3067 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3068 | } |
| 3069 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3070 | TEST_F(LayerTreeHostCommonTest, |
| 3071 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3072 | LayerImpl* root = root_layer(); |
| 3073 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3074 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 3075 | grand_child1->SetDrawsContent(true); |
| 3076 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 3077 | grand_child2->SetDrawsContent(true); |
| 3078 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 3079 | grand_child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3080 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3081 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3082 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3083 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3084 | true); |
| 3085 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 3086 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3087 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3088 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3089 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3090 | false, false); |
| 3091 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3092 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3093 | false, false); |
| 3094 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 3095 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3096 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3097 | |
| 3098 | child->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3099 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3100 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3101 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3102 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3103 | |
| 3104 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3105 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3106 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3107 | |
| 3108 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3109 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3110 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3111 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3112 | |
| 3113 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3114 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3115 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3117 | } |
| 3118 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3119 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 3120 | scoped_refptr<Layer> root = Layer::Create(); |
| 3121 | scoped_refptr<Layer> child = Layer::Create(); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3122 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 3123 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3124 | root->AddChild(child); |
| 3125 | child->AddChild(grand_child); |
| 3126 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 3127 | host()->SetRootLayer(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3128 | |
| 3129 | gfx::Transform identity_matrix; |
| 3130 | gfx::Transform child_scale_matrix; |
| 3131 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3132 | gfx::Transform grand_child_scale_matrix; |
| 3133 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
| 3134 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3135 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 3136 | SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(), |
| 3137 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 3138 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix, |
| 3139 | gfx::Point3F(), gfx::PointF(), |
| 3140 | gfx::Size(100, 100), true, false); |
| 3141 | |
| 3142 | child->SetMasksToBounds(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 3143 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3144 | |
| 3145 | // The visible rect is expanded to integer coordinates in target space before |
| 3146 | // being projected back to layer space, where it is once again expanded to |
| 3147 | // integer coordinates. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 3148 | EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_layer_rect_for_testing()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3149 | } |
| 3150 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3151 | TEST_F(LayerTreeHostCommonTest, |
| 3152 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3153 | LayerImpl* root = root_layer(); |
| 3154 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3155 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3156 | child1->SetDrawsContent(true); |
| 3157 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3158 | child2->SetDrawsContent(true); |
| 3159 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3160 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3161 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3162 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3163 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3164 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3165 | true); |
| 3166 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3167 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3168 | true); |
| 3169 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3170 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3171 | false, false); |
| 3172 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3173 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3174 | false, false); |
| 3175 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3176 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3177 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3178 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3179 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3180 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3181 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3182 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3183 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3184 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3185 | |
| 3186 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3187 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3188 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3189 | |
| 3190 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3191 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3192 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3193 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3194 | |
| 3195 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3196 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3197 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3198 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3199 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3200 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3201 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3202 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3203 | } |
| 3204 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3205 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3206 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
| 3207 | LayerImpl* root = root_layer(); |
| 3208 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3209 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3210 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3211 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3212 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3213 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3214 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3215 | |
| 3216 | root->SetDrawsContent(true); |
| 3217 | parent->SetDrawsContent(true); |
| 3218 | child1->SetDrawsContent(true); |
| 3219 | child2->SetDrawsContent(true); |
| 3220 | grand_child1->SetDrawsContent(true); |
| 3221 | grand_child2->SetDrawsContent(true); |
| 3222 | leaf_node1->SetDrawsContent(true); |
| 3223 | leaf_node2->SetDrawsContent(true); |
| 3224 | |
| 3225 | const gfx::Transform identity_matrix; |
| 3226 | |
| 3227 | // child1 and child2 get render surfaces when surfaces are enabled. |
| 3228 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3229 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3230 | true); |
| 3231 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 3232 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 3233 | false, false); |
| 3234 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3235 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 3236 | false, true); |
| 3237 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3238 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
| 3239 | false, true); |
| 3240 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3241 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 3242 | true, false, false); |
| 3243 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3244 | gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500), |
| 3245 | true, false, false); |
| 3246 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 3247 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 3248 | true, false, false); |
| 3249 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 3250 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
| 3251 | true, false, false); |
| 3252 | |
| 3253 | // Case 1: No layers clip. Visible rects are clipped by the viewport, but the |
| 3254 | // viewport clip doesn't apply to layers that draw into unclipped surfaces. |
| 3255 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3256 | // thing that changes with surfaces disabled is that target space is always |
| 3257 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3258 | root->SetHasRenderSurface(true); |
| 3259 | child1->SetHasRenderSurface(true); |
| 3260 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3261 | ExecuteCalculateDrawProperties(root); |
| 3262 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3263 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3266 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect()); |
| 3267 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3268 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect()); |
| 3269 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect()); |
| 3270 | |
| 3271 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3272 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3273 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3274 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3275 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3277 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3279 | |
| 3280 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3281 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3282 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3283 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3284 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3285 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3286 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3287 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3288 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3289 | |
| 3290 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3292 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3293 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3294 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3295 | grand_child1->drawable_content_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3297 | grand_child2->drawable_content_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3300 | |
| 3301 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3302 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3303 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3304 | // rects are clipped only until the next render surface is reached, so |
| 3305 | // descendants of parent have their drawable content rects clipped only when |
| 3306 | // surfaces are disabled. |
| 3307 | parent->SetMasksToBounds(true); |
| 3308 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3309 | root->SetHasRenderSurface(true); |
| 3310 | child1->SetHasRenderSurface(true); |
| 3311 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3312 | ExecuteCalculateDrawProperties(root); |
| 3313 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3314 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3315 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3316 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3317 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3318 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3319 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3320 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3321 | |
| 3322 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3323 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3324 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3325 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3326 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3328 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3329 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3330 | |
| 3331 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3332 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3333 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3334 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3335 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3336 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3337 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3338 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3339 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3340 | |
| 3341 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3342 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3343 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3344 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3345 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3346 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3347 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3348 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3349 | |
| 3350 | parent->SetMasksToBounds(false); |
| 3351 | |
| 3352 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
| 3353 | // layers have their visible rects clipped by them; without surfaces, these |
| 3354 | // rects are also clipped by the viewport. Similarly, descendants of these |
| 3355 | // layers have their drawable content rects clipped by them. |
| 3356 | child1->SetMasksToBounds(true); |
| 3357 | grand_child2->SetMasksToBounds(true); |
| 3358 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3359 | root->SetHasRenderSurface(true); |
| 3360 | child1->SetHasRenderSurface(true); |
| 3361 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3362 | ExecuteCalculateDrawProperties(root); |
| 3363 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3364 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3365 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3366 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3367 | EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); |
| 3368 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3369 | EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); |
| 3370 | EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); |
| 3371 | |
| 3372 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3373 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3374 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3375 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3376 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3377 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3378 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3379 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3380 | |
| 3381 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3382 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3383 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3384 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3385 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3386 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3387 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3388 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3389 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3390 | |
| 3391 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3392 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3393 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3394 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3395 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3396 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3397 | grand_child2->drawable_content_rect()); |
| 3398 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3399 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3400 | } |
| 3401 | |
| 3402 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3403 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3404 | LayerImpl* root = root_layer(); |
| 3405 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3406 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3407 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
| 3408 | child1->SetDrawsContent(true); |
| 3409 | child2->SetDrawsContent(true); |
| 3410 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3411 | |
| 3412 | gfx::Transform identity_matrix; |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3413 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3414 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3415 | true); |
| 3416 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3417 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3418 | false, false); |
| 3419 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3420 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3421 | false, false); |
| 3422 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3423 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3424 | true, false, false); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3425 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3426 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3427 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3428 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3429 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3430 | root, gfx::Size(), &render_surface_layer_list_impl, |
| 3431 | root->layer_tree_impl()->current_render_surface_list_id()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3432 | |
| 3433 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 3434 | ASSERT_TRUE(root->render_surface()); |
| 3435 | EXPECT_FALSE(root->is_clipped()); |
| 3436 | |
| 3437 | gfx::Rect empty; |
| 3438 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3439 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3440 | |
| 3441 | // Visible content rect calculation will check if the target surface is |
| 3442 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3443 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3444 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3445 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3446 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3450 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3451 | LayerImpl* root = root_layer(); |
| 3452 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3453 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3454 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3455 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3456 | gfx::Transform identity_matrix; |
| 3457 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3458 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3459 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3460 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3461 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3462 | true); |
| 3463 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3464 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3465 | false, false); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3466 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3467 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3468 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3469 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3470 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3471 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3472 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3473 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3474 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3475 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3476 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3477 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3478 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3479 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3480 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3481 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3482 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3483 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3484 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3485 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3486 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3487 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3488 | uninvertible_matrix.MakeIdentity(); |
| 3489 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3490 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3491 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3492 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3493 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3494 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3495 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3496 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3497 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3498 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3499 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3500 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3501 | } |
| 3502 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3503 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3504 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
| 3505 | LayerImpl* root = root_layer(); |
| 3506 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3507 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 3508 | child->SetDrawsContent(true); |
| 3509 | grand_child->SetDrawsContent(true); |
| 3510 | |
| 3511 | gfx::Transform identity_matrix; |
| 3512 | |
| 3513 | gfx::Transform perspective; |
| 3514 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3515 | |
| 3516 | gfx::Transform rotation; |
| 3517 | rotation.RotateAboutYAxis(45.0); |
| 3518 | |
| 3519 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3520 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3521 | true); |
| 3522 | SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(), |
| 3523 | gfx::PointF(10.f, 10.f), gfx::Size(100, 100), |
| 3524 | false, true, false); |
| 3525 | SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(), |
| 3526 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 3527 | false); |
| 3528 | |
| 3529 | ExecuteCalculateDrawProperties(root); |
| 3530 | |
| 3531 | // Though all layers have invertible transforms, matrix multiplication using |
| 3532 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3533 | EXPECT_FALSE(root->layer_tree_impl() |
| 3534 | ->property_trees() |
| 3535 | ->transform_tree.Node(grand_child->transform_tree_index()) |
| 3536 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3537 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3538 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3539 | // uninvertible |
| 3540 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | TEST_F(LayerTreeHostCommonTest, |
| 3544 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3545 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3546 | TestSharedBitmapManager shared_bitmap_manager; |
| 3547 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3548 | scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3549 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3550 | &task_graph_runner); |
| 3551 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 3552 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); |
| 3553 | scoped_ptr<LayerImpl> grand_child = |
| 3554 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 3555 | scoped_ptr<LayerImpl> occluding_child = |
| 3556 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 3557 | child->SetDrawsContent(true); |
| 3558 | grand_child->SetDrawsContent(true); |
| 3559 | occluding_child->SetDrawsContent(true); |
| 3560 | occluding_child->SetContentsOpaque(true); |
| 3561 | |
| 3562 | gfx::Transform identity_matrix; |
| 3563 | gfx::Transform perspective; |
| 3564 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3565 | |
| 3566 | gfx::Transform rotation; |
| 3567 | rotation.RotateAboutYAxis(45.0); |
| 3568 | |
| 3569 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3570 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3571 | false, true); |
| 3572 | SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(), |
| 3573 | gfx::PointF(10.f, 10.f), gfx::Size(300, 300), |
| 3574 | false, true, false); |
| 3575 | SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(), |
| 3576 | gfx::PointF(), gfx::Size(200, 200), false, true, |
| 3577 | false); |
| 3578 | SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix, |
| 3579 | gfx::Point3F(), gfx::PointF(), |
| 3580 | gfx::Size(200, 200), false, false, false); |
| 3581 | |
| 3582 | host_impl.SetViewportSize(root->bounds()); |
| 3583 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3584 | child->AddChild(std::move(grand_child)); |
| 3585 | root->AddChild(std::move(child)); |
| 3586 | root->AddChild(std::move(occluding_child)); |
| 3587 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3588 | host_impl.SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3589 | host_impl.InitializeRenderer(output_surface.get()); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 3590 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3591 | bool update_lcd_text = false; |
| 3592 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3593 | |
| 3594 | LayerImpl* grand_child_ptr = |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3595 | host_impl.active_tree()->root_layer()->children()[0]->children()[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3596 | |
| 3597 | // Though all layers have invertible transforms, matrix multiplication using |
| 3598 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3599 | EXPECT_FALSE( |
| 3600 | host_impl.active_tree() |
| 3601 | ->property_trees() |
| 3602 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
| 3603 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3604 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3605 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3606 | // skipped so |
| 3607 | // that we are not computing its occlusion_in_content_space. |
| 3608 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3609 | EXPECT_EQ( |
| 3610 | layer_bounds, |
| 3611 | grand_child_ptr->draw_properties() |
| 3612 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3613 | } |
| 3614 | |
| 3615 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3616 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3617 | LayerImpl* root = root_layer(); |
| 3618 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3619 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3620 | child1->SetDrawsContent(true); |
| 3621 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3622 | child2->SetDrawsContent(true); |
| 3623 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3624 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3626 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3627 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3628 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3629 | true); |
| 3630 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3631 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3632 | true); |
| 3633 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3634 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3635 | false, false); |
| 3636 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3637 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3638 | false, false); |
| 3639 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3640 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3641 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3642 | |
| 3643 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3644 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3645 | ExecuteCalculateDrawProperties(root); |
| 3646 | |
| 3647 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3648 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3649 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3650 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3651 | |
| 3652 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3653 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3654 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3655 | |
| 3656 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3657 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3658 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3659 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3660 | |
| 3661 | // All layers that draw content into the surface have their visible content |
| 3662 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3663 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3664 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3665 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3666 | |
| 3667 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3668 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3669 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3670 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3671 | } |
| 3672 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3673 | TEST_F(LayerTreeHostCommonTest, |
| 3674 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3675 | // Check that clipping does not propagate down surfaces. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3676 | LayerImpl* root = root_layer(); |
| 3677 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3678 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3679 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
| 3680 | child1->SetDrawsContent(true); |
| 3681 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 3682 | child2->SetDrawsContent(true); |
| 3683 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
| 3684 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3685 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3686 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3687 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3688 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3689 | true); |
| 3690 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3691 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3692 | true); |
| 3693 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3694 | gfx::PointF(), gfx::Size(7, 13), true, false, |
| 3695 | true); |
| 3696 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3697 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3698 | false, false); |
| 3699 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3700 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3701 | false, false); |
| 3702 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3703 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3704 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3705 | |
| 3706 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3707 | |
| 3708 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3709 | |
| 3710 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3711 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3712 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3713 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3714 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3715 | |
| 3716 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3717 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3718 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3719 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3720 | |
| 3721 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3722 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3723 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3724 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3725 | |
| 3726 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3727 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3728 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3729 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3730 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3731 | |
| 3732 | // All layers that draw content into render_surface2 think they are unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3733 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3734 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3735 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3736 | |
| 3737 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3738 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3739 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3740 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3741 | } |
| 3742 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3743 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3744 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
| 3745 | LayerImpl* root = root_layer(); |
| 3746 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3747 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3748 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3749 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
| 3750 | child1->SetDrawsContent(true); |
| 3751 | child2->SetDrawsContent(true); |
| 3752 | render_surface2->SetDrawsContent(true); |
| 3753 | |
| 3754 | gfx::Transform identity_matrix; |
| 3755 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3756 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3757 | true); |
| 3758 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3759 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3760 | true); |
| 3761 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3762 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 3763 | false); |
| 3764 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3765 | gfx::PointF(), gfx::Size(700, 700), true, false, |
| 3766 | false); |
| 3767 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3768 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3769 | false, true); |
| 3770 | |
| 3771 | child1->SetMasksToBounds(true); |
| 3772 | child2->SetMasksToBounds(true); |
| 3773 | |
| 3774 | ExecuteCalculateDrawProperties(root); |
| 3775 | EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); |
| 3776 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3777 | } |
| 3778 | |
jaydasika | 75ad0a4 | 2016-02-12 19:47:19 | [diff] [blame] | 3779 | TEST_F(LayerTreeHostCommonTest, ClipChildWithSingularTransform) { |
| 3780 | LayerImpl* root = root_layer(); |
| 3781 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3782 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 3783 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 3784 | |
| 3785 | clip_child->SetDrawsContent(true); |
| 3786 | clip_child->SetClipParent(clip_parent); |
| 3787 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3788 | clip_children->insert(clip_child); |
| 3789 | clip_parent->SetClipChildren(clip_children.release()); |
| 3790 | |
| 3791 | gfx::Transform identity_matrix; |
| 3792 | gfx::Transform singular_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3793 | ASSERT_FALSE(singular_matrix.IsInvertible()); |
| 3794 | |
| 3795 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3796 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3797 | true); |
| 3798 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3799 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3800 | false); |
| 3801 | SetLayerPropertiesForTesting(intervening, identity_matrix, gfx::Point3F(), |
| 3802 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3803 | false); |
| 3804 | SetLayerPropertiesForTesting(clip_child, singular_matrix, gfx::Point3F(), |
| 3805 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3806 | false); |
| 3807 | |
| 3808 | ExecuteCalculateDrawProperties(root); |
| 3809 | EXPECT_EQ(intervening->num_unclipped_descendants(), 1u); |
| 3810 | } |
| 3811 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3812 | TEST_F(LayerTreeHostCommonTest, |
| 3813 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
| 3814 | LayerImpl* root = root_layer(); |
| 3815 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3816 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3817 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3818 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3819 | |
| 3820 | render_surface1->SetDrawsContent(true); |
| 3821 | render_surface2->SetDrawsContent(true); |
| 3822 | clip_child->SetDrawsContent(true); |
| 3823 | clip_child->SetClipParent(clip_parent); |
| 3824 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3825 | clip_children->insert(clip_child); |
| 3826 | clip_parent->SetClipChildren(clip_children.release()); |
| 3827 | |
| 3828 | gfx::Transform identity_matrix; |
| 3829 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3830 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3831 | true); |
| 3832 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3833 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3834 | false); |
| 3835 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3836 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3837 | true); |
| 3838 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3839 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3840 | false); |
| 3841 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3842 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3843 | true); |
| 3844 | clip_parent->SetMasksToBounds(true); |
| 3845 | render_surface1->SetMasksToBounds(true); |
| 3846 | |
| 3847 | ExecuteCalculateDrawProperties(root); |
| 3848 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3849 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3850 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3851 | } |
| 3852 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3853 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
| 3854 | LayerImpl* root = root_layer(); |
| 3855 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3856 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3857 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3858 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3859 | |
| 3860 | render_surface1->SetDrawsContent(true); |
| 3861 | render_surface2->SetDrawsContent(true); |
| 3862 | clip_child->SetDrawsContent(true); |
| 3863 | clip_child->SetClipParent(clip_parent); |
| 3864 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3865 | clip_children->insert(clip_child); |
| 3866 | clip_parent->SetClipChildren(clip_children.release()); |
| 3867 | |
| 3868 | gfx::Transform identity_matrix; |
| 3869 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3870 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3871 | true); |
| 3872 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3873 | gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true, |
| 3874 | false, false); |
| 3875 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3876 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3877 | true); |
| 3878 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3879 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3880 | false); |
| 3881 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3882 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3883 | true); |
| 3884 | clip_parent->SetMasksToBounds(true); |
| 3885 | render_surface1->SetMasksToBounds(true); |
| 3886 | |
| 3887 | ExecuteCalculateDrawProperties(root); |
| 3888 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3889 | } |
| 3890 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3891 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3892 | // Test that only drawn layers contribute to render surface content rect. |
| 3893 | LayerImpl* root = root_layer(); |
| 3894 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3895 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3896 | |
| 3897 | test_layer->SetDrawsContent(false); |
| 3898 | surface->SetDrawsContent(true); |
| 3899 | gfx::Transform identity_matrix; |
| 3900 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3901 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 3902 | true); |
| 3903 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 3904 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3905 | true); |
| 3906 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 3907 | gfx::PointF(), gfx::Size(150, 150), true, false, |
| 3908 | false); |
| 3909 | |
| 3910 | ExecuteCalculateDrawProperties(root); |
| 3911 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3912 | |
| 3913 | test_layer->SetDrawsContent(true); |
| 3914 | ExecuteCalculateDrawProperties(root); |
| 3915 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3916 | } |
| 3917 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3918 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3919 | // Tests visible rects computation when we have unclipped_surface-> |
| 3920 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3921 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3922 | // clipped_surface below it. |
| 3923 | LayerImpl* root = root_layer(); |
| 3924 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3925 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3926 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3927 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3928 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3929 | |
| 3930 | unclipped_surface->SetDrawsContent(true); |
| 3931 | unclipped_desc_surface->SetDrawsContent(true); |
| 3932 | clipped_surface->SetDrawsContent(true); |
| 3933 | clip_child->SetClipParent(clip_parent); |
| 3934 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3935 | clip_children->insert(clip_child); |
| 3936 | clip_parent->SetClipChildren(clip_children.release()); |
| 3937 | |
| 3938 | gfx::Transform identity_matrix; |
| 3939 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3940 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3941 | true); |
| 3942 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3943 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 3944 | true, false, true); |
| 3945 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3946 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3947 | false); |
| 3948 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3949 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 3950 | true, false, true); |
| 3951 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3952 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3953 | false); |
| 3954 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 3955 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3956 | true); |
| 3957 | clip_parent->SetMasksToBounds(true); |
| 3958 | |
| 3959 | ExecuteCalculateDrawProperties(root); |
| 3960 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3961 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3962 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3963 | } |
| 3964 | |
| 3965 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3966 | // Tests visible rects computation when we have unclipped_surface-> |
| 3967 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3968 | // of root propagate to the clipped_surface. |
| 3969 | LayerImpl* root = root_layer(); |
| 3970 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3971 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3972 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3973 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3974 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3975 | |
| 3976 | unclipped_surface->SetDrawsContent(true); |
| 3977 | unclipped_desc_surface->SetDrawsContent(true); |
| 3978 | clipped_surface->SetDrawsContent(true); |
| 3979 | clip_child->SetClipParent(clip_parent); |
| 3980 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3981 | clip_children->insert(clip_child); |
| 3982 | clip_parent->SetClipChildren(clip_children.release()); |
| 3983 | |
| 3984 | gfx::Transform identity_matrix; |
| 3985 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3986 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 3987 | true); |
| 3988 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3989 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 3990 | true, false, true); |
| 3991 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3992 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3993 | false); |
| 3994 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3995 | gfx::Point3F(), gfx::PointF(), |
| 3996 | gfx::Size(100, 100), true, false, true); |
| 3997 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3998 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3999 | false); |
| 4000 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 4001 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4002 | true); |
| 4003 | clip_parent->SetMasksToBounds(true); |
| 4004 | unclipped_desc_surface->SetMasksToBounds(true); |
| 4005 | |
| 4006 | ExecuteCalculateDrawProperties(root); |
| 4007 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 4008 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4009 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 4010 | } |
| 4011 | |
| 4012 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4013 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4014 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4015 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4016 | LayerImpl* root = root_layer(); |
| 4017 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4018 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4019 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4020 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4021 | gfx::Transform identity_matrix; |
| 4022 | gfx::Transform child_rotation; |
| 4023 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4024 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4025 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4026 | true); |
| 4027 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4028 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4029 | true); |
| 4030 | SetLayerPropertiesForTesting( |
| 4031 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4032 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4033 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4034 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4035 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4036 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4037 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4038 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4039 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4040 | |
| 4041 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4042 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4043 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4044 | |
| 4045 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4046 | // regions of the subtree. |
| 4047 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4048 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4049 | gfx::Rect(50 - diagonal_radius, |
| 4050 | 50 - diagonal_radius, |
| 4051 | diagonal_radius * 2, |
| 4052 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4053 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4054 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4055 | |
| 4056 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4057 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4058 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | } |
| 4060 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4061 | TEST_F(LayerTreeHostCommonTest, |
| 4062 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4064 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4065 | LayerImpl* root = root_layer(); |
| 4066 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4067 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4068 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4069 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | gfx::Transform identity_matrix; |
| 4071 | gfx::Transform child_rotation; |
| 4072 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4073 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4074 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4075 | true); |
| 4076 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4077 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4078 | true); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4079 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4080 | SetLayerPropertiesForTesting( |
| 4081 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4082 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4083 | |
| 4084 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4085 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4086 | ExecuteCalculateDrawProperties(root); |
| 4087 | |
| 4088 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4089 | |
| 4090 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4091 | // rotated layer. |
| 4092 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4093 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4094 | 50 - diagonal_radius, |
| 4095 | diagonal_radius * 2, |
| 4096 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4097 | gfx::RectF expected_surface_drawable_content( |
| 4098 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4099 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4100 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4101 | |
| 4102 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4103 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4104 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4105 | // |
| 4106 | // Given the floating point math, this number is a little bit fuzzy. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4107 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4108 | |
| 4109 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4110 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4111 | } |
| 4112 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4113 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4114 | LayerImpl* root = root_layer(); |
| 4115 | FakePictureLayerImpl* render_surface1 = |
| 4116 | AddChildToRoot<FakePictureLayerImpl>(); |
| 4117 | render_surface1->SetDrawsContent(true); |
| 4118 | FakePictureLayerImpl* render_surface2 = |
| 4119 | AddChild<FakePictureLayerImpl>(render_surface1); |
| 4120 | render_surface2->SetDrawsContent(true); |
| 4121 | FakePictureLayerImpl* child1 = |
| 4122 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4123 | child1->SetDrawsContent(true); |
| 4124 | FakePictureLayerImpl* child2 = |
| 4125 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4126 | child2->SetDrawsContent(true); |
| 4127 | FakePictureLayerImpl* child3 = |
| 4128 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4129 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4130 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4131 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4132 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4133 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4134 | true); |
| 4135 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 4136 | gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true, |
| 4137 | false, true); |
| 4138 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 4139 | gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true, |
| 4140 | false, true); |
| 4141 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4142 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 4143 | false, false); |
| 4144 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4145 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 4146 | false, false); |
| 4147 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 4148 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 4149 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4150 | |
| 4151 | float device_scale_factor = 2.f; |
| 4152 | |
| 4153 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4154 | |
| 4155 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4156 | |
| 4157 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4158 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4159 | |
| 4160 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4161 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4162 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4163 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4164 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4165 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4166 | |
| 4167 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4168 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4169 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4170 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4171 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4172 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4173 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4174 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4175 | |
| 4176 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4177 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4178 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4179 | // All layer visible content rects are not expressed in content space of each |
| 4180 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4181 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4182 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4183 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 4184 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 4185 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4186 | } |
| 4187 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4188 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4190 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4191 | // "flattened" to each parent layer according to current W3C spec. |
| 4192 | |
| 4193 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4194 | scoped_refptr<Layer> parent = Layer::Create(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4195 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4196 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4197 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4198 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4199 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4200 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4201 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4202 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4203 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4204 | front_facing_child_of_front_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4205 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4206 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4207 | back_facing_child_of_front_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4208 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4209 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4210 | front_facing_child_of_back_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4211 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4212 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4213 | back_facing_child_of_back_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4214 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4215 | |
| 4216 | parent->AddChild(front_facing_child); |
| 4217 | parent->AddChild(back_facing_child); |
| 4218 | parent->AddChild(front_facing_surface); |
| 4219 | parent->AddChild(back_facing_surface); |
| 4220 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 4221 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 4222 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 4223 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 4224 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4225 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4226 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4227 | // Nothing is double-sided |
| 4228 | front_facing_child->SetDoubleSided(false); |
| 4229 | back_facing_child->SetDoubleSided(false); |
| 4230 | front_facing_surface->SetDoubleSided(false); |
| 4231 | back_facing_surface->SetDoubleSided(false); |
| 4232 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4233 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4234 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4235 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4236 | |
| 4237 | gfx::Transform backface_matrix; |
| 4238 | backface_matrix.Translate(50.0, 50.0); |
| 4239 | backface_matrix.RotateAboutYAxis(180.0); |
| 4240 | backface_matrix.Translate(-50.0, -50.0); |
| 4241 | |
| 4242 | // Having a descendant and opacity will force these to have render surfaces. |
| 4243 | front_facing_surface->SetOpacity(0.5f); |
| 4244 | back_facing_surface->SetOpacity(0.5f); |
| 4245 | |
| 4246 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 4247 | // these layers should blindly use their own local transforms to determine |
| 4248 | // back-face culling. |
| 4249 | SetLayerPropertiesForTesting(parent.get(), |
| 4250 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4251 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4252 | gfx::PointF(), |
| 4253 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4254 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4255 | false); |
| 4256 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 4257 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4258 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | gfx::PointF(), |
| 4260 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4261 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4262 | false); |
| 4263 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 4264 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4265 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4266 | gfx::PointF(), |
| 4267 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4268 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4269 | false); |
| 4270 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4271 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4272 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4273 | gfx::PointF(), |
| 4274 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4275 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4276 | false); |
| 4277 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4278 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4279 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4280 | gfx::PointF(), |
| 4281 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4282 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4283 | false); |
| 4284 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 4285 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4286 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4287 | gfx::PointF(), |
| 4288 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4289 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4290 | false); |
| 4291 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 4292 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4293 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4294 | gfx::PointF(), |
| 4295 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4296 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4297 | false); |
| 4298 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 4299 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4300 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4301 | gfx::PointF(), |
| 4302 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4303 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4304 | false); |
| 4305 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 4306 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4307 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4308 | gfx::PointF(), |
| 4309 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4310 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4311 | false); |
| 4312 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4313 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4314 | |
| 4315 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4316 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4317 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4318 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4319 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4320 | EXPECT_FALSE( |
| 4321 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4322 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4323 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4324 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4325 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4326 | EXPECT_EQ(4u, update_layer_list().size()); |
| 4327 | EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id())); |
| 4328 | EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id())); |
| 4329 | EXPECT_TRUE(UpdateLayerListContains( |
| 4330 | front_facing_child_of_front_facing_surface->id())); |
| 4331 | EXPECT_TRUE( |
| 4332 | UpdateLayerListContains(front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4333 | } |
| 4334 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4335 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4336 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4337 | // is used. |
| 4338 | |
| 4339 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4340 | LayerImpl* parent = root_layer(); |
| 4341 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4342 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4343 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4344 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4345 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4346 | AddChild<LayerImpl>(front_facing_surface); |
| 4347 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4348 | AddChild<LayerImpl>(front_facing_surface); |
| 4349 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4350 | AddChild<LayerImpl>(back_facing_surface); |
| 4351 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4352 | AddChild<LayerImpl>(back_facing_surface); |
| 4353 | // Opacity will not force creation of render surfaces in this case because of |
| 4354 | // the preserve-3d transform style. Instead, an example of when a surface |
| 4355 | // would be created with preserve-3d is when there is a replica layer. |
| 4356 | LayerImpl* dummy_replica_layer1 = |
| 4357 | AddReplicaLayer<LayerImpl>(front_facing_surface); |
| 4358 | LayerImpl* dummy_replica_layer2 = |
| 4359 | AddReplicaLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4360 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4361 | // Nothing is double-sided |
| 4362 | front_facing_child->SetDoubleSided(false); |
| 4363 | back_facing_child->SetDoubleSided(false); |
| 4364 | front_facing_surface->SetDoubleSided(false); |
| 4365 | back_facing_surface->SetDoubleSided(false); |
| 4366 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4367 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4368 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4369 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4370 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4371 | // Everything draws content. |
| 4372 | front_facing_child->SetDrawsContent(true); |
| 4373 | back_facing_child->SetDrawsContent(true); |
| 4374 | front_facing_surface->SetDrawsContent(true); |
| 4375 | back_facing_surface->SetDrawsContent(true); |
| 4376 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4377 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4378 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4379 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4380 | dummy_replica_layer1->SetDrawsContent(true); |
| 4381 | dummy_replica_layer2->SetDrawsContent(true); |
| 4382 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4383 | gfx::Transform backface_matrix; |
| 4384 | backface_matrix.Translate(50.0, 50.0); |
| 4385 | backface_matrix.RotateAboutYAxis(180.0); |
| 4386 | backface_matrix.Translate(-50.0, -50.0); |
| 4387 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4388 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4389 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4390 | // rendering context should use the transform with respect to that context. |
| 4391 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4392 | // and (b) the layer's transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4393 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4394 | gfx::PointF(), gfx::Size(100, 100), true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4395 | false); // parent transform style is flat. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4396 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4397 | gfx::Point3F(), gfx::PointF(), |
| 4398 | gfx::Size(100, 100), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4399 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4400 | gfx::Point3F(), gfx::PointF(), |
| 4401 | gfx::Size(100, 100), true, false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4402 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4403 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4404 | gfx::Point3F(), gfx::PointF(), |
| 4405 | gfx::Size(100, 100), false, true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4406 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4407 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4408 | gfx::Point3F(), gfx::PointF(), |
| 4409 | gfx::Size(100, 100), false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4410 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4411 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4412 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4413 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4414 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4415 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4416 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4417 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4418 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4419 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4420 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4421 | gfx::Size(100, 100), true, true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4422 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4423 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4424 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4425 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4426 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4427 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4428 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4429 | // We expect that a has_render_surface was created but not used. |
| 4430 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4431 | EXPECT_FALSE( |
| 4432 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4433 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4434 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4435 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4436 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4437 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4438 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4439 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4440 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4441 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4442 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4443 | } |
| 4444 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4445 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4446 | // Verify that layers are appropriately culled when their back face is showing |
| 4447 | // and they are not double sided, while animations are going on. |
| 4448 | // |
| 4449 | // Layers that are animating do not get culled on the main thread, as their |
| 4450 | // transforms should be treated as "unknown" so we can not be sure that their |
| 4451 | // back face is really showing. |
| 4452 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4453 | scoped_refptr<Layer> parent = Layer::Create(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4454 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4455 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4456 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4457 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4458 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4459 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4460 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4461 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4462 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4463 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4464 | |
| 4465 | parent->AddChild(child); |
| 4466 | parent->AddChild(animating_surface); |
| 4467 | animating_surface->AddChild(child_of_animating_surface); |
| 4468 | parent->AddChild(animating_child); |
| 4469 | parent->AddChild(child2); |
| 4470 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4471 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4472 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4473 | // Nothing is double-sided |
| 4474 | child->SetDoubleSided(false); |
| 4475 | child2->SetDoubleSided(false); |
| 4476 | animating_surface->SetDoubleSided(false); |
| 4477 | child_of_animating_surface->SetDoubleSided(false); |
| 4478 | animating_child->SetDoubleSided(false); |
| 4479 | |
| 4480 | gfx::Transform backface_matrix; |
| 4481 | backface_matrix.Translate(50.0, 50.0); |
| 4482 | backface_matrix.RotateAboutYAxis(180.0); |
| 4483 | backface_matrix.Translate(-50.0, -50.0); |
| 4484 | |
| 4485 | // Make our render surface. |
| 4486 | animating_surface->SetForceRenderSurface(true); |
| 4487 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4488 | // Animate the transform on the render surface. |
| 4489 | AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), timeline(), |
| 4490 | 10.0, 30, 0); |
| 4491 | // This is just an animating layer, not a surface. |
| 4492 | AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline(), 10.0, |
| 4493 | 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4494 | |
| 4495 | SetLayerPropertiesForTesting(parent.get(), |
| 4496 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4497 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4498 | gfx::PointF(), |
| 4499 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4500 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4501 | false); |
| 4502 | SetLayerPropertiesForTesting(child.get(), |
| 4503 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4504 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4505 | gfx::PointF(), |
| 4506 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4507 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4508 | false); |
| 4509 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 4510 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4511 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4512 | gfx::PointF(), |
| 4513 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4514 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4515 | false); |
| 4516 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 4517 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4518 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4519 | gfx::PointF(), |
| 4520 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4521 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4522 | false); |
| 4523 | SetLayerPropertiesForTesting(animating_child.get(), |
| 4524 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4525 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4526 | gfx::PointF(), |
| 4527 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4528 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4529 | false); |
| 4530 | SetLayerPropertiesForTesting(child2.get(), |
| 4531 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4532 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4533 | gfx::PointF(), |
| 4534 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4535 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4536 | false); |
| 4537 | |
jaydasika | 6b7c69d | 2016-04-01 00:54:43 | [diff] [blame] | 4538 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4539 | parent.get(), parent->bounds()); |
| 4540 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4541 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4542 | EXPECT_FALSE(child->has_render_surface()); |
| 4543 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4544 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4545 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4546 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4547 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4548 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
| 4549 | |
| 4550 | EXPECT_EQ(4u, update_layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4551 | |
| 4552 | // The non-animating child be culled from the layer list for the parent render |
| 4553 | // surface. |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4554 | EXPECT_TRUE(UpdateLayerListContains(animating_surface->id())); |
| 4555 | EXPECT_TRUE(UpdateLayerListContains(animating_child->id())); |
| 4556 | EXPECT_TRUE(UpdateLayerListContains(child2->id())); |
| 4557 | EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4558 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 4559 | EXPECT_FALSE(child2->visible_layer_rect_for_testing().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4560 | |
| 4561 | // The animating layers should have a visible content rect that represents the |
| 4562 | // area of the front face that is within the viewport. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 4563 | EXPECT_EQ(animating_child->visible_layer_rect_for_testing(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4564 | gfx::Rect(animating_child->bounds())); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 4565 | EXPECT_EQ(animating_surface->visible_layer_rect_for_testing(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4566 | gfx::Rect(animating_surface->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4567 | // And layers in the subtree of the animating layer should have valid visible |
| 4568 | // content rects also. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 4569 | EXPECT_EQ(child_of_animating_surface->visible_layer_rect_for_testing(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4570 | gfx::Rect(child_of_animating_surface->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4571 | } |
| 4572 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4573 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4574 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4575 | // Verify the behavior of back-face culling for a render surface that is |
| 4576 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4577 | |
| 4578 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4579 | scoped_refptr<Layer> parent = Layer::Create(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4580 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4581 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4582 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4583 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4584 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4585 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4586 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4587 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4588 | |
| 4589 | parent->AddChild(front_facing_surface); |
| 4590 | parent->AddChild(back_facing_surface); |
| 4591 | front_facing_surface->AddChild(child1); |
| 4592 | back_facing_surface->AddChild(child2); |
| 4593 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4594 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4595 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4596 | // RenderSurfaces are not double-sided |
| 4597 | front_facing_surface->SetDoubleSided(false); |
| 4598 | back_facing_surface->SetDoubleSided(false); |
| 4599 | |
| 4600 | gfx::Transform backface_matrix; |
| 4601 | backface_matrix.Translate(50.0, 50.0); |
| 4602 | backface_matrix.RotateAboutYAxis(180.0); |
| 4603 | backface_matrix.Translate(-50.0, -50.0); |
| 4604 | |
| 4605 | SetLayerPropertiesForTesting(parent.get(), |
| 4606 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4607 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4608 | gfx::PointF(), |
| 4609 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4610 | false, |
| 4611 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4612 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4613 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4614 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4615 | gfx::PointF(), |
| 4616 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4617 | true, |
| 4618 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4619 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4620 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4621 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | gfx::PointF(), |
| 4623 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4624 | true, |
| 4625 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4626 | SetLayerPropertiesForTesting(child1.get(), |
| 4627 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4628 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4629 | gfx::PointF(), |
| 4630 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4632 | false); |
| 4633 | SetLayerPropertiesForTesting(child2.get(), |
| 4634 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | gfx::PointF(), |
| 4637 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4639 | false); |
| 4640 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4641 | front_facing_surface->Set3dSortingContextId(1); |
| 4642 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4643 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4644 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4645 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4646 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4647 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4648 | |
| 4649 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4650 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4651 | EXPECT_FALSE(child1->has_render_surface()); |
| 4652 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4653 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4654 | EXPECT_EQ(2u, update_layer_list().size()); |
| 4655 | EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id())); |
| 4656 | EXPECT_TRUE(UpdateLayerListContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4657 | } |
| 4658 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4659 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4660 | // Verify draw and screen space transforms of layers not in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4661 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4662 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4663 | LayerImpl* parent = root_layer(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4664 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4665 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4666 | gfx::PointF(), gfx::Size(100, 100), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4668 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4669 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4670 | child->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4671 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4672 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4673 | true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4674 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4675 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
| 4676 | child2->SetDrawsContent(true); |
| 4677 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4678 | gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false, |
| 4679 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4680 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4681 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4682 | gfx::Size viewport_size(100, 100); |
| 4683 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4684 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4685 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent); |
| 4686 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4687 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4688 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4689 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4690 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4691 | // Verify parent transforms |
| 4692 | gfx::Transform expected_parent_transform; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4693 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4694 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4695 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4696 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4697 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4698 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4699 | // Verify results of transformed parent rects |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4700 | gfx::RectF parent_bounds(gfx::SizeF(parent->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4701 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4702 | gfx::RectF parent_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4703 | MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4704 | gfx::RectF parent_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4705 | MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4706 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4707 | gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4708 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4709 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4710 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4711 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4712 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4713 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4714 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4715 | expected_child_transform.Translate(child->position().x(), |
| 4716 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4717 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4718 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4719 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4720 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4721 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4722 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4723 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4724 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4725 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4726 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4727 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4728 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4729 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4730 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4731 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4732 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4733 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4734 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4735 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4736 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4737 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4738 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4739 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4740 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4741 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4742 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4743 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4744 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4745 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4746 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4747 | } |
| 4748 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4749 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4750 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4751 | gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | gfx::Transform perspective_matrix; |
| 4753 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4755 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4756 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4757 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4758 | LayerImpl* root = root_layer(); |
| 4759 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4760 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4761 | false); |
| 4762 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4763 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4764 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4765 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4766 | false); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4767 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4768 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
| 4769 | SetLayerPropertiesForTesting(perspective_surface, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4770 | perspective_matrix * scale_small_matrix, |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4771 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4772 | gfx::Size(10, 10), false, true, true); |
| 4773 | perspective_surface->SetDrawsContent(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4774 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4775 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
| 4776 | SetLayerPropertiesForTesting(scale_surface, scale_small_matrix, |
| 4777 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4778 | gfx::Size(10, 10), false, true, true); |
| 4779 | scale_surface->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4780 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4781 | float device_scale_factor = 2.5f; |
| 4782 | float page_scale_factor = 3.f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4783 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4784 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4785 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4786 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4787 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4788 | perspective_surface); |
| 4789 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4790 | // the nearest render target. Here this includes the layer transform as well |
| 4791 | // as the device and page scale factors. |
| 4792 | gfx::Transform transform = scale_small_matrix; |
| 4793 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4794 | device_scale_factor * page_scale_factor); |
| 4795 | gfx::Vector2dF scales = |
| 4796 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4797 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4798 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4799 | |
| 4800 | // The ideal scale will draw 1:1 with its render target space along |
| 4801 | // the larger-scale axis. |
| 4802 | gfx::Vector2dF target_space_transform_scales = |
| 4803 | MathUtil::ComputeTransform2dScaleComponents( |
| 4804 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4805 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4806 | std::max(target_space_transform_scales.x(), |
| 4807 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4808 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4809 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4810 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4811 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4812 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4813 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4814 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4815 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4816 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4817 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4818 | // with the screen, and then scaled during drawing. |
| 4819 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4820 | expected_perspective_surface_draw_transform.Translate( |
| 4821 | device_scale_factor * page_scale_factor * |
| 4822 | perspective_surface->position().x(), |
| 4823 | device_scale_factor * page_scale_factor * |
| 4824 | perspective_surface->position().y()); |
| 4825 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4826 | perspective_matrix); |
| 4827 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4828 | scale_small_matrix); |
| 4829 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4830 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4831 | device_scale_factor * page_scale_factor, |
| 4832 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4833 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4834 | expected_perspective_surface_draw_transform, |
| 4835 | perspective_surface->render_surface()->draw_transform()); |
| 4836 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4837 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4838 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4839 | } |
| 4840 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4841 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4842 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4843 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4844 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4845 | |
| 4846 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4847 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4848 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4849 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4850 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4851 | root->SetBounds(gfx::Size(100, 100)); |
| 4852 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4853 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4854 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4855 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4856 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4857 | false); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4858 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4859 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4860 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4861 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4862 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4863 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4864 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4865 | float device_scale_factor = 2.5f; |
| 4866 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4867 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4868 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4869 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4870 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4871 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4872 | // The ideal scale is able to go below 1. |
| 4873 | float expected_ideal_scale = |
| 4874 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4875 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4876 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4877 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4878 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4879 | initial_parent_scale * initial_child_scale; |
| 4880 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4881 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4882 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4883 | } |
| 4884 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4885 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4886 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4887 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4888 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4889 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4890 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4891 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4892 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4893 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4894 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4895 | root->SetBounds(gfx::Size(100, 100)); |
| 4896 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4897 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4898 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4899 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4900 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4901 | false); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4902 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4903 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4904 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4905 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4906 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4907 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4908 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4909 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4910 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4911 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4912 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 4913 | // Animating layers compute ideal scale in the same way as when |
| 4914 | // they are static. |
| 4915 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 4916 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4917 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4918 | } |
| 4919 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4920 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4921 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4922 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4923 | LayerImpl* parent = root_layer(); |
| 4924 | parent->SetDrawsContent(true); |
| 4925 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4926 | gfx::PointF(), gfx::Size(30, 30), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4927 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4928 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4929 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4930 | child->SetDrawsContent(true); |
| 4931 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4932 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4933 | true, true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4934 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4935 | gfx::Transform replica_transform; |
| 4936 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4937 | |
| 4938 | scoped_ptr<LayerImpl> replica = |
| 4939 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 4940 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 4941 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4942 | true, false); |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 4943 | // We need to set parent on replica layer for property tree building. |
| 4944 | replica->SetParent(child); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 4945 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4946 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4947 | // This layer should end up in the same surface as child, with the same draw |
| 4948 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4949 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
| 4950 | duplicate_child_non_owner->SetDrawsContent(true); |
| 4951 | SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix, |
| 4952 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 4953 | false, true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4954 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4955 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4956 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4958 | // We should have two render surfaces. The root's render surface and child's |
| 4959 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4960 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4961 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4962 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4963 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4965 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4967 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4968 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4969 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4970 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4971 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4972 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4973 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4975 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4976 | device_scale_factor); |
| 4977 | expected_screen_space_transform.Translate(child->position().x(), |
| 4978 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4979 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4980 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4981 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4983 | child->DrawTransform(); |
| 4984 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(), |
| 4985 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4986 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4987 | child->ScreenSpaceTransform(), |
| 4988 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4989 | EXPECT_EQ(child->drawable_content_rect(), |
| 4990 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4991 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4992 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4993 | gfx::Transform expected_render_surface_draw_transform; |
| 4994 | expected_render_surface_draw_transform.Translate( |
| 4995 | device_scale_factor * child->position().x(), |
| 4996 | device_scale_factor * child->position().y()); |
| 4997 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4998 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4999 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5000 | gfx::Transform expected_surface_draw_transform; |
| 5001 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5002 | device_scale_factor * 2.f); |
| 5003 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5004 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5005 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5006 | gfx::Transform expected_surface_screen_space_transform; |
| 5007 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5008 | device_scale_factor * 2.f); |
| 5009 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5010 | expected_surface_screen_space_transform, |
| 5011 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5012 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5013 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5014 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5015 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5016 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5017 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5018 | expected_replica_draw_transform, |
| 5019 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5020 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5021 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5022 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5023 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5024 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5025 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5026 | expected_replica_screen_space_transform, |
| 5027 | child->render_surface()->replica_screen_space_transform()); |
| 5028 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5029 | expected_replica_screen_space_transform, |
| 5030 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5031 | } |
| 5032 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5033 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5034 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5035 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5036 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5037 | LayerImpl* parent = root_layer(); |
| 5038 | parent->SetDrawsContent(true); |
| 5039 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 5040 | gfx::PointF(), gfx::Size(33, 31), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5041 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5042 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5043 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 5044 | child->SetDrawsContent(true); |
| 5045 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 5046 | gfx::PointF(), gfx::Size(13, 11), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5047 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5048 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5049 | gfx::Transform replica_transform; |
| 5050 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5051 | scoped_ptr<LayerImpl> replica = |
| 5052 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 5053 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 5054 | gfx::PointF(), gfx::Size(13, 11), false, true, |
| 5055 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5056 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5057 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5058 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5059 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5060 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5061 | // We should have two render surfaces. The root's render surface and child's |
| 5062 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5063 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5064 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5065 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5066 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5067 | child->render_surface()->draw_transform()); |
| 5068 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5069 | child->render_surface()->draw_transform()); |
| 5070 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5071 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5072 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5073 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5074 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5075 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5076 | expected_replica_draw_transform, |
| 5077 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5078 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5079 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5080 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5081 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5082 | expected_replica_screen_space_transform, |
| 5083 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5084 | } |
| 5085 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 5086 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5087 | scoped_refptr<Layer> root = Layer::Create(); |
| 5088 | scoped_refptr<Layer> child = Layer::Create(); |
| 5089 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5090 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5091 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5092 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5093 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5094 | child->AddChild(grand_child.get()); |
| 5095 | child->SetMaskLayer(mask_layer.get()); |
| 5096 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5097 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5098 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5099 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5100 | int nonexistent_id = -1; |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 5101 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 5102 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 5103 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 5104 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 5105 | EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id())); |
| 5106 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5107 | } |
| 5108 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5109 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5110 | scoped_refptr<Layer> root = Layer::Create(); |
| 5111 | scoped_refptr<Layer> child = Layer::Create(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5112 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5113 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5114 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5115 | const gfx::Transform identity_matrix; |
| 5116 | SetLayerPropertiesForTesting(root.get(), |
| 5117 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5118 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5119 | gfx::PointF(), |
| 5120 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5121 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5122 | false); |
| 5123 | SetLayerPropertiesForTesting(child.get(), |
| 5124 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5125 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5126 | gfx::PointF(), |
| 5127 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5128 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5129 | false); |
| 5130 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5131 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5132 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5133 | gfx::PointF(), |
| 5134 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5135 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5136 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5137 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5138 | root->AddChild(child); |
| 5139 | child->AddChild(grand_child); |
| 5140 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5141 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5142 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5143 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5144 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5145 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 5146 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5147 | } |
| 5148 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5149 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5150 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5151 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5152 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5153 | FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, |
| 5154 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5155 | host_impl.CreatePendingTree(); |
| 5156 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5157 | |
| 5158 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5159 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5160 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5161 | false); |
| 5162 | root->SetDrawsContent(true); |
| 5163 | |
| 5164 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5165 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5166 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5167 | false); |
| 5168 | child->SetDrawsContent(true); |
| 5169 | child->SetOpacity(0.0f); |
| 5170 | |
| 5171 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5172 | scoped_refptr<AnimationTimeline> timeline = |
| 5173 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5174 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5175 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5176 | AddOpacityTransitionToLayerWithPlayer(child->id(), timeline, 10.0, 0.0f, 1.0f, |
| 5177 | false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5178 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5179 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5180 | root->SetHasRenderSurface(true); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5181 | LayerImpl* root_layer = root.get(); |
| 5182 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5183 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5184 | LayerImplList render_surface_layer_list; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5185 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5186 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5187 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 5188 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5189 | inputs.can_adjust_raster_scales = true; |
| 5190 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5191 | |
| 5192 | // We should have one render surface and two layers. The child |
| 5193 | // layer should be included even though it is transparent. |
| 5194 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5195 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5196 | |
| 5197 | // If the root itself is hidden, the child should not be drawn even if it has |
| 5198 | // an animating opacity. |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5199 | root_layer->SetOpacity(0.0f); |
| 5200 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5201 | LayerImplList render_surface_layer_list2; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5202 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5203 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5204 | root_layer, root_layer->bounds(), &render_surface_layer_list2, |
| 5205 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5206 | inputs2.can_adjust_raster_scales = true; |
| 5207 | LayerTreeHostCommon::CalculateDrawProperties(&inputs2); |
| 5208 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5209 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 5210 | EffectTree tree = |
| 5211 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5212 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
| 5213 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5214 | |
| 5215 | // A layer should be drawn and it should contribute to drawn surface when |
| 5216 | // it has animating opacity even if it has opacity 0. |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5217 | root_layer->SetOpacity(1.0f); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5218 | child_ptr->SetOpacity(0.0f); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5219 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5220 | LayerImplList render_surface_layer_list3; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5221 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5222 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5223 | root_layer, root_layer->bounds(), &render_surface_layer_list3, |
| 5224 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5225 | inputs3.can_adjust_raster_scales = true; |
| 5226 | LayerTreeHostCommon::CalculateDrawProperties(&inputs3); |
| 5227 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5228 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 5229 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5230 | node = tree.Node(child_ptr->effect_tree_index()); |
| 5231 | EXPECT_TRUE(node->data.is_drawn); |
| 5232 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5233 | } |
| 5234 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5235 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 5236 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 5237 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5238 | public: |
| 5239 | LCDTextTest() |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5240 | : LayerTreeHostCommonTestBase(LayerTreeSettings()), |
| 5241 | host_impl_(&task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5242 | &shared_bitmap_manager_, |
| 5243 | &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5244 | root_(nullptr), |
| 5245 | child_(nullptr), |
| 5246 | grand_child_(nullptr) {} |
| 5247 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5248 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5250 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5251 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5252 | timeline_ = |
| 5253 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5254 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5255 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5256 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5257 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5258 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5259 | scoped_ptr<LayerImpl> root_ptr = |
| 5260 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5261 | scoped_ptr<LayerImpl> child_ptr = |
| 5262 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5263 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5264 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5265 | |
| 5266 | // Stash raw pointers to look at later. |
| 5267 | root_ = root_ptr.get(); |
| 5268 | child_ = child_ptr.get(); |
| 5269 | grand_child_ = grand_child_ptr.get(); |
| 5270 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5271 | child_->AddChild(std::move(grand_child_ptr)); |
| 5272 | root_->AddChild(std::move(child_ptr)); |
| 5273 | host_impl_.active_tree()->SetRootLayer(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5274 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5275 | root_->SetContentsOpaque(true); |
| 5276 | child_->SetContentsOpaque(true); |
| 5277 | grand_child_->SetContentsOpaque(true); |
| 5278 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5279 | root_->SetDrawsContent(true); |
| 5280 | child_->SetDrawsContent(true); |
| 5281 | grand_child_->SetDrawsContent(true); |
| 5282 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5283 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5284 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5285 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5286 | true); |
| 5287 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5288 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5289 | std::tr1::get<2>(GetParam())); |
| 5290 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5291 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5292 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5293 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5294 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5295 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5296 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5297 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5298 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5299 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5300 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5301 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5302 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5303 | |
| 5304 | LayerImpl* root_; |
| 5305 | LayerImpl* child_; |
| 5306 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5307 | }; |
| 5308 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5309 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5310 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5311 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5312 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5313 | // Case 1: Identity transform. |
| 5314 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5315 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5316 | layers_always_allowed_lcd_text_); |
| 5317 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5318 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5319 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5321 | // Case 2: Integral translation. |
| 5322 | gfx::Transform integral_translation; |
| 5323 | integral_translation.Translate(1.0, 2.0); |
| 5324 | child_->SetTransform(integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5325 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5326 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5327 | layers_always_allowed_lcd_text_); |
| 5328 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5329 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5330 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5331 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5332 | // Case 3: Non-integral translation. |
| 5333 | gfx::Transform non_integral_translation; |
| 5334 | non_integral_translation.Translate(1.5, 2.5); |
| 5335 | child_->SetTransform(non_integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5336 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5337 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5338 | layers_always_allowed_lcd_text_); |
| 5339 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5340 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5341 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5342 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5343 | // Case 4: Rotation. |
| 5344 | gfx::Transform rotation; |
| 5345 | rotation.Rotate(10.0); |
| 5346 | child_->SetTransform(rotation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5347 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5348 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5349 | layers_always_allowed_lcd_text_); |
| 5350 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5351 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5352 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5353 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5354 | // Case 5: Scale. |
| 5355 | gfx::Transform scale; |
| 5356 | scale.Scale(2.0, 2.0); |
| 5357 | child_->SetTransform(scale); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5358 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5359 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5360 | layers_always_allowed_lcd_text_); |
| 5361 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5362 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5363 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5364 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5365 | // Case 6: Skew. |
| 5366 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5367 | skew.Skew(10.0, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5368 | child_->SetTransform(skew); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5369 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5370 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5371 | layers_always_allowed_lcd_text_); |
| 5372 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5373 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5374 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5375 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5376 | // Case 7: Translucent. |
| 5377 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5378 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5379 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5380 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5381 | layers_always_allowed_lcd_text_); |
| 5382 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5383 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5384 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5385 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5386 | // Case 8: Sanity check: restore transform and opacity. |
| 5387 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5388 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5389 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5390 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5391 | layers_always_allowed_lcd_text_); |
| 5392 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5393 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5394 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5395 | |
| 5396 | // Case 9: Non-opaque content. |
| 5397 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5398 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5399 | layers_always_allowed_lcd_text_); |
| 5400 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5401 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5402 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5403 | |
| 5404 | // Case 10: Sanity check: restore content opaqueness. |
| 5405 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5406 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5407 | layers_always_allowed_lcd_text_); |
| 5408 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5409 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5410 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5411 | } |
| 5412 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5413 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5414 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5415 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5416 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5417 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5418 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5419 | layers_always_allowed_lcd_text_); |
| 5420 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5421 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5422 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5424 | // Add opacity animation. |
| 5425 | child_->SetOpacity(0.9f); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5426 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5427 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5428 | 0.1f, false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5429 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5430 | layers_always_allowed_lcd_text_); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5431 | // Text LCD should be adjusted while animation is active. |
| 5432 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5433 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5434 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
| 5435 | } |
| 5436 | |
| 5437 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5438 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5439 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5440 | |
| 5441 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5442 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5443 | layers_always_allowed_lcd_text_); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5444 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5445 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5446 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5447 | |
| 5448 | // Mark contents non-opaque within the first animation frame. |
| 5449 | child_->SetContentsOpaque(false); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5450 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5451 | 0.1f, false); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5452 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5453 | layers_always_allowed_lcd_text_); |
| 5454 | // LCD text should be disabled for non-opaque layers even during animations. |
| 5455 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5456 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5457 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5461 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5462 | testing::Combine(testing::Bool(), |
| 5463 | testing::Bool(), |
| 5464 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5465 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5466 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5467 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5468 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5469 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5470 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5471 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5472 | host_impl.CreatePendingTree(); |
| 5473 | const gfx::Transform identity_matrix; |
| 5474 | |
| 5475 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5476 | LayerImpl* root_layer = root.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5477 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5478 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5479 | false); |
| 5480 | root->SetDrawsContent(true); |
| 5481 | |
| 5482 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5483 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5484 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5485 | false); |
| 5486 | child->SetDrawsContent(true); |
| 5487 | |
| 5488 | scoped_ptr<LayerImpl> grand_child = |
| 5489 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5490 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5491 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5492 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5493 | grand_child->SetDrawsContent(true); |
| 5494 | grand_child->SetHideLayerAndSubtree(true); |
| 5495 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5496 | child->AddChild(std::move(grand_child)); |
| 5497 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5498 | root->SetHasRenderSurface(true); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5499 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5500 | |
| 5501 | LayerImplList render_surface_layer_list; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5502 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5503 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5504 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 5505 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5506 | inputs.can_adjust_raster_scales = true; |
| 5507 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5508 | |
| 5509 | // We should have one render surface and two layers. The grand child has |
| 5510 | // hidden itself. |
| 5511 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5512 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5513 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5514 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5515 | } |
| 5516 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5517 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5518 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5519 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5520 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5521 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5522 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5523 | host_impl.CreatePendingTree(); |
| 5524 | const gfx::Transform identity_matrix; |
| 5525 | |
| 5526 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5527 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5528 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5529 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5530 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5531 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5532 | |
| 5533 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5534 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5535 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5536 | false); |
| 5537 | child->SetDrawsContent(true); |
| 5538 | child->SetHideLayerAndSubtree(true); |
| 5539 | |
| 5540 | scoped_ptr<LayerImpl> grand_child = |
| 5541 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5542 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5543 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5544 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5545 | grand_child->SetDrawsContent(true); |
| 5546 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5547 | child->AddChild(std::move(grand_child)); |
| 5548 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5549 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5550 | |
| 5551 | LayerImplList render_surface_layer_list; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5552 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5553 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5554 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 5555 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5556 | inputs.can_adjust_raster_scales = true; |
| 5557 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5558 | |
| 5559 | // We should have one render surface and one layers. The child has |
| 5560 | // hidden itself and the grand child. |
| 5561 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5562 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5563 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5564 | } |
| 5565 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5566 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 5567 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5568 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5569 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5570 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5571 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5572 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5573 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5574 | host_impl.CreatePendingTree(); |
| 5575 | const gfx::Transform identity_matrix; |
| 5576 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5577 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5578 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5579 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5580 | true); |
| 5581 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5582 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5583 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5584 | scoped_ptr<LayerImpl> copy_grand_parent = |
| 5585 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5586 | SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix, |
| 5587 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 5588 | true, false, false); |
| 5589 | copy_grand_parent->SetDrawsContent(true); |
| 5590 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5591 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5592 | scoped_ptr<LayerImpl> copy_parent = |
| 5593 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5594 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5595 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5596 | true, false, true); |
| 5597 | copy_parent->SetDrawsContent(true); |
| 5598 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5599 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5600 | scoped_ptr<LayerImpl> copy_request = |
| 5601 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5602 | SetLayerPropertiesForTesting(copy_request.get(), identity_matrix, |
| 5603 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5604 | true, false, true); |
| 5605 | copy_request->SetDrawsContent(true); |
| 5606 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5607 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5608 | scoped_ptr<LayerImpl> copy_child = |
| 5609 | LayerImpl::Create(host_impl.pending_tree(), 5); |
| 5610 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5611 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5612 | true, false, false); |
| 5613 | copy_child->SetDrawsContent(true); |
| 5614 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5615 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5616 | scoped_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5617 | LayerImpl::Create(host_impl.pending_tree(), 6); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5618 | SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix, |
| 5619 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5620 | true, false, false); |
| 5621 | copy_child->SetDrawsContent(true); |
| 5622 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5623 | |
| 5624 | scoped_ptr<LayerImpl> copy_grand_parent_sibling_before = |
| 5625 | LayerImpl::Create(host_impl.pending_tree(), 7); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5626 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5627 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5628 | gfx::Size(40, 40), true, false, false); |
| 5629 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5630 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5631 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5632 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5633 | scoped_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5634 | LayerImpl::Create(host_impl.pending_tree(), 8); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5635 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5636 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5637 | gfx::Size(40, 40), true, false, false); |
| 5638 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5639 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5640 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5641 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5642 | copy_child->AddChild(std::move(copy_grand_child)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5643 | copy_request->AddChild(std::move(copy_child)); |
| 5644 | copy_parent->AddChild(std::move(copy_request)); |
| 5645 | copy_grand_parent->AddChild(std::move(copy_parent)); |
| 5646 | root->AddChild(std::move(copy_grand_parent_sibling_before)); |
| 5647 | root->AddChild(std::move(copy_grand_parent)); |
| 5648 | root->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5649 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5650 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5651 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5652 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5653 | // subtree. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5654 | copy_grand_parent_layer->SetHideLayerAndSubtree(true); |
| 5655 | copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true); |
| 5656 | copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5657 | copy_grand_child_layer->SetHideLayerAndSubtree(true); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5658 | |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 5659 | std::vector<scoped_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5660 | copy_requests.push_back( |
| 5661 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5662 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5663 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5664 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5665 | LayerImplList render_surface_layer_list; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5666 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5667 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5668 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 5669 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5670 | inputs.can_adjust_raster_scales = true; |
| 5671 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5672 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5673 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5674 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5675 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5676 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5677 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5678 | // We should have four render surfaces, one for the root, one for the grand |
| 5679 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5680 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5681 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5682 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5683 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5684 | render_surface_layer_list.at(1)->id()); |
| 5685 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5686 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5687 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5688 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5689 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5690 | EXPECT_EQ(root_layer->id(), |
| 5691 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5692 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5693 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5694 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5695 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5696 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5697 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5698 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5699 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5700 | |
| 5701 | // The copy_layer's render surface should have two contributing layers. |
| 5702 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5703 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5704 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5705 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5706 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5707 | |
| 5708 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5709 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5710 | // copy grand child should not be drawn as its hidden even in the copy |
| 5711 | // request. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5712 | EffectTree tree = |
| 5713 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5714 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
| 5715 | EXPECT_FALSE(node->data.is_drawn); |
| 5716 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
| 5717 | EXPECT_FALSE(node->data.is_drawn); |
| 5718 | node = tree.Node(copy_layer->effect_tree_index()); |
| 5719 | EXPECT_TRUE(node->data.is_drawn); |
| 5720 | node = tree.Node(copy_child_layer->effect_tree_index()); |
| 5721 | EXPECT_TRUE(node->data.is_drawn); |
| 5722 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
| 5723 | EXPECT_FALSE(node->data.is_drawn); |
| 5724 | |
| 5725 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5726 | // actually hidden. |
| 5727 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5728 | } |
| 5729 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5730 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5731 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5732 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5733 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5734 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5735 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5736 | host_impl.CreatePendingTree(); |
| 5737 | const gfx::Transform identity_matrix; |
| 5738 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5739 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5740 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5741 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5742 | true); |
| 5743 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5744 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5745 | scoped_ptr<LayerImpl> copy_parent = |
| 5746 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5747 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5748 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 5749 | false, false); |
| 5750 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5751 | copy_parent->SetMasksToBounds(true); |
| 5752 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5753 | scoped_ptr<LayerImpl> copy_layer = |
| 5754 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5755 | SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix, |
| 5756 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5757 | true, false, true); |
| 5758 | copy_layer->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5759 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5760 | scoped_ptr<LayerImpl> copy_child = |
| 5761 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5762 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5763 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5764 | true, false, false); |
| 5765 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5766 | |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 5767 | std::vector<scoped_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5768 | copy_requests.push_back( |
| 5769 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5770 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5771 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5772 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5773 | copy_layer->AddChild(std::move(copy_child)); |
| 5774 | copy_parent->AddChild(std::move(copy_layer)); |
| 5775 | root->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5776 | |
| 5777 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5778 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 5779 | LayerImpl* root_layer = root.get(); |
| 5780 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5781 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5782 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 5783 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5784 | inputs.can_adjust_raster_scales = true; |
| 5785 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5786 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5787 | // We should have two render surface, as the others are clipped out. |
| 5788 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5789 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5790 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5791 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5792 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5793 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5794 | EXPECT_EQ(root_layer->id(), |
| 5795 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5796 | } |
| 5797 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5798 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5799 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5800 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5801 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5802 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5803 | &task_graph_runner); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5804 | host_impl.CreatePendingTree(); |
| 5805 | const gfx::Transform identity_matrix; |
| 5806 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5807 | scoped_refptr<Layer> root = Layer::Create(); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5808 | SetLayerPropertiesForTesting(root.get(), |
| 5809 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5810 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5811 | gfx::PointF(), |
| 5812 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5813 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5814 | false); |
| 5815 | root->SetIsDrawable(true); |
| 5816 | |
| 5817 | // The surface is moved slightly outside of the viewport. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5818 | scoped_refptr<Layer> surface = Layer::Create(); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5819 | SetLayerPropertiesForTesting(surface.get(), |
| 5820 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5821 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5822 | gfx::PointF(-10, -20), |
| 5823 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5824 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5825 | false); |
| 5826 | surface->SetForceRenderSurface(true); |
| 5827 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5828 | scoped_refptr<Layer> surface_child = Layer::Create(); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5829 | SetLayerPropertiesForTesting(surface_child.get(), |
| 5830 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5831 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5832 | gfx::PointF(), |
| 5833 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5834 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5835 | false); |
| 5836 | surface_child->SetIsDrawable(true); |
| 5837 | |
| 5838 | surface->AddChild(surface_child); |
| 5839 | root->AddChild(surface); |
| 5840 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5841 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5842 | |
jaydasika | 6b7c69d | 2016-04-01 00:54:43 | [diff] [blame] | 5843 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(root.get(), |
| 5844 | root->bounds()); |
| 5845 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5846 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 5847 | // The visible_layer_rect for the |surface_child| should not be clipped by |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5848 | // the viewport. |
| 5849 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 5850 | surface_child->visible_layer_rect_for_testing().ToString()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5851 | } |
| 5852 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5853 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5854 | // Ensure that a transform between the layer and its render surface is not a |
| 5855 | // problem. Constructs the following layer tree. |
| 5856 | // |
| 5857 | // root (a render surface) |
| 5858 | // + render_surface |
| 5859 | // + clip_parent (scaled) |
| 5860 | // + intervening_clipping_layer |
| 5861 | // + clip_child |
| 5862 | // |
| 5863 | // The render surface should be resized correctly and the clip child should |
| 5864 | // inherit the right clip rect. |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5865 | LayerImpl* root = root_layer(); |
| 5866 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5867 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5868 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5869 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5870 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5871 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5872 | clip_child->SetDrawsContent(true); |
| 5873 | clip_child->SetClipParent(clip_parent); |
| 5874 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 5875 | clip_children->insert(clip_child); |
| 5876 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5877 | |
| 5878 | intervening->SetMasksToBounds(true); |
| 5879 | clip_parent->SetMasksToBounds(true); |
| 5880 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5881 | gfx::Transform scale_transform; |
| 5882 | scale_transform.Scale(2, 2); |
| 5883 | |
| 5884 | gfx::Transform identity_transform; |
| 5885 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5886 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5887 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5888 | true); |
| 5889 | SetLayerPropertiesForTesting(render_surface, identity_transform, |
| 5890 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5891 | true, false, true); |
| 5892 | SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(), |
| 5893 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5894 | false, false); |
| 5895 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5896 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5897 | false, false); |
| 5898 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5899 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5900 | false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5901 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5902 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5903 | |
| 5904 | ASSERT_TRUE(root->render_surface()); |
| 5905 | ASSERT_TRUE(render_surface->render_surface()); |
| 5906 | |
| 5907 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5908 | // by the intervening clip layer. |
| 5909 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 5910 | clip_parent->clip_rect().ToString()); |
| 5911 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 5912 | clip_child->clip_rect().ToString()); |
| 5913 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 5914 | intervening->clip_rect().ToString()); |
| 5915 | |
| 5916 | // Ensure that the render surface reports a content rect that has been grown |
| 5917 | // to accomodate for the clip child. |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5918 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5919 | render_surface->render_surface()->content_rect().ToString()); |
| 5920 | |
| 5921 | // The above check implies the two below, but they nicely demonstrate that |
| 5922 | // we've grown, despite the intervening layer's clip. |
| 5923 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5924 | render_surface->render_surface()->content_rect())); |
| 5925 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5926 | render_surface->render_surface()->content_rect())); |
| 5927 | } |
| 5928 | |
| 5929 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5930 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5931 | // case. In the following tree, both render surfaces should be resized to |
| 5932 | // accomodate for the clip child, despite an intervening clip. |
| 5933 | // |
| 5934 | // root (a render surface) |
| 5935 | // + clip_parent (masks to bounds) |
| 5936 | // + render_surface1 (sets opacity) |
| 5937 | // + intervening (masks to bounds) |
| 5938 | // + render_surface2 (also sets opacity) |
| 5939 | // + clip_child |
| 5940 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5941 | LayerImpl* root = root_layer(); |
| 5942 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5943 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5944 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5945 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5946 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5947 | render_surface1->SetDrawsContent(true); |
| 5948 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5949 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5950 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5951 | clip_child->SetClipParent(clip_parent); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5952 | |
| 5953 | intervening->SetMasksToBounds(true); |
| 5954 | clip_parent->SetMasksToBounds(true); |
| 5955 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5956 | gfx::Transform translation_transform; |
| 5957 | translation_transform.Translate(2, 2); |
| 5958 | |
| 5959 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5960 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5961 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5962 | true); |
| 5963 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5964 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5965 | gfx::Size(40, 40), true, false, false); |
| 5966 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5967 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5968 | true, false, true); |
| 5969 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5970 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5971 | false, false); |
| 5972 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5973 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5974 | true, false, true); |
| 5975 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5976 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 5977 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5978 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5979 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5980 | |
| 5981 | EXPECT_TRUE(root->render_surface()); |
| 5982 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5983 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5984 | |
| 5985 | // Since the render surfaces could have expanded, they should not clip (their |
| 5986 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5987 | // in this case. |
| 5988 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 5989 | render_surface1->render_surface()->clip_rect().ToString()); |
| 5990 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5991 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 5992 | render_surface2->render_surface()->clip_rect().ToString()); |
| 5993 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5994 | |
| 5995 | // NB: clip rects are in target space. |
| 5996 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 5997 | render_surface1->clip_rect().ToString()); |
| 5998 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5999 | |
| 6000 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6001 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6002 | render_surface2->clip_rect().ToString()); |
| 6003 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6004 | |
| 6005 | // The content rects of both render surfaces should both have expanded to |
| 6006 | // contain the clip child. |
| 6007 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6008 | render_surface1->render_surface()->content_rect().ToString()); |
| 6009 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6010 | render_surface2->render_surface()->content_rect().ToString()); |
| 6011 | |
| 6012 | // The clip child should have inherited the clip parent's clip (projected to |
| 6013 | // the right space, of course), and should have the correctly sized visible |
| 6014 | // content rect. |
| 6015 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6016 | clip_child->clip_rect().ToString()); |
| 6017 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6018 | clip_child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6019 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6020 | } |
| 6021 | |
| 6022 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6023 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6024 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6025 | // of transform. |
| 6026 | // |
| 6027 | // root (a render surface) |
| 6028 | // + clip_parent (masks to bounds) |
| 6029 | // + render_surface1 (sets opacity) |
| 6030 | // + intervening (masks to bounds AND scrolls) |
| 6031 | // + render_surface2 (also sets opacity) |
| 6032 | // + clip_child |
| 6033 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6034 | LayerImpl* root = root_layer(); |
| 6035 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6036 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 6037 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 6038 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 6039 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 6040 | render_surface1->SetDrawsContent(true); |
| 6041 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6042 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6043 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6044 | clip_child->SetClipParent(clip_parent); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6045 | |
| 6046 | intervening->SetMasksToBounds(true); |
| 6047 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6048 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 6049 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6050 | |
| 6051 | gfx::Transform translation_transform; |
| 6052 | translation_transform.Translate(2, 2); |
| 6053 | |
| 6054 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6055 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6056 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6057 | true); |
| 6058 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 6059 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 6060 | gfx::Size(40, 40), true, false, false); |
| 6061 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6062 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 6063 | true, false, true); |
| 6064 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 6065 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 6066 | false, false); |
| 6067 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6068 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 6069 | true, false, true); |
| 6070 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6071 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 6072 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6073 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6074 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6075 | |
| 6076 | EXPECT_TRUE(root->render_surface()); |
| 6077 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6078 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6079 | |
| 6080 | // Since the render surfaces could have expanded, they should not clip (their |
| 6081 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6082 | // in this case. |
| 6083 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6084 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6085 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6086 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6087 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6088 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6089 | |
| 6090 | // NB: clip rects are in target space. |
| 6091 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6092 | render_surface1->clip_rect().ToString()); |
| 6093 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6094 | |
| 6095 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6096 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6097 | render_surface2->clip_rect().ToString()); |
| 6098 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6099 | |
| 6100 | // The content rects of both render surfaces should both have expanded to |
| 6101 | // contain the clip child. |
| 6102 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6103 | render_surface1->render_surface()->content_rect().ToString()); |
| 6104 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6105 | render_surface2->render_surface()->content_rect().ToString()); |
| 6106 | |
| 6107 | // The clip child should have inherited the clip parent's clip (projected to |
| 6108 | // the right space, of course), and should have the correctly sized visible |
| 6109 | // content rect. |
| 6110 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6111 | clip_child->clip_rect().ToString()); |
| 6112 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6113 | clip_child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6114 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6115 | } |
| 6116 | |
| 6117 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6118 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6119 | // |
| 6120 | // root (a render surface) |
| 6121 | // + clip_parent (masks to bounds) |
| 6122 | // + intervening (masks to bounds) |
| 6123 | // + clip_child |
| 6124 | // + child |
| 6125 | // |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6126 | LayerImpl* root = root_layer(); |
| 6127 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 6128 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 6129 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 6130 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 6131 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6132 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6133 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6134 | clip_child->SetClipParent(clip_parent); |
| 6135 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 6136 | clip_children->insert(clip_child); |
| 6137 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6138 | |
| 6139 | intervening->SetMasksToBounds(true); |
| 6140 | clip_parent->SetMasksToBounds(true); |
| 6141 | |
| 6142 | gfx::Transform identity_transform; |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6143 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6144 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6145 | true); |
| 6146 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6147 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6148 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6149 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 6150 | gfx::PointF(), gfx::Size(5, 5), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6151 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6152 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6153 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6154 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6155 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6156 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6157 | false); |
| 6158 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6159 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6160 | |
| 6161 | EXPECT_TRUE(root->render_surface()); |
| 6162 | |
| 6163 | // Neither the clip child nor its descendant should have inherited the clip |
| 6164 | // from |intervening|. |
| 6165 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6166 | clip_child->clip_rect().ToString()); |
| 6167 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6168 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6169 | child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6170 | EXPECT_TRUE(child->is_clipped()); |
| 6171 | } |
| 6172 | |
| 6173 | TEST_F(LayerTreeHostCommonTest, |
| 6174 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6175 | // Ensures that non-descendant clip children in the tree do not affect |
| 6176 | // render surfaces. |
| 6177 | // |
| 6178 | // root (a render surface) |
| 6179 | // + clip_parent (masks to bounds) |
| 6180 | // + render_surface1 |
| 6181 | // + clip_child |
| 6182 | // + render_surface2 |
| 6183 | // + non_clip_child |
| 6184 | // |
| 6185 | // In this example render_surface2 should be unaffected by clip_child. |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6186 | LayerImpl* root = root_layer(); |
| 6187 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6188 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6189 | render_surface1->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6190 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 6191 | clip_child->SetDrawsContent(true); |
| 6192 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6193 | render_surface2->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6194 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
| 6195 | non_clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6196 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6197 | clip_child->SetClipParent(clip_parent); |
| 6198 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 6199 | clip_children->insert(clip_child); |
| 6200 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6201 | |
| 6202 | clip_parent->SetMasksToBounds(true); |
| 6203 | render_surface1->SetMasksToBounds(true); |
| 6204 | |
| 6205 | gfx::Transform identity_transform; |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6206 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6207 | gfx::PointF(), gfx::Size(15, 15), true, false, |
| 6208 | true); |
| 6209 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6210 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6211 | false); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6212 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6213 | gfx::Point3F(), gfx::PointF(5, 5), |
| 6214 | gfx::Size(5, 5), true, false, true); |
| 6215 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6216 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6217 | true, false, true); |
| 6218 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6219 | gfx::PointF(-1, 1), gfx::Size(10, 10), true, |
| 6220 | false, false); |
| 6221 | SetLayerPropertiesForTesting(non_clip_child, identity_transform, |
| 6222 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6223 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6224 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6225 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6226 | |
| 6227 | EXPECT_TRUE(root->render_surface()); |
| 6228 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6229 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6230 | |
| 6231 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6232 | render_surface1->clip_rect().ToString()); |
| 6233 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6234 | |
| 6235 | // The render surface should not clip (it has unclipped descendants), instead |
| 6236 | // it should rely on layer clipping. |
| 6237 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6238 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6239 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6240 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6241 | // That said, it should have grown to accomodate the unclipped descendant and |
| 6242 | // its own size. |
| 6243 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5).ToString(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6244 | render_surface1->render_surface()->content_rect().ToString()); |
| 6245 | |
| 6246 | // This render surface should clip. It has no unclipped descendants. |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 6247 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10).ToString(), |
| 6248 | render_surface2->render_surface()->clip_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6249 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 6250 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6251 | |
| 6252 | // It also shouldn't have grown to accomodate the clip child. |
| 6253 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6254 | render_surface2->render_surface()->content_rect().ToString()); |
| 6255 | |
| 6256 | // Sanity check our num_unclipped_descendants values. |
vmpstr | 762e70d | 2015-06-10 02:12:57 | [diff] [blame] | 6257 | EXPECT_EQ(1u, render_surface1->num_unclipped_descendants()); |
| 6258 | EXPECT_EQ(0u, render_surface2->num_unclipped_descendants()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6259 | } |
| 6260 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6261 | TEST_F(LayerTreeHostCommonTest, |
| 6262 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 6263 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 6264 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6265 | LayerImpl* root = root_layer(); |
| 6266 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 6267 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 6268 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 6269 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6270 | |
| 6271 | const gfx::Transform identity_matrix; |
| 6272 | gfx::Point3F transform_origin; |
| 6273 | gfx::PointF position; |
| 6274 | gfx::Size bounds(100, 100); |
| 6275 | |
| 6276 | SetLayerPropertiesForTesting(root, identity_matrix, transform_origin, |
| 6277 | position, bounds, true, false); |
| 6278 | SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin, |
| 6279 | position, bounds, false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6280 | child1->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6281 | SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin, |
| 6282 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6283 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6284 | SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin, |
| 6285 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6286 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6287 | |
| 6288 | child2->Set3dSortingContextId(1); |
| 6289 | child3->Set3dSortingContextId(1); |
| 6290 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6291 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6292 | |
| 6293 | // Verify which render surfaces were created. |
| 6294 | EXPECT_TRUE(root->has_render_surface()); |
| 6295 | EXPECT_FALSE(child1->has_render_surface()); |
| 6296 | EXPECT_TRUE(child2->has_render_surface()); |
| 6297 | EXPECT_FALSE(child3->has_render_surface()); |
| 6298 | } |
| 6299 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6300 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6301 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6302 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6303 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6304 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6305 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6306 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6307 | scoped_ptr<LayerImpl> root = |
| 6308 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6309 | scoped_ptr<LayerImpl> child1 = |
| 6310 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6311 | scoped_ptr<LayerImpl> child2 = |
| 6312 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6313 | scoped_ptr<LayerImpl> child3 = |
| 6314 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6315 | |
| 6316 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6317 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6318 | gfx::PointF position; |
| 6319 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6320 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6321 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6322 | root->SetDrawsContent(true); |
| 6323 | |
| 6324 | // This layer structure normally forces render surface due to preserves3d |
| 6325 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6326 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6327 | position, bounds, false, true, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6328 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6329 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6330 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6331 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6332 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 6333 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6334 | child3->SetDrawsContent(true); |
| 6335 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6336 | child2->Set3dSortingContextId(1); |
| 6337 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6338 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 6339 | child2->AddChild(std::move(child3)); |
| 6340 | child1->AddChild(std::move(child2)); |
| 6341 | root->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6342 | LayerImpl* root_layer = root.get(); |
| 6343 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6344 | |
| 6345 | { |
| 6346 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6347 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
| 6348 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6349 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6350 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 6351 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6352 | inputs.can_render_to_separate_surface = true; |
| 6353 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6354 | |
| 6355 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6356 | |
| 6357 | int count_represents_target_render_surface = 0; |
| 6358 | int count_represents_contributing_render_surface = 0; |
| 6359 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6360 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6361 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6362 | it != end; ++it) { |
| 6363 | if (it.represents_target_render_surface()) |
| 6364 | count_represents_target_render_surface++; |
| 6365 | if (it.represents_contributing_render_surface()) |
| 6366 | count_represents_contributing_render_surface++; |
| 6367 | if (it.represents_itself()) |
| 6368 | count_represents_itself++; |
| 6369 | } |
| 6370 | |
| 6371 | // Two render surfaces. |
| 6372 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6373 | // Second render surface contributes to root render surface. |
| 6374 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6375 | // All 4 layers represent itself. |
| 6376 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | { |
| 6380 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6381 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6382 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6383 | root_layer, root_layer->bounds(), &render_surface_layer_list, |
| 6384 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6385 | inputs.can_render_to_separate_surface = false; |
| 6386 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6387 | |
| 6388 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6389 | |
| 6390 | int count_represents_target_render_surface = 0; |
| 6391 | int count_represents_contributing_render_surface = 0; |
| 6392 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6393 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6394 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6395 | it != end; ++it) { |
| 6396 | if (it.represents_target_render_surface()) |
| 6397 | count_represents_target_render_surface++; |
| 6398 | if (it.represents_contributing_render_surface()) |
| 6399 | count_represents_contributing_render_surface++; |
| 6400 | if (it.represents_itself()) |
| 6401 | count_represents_itself++; |
| 6402 | } |
| 6403 | |
| 6404 | // Only root layer has a render surface. |
| 6405 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6406 | // No layer contributes a render surface to root render surface. |
| 6407 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6408 | // All 4 layers represent itself. |
| 6409 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6410 | } |
| 6411 | } |
| 6412 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6413 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6414 | LayerImpl* root = root_layer(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6415 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6416 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6417 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6418 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6419 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 6420 | child1->SetDrawsContent(true); |
| 6421 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6422 | |
| 6423 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6424 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6425 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6426 | true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6427 | SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(), |
| 6428 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6429 | false); |
| 6430 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6431 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6432 | false, true, true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6433 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6434 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6435 | false, true, true); |
| 6436 | SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(), |
| 6437 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 6438 | false); |
| 6439 | SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(), |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6440 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6441 | false); |
| 6442 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6443 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6444 | root->Set3dSortingContextId(1); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6445 | back_facing->Set3dSortingContextId(1); |
| 6446 | back_facing->SetShouldFlattenTransform(false); |
| 6447 | render_surface1->SetDoubleSided(false); |
| 6448 | render_surface2->Set3dSortingContextId(2); |
| 6449 | render_surface2->SetDoubleSided(false); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6450 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6451 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6452 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6453 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6454 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6455 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6456 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6457 | ->at(0) |
| 6458 | ->render_surface() |
| 6459 | ->layer_list() |
| 6460 | .size()); |
| 6461 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6462 | ->at(1) |
| 6463 | ->render_surface() |
| 6464 | ->layer_list() |
| 6465 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6466 | |
| 6467 | gfx::Transform rotation_transform = identity_transform; |
| 6468 | rotation_transform.RotateAboutXAxis(180.0); |
| 6469 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6470 | back_facing->SetTransform(rotation_transform); |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6471 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6472 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6473 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6474 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6475 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6476 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6477 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6478 | // context. |
| 6479 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6480 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6481 | ->at(0) |
| 6482 | ->render_surface() |
| 6483 | ->layer_list() |
| 6484 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6485 | } |
| 6486 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6487 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
| 6488 | LayerImpl* root = root_layer(); |
| 6489 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6490 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 6491 | grand_child->SetDrawsContent(true); |
| 6492 | |
| 6493 | child->SetDoubleSided(false); |
| 6494 | grand_child->SetUseParentBackfaceVisibility(true); |
| 6495 | |
| 6496 | gfx::Transform identity_transform; |
| 6497 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6498 | gfx::PointF(), gfx::Size(50, 50), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6499 | true); |
| 6500 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6501 | gfx::PointF(), gfx::Size(30, 30), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6502 | false); |
| 6503 | SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6504 | gfx::PointF(), gfx::Size(20, 20), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6505 | false); |
| 6506 | |
| 6507 | ExecuteCalculateDrawProperties(root); |
| 6508 | |
| 6509 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6510 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6511 | ->at(0) |
| 6512 | ->render_surface() |
| 6513 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6514 | |
| 6515 | // As all layers have identity transform, we shouldn't check for backface |
| 6516 | // visibility. |
| 6517 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6518 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6519 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6520 | // As there are no 3d rendering contexts, all layers should use their local |
| 6521 | // transform for backface visibility. |
| 6522 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6523 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6524 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6525 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6526 | gfx::Transform rotation_transform = identity_transform; |
| 6527 | rotation_transform.RotateAboutXAxis(180.0); |
| 6528 | |
| 6529 | child->SetTransform(rotation_transform); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6530 | child->Set3dSortingContextId(1); |
| 6531 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6532 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6533 | |
| 6534 | ExecuteCalculateDrawProperties(root); |
| 6535 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6536 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6537 | ->at(0) |
| 6538 | ->render_surface() |
| 6539 | ->layer_list() |
| 6540 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6541 | |
| 6542 | // We should check for backface visibilty of child as it has a rotation |
| 6543 | // transform. We should also check for grand_child as it uses the backface |
| 6544 | // visibility of its parent. |
| 6545 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6546 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6547 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6548 | // child uses its local transform for backface visibility as it is the root of |
| 6549 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6550 | // the root, but it derives its backface visibility from its parent which uses |
| 6551 | // its local transform. |
| 6552 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6553 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6554 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6555 | |
| 6556 | grand_child->SetUseParentBackfaceVisibility(false); |
| 6557 | grand_child->SetDoubleSided(false); |
| 6558 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6559 | |
| 6560 | ExecuteCalculateDrawProperties(root); |
| 6561 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6562 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6563 | ->at(0) |
| 6564 | ->render_surface() |
| 6565 | ->layer_list() |
| 6566 | .size()); |
| 6567 | |
| 6568 | // We should check the backface visibility of child as it has a rotation |
| 6569 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6570 | // the root of it. |
| 6571 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6572 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6573 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6574 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6575 | // local transform for backface visibility. |
| 6576 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6577 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6578 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6579 | } |
| 6580 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6581 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6582 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6583 | // have been processed before you anyhow) results in the right clips. |
| 6584 | // |
| 6585 | // + root |
| 6586 | // + scroll_parent_border |
| 6587 | // | + scroll_parent_clip |
| 6588 | // | + scroll_parent |
| 6589 | // + scroll_child |
| 6590 | // |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6591 | LayerImpl* root = root_layer(); |
| 6592 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6593 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6594 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6595 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6596 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6597 | scroll_parent->SetDrawsContent(true); |
| 6598 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6599 | scroll_parent_clip->SetMasksToBounds(true); |
| 6600 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6601 | scroll_child->SetScrollParent(scroll_parent); |
| 6602 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6603 | scroll_children->insert(scroll_child); |
| 6604 | scroll_parent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6605 | |
| 6606 | gfx::Transform identity_transform; |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6607 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6608 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6609 | true); |
| 6610 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6611 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6612 | true, false, false); |
| 6613 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6614 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6615 | true, false, false); |
| 6616 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6617 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6618 | true, false, false); |
| 6619 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6620 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6621 | false); |
| 6622 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6623 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6624 | |
| 6625 | EXPECT_TRUE(root->render_surface()); |
| 6626 | |
| 6627 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 6628 | scroll_child->clip_rect().ToString()); |
| 6629 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6630 | } |
| 6631 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6632 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6633 | // Tests the computation of draw transform for the scroll child when its |
| 6634 | // target is different from its scroll parent's target. |
| 6635 | LayerImpl* root = root_layer(); |
| 6636 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6637 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6638 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6639 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6640 | |
| 6641 | scroll_parent->SetDrawsContent(true); |
| 6642 | scroll_child->SetDrawsContent(true); |
| 6643 | |
| 6644 | scroll_child->SetScrollParent(scroll_parent); |
| 6645 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6646 | scroll_children->insert(scroll_child); |
| 6647 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6648 | |
| 6649 | gfx::Transform identity_transform; |
| 6650 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6651 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6652 | true); |
| 6653 | SetLayerPropertiesForTesting(scroll_child_target, identity_transform, |
| 6654 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6655 | true, false, true); |
| 6656 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6657 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6658 | false); |
| 6659 | SetLayerPropertiesForTesting(scroll_parent_target, identity_transform, |
| 6660 | gfx::Point3F(), gfx::PointF(10, 10), |
| 6661 | gfx::Size(50, 50), true, false, true); |
| 6662 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6663 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6664 | true, false, false); |
| 6665 | scroll_parent_target->SetMasksToBounds(true); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6666 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6667 | float device_scale_factor = 1.5f; |
| 6668 | LayerImplList render_surface_layer_list_impl; |
| 6669 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 6670 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6671 | root, root->bounds(), identity_transform, &render_surface_layer_list_impl, |
| 6672 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 6673 | inputs.device_scale_factor = device_scale_factor; |
| 6674 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6675 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6676 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6677 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6678 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6679 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6680 | gfx::Transform scale; |
| 6681 | scale.Scale(1.5f, 1.5f); |
| 6682 | EXPECT_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6683 | } |
| 6684 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6685 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6686 | LayerImpl* root = root_layer(); |
| 6687 | root->SetDrawsContent(true); |
| 6688 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 6689 | parent->SetDrawsContent(true); |
| 6690 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 6691 | child->SetDrawsContent(true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6692 | |
| 6693 | gfx::Transform identity_transform; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6694 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6695 | gfx::PointF(), gfx::Size(50, 50), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6696 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6697 | SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(), |
| 6698 | gfx::PointF(), gfx::Size(30, 30), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6699 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6700 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6701 | gfx::PointF(), gfx::Size(20, 20), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6702 | true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6703 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6704 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6705 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6706 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6707 | |
| 6708 | gfx::Transform singular_transform; |
| 6709 | singular_transform.Scale3d( |
| 6710 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6711 | |
| 6712 | child->SetTransform(singular_transform); |
| 6713 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6714 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6715 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6716 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6717 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6718 | |
| 6719 | // Ensure that the entire subtree under a layer with singular transform does |
| 6720 | // not get rendered. |
| 6721 | parent->SetTransform(singular_transform); |
| 6722 | child->SetTransform(identity_transform); |
| 6723 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6724 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6725 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6726 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6727 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6728 | } |
| 6729 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6730 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6731 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6732 | // still results in correct clipping. |
| 6733 | // |
| 6734 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6735 | // + scroll_parent_border |
| 6736 | // + scroll_parent_clip |
| 6737 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6738 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6739 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6740 | LayerImpl* root = root_layer(); |
| 6741 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6742 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6743 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6744 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6745 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6746 | scroll_parent->SetDrawsContent(true); |
| 6747 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6748 | |
| 6749 | scroll_parent_clip->SetMasksToBounds(true); |
| 6750 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6751 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6752 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6753 | scroll_children->insert(scroll_child); |
| 6754 | scroll_parent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6755 | |
| 6756 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6757 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6758 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6759 | true); |
| 6760 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6761 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6762 | true, false, false); |
| 6763 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6764 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6765 | true, false, false); |
| 6766 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6767 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6768 | true, false, false); |
| 6769 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6770 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6771 | false); |
| 6772 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6773 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6774 | |
| 6775 | EXPECT_TRUE(root->render_surface()); |
| 6776 | |
| 6777 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 6778 | scroll_child->clip_rect().ToString()); |
| 6779 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6780 | } |
| 6781 | |
| 6782 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6783 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6784 | // you in paint order still results in correct clipping. |
| 6785 | // |
| 6786 | // + root |
| 6787 | // + scroll_child |
| 6788 | // + scroll_parent_border |
| 6789 | // | + scroll_parent_clip |
| 6790 | // | + scroll_parent |
| 6791 | // + scroll_grandparent_border |
| 6792 | // + scroll_grandparent_clip |
| 6793 | // + scroll_grandparent |
| 6794 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6795 | LayerImpl* root = root_layer(); |
| 6796 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6797 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6798 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6799 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6800 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6801 | LayerImpl* scroll_grandparent_clip = |
| 6802 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6803 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6804 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6805 | scroll_parent->SetDrawsContent(true); |
| 6806 | scroll_grandparent->SetDrawsContent(true); |
| 6807 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6808 | |
| 6809 | scroll_parent_clip->SetMasksToBounds(true); |
| 6810 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6811 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6812 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6813 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6814 | scroll_children->insert(scroll_child); |
| 6815 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6816 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6817 | scroll_parent_border->SetScrollParent(scroll_grandparent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6818 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6819 | scroll_children->insert(scroll_parent_border); |
| 6820 | scroll_grandparent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6821 | |
| 6822 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6823 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6824 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6825 | true); |
| 6826 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6827 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6828 | true, false, false); |
| 6829 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6830 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6831 | true, false, false); |
| 6832 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6833 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6834 | true, false, false); |
| 6835 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6836 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6837 | true, false, false); |
| 6838 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6839 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6840 | true, false, false); |
| 6841 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6842 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6843 | true, false, false); |
| 6844 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6845 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6846 | false); |
| 6847 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6848 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6849 | |
| 6850 | EXPECT_TRUE(root->render_surface()); |
| 6851 | |
| 6852 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 6853 | scroll_child->clip_rect().ToString()); |
| 6854 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6855 | |
| 6856 | // Despite the fact that we visited the above layers out of order to get the |
| 6857 | // correct clip, the layer lists should be unaffected. |
| 6858 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6859 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6860 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6861 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6865 | // Ensures that even if we visit layers out of order, we still produce a |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 6866 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6867 | // + root |
| 6868 | // + scroll_child |
| 6869 | // + scroll_parent_border |
| 6870 | // + scroll_parent_clip |
| 6871 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6872 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6873 | // + scroll_grandparent_border |
| 6874 | // + scroll_grandparent_clip |
| 6875 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6876 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6877 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6878 | LayerImpl* root = root_layer(); |
| 6879 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6880 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6881 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6882 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6883 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6884 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6885 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6886 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6887 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6888 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6889 | LayerImpl* scroll_grandparent_clip = |
| 6890 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6891 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6892 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6893 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6894 | scroll_parent->SetDrawsContent(true); |
| 6895 | render_surface1->SetDrawsContent(true); |
| 6896 | scroll_grandparent->SetDrawsContent(true); |
| 6897 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6898 | |
| 6899 | scroll_parent_clip->SetMasksToBounds(true); |
| 6900 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6901 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6902 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6903 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6904 | scroll_children->insert(scroll_child); |
| 6905 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6906 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6907 | scroll_parent_border->SetScrollParent(scroll_grandparent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6908 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6909 | scroll_children->insert(scroll_parent_border); |
| 6910 | scroll_grandparent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6911 | |
| 6912 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6913 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6914 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6915 | true); |
| 6916 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6917 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6918 | true, false, false); |
| 6919 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6920 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6921 | true, false, false); |
| 6922 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6923 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6924 | true, false, false); |
| 6925 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6926 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6927 | true, false, true); |
| 6928 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6929 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6930 | true, false, false); |
| 6931 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6932 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6933 | true, false, false); |
| 6934 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6935 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6936 | true, false, false); |
| 6937 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6938 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6939 | true, false, true); |
| 6940 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6941 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6942 | false); |
| 6943 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6944 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6945 | |
| 6946 | EXPECT_TRUE(root->render_surface()); |
| 6947 | |
| 6948 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 6949 | scroll_child->clip_rect().ToString()); |
| 6950 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6951 | |
| 6952 | // Despite the fact that we had to process the layers out of order to get the |
| 6953 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6954 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6955 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6956 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6957 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6958 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6959 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6960 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6961 | } |
| 6962 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6963 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6964 | // Ensures that when we have a render surface between a fixed position layer |
| 6965 | // and its container, we compute the fixed position layer's draw transform |
| 6966 | // with respect to that intervening render surface, not with respect to its |
| 6967 | // container's render target. |
| 6968 | // |
| 6969 | // + root |
| 6970 | // + render_surface |
| 6971 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6972 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6973 | // |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6974 | LayerImpl* root = root_layer(); |
| 6975 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6976 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6977 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6978 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6979 | render_surface->SetDrawsContent(true); |
| 6980 | fixed->SetDrawsContent(true); |
| 6981 | child->SetDrawsContent(true); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6982 | |
| 6983 | root->SetIsContainerForFixedPositionLayers(true); |
| 6984 | render_surface->SetForceRenderSurface(true); |
| 6985 | |
| 6986 | LayerPositionConstraint constraint; |
| 6987 | constraint.set_is_fixed_position(true); |
| 6988 | fixed->SetPositionConstraint(constraint); |
| 6989 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6990 | SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6991 | gfx::PointF(), gfx::Size(50, 50), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6992 | SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(), |
| 6993 | gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true, |
| 6994 | false); |
| 6995 | SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6996 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 6997 | false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6998 | SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(), |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6999 | gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, |
| 7000 | false); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7001 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7002 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7003 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7004 | TransformTree& tree = |
| 7005 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7006 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7007 | gfx::Transform expected_fixed_draw_transform; |
| 7008 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7009 | EXPECT_EQ(expected_fixed_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7010 | draw_property_utils::DrawTransform(fixed, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7011 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7012 | gfx::Transform expected_fixed_screen_space_transform; |
| 7013 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
| 7014 | EXPECT_EQ(expected_fixed_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7015 | draw_property_utils::ScreenSpaceTransform(fixed, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7016 | |
| 7017 | gfx::Transform expected_child_draw_transform; |
| 7018 | expected_child_draw_transform.Translate(11.f, 17.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7019 | EXPECT_EQ(expected_child_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7020 | draw_property_utils::DrawTransform(child, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7021 | |
| 7022 | gfx::Transform expected_child_screen_space_transform; |
| 7023 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
| 7024 | EXPECT_EQ(expected_child_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7025 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7026 | } |
| 7027 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7028 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7029 | // This test verifies that a scrolling layer that gets snapped to |
| 7030 | // integer coordinates doesn't move a fixed position child. |
| 7031 | // |
| 7032 | // + root |
| 7033 | // + container |
| 7034 | // + scroller |
| 7035 | // + fixed |
| 7036 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7037 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7038 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7039 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7040 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7041 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7042 | host_impl.CreatePendingTree(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7043 | scoped_ptr<LayerImpl> root_ptr = |
| 7044 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7045 | LayerImpl* root = root_ptr.get(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7046 | scoped_ptr<LayerImpl> container = |
| 7047 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7048 | LayerImpl* container_layer = container.get(); |
| 7049 | scoped_ptr<LayerImpl> scroller = |
| 7050 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7051 | LayerImpl* scroll_layer = scroller.get(); |
| 7052 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7053 | LayerImpl* fixed_layer = fixed.get(); |
| 7054 | |
| 7055 | container->SetIsContainerForFixedPositionLayers(true); |
| 7056 | |
| 7057 | LayerPositionConstraint constraint; |
| 7058 | constraint.set_is_fixed_position(true); |
| 7059 | fixed->SetPositionConstraint(constraint); |
| 7060 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7061 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7062 | |
| 7063 | gfx::Transform identity_transform; |
| 7064 | gfx::Transform container_transform; |
| 7065 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7066 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7067 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7068 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7069 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7070 | true); |
| 7071 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7072 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7073 | true, false, false); |
| 7074 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7075 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7076 | true, false, false); |
| 7077 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7078 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7079 | false); |
| 7080 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7081 | root->SetDrawsContent(true); |
| 7082 | container->SetDrawsContent(true); |
| 7083 | scroller->SetDrawsContent(true); |
| 7084 | fixed->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7085 | scroller->AddChild(std::move(fixed)); |
| 7086 | container->AddChild(std::move(scroller)); |
| 7087 | root->AddChild(std::move(container)); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7088 | |
| 7089 | // Rounded to integers already. |
| 7090 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7091 | root->layer_tree_impl()->SetRootLayer(std::move(root_ptr)); |
| 7092 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 7093 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7094 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7095 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7096 | |
| 7097 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7098 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7099 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7100 | root, root->bounds(), &render_surface_layer_list, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7101 | root->layer_tree_impl()->current_render_surface_list_id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7102 | root->layer_tree_impl() |
| 7103 | ->property_trees() |
| 7104 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7105 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7106 | |
| 7107 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7108 | container_layer->draw_properties().screen_space_transform, |
| 7109 | fixed_layer->draw_properties().screen_space_transform); |
| 7110 | EXPECT_VECTOR_EQ( |
| 7111 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7112 | container_offset); |
| 7113 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7114 | .screen_space_transform.To2dTranslation(), |
| 7115 | container_offset - scroll_delta); |
| 7116 | } |
| 7117 | |
| 7118 | // Scroll delta requiring rounding. |
| 7119 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7120 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 7121 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7122 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7123 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7124 | |
| 7125 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7126 | |
| 7127 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7128 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7129 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7130 | root, root->bounds(), &render_surface_layer_list, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7131 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7132 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7133 | |
| 7134 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7135 | container_layer->draw_properties().screen_space_transform, |
| 7136 | fixed_layer->draw_properties().screen_space_transform); |
| 7137 | EXPECT_VECTOR_EQ( |
| 7138 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7139 | container_offset); |
| 7140 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7141 | .screen_space_transform.To2dTranslation(), |
| 7142 | container_offset - rounded_scroll_delta); |
| 7143 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7144 | |
| 7145 | // Scale is applied earlier in the tree. |
| 7146 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7147 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7148 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7149 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7150 | container_layer->SetTransform(scaled_container_transform); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7151 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7152 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7153 | |
| 7154 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7155 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7156 | |
| 7157 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7158 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7159 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7160 | root, root->bounds(), &render_surface_layer_list, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7161 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7162 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7163 | |
| 7164 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7165 | container_layer->draw_properties().screen_space_transform, |
| 7166 | fixed_layer->draw_properties().screen_space_transform); |
| 7167 | EXPECT_VECTOR_EQ( |
| 7168 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7169 | container_offset); |
| 7170 | |
| 7171 | container_layer->SetTransform(container_transform); |
| 7172 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7173 | } |
| 7174 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7175 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7176 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 7177 | // This test verifies that a scrolling layer whose screen space transform is |
| 7178 | // animating doesn't get snapped to integer coordinates. |
| 7179 | // |
| 7180 | // + root |
| 7181 | // + animated layer |
| 7182 | // + surface |
| 7183 | // + container |
| 7184 | // + scroller |
| 7185 | // |
| 7186 | LayerImpl* root = root_layer(); |
| 7187 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 7188 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 7189 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 7190 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
| 7191 | scroller->SetScrollClipLayer(container->id()); |
| 7192 | scroller->SetDrawsContent(true); |
| 7193 | |
| 7194 | gfx::Transform identity_transform; |
| 7195 | gfx::Transform start_scale; |
| 7196 | start_scale.Scale(1.5f, 1.5f); |
| 7197 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 7198 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7199 | true); |
| 7200 | SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(), |
| 7201 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7202 | false); |
| 7203 | SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(), |
| 7204 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7205 | true); |
| 7206 | SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(), |
| 7207 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7208 | false); |
| 7209 | SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(), |
| 7210 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 7211 | false); |
| 7212 | |
| 7213 | gfx::Transform end_scale; |
| 7214 | end_scale.Scale(2.f, 2.f); |
| 7215 | TransformOperations start_operations; |
| 7216 | start_operations.AppendMatrix(start_scale); |
| 7217 | TransformOperations end_operations; |
| 7218 | end_operations.AppendMatrix(end_scale); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7219 | AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(), |
| 7220 | 1.0, start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7221 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7222 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7223 | |
| 7224 | ExecuteCalculateDrawProperties(root); |
| 7225 | |
| 7226 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 7227 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7228 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7229 | } |
| 7230 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7231 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7232 | public: |
| 7233 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7234 | LayerTreeImpl* tree_impl, |
| 7235 | int id) { |
| 7236 | return make_scoped_ptr( |
| 7237 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7238 | } |
| 7239 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7240 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7241 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7242 | private: |
| 7243 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7244 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7245 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7246 | SetDrawsContent(true); |
| 7247 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7248 | }; |
| 7249 | |
| 7250 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7251 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7252 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7253 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7254 | LayerTreeSettings settings = host()->settings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7255 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7256 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7257 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7258 | gfx::Transform identity_matrix; |
| 7259 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7260 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7261 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7262 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7263 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7264 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7265 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7266 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7267 | |
| 7268 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7269 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7270 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7271 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7272 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7273 | child->AddChild(std::move(grand_child)); |
| 7274 | parent->AddChild(std::move(child)); |
| 7275 | grand_parent->AddChild(std::move(parent)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7276 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7277 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7278 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7279 | true, false, true); |
| 7280 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7281 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7282 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7283 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7284 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7285 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7286 | |
| 7287 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7288 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7289 | false); |
| 7290 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7291 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
| 7292 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7293 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7294 | |
| 7295 | // No layers have animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7296 | EXPECT_EQ( |
| 7297 | 0.f, |
| 7298 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7299 | EXPECT_EQ(0.f, |
| 7300 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7301 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7302 | EXPECT_EQ( |
| 7303 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7304 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7305 | EXPECT_EQ( |
| 7306 | 0.f, |
| 7307 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7308 | EXPECT_EQ(0.f, |
| 7309 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7310 | EXPECT_EQ(0.f, |
| 7311 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7312 | EXPECT_EQ( |
| 7313 | 0.f, |
| 7314 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7315 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7316 | TransformOperations translation; |
| 7317 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7318 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7319 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7320 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7321 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7322 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7323 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7324 | TransformOperations(), translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7325 | |
| 7326 | // No layers have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7327 | EXPECT_EQ( |
| 7328 | 0.f, |
| 7329 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7330 | EXPECT_EQ(0.f, |
| 7331 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7332 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7333 | EXPECT_EQ( |
| 7334 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7335 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7336 | EXPECT_EQ( |
| 7337 | 0.f, |
| 7338 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7339 | EXPECT_EQ(0.f, |
| 7340 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7341 | EXPECT_EQ(0.f, |
| 7342 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7343 | EXPECT_EQ( |
| 7344 | 0.f, |
| 7345 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7346 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7347 | TransformOperations scale; |
| 7348 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7349 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7350 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7351 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7352 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7353 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7354 | |
| 7355 | // Only |child| has a scale-affecting animation. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7356 | EXPECT_EQ( |
| 7357 | 0.f, |
| 7358 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7359 | EXPECT_EQ(0.f, |
| 7360 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7361 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7362 | EXPECT_EQ( |
| 7363 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7364 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7365 | EXPECT_EQ( |
| 7366 | 0.f, |
| 7367 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7368 | EXPECT_EQ(0.f, |
| 7369 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7370 | EXPECT_EQ(1.f, |
| 7371 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7372 | EXPECT_EQ( |
| 7373 | 1.f, |
| 7374 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7375 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7376 | AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7377 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7378 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7379 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7380 | |
| 7381 | // |grand_parent| and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7382 | EXPECT_EQ( |
| 7383 | 5.f, |
| 7384 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7385 | EXPECT_EQ(5.f, |
| 7386 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7387 | // We don't support combining animated scales from two nodes; 0.f means |
| 7388 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7389 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7390 | EXPECT_EQ( |
| 7391 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7392 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7393 | EXPECT_EQ( |
| 7394 | 1.f, |
| 7395 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7396 | EXPECT_EQ(1.f, |
| 7397 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7398 | EXPECT_EQ(0.f, |
| 7399 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7400 | EXPECT_EQ( |
| 7401 | 0.f, |
| 7402 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7403 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7404 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7405 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7406 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7407 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7408 | |
| 7409 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7410 | EXPECT_EQ( |
| 7411 | 5.f, |
| 7412 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7413 | EXPECT_EQ(0.f, |
| 7414 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7415 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7416 | EXPECT_EQ( |
| 7417 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7418 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7419 | EXPECT_EQ( |
| 7420 | 1.f, |
| 7421 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7422 | EXPECT_EQ(0.f, |
| 7423 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7424 | EXPECT_EQ(0.f, |
| 7425 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7426 | EXPECT_EQ( |
| 7427 | 0.f, |
| 7428 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7429 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7430 | AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7431 | TargetProperty::TRANSFORM); |
| 7432 | AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline, |
| 7433 | TargetProperty::TRANSFORM); |
| 7434 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7435 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7436 | |
| 7437 | TransformOperations perspective; |
| 7438 | perspective.AppendPerspective(10.f); |
| 7439 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7440 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7441 | TransformOperations(), perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7442 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7443 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7444 | |
| 7445 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7446 | // animation is not supported. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7447 | EXPECT_EQ( |
| 7448 | 0.f, |
| 7449 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7450 | EXPECT_EQ(0.f, |
| 7451 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7452 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7453 | EXPECT_EQ( |
| 7454 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7455 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7456 | EXPECT_EQ( |
| 7457 | 0.f, |
| 7458 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7459 | EXPECT_EQ(0.f, |
| 7460 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7461 | EXPECT_EQ(0.f, |
| 7462 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7463 | EXPECT_EQ( |
| 7464 | 0.f, |
| 7465 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7466 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7467 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7468 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7469 | gfx::Transform scale_matrix; |
| 7470 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7471 | grand_parent_raw->SetTransform(scale_matrix); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7472 | parent_raw->SetTransform(scale_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7473 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7474 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7475 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7476 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7477 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7478 | |
| 7479 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7480 | // animation with maximum scale 5.f. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7481 | EXPECT_EQ( |
| 7482 | 0.f, |
| 7483 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7484 | EXPECT_EQ(10.f, |
| 7485 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7486 | EXPECT_EQ(10.f, |
| 7487 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 7488 | EXPECT_EQ( |
| 7489 | 10.f, |
| 7490 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7491 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7492 | EXPECT_EQ( |
| 7493 | 0.f, |
| 7494 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7495 | EXPECT_EQ(2.f, |
| 7496 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7497 | EXPECT_EQ(2.f, |
| 7498 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7499 | EXPECT_EQ( |
| 7500 | 2.f, |
| 7501 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7502 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7503 | gfx::Transform perspective_matrix; |
| 7504 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 7505 | child_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7506 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7507 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7508 | |
| 7509 | // |child| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7510 | EXPECT_EQ( |
| 7511 | 0.f, |
| 7512 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7513 | EXPECT_EQ(10.f, |
| 7514 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7515 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7516 | EXPECT_EQ( |
| 7517 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7518 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7519 | EXPECT_EQ( |
| 7520 | 0.f, |
| 7521 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7522 | EXPECT_EQ(2.f, |
| 7523 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7524 | EXPECT_EQ(0.f, |
| 7525 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7526 | EXPECT_EQ( |
| 7527 | 0.f, |
| 7528 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7529 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7530 | parent_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7531 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7532 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7533 | |
| 7534 | // |parent| and |child| have transforms that are neither translations nor |
| 7535 | // scales. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7536 | EXPECT_EQ( |
| 7537 | 0.f, |
| 7538 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7539 | EXPECT_EQ(0.f, |
| 7540 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7541 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7542 | EXPECT_EQ( |
| 7543 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7544 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7545 | EXPECT_EQ( |
| 7546 | 0.f, |
| 7547 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7548 | EXPECT_EQ(0.f, |
| 7549 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7550 | EXPECT_EQ(0.f, |
| 7551 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7552 | EXPECT_EQ( |
| 7553 | 0.f, |
| 7554 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7555 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7556 | parent_raw->SetTransform(identity_matrix); |
| 7557 | child_raw->SetTransform(identity_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7558 | grand_parent_raw->SetTransform(perspective_matrix); |
| 7559 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7560 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7561 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7562 | |
| 7563 | // |grand_parent| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7564 | EXPECT_EQ( |
| 7565 | 0.f, |
| 7566 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7567 | EXPECT_EQ(0.f, |
| 7568 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7569 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7570 | EXPECT_EQ( |
| 7571 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7572 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7573 | EXPECT_EQ( |
| 7574 | 0.f, |
| 7575 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7576 | EXPECT_EQ(0.f, |
| 7577 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7578 | EXPECT_EQ(0.f, |
| 7579 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7580 | EXPECT_EQ( |
| 7581 | 0.f, |
| 7582 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7583 | } |
| 7584 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7585 | static int membership_id(LayerImpl* layer) { |
| 7586 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 7587 | } |
| 7588 | |
| 7589 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 7590 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7591 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7592 | end = LayerIterator::End(rsll); |
| 7593 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7594 | LayerImpl* layer = *it; |
| 7595 | if (it.represents_itself()) |
| 7596 | drawn_layers->insert(layer); |
| 7597 | |
| 7598 | if (!it.represents_contributing_render_surface()) |
| 7599 | continue; |
| 7600 | |
| 7601 | if (layer->mask_layer()) |
| 7602 | drawn_layers->insert(layer->mask_layer()); |
| 7603 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 7604 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 7605 | } |
| 7606 | } |
| 7607 | |
| 7608 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7609 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7610 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7611 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7612 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7613 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7614 | gfx::Transform identity_matrix; |
| 7615 | |
| 7616 | scoped_ptr<LayerImpl> grand_parent = |
| 7617 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7618 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 7619 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 7620 | scoped_ptr<LayerImpl> grand_child1 = |
| 7621 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 7622 | scoped_ptr<LayerImpl> grand_child2 = |
| 7623 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7624 | |
| 7625 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7626 | LayerImpl* parent_raw = parent.get(); |
| 7627 | LayerImpl* child_raw = child.get(); |
| 7628 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7629 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7630 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7631 | child->AddChild(std::move(grand_child1)); |
| 7632 | child->AddChild(std::move(grand_child2)); |
| 7633 | parent->AddChild(std::move(child)); |
| 7634 | grand_parent->AddChild(std::move(parent)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7635 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7636 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7637 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 7638 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7639 | true, false, true); |
| 7640 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7641 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7642 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7643 | |
| 7644 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7645 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7646 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7647 | |
| 7648 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 7649 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7650 | true, false, false); |
| 7651 | |
| 7652 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 7653 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7654 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7655 | |
| 7656 | // Start with nothing being drawn. |
| 7657 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7658 | int member_id = render_surface_layer_list_count(); |
| 7659 | |
| 7660 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7661 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7662 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7663 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7664 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7665 | |
| 7666 | std::set<LayerImpl*> expected; |
| 7667 | std::set<LayerImpl*> actual; |
| 7668 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7669 | EXPECT_EQ(expected, actual); |
| 7670 | |
| 7671 | // If we force render surface, but none of the layers are in the layer list, |
| 7672 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7673 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7674 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7675 | |
| 7676 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7677 | member_id = render_surface_layer_list_count(); |
| 7678 | |
| 7679 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7680 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7681 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7682 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7683 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7684 | |
| 7685 | expected.clear(); |
| 7686 | actual.clear(); |
| 7687 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7688 | EXPECT_EQ(expected, actual); |
| 7689 | |
| 7690 | // However, if we say that this layer also draws content, it will appear in |
| 7691 | // RSLL. |
| 7692 | grand_child1_raw->SetDrawsContent(true); |
| 7693 | |
| 7694 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7695 | member_id = render_surface_layer_list_count(); |
| 7696 | |
| 7697 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7698 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7699 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7700 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 7701 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7702 | |
| 7703 | expected.clear(); |
| 7704 | expected.insert(grand_child1_raw); |
| 7705 | |
| 7706 | actual.clear(); |
| 7707 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7708 | EXPECT_EQ(expected, actual); |
| 7709 | |
| 7710 | // Now child is forced to have a render surface, and one if its children draws |
| 7711 | // content. |
| 7712 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7713 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7714 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7715 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7716 | grand_child2_raw->SetDrawsContent(true); |
| 7717 | |
| 7718 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7719 | member_id = render_surface_layer_list_count(); |
| 7720 | |
| 7721 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7722 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7723 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7724 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7725 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7726 | |
| 7727 | expected.clear(); |
| 7728 | expected.insert(grand_child2_raw); |
| 7729 | |
| 7730 | actual.clear(); |
| 7731 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7732 | EXPECT_EQ(expected, actual); |
| 7733 | |
| 7734 | // Add a mask layer to child. |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7735 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7736 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7737 | |
| 7738 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7739 | member_id = render_surface_layer_list_count(); |
| 7740 | |
| 7741 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7742 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7743 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7744 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7745 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7746 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7747 | |
| 7748 | expected.clear(); |
| 7749 | expected.insert(grand_child2_raw); |
| 7750 | expected.insert(child_raw->mask_layer()); |
| 7751 | |
| 7752 | expected.clear(); |
| 7753 | expected.insert(grand_child2_raw); |
| 7754 | expected.insert(child_raw->mask_layer()); |
| 7755 | |
| 7756 | actual.clear(); |
| 7757 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7758 | EXPECT_EQ(expected, actual); |
| 7759 | |
| 7760 | // Add replica mask layer. |
| 7761 | scoped_ptr<LayerImpl> replica_layer = |
| 7762 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 7763 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7764 | child_raw->SetReplicaLayer(std::move(replica_layer)); |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 7765 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7766 | |
| 7767 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7768 | member_id = render_surface_layer_list_count(); |
| 7769 | |
| 7770 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7771 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7772 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7773 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7774 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 7775 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7776 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7777 | |
| 7778 | expected.clear(); |
| 7779 | expected.insert(grand_child2_raw); |
| 7780 | expected.insert(child_raw->mask_layer()); |
| 7781 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 7782 | |
| 7783 | actual.clear(); |
| 7784 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7785 | EXPECT_EQ(expected, actual); |
| 7786 | |
| 7787 | child_raw->TakeReplicaLayer(); |
| 7788 | |
| 7789 | // With nothing drawing, we should have no layers. |
| 7790 | grand_child2_raw->SetDrawsContent(false); |
| 7791 | |
| 7792 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7793 | member_id = render_surface_layer_list_count(); |
| 7794 | |
| 7795 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7796 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7797 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7798 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 7799 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7800 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7801 | |
| 7802 | expected.clear(); |
| 7803 | actual.clear(); |
| 7804 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7805 | EXPECT_EQ(expected, actual); |
| 7806 | |
| 7807 | // Child itself draws means that we should have the child and the mask in the |
| 7808 | // list. |
| 7809 | child_raw->SetDrawsContent(true); |
| 7810 | |
| 7811 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7812 | member_id = render_surface_layer_list_count(); |
| 7813 | |
| 7814 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7815 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7816 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 7817 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7818 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7819 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7820 | |
| 7821 | expected.clear(); |
| 7822 | expected.insert(child_raw); |
| 7823 | expected.insert(child_raw->mask_layer()); |
| 7824 | actual.clear(); |
| 7825 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7826 | EXPECT_EQ(expected, actual); |
| 7827 | |
| 7828 | child_raw->TakeMaskLayer(); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7829 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7830 | |
| 7831 | // Now everyone's a member! |
| 7832 | grand_parent_raw->SetDrawsContent(true); |
| 7833 | parent_raw->SetDrawsContent(true); |
| 7834 | child_raw->SetDrawsContent(true); |
| 7835 | grand_child1_raw->SetDrawsContent(true); |
| 7836 | grand_child2_raw->SetDrawsContent(true); |
| 7837 | |
| 7838 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7839 | member_id = render_surface_layer_list_count(); |
| 7840 | |
| 7841 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 7842 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 7843 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 7844 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 7845 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7846 | |
| 7847 | expected.clear(); |
| 7848 | expected.insert(grand_parent_raw); |
| 7849 | expected.insert(parent_raw); |
| 7850 | expected.insert(child_raw); |
| 7851 | expected.insert(grand_child1_raw); |
| 7852 | expected.insert(grand_child2_raw); |
| 7853 | |
| 7854 | actual.clear(); |
| 7855 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7856 | EXPECT_EQ(expected, actual); |
| 7857 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7858 | |
| 7859 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7860 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7861 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7862 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7863 | LayerTreeSettings settings = host()->settings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7864 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7865 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7866 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7867 | |
| 7868 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7869 | LayerImpl* root_layer = root.get(); |
| 7870 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 7871 | LayerImpl* child1_layer = child1.get(); |
| 7872 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 7873 | LayerImpl* child2_layer = child2.get(); |
| 7874 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7875 | root->AddChild(std::move(child1)); |
| 7876 | root->AddChild(std::move(child2)); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 7877 | root->SetForceRenderSurface(true); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7878 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7879 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7880 | |
| 7881 | gfx::Transform identity_matrix, scale_transform_child1, |
| 7882 | scale_transform_child2; |
| 7883 | scale_transform_child1.Scale(2, 3); |
| 7884 | scale_transform_child2.Scale(4, 5); |
| 7885 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7886 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 7887 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 7888 | true); |
| 7889 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7890 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7891 | true, false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7892 | |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7893 | child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7894 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7895 | |
| 7896 | scoped_ptr<LayerImpl> replica_layer = |
| 7897 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7898 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7899 | child1_layer->SetReplicaLayer(std::move(replica_layer)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7900 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7901 | |
| 7902 | ExecuteCalculateDrawProperties(root_layer); |
| 7903 | |
| 7904 | TransformOperations scale; |
| 7905 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7906 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7907 | scoped_refptr<AnimationTimeline> timeline = |
| 7908 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7909 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7910 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7911 | AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0, |
| 7912 | TransformOperations(), scale); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7913 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7914 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7915 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7916 | true, false, false); |
| 7917 | child2_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7918 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7919 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7920 | ExecuteCalculateDrawProperties(root_layer); |
| 7921 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7922 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7923 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
| 7924 | EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
| 7925 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7926 | |
| 7927 | EXPECT_FLOAT_EQ( |
| 7928 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7929 | EXPECT_FLOAT_EQ( |
| 7930 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7931 | EXPECT_FLOAT_EQ(0.f, |
| 7932 | child1_layer->mask_layer() |
| 7933 | ->draw_properties() |
| 7934 | .maximum_animation_contents_scale); |
| 7935 | EXPECT_FLOAT_EQ(0.f, |
| 7936 | child1_layer->replica_layer() |
| 7937 | ->mask_layer() |
| 7938 | ->draw_properties() |
| 7939 | .maximum_animation_contents_scale); |
| 7940 | EXPECT_FLOAT_EQ( |
| 7941 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7942 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7943 | // Changing page-scale would affect ideal_contents_scale and |
| 7944 | // maximum_animation_contents_scale. |
| 7945 | |
| 7946 | float page_scale_factor = 3.f; |
| 7947 | float device_scale_factor = 1.0f; |
| 7948 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7949 | gfx::Size device_viewport_size = |
| 7950 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7951 | root_layer->bounds().height() * device_scale_factor); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7952 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7953 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7954 | root_layer, device_viewport_size, &render_surface_layer_list, |
| 7955 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7956 | |
| 7957 | inputs.page_scale_factor = page_scale_factor; |
| 7958 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7959 | inputs.page_scale_layer = root_layer; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7960 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7961 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7962 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7963 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
| 7964 | EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7965 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7966 | 9.f, |
| 7967 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 7968 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7969 | |
| 7970 | EXPECT_FLOAT_EQ( |
| 7971 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7972 | EXPECT_FLOAT_EQ( |
| 7973 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7974 | EXPECT_FLOAT_EQ(0.f, |
| 7975 | child1_layer->mask_layer() |
| 7976 | ->draw_properties() |
| 7977 | .maximum_animation_contents_scale); |
| 7978 | EXPECT_FLOAT_EQ(0.f, |
| 7979 | child1_layer->replica_layer() |
| 7980 | ->mask_layer() |
| 7981 | ->draw_properties() |
| 7982 | .maximum_animation_contents_scale); |
| 7983 | EXPECT_FLOAT_EQ( |
| 7984 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7985 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7986 | // Changing device-scale would affect ideal_contents_scale and |
| 7987 | // maximum_animation_contents_scale. |
| 7988 | |
| 7989 | device_scale_factor = 4.0f; |
| 7990 | inputs.device_scale_factor = device_scale_factor; |
| 7991 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7992 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7993 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7994 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7995 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7996 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
| 7997 | EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7998 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7999 | 36.f, |
| 8000 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 8001 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8002 | |
| 8003 | EXPECT_FLOAT_EQ( |
| 8004 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8005 | EXPECT_FLOAT_EQ( |
| 8006 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8007 | EXPECT_FLOAT_EQ(0.f, |
| 8008 | child1_layer->mask_layer() |
| 8009 | ->draw_properties() |
| 8010 | .maximum_animation_contents_scale); |
| 8011 | EXPECT_FLOAT_EQ(0.f, |
| 8012 | child1_layer->replica_layer() |
| 8013 | ->mask_layer() |
| 8014 | ->draw_properties() |
| 8015 | .maximum_animation_contents_scale); |
| 8016 | EXPECT_FLOAT_EQ( |
| 8017 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8018 | } |
| 8019 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8020 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8021 | scoped_refptr<Layer> root = Layer::Create(); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8022 | SetLayerPropertiesForTesting(root.get(), |
| 8023 | gfx::Transform(), |
| 8024 | gfx::Point3F(), |
| 8025 | gfx::PointF(), |
| 8026 | gfx::Size(768 / 2, 3000), |
| 8027 | true, |
| 8028 | false); |
| 8029 | root->SetIsDrawable(true); |
| 8030 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8031 | scoped_refptr<Layer> clip = Layer::Create(); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8032 | SetLayerPropertiesForTesting(clip.get(), |
| 8033 | gfx::Transform(), |
| 8034 | gfx::Point3F(), |
| 8035 | gfx::PointF(), |
| 8036 | gfx::Size(768 / 2, 10000), |
| 8037 | true, |
| 8038 | false); |
| 8039 | clip->SetMasksToBounds(true); |
| 8040 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8041 | scoped_refptr<Layer> content = Layer::Create(); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8042 | SetLayerPropertiesForTesting(content.get(), |
| 8043 | gfx::Transform(), |
| 8044 | gfx::Point3F(), |
| 8045 | gfx::PointF(), |
| 8046 | gfx::Size(768 / 2, 10000), |
| 8047 | true, |
| 8048 | false); |
| 8049 | content->SetIsDrawable(true); |
| 8050 | content->SetForceRenderSurface(true); |
| 8051 | |
| 8052 | root->AddChild(clip); |
| 8053 | clip->AddChild(content); |
| 8054 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8055 | host()->SetRootLayer(root); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8056 | |
| 8057 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6b7c69d | 2016-04-01 00:54:43 | [diff] [blame] | 8058 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8059 | host()->root_layer(), device_viewport_size); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8060 | inputs.device_scale_factor = 2.f; |
| 8061 | inputs.page_scale_factor = 1.f; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8062 | inputs.page_scale_layer = NULL; |
jaydasika | 6b7c69d | 2016-04-01 00:54:43 | [diff] [blame] | 8063 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8064 | |
| 8065 | // Layers in the root render surface have their visible content rect clipped |
| 8066 | // by the viewport. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8067 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), |
| 8068 | root->visible_layer_rect_for_testing()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8069 | |
| 8070 | // Layers drawing to a child render surface should still have their visible |
| 8071 | // content rect clipped by the viewport. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8072 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), |
| 8073 | content->visible_layer_rect_for_testing()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8074 | } |
| 8075 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8076 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8077 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8078 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8079 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8080 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8081 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8082 | |
| 8083 | // Set two layers: the root layer clips it's child, |
| 8084 | // the child draws its content. |
| 8085 | |
| 8086 | gfx::Size root_size = gfx::Size(300, 500); |
| 8087 | |
| 8088 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8089 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8090 | |
| 8091 | // Device viewport accomidated the root and the top controls. |
| 8092 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8093 | gfx::Transform identity_matrix; |
| 8094 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8095 | host_impl.SetViewportSize(device_viewport_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8096 | host_impl.active_tree()->SetRootLayer( |
| 8097 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8098 | |
| 8099 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8100 | SetLayerPropertiesForTesting(root, |
| 8101 | identity_matrix, |
| 8102 | gfx::Point3F(), |
| 8103 | gfx::PointF(), |
| 8104 | root_size, |
| 8105 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8106 | false, |
| 8107 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8108 | root->SetMasksToBounds(true); |
| 8109 | |
| 8110 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8111 | |
| 8112 | LayerImpl* sublayer = root->child_at(0); |
| 8113 | SetLayerPropertiesForTesting(sublayer, |
| 8114 | identity_matrix, |
| 8115 | gfx::Point3F(), |
| 8116 | gfx::PointF(), |
| 8117 | sublayer_size, |
| 8118 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8119 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8120 | false); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8121 | sublayer->SetDrawsContent(true); |
| 8122 | |
| 8123 | LayerImplList layer_impl_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8124 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8125 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8126 | root, device_viewport_size, &layer_impl_list, |
| 8127 | root->layer_tree_impl()->current_render_surface_list_id()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8128 | |
| 8129 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8130 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8131 | |
| 8132 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8133 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8134 | |
| 8135 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8136 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8137 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8138 | } |
| 8139 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8140 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8141 | scoped_refptr<Layer> root = Layer::Create(); |
| 8142 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8143 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8144 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8145 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8146 | |
| 8147 | root->AddChild(inner_viewport_container_layer); |
| 8148 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8149 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8150 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8151 | |
| 8152 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8153 | inner_viewport_container_layer->id()); |
| 8154 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8155 | outer_viewport_container_layer->id()); |
| 8156 | |
| 8157 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8158 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8159 | |
| 8160 | host()->SetRootLayer(root); |
| 8161 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 8162 | outer_viewport_scroll_layer); |
| 8163 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8164 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8165 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8166 | |
| 8167 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8168 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8169 | |
| 8170 | LayerPositionConstraint fixed_to_right; |
| 8171 | fixed_to_right.set_is_fixed_position(true); |
| 8172 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8173 | |
| 8174 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8175 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8176 | |
| 8177 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8178 | |
| 8179 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8180 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8181 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8182 | |
| 8183 | LayerPositionConstraint fixed_to_left; |
| 8184 | fixed_to_left.set_is_fixed_position(true); |
| 8185 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8186 | |
| 8187 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8188 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8189 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8190 | |
| 8191 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8192 | |
| 8193 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8194 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8195 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8196 | } |
| 8197 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8198 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8199 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8200 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8201 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8202 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8203 | |
| 8204 | root->AddChild(animated); |
| 8205 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8206 | host()->SetRootLayer(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8207 | |
| 8208 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8209 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8210 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8211 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8212 | |
| 8213 | root->SetMasksToBounds(true); |
| 8214 | root->SetForceRenderSurface(true); |
| 8215 | animated->SetOpacity(0.f); |
| 8216 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8217 | AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f, |
| 8218 | 1.f, false); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8219 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8220 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8221 | EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8222 | } |
| 8223 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8224 | TEST_F(LayerTreeHostCommonTest, |
| 8225 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
| 8226 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8227 | scoped_refptr<Layer> root = Layer::Create(); |
| 8228 | scoped_refptr<Layer> clip = Layer::Create(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8229 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8230 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8231 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8232 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8233 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8234 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8235 | |
| 8236 | root->AddChild(clip); |
| 8237 | clip->AddChild(animated); |
| 8238 | animated->AddChild(surface); |
| 8239 | surface->AddChild(descendant_of_animation); |
| 8240 | |
| 8241 | clip->SetMasksToBounds(true); |
| 8242 | surface->SetForceRenderSurface(true); |
| 8243 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8244 | host()->SetRootLayer(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8245 | |
| 8246 | gfx::Transform uninvertible_matrix; |
| 8247 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8248 | |
| 8249 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8250 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8251 | SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 8252 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8253 | SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix, |
| 8254 | gfx::Point3F(), gfx::PointF(), |
| 8255 | gfx::Size(120, 120), true, false); |
| 8256 | SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 8257 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8258 | SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix, |
| 8259 | gfx::Point3F(), gfx::PointF(), |
| 8260 | gfx::Size(200, 200), true, false); |
| 8261 | |
| 8262 | TransformOperations start_transform_operations; |
| 8263 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8264 | TransformOperations end_transform_operations; |
| 8265 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8266 | AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0, |
| 8267 | start_transform_operations, |
| 8268 | end_transform_operations); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8269 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8270 | |
| 8271 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8272 | // clipped target space, so is treated as fully visible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8273 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8274 | |
| 8275 | // The singular transform on |animated| is flattened when inherited by |
| 8276 | // |surface|, and this happens to make it invertible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8277 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing()); |
| 8278 | EXPECT_EQ(gfx::Rect(2, 2), |
| 8279 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8280 | |
| 8281 | gfx::Transform zero_matrix; |
| 8282 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8283 | SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(), |
| 8284 | gfx::PointF(), gfx::Size(120, 120), true, false); |
| 8285 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8286 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8287 | |
| 8288 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8289 | // treated as having an empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8290 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8291 | |
| 8292 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8293 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8294 | // |surface| and layers that draw into it as having empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8295 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing()); |
| 8296 | EXPECT_EQ(gfx::Rect(), |
| 8297 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8298 | } |
| 8299 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8300 | // Verify that having an animated filter (but no current filter, as these |
| 8301 | // are mutually exclusive) correctly creates a render surface. |
| 8302 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8303 | scoped_refptr<Layer> root = Layer::Create(); |
| 8304 | scoped_refptr<Layer> child = Layer::Create(); |
| 8305 | scoped_refptr<Layer> grandchild = Layer::Create(); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8306 | root->AddChild(child); |
| 8307 | child->AddChild(grandchild); |
| 8308 | |
| 8309 | gfx::Transform identity_transform; |
| 8310 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8311 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8312 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8313 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8314 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8315 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8316 | true, false); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8317 | host()->SetRootLayer(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8318 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8319 | AddAnimatedFilterToLayerWithPlayer(child->id(), timeline(), 10.0, 0.1f, 0.2f); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8320 | ExecuteCalculateDrawProperties(root.get()); |
| 8321 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8322 | EXPECT_TRUE(root->has_render_surface()); |
| 8323 | EXPECT_TRUE(child->has_render_surface()); |
| 8324 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8325 | |
| 8326 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8327 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8328 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8329 | |
| 8330 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8331 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8332 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8333 | } |
| 8334 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8335 | // Verify that having a filter animation with a delayed start time creates a |
| 8336 | // render surface. |
| 8337 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8338 | scoped_refptr<Layer> root = Layer::Create(); |
| 8339 | scoped_refptr<Layer> child = Layer::Create(); |
| 8340 | scoped_refptr<Layer> grandchild = Layer::Create(); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8341 | root->AddChild(child); |
| 8342 | child->AddChild(grandchild); |
| 8343 | |
| 8344 | gfx::Transform identity_transform; |
| 8345 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8346 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8347 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8348 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8349 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8350 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8351 | true, false); |
| 8352 | host()->SetRootLayer(root); |
| 8353 | |
| 8354 | scoped_ptr<KeyframedFilterAnimationCurve> curve( |
| 8355 | KeyframedFilterAnimationCurve::Create()); |
| 8356 | FilterOperations start_filters; |
| 8357 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8358 | FilterOperations end_filters; |
| 8359 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8360 | curve->AddKeyframe( |
| 8361 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8362 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8363 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
| 8364 | scoped_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8365 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8366 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 8367 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8368 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8369 | AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8370 | ExecuteCalculateDrawProperties(root.get()); |
| 8371 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8372 | EXPECT_TRUE(root->has_render_surface()); |
| 8373 | EXPECT_TRUE(child->has_render_surface()); |
| 8374 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8375 | |
| 8376 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8377 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8378 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8379 | |
| 8380 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8381 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8382 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8383 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8384 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8385 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8386 | } |
| 8387 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8388 | // Ensures that the property tree code accounts for offsets between fixed |
| 8389 | // position layers and their respective containers. |
| 8390 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8391 | scoped_refptr<Layer> root = Layer::Create(); |
| 8392 | scoped_refptr<Layer> child = Layer::Create(); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8393 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8394 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8395 | |
| 8396 | root->AddChild(child); |
| 8397 | child->AddChild(grandchild); |
| 8398 | |
| 8399 | gfx::Transform identity_transform; |
| 8400 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8401 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8402 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8403 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8404 | false); |
| 8405 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8406 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8407 | gfx::Size(50, 50), true, false); |
| 8408 | |
| 8409 | root->SetMasksToBounds(true); |
| 8410 | root->SetIsContainerForFixedPositionLayers(true); |
| 8411 | LayerPositionConstraint constraint; |
| 8412 | constraint.set_is_fixed_position(true); |
| 8413 | grandchild->SetPositionConstraint(constraint); |
| 8414 | |
| 8415 | root->SetIsContainerForFixedPositionLayers(true); |
| 8416 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8417 | host()->SetRootLayer(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8418 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8419 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8420 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8421 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8422 | grandchild->visible_layer_rect_for_testing()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8423 | } |
| 8424 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8425 | // Ensures that the property tree code accounts for offsets between fixed |
| 8426 | // position containers and their transform tree parents, when a fixed position |
| 8427 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8428 | // own transform tree node. |
| 8429 | TEST_F(LayerTreeHostCommonTest, |
| 8430 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8431 | scoped_refptr<Layer> root = Layer::Create(); |
| 8432 | scoped_refptr<Layer> child = Layer::Create(); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8433 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8434 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8435 | |
| 8436 | root->AddChild(child); |
| 8437 | child->AddChild(grandchild); |
| 8438 | |
| 8439 | gfx::Transform identity_transform; |
| 8440 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8441 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8442 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8443 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8444 | false); |
| 8445 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8446 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8447 | gfx::Size(50, 50), true, false); |
| 8448 | |
| 8449 | root->SetMasksToBounds(true); |
| 8450 | child->SetIsContainerForFixedPositionLayers(true); |
| 8451 | LayerPositionConstraint constraint; |
| 8452 | constraint.set_is_fixed_position(true); |
| 8453 | grandchild->SetPositionConstraint(constraint); |
| 8454 | |
| 8455 | root->SetIsContainerForFixedPositionLayers(true); |
| 8456 | |
| 8457 | host()->SetRootLayer(root); |
| 8458 | |
| 8459 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8460 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8461 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8462 | grandchild->visible_layer_rect_for_testing()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8463 | } |
| 8464 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8465 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8466 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8467 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8468 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8469 | // test ensures that happens. |
| 8470 | |
| 8471 | gfx::Transform rotate; |
| 8472 | rotate.Rotate(5); |
| 8473 | gfx::Transform identity; |
| 8474 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8475 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8476 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8477 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8478 | false); |
| 8479 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8480 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8481 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8482 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8483 | false); |
| 8484 | frame_clip->SetMasksToBounds(true); |
| 8485 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8486 | scoped_refptr<Layer> rotated = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8487 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8488 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8489 | gfx::Size(2500, 500), true, false); |
| 8490 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8491 | scoped_refptr<Layer> surface = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8492 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8493 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8494 | false); |
| 8495 | surface->SetOpacity(0.5); |
| 8496 | |
| 8497 | scoped_refptr<LayerWithForcedDrawsContent> container = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8498 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8499 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8500 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8501 | |
| 8502 | scoped_refptr<LayerWithForcedDrawsContent> box = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8503 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8504 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8505 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8506 | |
| 8507 | root->AddChild(frame_clip); |
| 8508 | frame_clip->AddChild(rotated); |
| 8509 | rotated->AddChild(surface); |
| 8510 | surface->AddChild(container); |
| 8511 | surface->AddChild(box); |
| 8512 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8513 | host()->SetRootLayer(root); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8514 | |
| 8515 | ExecuteCalculateDrawProperties(root.get()); |
| 8516 | } |
| 8517 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8518 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
| 8519 | gfx::Transform identity; |
| 8520 | gfx::Transform translate_z; |
| 8521 | translate_z.Translate3d(0, 0, 10); |
| 8522 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8523 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8524 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8525 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8526 | root->SetIsContainerForFixedPositionLayers(true); |
| 8527 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8528 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8529 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 8530 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8531 | false); |
| 8532 | frame_clip->SetMasksToBounds(true); |
| 8533 | |
| 8534 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8535 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8536 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8537 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8538 | false); |
| 8539 | |
| 8540 | LayerPositionConstraint constraint; |
| 8541 | constraint.set_is_fixed_position(true); |
| 8542 | fixed->SetPositionConstraint(constraint); |
| 8543 | |
| 8544 | root->AddChild(frame_clip); |
| 8545 | frame_clip->AddChild(fixed); |
| 8546 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8547 | host()->SetRootLayer(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8548 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8549 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8550 | |
| 8551 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8552 | EXPECT_EQ(expected, fixed->visible_layer_rect_for_testing()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8553 | } |
| 8554 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8555 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
| 8556 | gfx::Transform identity; |
| 8557 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8558 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8559 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8560 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8561 | root->SetIsContainerForFixedPositionLayers(true); |
| 8562 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8563 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8564 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8565 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8566 | false); |
| 8567 | frame_clip->SetMasksToBounds(true); |
| 8568 | |
| 8569 | scoped_refptr<LayerWithForcedDrawsContent> scroller = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8570 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8571 | SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), |
| 8572 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8573 | false); |
| 8574 | |
| 8575 | scroller->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8576 | scroller->SetScrollClipLayerId(frame_clip->id()); |
| 8577 | |
| 8578 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8579 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8580 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8581 | gfx::PointF(100, 100), gfx::Size(50, 50), true, |
| 8582 | false); |
| 8583 | |
| 8584 | LayerPositionConstraint constraint; |
| 8585 | constraint.set_is_fixed_position(true); |
| 8586 | fixed->SetPositionConstraint(constraint); |
| 8587 | fixed->SetForceRenderSurface(true); |
| 8588 | fixed->SetMasksToBounds(true); |
| 8589 | |
| 8590 | root->AddChild(frame_clip); |
| 8591 | frame_clip->AddChild(scroller); |
| 8592 | scroller->AddChild(fixed); |
| 8593 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8594 | host()->SetRootLayer(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8595 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8596 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8597 | |
| 8598 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8599 | EXPECT_EQ(expected, fixed->visible_layer_rect_for_testing()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8600 | } |
| 8601 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8602 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
| 8603 | gfx::Transform identity; |
| 8604 | gfx::Transform translate; |
| 8605 | gfx::Transform rotate; |
| 8606 | |
| 8607 | translate.Translate(10, 10); |
| 8608 | rotate.Rotate(45); |
| 8609 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8610 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8611 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8612 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8613 | root->SetIsContainerForFixedPositionLayers(true); |
| 8614 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8615 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8616 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8617 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8618 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8619 | |
| 8620 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8621 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8622 | |
| 8623 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8624 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8625 | } |
| 8626 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8627 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8628 | scoped_refptr<Layer> root = Layer::Create(); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8629 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8630 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8631 | root->AddChild(child); |
| 8632 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8633 | host()->SetRootLayer(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8634 | |
| 8635 | gfx::Transform identity_matrix; |
| 8636 | gfx::Transform scale_matrix; |
| 8637 | scale_matrix.Scale(2.f, 2.f); |
| 8638 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8639 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8640 | SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(), |
| 8641 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8642 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8643 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8644 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect_for_testing()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8645 | |
| 8646 | child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f)); |
| 8647 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8648 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8649 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect_for_testing()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8650 | } |
| 8651 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8652 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8653 | scoped_refptr<Layer> root = Layer::Create(); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8654 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8655 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8656 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8657 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8658 | |
| 8659 | root->AddChild(scroll_child); |
| 8660 | root->AddChild(scroll_parent); |
| 8661 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 8662 | scroll_parent->SetScrollClipLayerId(root->id()); |
| 8663 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8664 | host()->SetRootLayer(root); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8665 | |
| 8666 | gfx::Transform identity_transform; |
| 8667 | gfx::Transform scale; |
| 8668 | scale.Scale(2.f, 2.f); |
| 8669 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8670 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8671 | SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(), |
| 8672 | gfx::PointF(), gfx::Size(40, 40), true, false); |
| 8673 | SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, |
| 8674 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 8675 | true, false); |
| 8676 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8677 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8678 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect_for_testing()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8679 | |
| 8680 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
| 8681 | scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8682 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8683 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), |
| 8684 | scroll_child->visible_layer_rect_for_testing()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8685 | } |
| 8686 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8687 | static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 8688 | } |
| 8689 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8690 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8691 | // If the layer has a node in effect_tree, the return value of |
| 8692 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8693 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8694 | // to be the value of its nearest ancestor that owns an effect node and |
| 8695 | // greater than or equal to the actual number of copy requests in the |
| 8696 | // sub-layer_tree. |
| 8697 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8698 | scoped_refptr<Layer> root = Layer::Create(); |
| 8699 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8700 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8701 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8702 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8703 | |
| 8704 | root->AddChild(child1); |
| 8705 | root->AddChild(child2); |
| 8706 | child1->AddChild(grandchild); |
| 8707 | grandchild->AddChild(greatgrandchild); |
| 8708 | host()->SetRootLayer(root); |
| 8709 | |
| 8710 | child1->RequestCopyOfOutput( |
| 8711 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8712 | greatgrandchild->RequestCopyOfOutput( |
| 8713 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8714 | child2->SetOpacity(0.f); |
| 8715 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8716 | |
| 8717 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8718 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8719 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8720 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8721 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8722 | } |
| 8723 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8724 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
| 8725 | gfx::Transform identity; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8726 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8727 | FakeContentLayerClient client; |
| 8728 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8729 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8730 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8731 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8732 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8733 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8734 | FakePictureLayer::Create(&client)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8735 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8736 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8737 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8738 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8739 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8740 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8741 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 8742 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8743 | |
| 8744 | root->AddChild(child); |
| 8745 | child->AddChild(grandchild); |
| 8746 | grandchild->AddChild(greatgrandchild); |
| 8747 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8748 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8749 | |
| 8750 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8751 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8752 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8753 | |
| 8754 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8755 | // and we will configure |child| in several ways that should force the subtree |
| 8756 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8757 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8758 | grandchild->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8759 | gfx::Transform singular; |
| 8760 | singular.matrix().set(0, 0, 0); |
| 8761 | |
| 8762 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8763 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8764 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8765 | child->SetTransform(identity); |
| 8766 | |
| 8767 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8768 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8769 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8770 | child->SetHideLayerAndSubtree(false); |
| 8771 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8772 | gfx::Transform zero_z_scale; |
| 8773 | zero_z_scale.Scale3d(1, 1, 0); |
| 8774 | child->SetTransform(zero_z_scale); |
| 8775 | |
| 8776 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8777 | // a singular transform, the subtree should still get processed. |
| 8778 | int animation_id = 0; |
| 8779 | scoped_ptr<Animation> animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 8780 | scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8781 | animation_id, 1, TargetProperty::TRANSFORM); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8782 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 8783 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8784 | AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8785 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8786 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8787 | grandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8788 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8789 | RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(), |
| 8790 | animation_id); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8791 | child->SetTransform(identity); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8792 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8793 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8794 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8795 | |
| 8796 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8797 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8798 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8799 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8800 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8801 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8802 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8803 | greatgrandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8804 | |
| 8805 | // Add an opacity animation with a start delay. |
| 8806 | animation_id = 1; |
| 8807 | animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 8808 | scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8809 | animation_id, 1, TargetProperty::OPACITY); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8810 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 8811 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8812 | AddAnimationToLayerWithExistingPlayer(child->id(), timeline(), |
| 8813 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8814 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8815 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8816 | } |
| 8817 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8818 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8819 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8820 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8821 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8822 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8823 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8824 | |
| 8825 | gfx::Transform identity; |
| 8826 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8827 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8828 | scoped_ptr<LayerImpl> grandchild = |
| 8829 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8830 | |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8831 | scoped_ptr<FakePictureLayerImpl> greatgrandchild( |
| 8832 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8833 | |
| 8834 | child->SetDrawsContent(true); |
| 8835 | grandchild->SetDrawsContent(true); |
| 8836 | greatgrandchild->SetDrawsContent(true); |
| 8837 | |
| 8838 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8839 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8840 | true); |
| 8841 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8842 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8843 | false); |
| 8844 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8845 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8846 | false); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8847 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8848 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8849 | LayerImpl* child_ptr = child.get(); |
| 8850 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8851 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8852 | child->AddChild(std::move(grandchild)); |
| 8853 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8854 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8855 | |
| 8856 | // Check the non-skipped case. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8857 | // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8858 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8859 | |
| 8860 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8861 | // and we will configure |child| in several ways that should force the subtree |
| 8862 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8863 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8864 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8865 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8866 | gfx::Transform singular; |
| 8867 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8868 | // This line is used to make the results of skipping and not skipping layers |
| 8869 | // different. |
| 8870 | singular.matrix().set(0, 1, 1); |
| 8871 | |
| 8872 | gfx::Transform rotate; |
| 8873 | rotate.Rotate(90); |
| 8874 | |
| 8875 | gfx::Transform rotate_back_and_translate; |
| 8876 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8877 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8878 | |
| 8879 | child_ptr->SetTransform(singular); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8880 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8881 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8882 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8883 | child_ptr->SetTransform(identity); |
| 8884 | |
| 8885 | child_ptr->SetHideLayerAndSubtree(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8886 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8887 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8888 | child_ptr->SetHideLayerAndSubtree(false); |
| 8889 | |
| 8890 | child_ptr->SetOpacity(0.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8891 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8892 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8893 | child_ptr->SetOpacity(1.f); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8894 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8895 | root_ptr->SetTransform(singular); |
| 8896 | // Force transform tree to have a node for child, so that ancestor's |
| 8897 | // invertible transform can be tested. |
| 8898 | child_ptr->SetTransform(rotate); |
| 8899 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8900 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8901 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
| 8902 | root_ptr->SetTransform(identity); |
| 8903 | child_ptr->SetTransform(identity); |
| 8904 | |
| 8905 | root_ptr->SetOpacity(0.f); |
| 8906 | child_ptr->SetOpacity(0.7f); |
| 8907 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8908 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8909 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
| 8910 | root_ptr->SetOpacity(1.f); |
| 8911 | |
| 8912 | child_ptr->SetOpacity(0.f); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8913 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8914 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8915 | // processed anyhow. |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 8916 | std::vector<scoped_ptr<CopyOutputRequest>> requests; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8917 | requests.push_back(CopyOutputRequest::CreateEmptyRequest()); |
| 8918 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8919 | grandchild_ptr->PassCopyRequests(&requests); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8920 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8921 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8922 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8923 | requests.clear(); |
| 8924 | grandchild_ptr->PassCopyRequests(&requests); |
| 8925 | child_ptr->SetOpacity(1.f); |
| 8926 | |
| 8927 | // A double sided render surface with backface visible should not be skipped |
| 8928 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8929 | child_ptr->SetHasRenderSurface(true); |
| 8930 | child_ptr->SetDoubleSided(true); |
| 8931 | child_ptr->SetTransform(rotate_back_and_translate); |
| 8932 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8933 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8934 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8935 | child_ptr->SetTransform(identity); |
| 8936 | |
| 8937 | scoped_ptr<KeyframedTransformAnimationCurve> curve( |
| 8938 | KeyframedTransformAnimationCurve::Create()); |
| 8939 | TransformOperations start; |
| 8940 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8941 | gfx::Transform transform; |
| 8942 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8943 | TransformOperations operation; |
| 8944 | operation.AppendMatrix(transform); |
| 8945 | curve->AddKeyframe( |
| 8946 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8947 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8948 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 8949 | scoped_ptr<Animation> transform_animation( |
| 8950 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8951 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
| 8952 | host_impl.active_tree()->animation_host()->RegisterPlayerForLayer( |
| 8953 | root_ptr->id(), player.get()); |
| 8954 | host_impl.active_tree() |
| 8955 | ->animation_host() |
| 8956 | ->GetControllerForLayerId(root_ptr->id()) |
| 8957 | ->AddAnimation(std::move(transform_animation)); |
| 8958 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8959 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
| 8960 | root_ptr->SetTransform(singular); |
| 8961 | child_ptr->SetTransform(singular); |
| 8962 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8963 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8964 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8965 | |
| 8966 | host_impl.active_tree()->animation_host()->UnregisterPlayerForLayer( |
| 8967 | root_ptr->id(), player.get()); |
| 8968 | } |
| 8969 | |
| 8970 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8971 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8972 | TestSharedBitmapManager shared_bitmap_manager; |
| 8973 | TestTaskGraphRunner task_graph_runner; |
| 8974 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 8975 | &task_graph_runner); |
| 8976 | |
| 8977 | gfx::Transform identity; |
| 8978 | host_impl.CreatePendingTree(); |
| 8979 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8980 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8981 | scoped_ptr<LayerImpl> grandchild = |
| 8982 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8983 | |
| 8984 | scoped_ptr<FakePictureLayerImpl> greatgrandchild( |
| 8985 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8986 | |
| 8987 | child->SetDrawsContent(true); |
| 8988 | grandchild->SetDrawsContent(true); |
| 8989 | greatgrandchild->SetDrawsContent(true); |
| 8990 | |
| 8991 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8992 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8993 | true); |
| 8994 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8995 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8996 | false); |
| 8997 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8998 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8999 | false); |
| 9000 | |
| 9001 | LayerImpl* root_ptr = root.get(); |
| 9002 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9003 | |
| 9004 | child->AddChild(std::move(grandchild)); |
| 9005 | root->AddChild(std::move(child)); |
| 9006 | |
| 9007 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
| 9008 | |
| 9009 | // Check the non-skipped case. |
| 9010 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 9011 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9012 | |
| 9013 | scoped_ptr<KeyframedFloatAnimationCurve> curve( |
| 9014 | KeyframedFloatAnimationCurve::Create()); |
| 9015 | scoped_ptr<TimingFunction> func = EaseTimingFunction::Create(); |
| 9016 | curve->AddKeyframe( |
| 9017 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 9018 | curve->AddKeyframe( |
| 9019 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
| 9020 | scoped_ptr<Animation> animation( |
| 9021 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9022 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
| 9023 | host_impl.active_tree()->animation_host()->RegisterPlayerForLayer( |
| 9024 | root_ptr->id(), player.get()); |
| 9025 | host_impl.active_tree() |
| 9026 | ->animation_host() |
| 9027 | ->GetControllerForLayerId(root_ptr->id()) |
| 9028 | ->AddAnimation(std::move(animation)); |
| 9029 | root_ptr->SetOpacity(0); |
| 9030 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9031 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9032 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 9033 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9034 | |
| 9035 | host_impl.active_tree()->animation_host()->UnregisterPlayerForLayer( |
| 9036 | root_ptr->id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9037 | } |
| 9038 | |
| 9039 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
| 9040 | gfx::Transform identity; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9041 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 9042 | FakeContentLayerClient client; |
| 9043 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9044 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9045 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9046 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9047 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9048 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9049 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9050 | root->AddChild(child); |
| 9051 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9052 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9053 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9054 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 9055 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9056 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9057 | |
| 9058 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9059 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 9060 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9061 | child->SetHideLayerAndSubtree(false); |
| 9062 | |
| 9063 | child->SetBounds(gfx::Size()); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9064 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 9065 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9066 | child->SetBounds(gfx::Size(10, 10)); |
| 9067 | |
| 9068 | gfx::Transform rotate; |
| 9069 | child->SetDoubleSided(false); |
| 9070 | rotate.RotateAboutXAxis(180.f); |
| 9071 | child->SetTransform(rotate); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9072 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 9073 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9074 | child->SetDoubleSided(true); |
| 9075 | child->SetTransform(identity); |
| 9076 | |
| 9077 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9078 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 9079 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9080 | } |
| 9081 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9082 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9083 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9084 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9085 | scoped_refptr<Layer> root = Layer::Create(); |
| 9086 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9087 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9088 | |
| 9089 | root->AddChild(parent); |
| 9090 | parent->AddChild(child); |
| 9091 | |
| 9092 | child->SetClipParent(root.get()); |
| 9093 | |
| 9094 | gfx::Transform identity; |
| 9095 | |
| 9096 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9097 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9098 | SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(), |
| 9099 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9100 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9101 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9102 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9103 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9104 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9105 | child->RequestCopyOfOutput( |
| 9106 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9107 | |
| 9108 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9109 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9110 | |
| 9111 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 9112 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9113 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9114 | } |
| 9115 | |
| 9116 | TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) { |
| 9117 | // Ensure that the treewalk in LayertreeHostCommon:: |
| 9118 | // PreCalculateMetaInformation updates input handlers correctly. |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9119 | LayerImpl* root = root_layer(); |
| 9120 | LayerImpl* child = AddChild<LayerImpl>(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9121 | |
| 9122 | gfx::Transform identity; |
| 9123 | |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9124 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 9125 | gfx::Size(100, 100), true, false, true); |
| 9126 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 9127 | gfx::Size(100, 100), true, false, false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9128 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9129 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9130 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9131 | child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9132 | ExecuteCalculateDrawProperties(root); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9133 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), true); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9134 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9135 | child->SetTouchEventHandlerRegion(gfx::Rect()); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9136 | ExecuteCalculateDrawProperties(root); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9137 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9138 | } |
| 9139 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9140 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
| 9141 | gfx::Transform identity; |
| 9142 | gfx::Transform translate_z; |
| 9143 | translate_z.Translate3d(0, 0, 10); |
| 9144 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9145 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9146 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9147 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9148 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9149 | scoped_refptr<Layer> child = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9150 | SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(), |
| 9151 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9152 | |
| 9153 | root->AddChild(child); |
| 9154 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9155 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9156 | |
| 9157 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9158 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9159 | |
| 9160 | child->RemoveFromParent(); |
| 9161 | |
| 9162 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9163 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9164 | } |
| 9165 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9166 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9167 | // Ensure that a Clip Node is added when a render surface applies clip. |
| 9168 | LayerImpl* root = root_layer(); |
| 9169 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9170 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9171 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9172 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9173 | |
| 9174 | const gfx::Transform identity_matrix; |
| 9175 | // This transform should be a significant one so that a transform node is |
| 9176 | // formed for it. |
| 9177 | gfx::Transform transform1; |
| 9178 | transform1.RotateAboutYAxis(45); |
| 9179 | transform1.RotateAboutXAxis(30); |
| 9180 | // This transform should be a 3d transform as we want the render surface |
| 9181 | // to flatten the transform |
| 9182 | gfx::Transform transform2; |
| 9183 | transform2.Translate3d(10, 10, 10); |
| 9184 | |
| 9185 | layer_clips_subtree->SetMasksToBounds(true); |
| 9186 | test_layer->SetDrawsContent(true); |
| 9187 | |
| 9188 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9189 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9190 | SetLayerPropertiesForTesting(significant_transform, transform1, |
| 9191 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9192 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9193 | SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix, |
| 9194 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9195 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9196 | SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9197 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9198 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9199 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9200 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9201 | root->SetForceRenderSurface(true); |
| 9202 | significant_transform->SetForceRenderSurface(false); |
| 9203 | layer_clips_subtree->SetForceRenderSurface(true); |
| 9204 | render_surface->SetForceRenderSurface(true); |
| 9205 | test_layer->SetForceRenderSurface(false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9206 | ExecuteCalculateDrawProperties(root); |
| 9207 | |
| 9208 | TransformTree transform_tree = |
| 9209 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9210 | TransformNode* transform_node = |
| 9211 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9212 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9213 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9214 | EXPECT_TRUE(root->has_render_surface()); |
| 9215 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9216 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9217 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9218 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9219 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9220 | ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
| 9221 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9222 | EXPECT_FALSE(clip_node->data.applies_local_clip); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9223 | EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9224 | } |
| 9225 | |
| 9226 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9227 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9228 | // clip node's target, clip is 'projected' from parent space to current |
| 9229 | // target space and visible rects are calculated correctly. |
| 9230 | LayerImpl* root = root_layer(); |
| 9231 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9232 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9233 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9234 | |
| 9235 | const gfx::Transform identity_matrix; |
| 9236 | gfx::Transform transform; |
| 9237 | transform.RotateAboutYAxis(45); |
| 9238 | clip_layer->SetMasksToBounds(true); |
| 9239 | target_layer->SetMasksToBounds(true); |
| 9240 | test_layer->SetDrawsContent(true); |
| 9241 | |
| 9242 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9243 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9244 | true); |
| 9245 | SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(), |
| 9246 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9247 | false); |
| 9248 | SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), |
| 9249 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9250 | true); |
| 9251 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9252 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9253 | false); |
| 9254 | ExecuteCalculateDrawProperties(root); |
| 9255 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9256 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9257 | } |
| 9258 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9259 | TEST_F(LayerTreeHostCommonTest, |
| 9260 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9261 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9262 | // descendants. |
| 9263 | LayerImpl* root = root_layer(); |
| 9264 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9265 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9266 | LayerImpl* render_surface = |
| 9267 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9268 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9269 | |
| 9270 | const gfx::Transform identity_matrix; |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9271 | gfx::Transform translate; |
| 9272 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9273 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9274 | clip_parent->SetMasksToBounds(true); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9275 | test_layer->SetDrawsContent(true); |
| 9276 | render_surface->SetClipParent(clip_parent); |
jaydasika | e9d0970 | 2015-09-15 01:26:41 | [diff] [blame] | 9277 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9278 | clip_children->insert(render_surface); |
| 9279 | clip_parent->SetClipChildren(clip_children.release()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9280 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9281 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9282 | true); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9283 | SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(), |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9284 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9285 | false); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9286 | SetLayerPropertiesForTesting(between_clip_parent_and_child, translate, |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9287 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 9288 | true, false, false); |
| 9289 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9290 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9291 | true); |
| 9292 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9293 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9294 | false); |
| 9295 | |
| 9296 | ExecuteCalculateDrawProperties(root); |
| 9297 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9298 | EXPECT_TRUE(test_layer->is_clipped()); |
| 9299 | EXPECT_FALSE(test_layer->render_target()->render_surface()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9300 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9301 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9302 | } |
| 9303 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9304 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9305 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9306 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9307 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9308 | // a clip. |
| 9309 | LayerImpl* root = root_layer(); |
| 9310 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9311 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9312 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9313 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9314 | |
| 9315 | const gfx::Transform identity_matrix; |
| 9316 | |
| 9317 | clip_child->SetDrawsContent(true); |
| 9318 | child->SetDrawsContent(true); |
| 9319 | clip_child->SetClipParent(clip_parent); |
| 9320 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9321 | clip_children->insert(clip_child); |
| 9322 | clip_parent->SetClipChildren(clip_children.release()); |
| 9323 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9324 | gfx::PointF(), gfx::Size(30, 10), true, false, |
| 9325 | true); |
| 9326 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9327 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9328 | false); |
| 9329 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9330 | gfx::PointF(), gfx::Size(10, 15), true, false, |
| 9331 | true); |
| 9332 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9333 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9334 | false); |
| 9335 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 9336 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 9337 | false); |
| 9338 | |
| 9339 | ExecuteCalculateDrawProperties(root); |
| 9340 | EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect()); |
| 9341 | } |
| 9342 | |
| 9343 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9344 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
| 9345 | LayerImpl* root = root_layer(); |
| 9346 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9347 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9348 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9349 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9350 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9351 | |
| 9352 | const gfx::Transform identity_matrix; |
| 9353 | root->SetMasksToBounds(true); |
| 9354 | render_surface->SetMasksToBounds(true); |
| 9355 | render_surface->SetDrawsContent(true); |
| 9356 | clip_child->SetDrawsContent(true); |
| 9357 | test_layer1->SetDrawsContent(true); |
| 9358 | test_layer2->SetDrawsContent(true); |
| 9359 | clip_child->SetClipParent(clip_parent); |
| 9360 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9361 | clip_children->insert(clip_child); |
| 9362 | clip_parent->SetClipChildren(clip_children.release()); |
| 9363 | |
| 9364 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9365 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9366 | true); |
| 9367 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9368 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9369 | false); |
| 9370 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9371 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9372 | true); |
| 9373 | SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(), |
| 9374 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9375 | false); |
| 9376 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9377 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9378 | false); |
| 9379 | SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(), |
| 9380 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9381 | false); |
| 9382 | |
| 9383 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9384 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9385 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9386 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9387 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9388 | } |
| 9389 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9390 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
| 9391 | LayerImpl* root = root_layer(); |
| 9392 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9393 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9394 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9395 | |
| 9396 | const gfx::Transform identity_matrix; |
| 9397 | clip_parent->SetDrawsContent(true); |
| 9398 | render_surface->SetMasksToBounds(true); |
| 9399 | render_surface->SetDrawsContent(true); |
| 9400 | clip_child->SetDrawsContent(true); |
| 9401 | |
| 9402 | clip_child->SetClipParent(clip_parent); |
| 9403 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9404 | clip_children->insert(clip_child); |
| 9405 | clip_parent->SetClipChildren(clip_children.release()); |
| 9406 | |
| 9407 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9408 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9409 | true); |
| 9410 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9411 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9412 | false); |
| 9413 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9414 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9415 | true); |
| 9416 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9417 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9418 | false); |
| 9419 | |
| 9420 | ExecuteCalculateDrawProperties(root); |
| 9421 | |
| 9422 | // The clip child should inherit its clip parent's clipping state, not its |
| 9423 | // tree parent's clipping state. |
| 9424 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9425 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9426 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9427 | } |
| 9428 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9429 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9430 | // Tests the value of render surface content rect when we have multiple types |
| 9431 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9432 | // clipped surfaces. |
| 9433 | LayerImpl* root = root_layer(); |
| 9434 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9435 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9436 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9437 | LayerImpl* unclipped_desc_surface2 = |
| 9438 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9439 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9440 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9441 | |
| 9442 | unclipped_surface->SetDrawsContent(true); |
| 9443 | unclipped_desc_surface->SetDrawsContent(true); |
| 9444 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9445 | clipped_surface->SetDrawsContent(true); |
| 9446 | clip_child->SetClipParent(clip_parent); |
| 9447 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9448 | clip_children->insert(clip_child); |
| 9449 | clip_parent->SetClipChildren(clip_children.release()); |
| 9450 | |
| 9451 | gfx::Transform identity_matrix; |
| 9452 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9453 | gfx::PointF(), gfx::Size(80, 80), true, false, |
| 9454 | true); |
| 9455 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 9456 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 9457 | true, false, true); |
| 9458 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9459 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9460 | false); |
| 9461 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9462 | gfx::Point3F(), gfx::PointF(), |
| 9463 | gfx::Size(100, 100), true, false, true); |
| 9464 | SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix, |
| 9465 | gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60), |
| 9466 | true, false, true); |
| 9467 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9468 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9469 | false); |
| 9470 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 9471 | gfx::PointF(), gfx::Size(70, 70), true, false, |
| 9472 | true); |
| 9473 | clip_parent->SetMasksToBounds(true); |
| 9474 | unclipped_surface->SetMasksToBounds(true); |
| 9475 | unclipped_desc_surface->SetMasksToBounds(true); |
| 9476 | |
| 9477 | ExecuteCalculateDrawProperties(root); |
| 9478 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9479 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9480 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9481 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9482 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9483 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9484 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9485 | clipped_surface->render_surface()->content_rect()); |
| 9486 | } |
| 9487 | |
| 9488 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9489 | // Tests the value of render surface content rect when we have a layer that |
| 9490 | // clips between the clip parent's target and clip child's target. |
| 9491 | LayerImpl* root = root_layer(); |
| 9492 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9493 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9494 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9495 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9496 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9497 | |
| 9498 | clip_child->SetDrawsContent(true); |
| 9499 | unclipped_desc_surface->SetDrawsContent(true); |
| 9500 | clip_child->SetClipParent(clip_parent); |
| 9501 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9502 | clip_children->insert(clip_child); |
| 9503 | clip_parent->SetClipChildren(clip_children.release()); |
| 9504 | |
| 9505 | gfx::Transform identity_matrix; |
| 9506 | gfx::Transform translate; |
| 9507 | translate.Translate(10, 10); |
| 9508 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9509 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9510 | true); |
| 9511 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 9512 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9513 | true); |
| 9514 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9515 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9516 | false); |
| 9517 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9518 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9519 | false); |
| 9520 | SetLayerPropertiesForTesting(unclipped_desc_surface, translate, |
| 9521 | gfx::Point3F(), gfx::PointF(), |
| 9522 | gfx::Size(100, 100), true, false, true); |
| 9523 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9524 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9525 | false); |
| 9526 | surface->SetMasksToBounds(true); |
| 9527 | clip_layer->SetMasksToBounds(true); |
| 9528 | |
| 9529 | ExecuteCalculateDrawProperties(root); |
| 9530 | |
| 9531 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9532 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9533 | } |
| 9534 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9535 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
| 9536 | LayerImpl* root = root_layer(); |
| 9537 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9538 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9539 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9540 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9541 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9542 | |
| 9543 | clip_child->SetDrawsContent(true); |
| 9544 | unclipped_desc_surface->SetDrawsContent(true); |
| 9545 | clip_child->SetClipParent(clip_parent); |
| 9546 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9547 | clip_children->insert(clip_child); |
| 9548 | clip_parent->SetClipChildren(clip_children.release()); |
| 9549 | |
| 9550 | gfx::Transform identity_matrix; |
| 9551 | gfx::Transform scale; |
| 9552 | scale.Scale(2, 2); |
| 9553 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9554 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9555 | true); |
| 9556 | SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(), |
| 9557 | gfx::Size(100, 100), true, false, true); |
| 9558 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9559 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9560 | false); |
| 9561 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9562 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9563 | false); |
| 9564 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9565 | gfx::Point3F(), gfx::PointF(), |
| 9566 | gfx::Size(100, 100), true, false, true); |
| 9567 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9568 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9569 | false); |
| 9570 | surface->SetMasksToBounds(true); |
| 9571 | clip_layer->SetMasksToBounds(true); |
| 9572 | |
| 9573 | ExecuteCalculateDrawProperties(root); |
| 9574 | |
| 9575 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9576 | } |
| 9577 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9578 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
| 9579 | LayerImpl* root = root_layer(); |
| 9580 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9581 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9582 | |
| 9583 | const gfx::Transform identity_matrix; |
| 9584 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9585 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9586 | true); |
| 9587 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9588 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9589 | true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9590 | gfx::Transform translation; |
| 9591 | translation.Translate(10, 10); |
| 9592 | SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(), |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9593 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9594 | false); |
| 9595 | |
| 9596 | render_surface->SetMasksToBounds(true); |
| 9597 | test_layer->SetDrawsContent(true); |
| 9598 | test_layer->SetOpacity(0); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9599 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9600 | |
| 9601 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9602 | EXPECT_EQ(translation, test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9603 | } |
| 9604 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9605 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
| 9606 | LayerImpl* root = root_layer(); |
| 9607 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9608 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9609 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9610 | |
| 9611 | const gfx::Transform identity_matrix; |
| 9612 | clip_parent->SetMasksToBounds(true); |
| 9613 | render_surface->SetMasksToBounds(true); |
| 9614 | render_surface->SetDrawsContent(true); |
| 9615 | clip_child->SetDrawsContent(true); |
| 9616 | clip_child->SetClipParent(clip_parent); |
| 9617 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9618 | clip_children->insert(clip_child); |
| 9619 | clip_parent->SetClipChildren(clip_children.release()); |
| 9620 | |
| 9621 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9622 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9623 | true); |
| 9624 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9625 | gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true, |
| 9626 | false, false); |
| 9627 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9628 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9629 | true); |
| 9630 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9631 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9632 | false); |
| 9633 | |
| 9634 | ExecuteCalculateDrawProperties(root); |
| 9635 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect()); |
| 9636 | } |
| 9637 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9638 | TEST_F(LayerTreeHostCommonTest, |
| 9639 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
| 9640 | LayerImpl* root = root_layer(); |
| 9641 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9642 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9643 | const gfx::Transform identity_matrix; |
| 9644 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9645 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9646 | true); |
| 9647 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9648 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9649 | true); |
| 9650 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9651 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9652 | false); |
| 9653 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9654 | root->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9655 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9656 | render_surface->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9657 | test_layer->SetMasksToBounds(true); |
| 9658 | test_layer->SetDrawsContent(true); |
| 9659 | ExecuteCalculateDrawProperties(root); |
| 9660 | |
| 9661 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9662 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9663 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9664 | } |
| 9665 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9666 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9667 | // Tests that subtree is hidden is updated. |
| 9668 | LayerImpl* root = root_layer(); |
| 9669 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9670 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9671 | |
| 9672 | const gfx::Transform identity_matrix; |
| 9673 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9674 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9675 | true); |
| 9676 | SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(), |
| 9677 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9678 | false, true); |
| 9679 | SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(), |
| 9680 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9681 | true); |
| 9682 | |
| 9683 | hidden->SetHideLayerAndSubtree(true); |
| 9684 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9685 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9686 | |
| 9687 | hidden->SetHideLayerAndSubtree(false); |
| 9688 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9689 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9690 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9691 | } |
| 9692 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9693 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
| 9694 | LayerImpl* root = root_layer(); |
| 9695 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9696 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9697 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9698 | |
| 9699 | const gfx::Transform identity_matrix; |
| 9700 | clip_child->SetClipParent(root); |
| 9701 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9702 | clip_children->insert(clip_child); |
| 9703 | root->SetClipChildren(clip_children.release()); |
| 9704 | root->SetMasksToBounds(true); |
| 9705 | render_surface1->SetDrawsContent(true); |
| 9706 | render_surface2->SetDrawsContent(true); |
| 9707 | |
| 9708 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9709 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9710 | true); |
| 9711 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 9712 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9713 | false, true); |
| 9714 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9715 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9716 | true); |
| 9717 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9718 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9719 | false); |
| 9720 | ExecuteCalculateDrawProperties(root); |
| 9721 | |
| 9722 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9723 | // A clip node is created for every render surface and for layers that have |
| 9724 | // local clip. So, here it should be craeted for every layer. |
| 9725 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9726 | } |
| 9727 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9728 | TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) { |
| 9729 | // Tests that the mask layer gets its owning layer's screen space transform. |
| 9730 | LayerImpl* root = root_layer(); |
| 9731 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9732 | |
| 9733 | const gfx::Transform identity_matrix; |
| 9734 | gfx::Transform transform; |
| 9735 | transform.Translate(10, 10); |
| 9736 | |
| 9737 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9738 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9739 | true); |
| 9740 | SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(), |
| 9741 | gfx::Size(30, 30), true, false, false); |
| 9742 | root->SetDrawsContent(true); |
| 9743 | child->SetDrawsContent(false); |
| 9744 | child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9745 | ExecuteCalculateDrawProperties(root); |
| 9746 | |
| 9747 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9748 | child->mask_layer()->ScreenSpaceTransform()); |
| 9749 | transform.Translate(10, 10); |
| 9750 | child->SetTransform(transform); |
| 9751 | child->SetDrawsContent(true); |
| 9752 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9753 | ExecuteCalculateDrawProperties(root); |
| 9754 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9755 | child->mask_layer()->ScreenSpaceTransform()); |
| 9756 | } |
| 9757 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9758 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
| 9759 | LayerImpl* root = root_layer(); |
| 9760 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9761 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9762 | |
| 9763 | const gfx::Transform identity_matrix; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9764 | child->SetDrawsContent(true); |
| 9765 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9766 | |
| 9767 | gfx::Transform large_transform; |
| 9768 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9769 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9770 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9771 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9772 | |
| 9773 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9774 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9775 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9776 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9777 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9778 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9779 | // TODO(sunxd): we make child have no render surface, because if the |
| 9780 | // child has one, the large transform applied to child will result in NaNs in |
| 9781 | // the draw_transform of the render_surface, thus make draw property updates |
| 9782 | // skip the child layer. We need further investigation into this to know |
| 9783 | // what exactly happens here. |
| 9784 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9785 | gfx::PointF(), gfx::Size(30, 30), true, false, |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9786 | false); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9787 | |
| 9788 | ExecuteCalculateDrawProperties(root); |
| 9789 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9790 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9791 | render_surface1->render_surface()->DrawableContentRect()); |
| 9792 | |
| 9793 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9794 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9795 | EXPECT_TRUE(is_inf_or_nan); |
| 9796 | |
| 9797 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9798 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9799 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9800 | |
| 9801 | std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); |
| 9802 | bool root_in_rsll = |
| 9803 | std::find(rsll->begin(), rsll->end(), root) != rsll->end(); |
| 9804 | EXPECT_TRUE(root_in_rsll); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9805 | } |
| 9806 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9807 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9808 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9809 | scroll.layer_id = 2; |
| 9810 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9811 | |
| 9812 | proto::ScrollUpdateInfo proto; |
| 9813 | scroll.ToProtobuf(&proto); |
| 9814 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9815 | new_scroll.FromProtobuf(proto); |
| 9816 | |
| 9817 | EXPECT_EQ(scroll, new_scroll); |
| 9818 | } |
| 9819 | |
| 9820 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9821 | ScrollAndScaleSet scroll_and_scale_set; |
| 9822 | |
| 9823 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9824 | scroll1.layer_id = 1; |
| 9825 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9826 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9827 | scroll2.layer_id = 2; |
| 9828 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9829 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9830 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9831 | |
| 9832 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9833 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 9834 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 9835 | |
| 9836 | proto::ScrollAndScaleSet proto; |
| 9837 | scroll_and_scale_set.ToProtobuf(&proto); |
| 9838 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 9839 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 9840 | |
| 9841 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 9842 | } |
| 9843 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9844 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9845 | // Test the behavior of scroll tree builder |
| 9846 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9847 | // +root1(1)[inner_viewport_container_layer] |
| 9848 | // +-page_scale_layer |
| 9849 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9850 | // scrollable, inner_viewport_scroll_layer] |
| 9851 | // +------child6(6)[kScrollbarScrolling] |
| 9852 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9853 | // +----parent3(3) |
| 9854 | // +------child7(7)[scrollable] |
| 9855 | // +------child8(8)[scroll_parent=7] |
| 9856 | // +--------grand_child11(11)[scrollable] |
| 9857 | // +----parent4(4) |
| 9858 | // +------child9(9) |
| 9859 | // +--------grand_child12(12) |
| 9860 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9861 | // |
| 9862 | // Expected scroll tree topology: |
| 9863 | // +property_tree_root---owner:-1 |
| 9864 | // +--root---owner:1, id:1 |
| 9865 | // +----node---owner:2, id:2 |
| 9866 | // +------node---owner:6, id:3 |
| 9867 | // +----node---owner:7, id:4 |
| 9868 | // +------node---owner:11, id:5 |
| 9869 | // +----node---owner:5, id:6 |
| 9870 | // |
| 9871 | // Extra check: |
| 9872 | // scroll_tree_index() of: |
| 9873 | // grand_child10:3 |
| 9874 | // parent3:1 |
| 9875 | // child8:4 |
| 9876 | // parent4:1 |
| 9877 | // child9:1 |
| 9878 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9879 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 9880 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 9881 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 9882 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 9883 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 9884 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 9885 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 9886 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 9887 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 9888 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 9889 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 9890 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 9891 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9892 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9893 | root1->AddChild(page_scale_layer); |
| 9894 | page_scale_layer->AddChild(parent2); |
| 9895 | page_scale_layer->AddChild(parent3); |
| 9896 | page_scale_layer->AddChild(parent4); |
| 9897 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9898 | parent2->AddChild(child6); |
| 9899 | parent3->AddChild(child7); |
| 9900 | parent3->AddChild(child8); |
| 9901 | parent4->AddChild(child9); |
| 9902 | child6->AddChild(grand_child10); |
| 9903 | child8->AddChild(grand_child11); |
| 9904 | child9->AddChild(grand_child12); |
| 9905 | host()->SetRootLayer(root1); |
| 9906 | |
| 9907 | parent2->AddMainThreadScrollingReasons( |
| 9908 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9909 | parent2->AddMainThreadScrollingReasons( |
| 9910 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9911 | parent2->SetScrollClipLayerId(root1->id()); |
| 9912 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9913 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9914 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9915 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9916 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9917 | child7->SetScrollClipLayerId(parent3->id()); |
| 9918 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9919 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9920 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9921 | |
| 9922 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9923 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9924 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9925 | host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9926 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 9927 | |
| 9928 | const int kInvalidPropertyTreeNodeId = -1; |
| 9929 | const int kRootPropertyTreeNodeId = 0; |
| 9930 | |
| 9931 | // Property tree root |
| 9932 | ScrollTree scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 9933 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 9934 | property_trees.is_main_thread = true; |
| 9935 | property_trees.is_active = false; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 9936 | ScrollTree expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9937 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 9938 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 9939 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 9940 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
| 9941 | property_tree_root->data.scrollable = false; |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9942 | property_tree_root->data.main_thread_scrolling_reasons = |
| 9943 | MainThreadScrollingReason::kNotScrollingOnMain; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9944 | property_tree_root->data.contains_non_fast_scrollable_region = false; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9945 | property_tree_root->data.transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9946 | |
| 9947 | // The node owned by root1 |
| 9948 | ScrollNode scroll_root1; |
| 9949 | scroll_root1.id = 1; |
| 9950 | scroll_root1.owner_id = root1->id(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 9951 | scroll_root1.data.user_scrollable_horizontal = true; |
| 9952 | scroll_root1.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9953 | scroll_root1.data.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9954 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 9955 | |
| 9956 | // The node owned by parent2 |
| 9957 | ScrollNode scroll_parent2; |
| 9958 | scroll_parent2.id = 2; |
| 9959 | scroll_parent2.owner_id = parent2->id(); |
| 9960 | scroll_parent2.data.scrollable = true; |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9961 | scroll_parent2.data.main_thread_scrolling_reasons = |
| 9962 | parent2->main_thread_scrolling_reasons(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9963 | scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds(); |
| 9964 | scroll_parent2.data.bounds = parent2->bounds(); |
| 9965 | scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true; |
| 9966 | scroll_parent2.data.is_inner_viewport_scroll_layer = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 9967 | scroll_parent2.data.user_scrollable_horizontal = true; |
| 9968 | scroll_parent2.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9969 | scroll_parent2.data.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9970 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 9971 | |
| 9972 | // The node owned by child6 |
| 9973 | ScrollNode scroll_child6; |
| 9974 | scroll_child6.id = 3; |
| 9975 | scroll_child6.owner_id = child6->id(); |
sunxd | 29f17bf42 | 2016-02-03 02:47:48 | [diff] [blame] | 9976 | scroll_child6.data.main_thread_scrolling_reasons = |
| 9977 | child6->main_thread_scrolling_reasons(); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9978 | scroll_child6.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 9979 | scroll_child6.data.user_scrollable_horizontal = true; |
| 9980 | scroll_child6.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9981 | scroll_child6.data.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9982 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 9983 | |
| 9984 | // The node owned by child7, child7 also owns a transform node |
| 9985 | ScrollNode scroll_child7; |
| 9986 | scroll_child7.id = 4; |
| 9987 | scroll_child7.owner_id = child7->id(); |
| 9988 | scroll_child7.data.scrollable = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9989 | scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds(); |
| 9990 | scroll_child7.data.bounds = child7->bounds(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 9991 | scroll_child7.data.user_scrollable_horizontal = true; |
| 9992 | scroll_child7.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 9993 | scroll_child7.data.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9994 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 9995 | |
| 9996 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 9997 | ScrollNode scroll_grand_child11; |
| 9998 | scroll_grand_child11.id = 5; |
| 9999 | scroll_grand_child11.owner_id = grand_child11->id(); |
| 10000 | scroll_grand_child11.data.scrollable = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10001 | scroll_grand_child11.data.user_scrollable_horizontal = true; |
| 10002 | scroll_grand_child11.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10003 | scroll_grand_child11.data.transform_id = |
| 10004 | grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10005 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10006 | |
| 10007 | // The node owned by parent5 |
| 10008 | ScrollNode scroll_parent5; |
| 10009 | scroll_parent5.id = 8; |
| 10010 | scroll_parent5.owner_id = parent5->id(); |
| 10011 | scroll_parent5.data.contains_non_fast_scrollable_region = true; |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10012 | scroll_parent5.data.bounds = gfx::Size(10, 10); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10013 | scroll_parent5.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10014 | scroll_parent5.data.user_scrollable_horizontal = true; |
| 10015 | scroll_parent5.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10016 | scroll_parent5.data.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10017 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10018 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10019 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10020 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10021 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10022 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10023 | expected_scroll_tree.set_needs_update(false); |
| 10024 | |
| 10025 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10026 | |
| 10027 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10028 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10029 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10030 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10031 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10032 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10033 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10034 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10035 | } |
| 10036 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10037 | } // namespace |
| 10038 | } // namespace cc |