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> |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 11 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 13 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 15 | #include "cc/animation/animation_host.h" |
| 16 | #include "cc/animation/animation_id_provider.h" |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 17 | #include "cc/animation/animation_player.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 18 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 19 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 20 | #include "cc/base/math_util.h" |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 21 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 24 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 25 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 26 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 27 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 28 | #include "cc/output/copy_output_request.h" |
| 29 | #include "cc/output/copy_output_result.h" |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 30 | #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 31 | #include "cc/proto/gfx_conversions.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 32 | #include "cc/test/animation_test_common.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 33 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 34 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 35 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 36 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 37 | #include "cc/test/fake_output_surface.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 38 | #include "cc/test/fake_picture_layer.h" |
| 39 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 40 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 41 | #include "cc/test/layer_tree_host_common_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 42 | #include "cc/test/test_task_graph_runner.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 43 | #include "cc/trees/draw_property_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 44 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 45 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 46 | #include "cc/trees/task_runner_provider.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 47 | #include "testing/gmock/include/gmock/gmock.h" |
| 48 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 49 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 50 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 51 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 53 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 54 | namespace { |
| 55 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 56 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 57 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 58 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 60 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 61 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 62 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 63 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 64 | }; |
| 65 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 66 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 67 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 68 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 69 | public: |
| 70 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 71 | ~MockContentLayerClient() override {} |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 72 | gfx::Rect PaintableRegion() override { return gfx::Rect(); } |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 73 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 74 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 75 | NOTIMPLEMENTED(); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 76 | return nullptr; |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 77 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 78 | bool FillsBoundsCompletely() const override { return false; } |
jbroman | 9f60f1a | 2015-07-16 21:40:32 | [diff] [blame] | 79 | size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 80 | }; |
| 81 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 82 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 83 | do { \ |
| 84 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 85 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 86 | } while (false) |
| 87 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 88 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 89 | do { \ |
| 90 | EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \ |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 91 | } while (false) |
| 92 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 93 | class LayerTreeSettingsScaleContent : public LayerTreeSettings { |
| 94 | public: |
| 95 | LayerTreeSettingsScaleContent() { |
| 96 | layer_transforms_should_scale_layer_contents = true; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest { |
| 101 | public: |
| 102 | LayerTreeHostCommonScalingTest() |
| 103 | : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {} |
| 104 | }; |
| 105 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 106 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 107 | public: |
| 108 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 109 | |
| 110 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 111 | const gfx::Rect& target_rect, |
| 112 | const gfx::Transform& layer_transform, |
| 113 | const gfx::Rect& layer_rect) { |
| 114 | LayerImpl* root = root_layer(); |
| 115 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 116 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 117 | |
| 118 | root->SetDrawsContent(true); |
| 119 | target->SetDrawsContent(true); |
| 120 | target->SetMasksToBounds(true); |
| 121 | drawing_layer->SetDrawsContent(true); |
| 122 | |
| 123 | gfx::Transform identity; |
| 124 | |
| 125 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 126 | gfx::Size(500, 500), true, false, true); |
| 127 | SetLayerPropertiesForTesting(target, identity, gfx::Point3F(), |
| 128 | gfx::PointF(target_rect.origin()), |
| 129 | target_rect.size(), true, false, true); |
| 130 | SetLayerPropertiesForTesting(drawing_layer, layer_transform, gfx::Point3F(), |
| 131 | gfx::PointF(layer_rect.origin()), |
| 132 | layer_rect.size(), true, false, false); |
| 133 | |
| 134 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 135 | ExecuteCalculateDrawProperties(root); |
| 136 | |
| 137 | return drawing_layer; |
| 138 | } |
| 139 | }; |
| 140 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 141 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 142 | // Sanity check: For layers positioned at zero, with zero size, |
| 143 | // and with identity transforms, then the draw transform, |
| 144 | // screen space transform, and the hierarchy passed on to children |
| 145 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 147 | LayerImpl* parent = root_layer(); |
| 148 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 149 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 150 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 151 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 152 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 153 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 154 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 155 | gfx::PointF(), gfx::Size(), true, false); |
| 156 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 157 | gfx::PointF(), gfx::Size(), true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 158 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 159 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 160 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 161 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 162 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 163 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 164 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 165 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 166 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 167 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 168 | } |
| 169 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 170 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 171 | // Tests that effect tree node gets a valid transform id when a layer |
| 172 | // has opacity but doesn't create a render surface. |
| 173 | LayerImpl* parent = root_layer(); |
| 174 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 175 | child->SetDrawsContent(true); |
| 176 | |
| 177 | gfx::Transform identity_matrix; |
| 178 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 179 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 180 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 181 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
| 182 | false); |
| 183 | child->SetOpacity(0.f); |
| 184 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 185 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 186 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 187 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 188 | const int transform_tree_size = parent->layer_tree_impl() |
| 189 | ->property_trees() |
| 190 | ->transform_tree.next_available_id(); |
| 191 | EXPECT_LT(node->data.transform_id, transform_tree_size); |
| 192 | } |
| 193 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 194 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 195 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 196 | LayerImpl* root = root_layer(); |
| 197 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 198 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 199 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 200 | gfx::PointF(), gfx::Size(1, 2), true, false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 201 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 202 | TransformTree& tree = |
| 203 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 204 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 205 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 206 | // transform or the screenspace transform. |
| 207 | gfx::Transform translation_to_center; |
| 208 | translation_to_center.Translate(5.0, 6.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 209 | SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 210 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 211 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 212 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 213 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 214 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 215 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 216 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 217 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 218 | // no effect on the transforms. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 219 | SetLayerPropertiesForTesting(layer, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 220 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 221 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 222 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 223 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 224 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 225 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 226 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 227 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 228 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 229 | // Case 4: A change in actual position affects both the draw transform and |
| 230 | // screen space transform. |
| 231 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 232 | position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 233 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 234 | layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 235 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 236 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 237 | ExecuteCalculateDrawProperties(root); |
| 238 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 239 | position_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 240 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 241 | position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 242 | draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 243 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 244 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 245 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 246 | // scale transform, because scale and translation are not commutative. |
| 247 | gfx::Transform layer_transform; |
| 248 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 249 | SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 250 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 251 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 252 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 253 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 254 | layer_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 255 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 256 | layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 257 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 258 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 259 | gfx::Transform translation_to_anchor; |
| 260 | translation_to_anchor.Translate(5.0, 0.0); |
| 261 | gfx::Transform expected_result = |
| 262 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 263 | SetLayerPropertiesForTesting(layer, layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 264 | gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(), |
| 265 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 266 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 267 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 268 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 269 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 270 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 271 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 272 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 273 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 274 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 275 | // it is still worth testing to detect accidental regressions. |
| 276 | expected_result = position_transform * translation_to_anchor * |
| 277 | layer_transform * Inverse(translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 278 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 279 | layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 280 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 281 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 282 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 283 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 284 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 285 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 286 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 289 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 290 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 291 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 292 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 293 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 294 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 295 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 296 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 297 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 298 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 299 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 300 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 301 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 302 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 303 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 304 | gfx::Transform identity_matrix; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 305 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 306 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 307 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 308 | sublayer->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 309 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 310 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 311 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 312 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 313 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 314 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 315 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 316 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 317 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 318 | false); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 319 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 320 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 321 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 322 | |
| 323 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 324 | clip_layer->SetBounds( |
| 325 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 326 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 327 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 328 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 329 | gfx::Transform impl_transform; |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 330 | scroll_layer->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 331 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 332 | clip_layer->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 333 | scroll_layer_raw_ptr->layer_tree_impl() |
| 334 | ->property_trees() |
| 335 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 336 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 337 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 338 | std::unique_ptr<LayerImpl> root( |
| 339 | LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 340 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 341 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 342 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 343 | root->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 344 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 345 | LayerImpl* root_layer = root.get(); |
| 346 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 347 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 348 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 349 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 350 | gfx::Transform expected_transform = identity_matrix; |
| 351 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 352 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 353 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 354 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 355 | page_scale * kDeviceScale)); |
| 356 | expected_transform.Scale(page_scale * kDeviceScale, |
| 357 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 358 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 359 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 360 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 361 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 362 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 363 | gfx::Transform arbitrary_translate; |
| 364 | const float kTranslateX = 10.6f; |
| 365 | const float kTranslateY = 20.6f; |
| 366 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 367 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 368 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 369 | true, false, false); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 370 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 371 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 372 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 373 | expected_transform.MakeIdentity(); |
| 374 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 375 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 376 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 377 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 378 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 379 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 380 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 381 | expected_transform.Scale(page_scale * kDeviceScale, |
| 382 | page_scale * kDeviceScale); |
| 383 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 384 | sublayer->DrawTransform()); |
| 385 | |
| 386 | // Test that page scale is updated even when we don't rebuild property trees. |
| 387 | page_scale = 1.888f; |
| 388 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 389 | Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID, |
| 390 | Layer::INVALID_ID); |
| 391 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 392 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 393 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 394 | scroll_layer->parent()); |
| 395 | |
| 396 | expected_transform.MakeIdentity(); |
| 397 | expected_transform.Translate( |
| 398 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 399 | sub_layer_screen_position.x() * page_scale * |
| 400 | kDeviceScale), |
| 401 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 402 | sub_layer_screen_position.y() * page_scale * |
| 403 | kDeviceScale)); |
| 404 | expected_transform.Scale(page_scale * kDeviceScale, |
| 405 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 406 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 407 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 410 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 411 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 412 | LayerImpl* root = root_layer(); |
| 413 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 414 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 415 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 416 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 417 | // One-time setup of root layer |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 418 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 419 | gfx::PointF(), gfx::Size(1, 2), true, false); |
| 420 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 421 | TransformTree& tree = |
| 422 | host_impl()->active_tree()->property_trees()->transform_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 424 | // Case 1: parent's anchor point should not affect child or grand_child. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 425 | SetLayerPropertiesForTesting(parent, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 426 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 427 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 428 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 429 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 430 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 431 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 432 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 433 | |
| 434 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 435 | identity_matrix, draw_property_utils::DrawTransform(child, tree)); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 437 | identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree)); |
| 438 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 439 | identity_matrix, draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 440 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 441 | identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 442 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | // Case 2: parent's position affects child and grand_child. |
| 445 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 446 | parent_position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 447 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 448 | parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 449 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 450 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 451 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 452 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 453 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 454 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 455 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 456 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 457 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 458 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 459 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 460 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 461 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 462 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 463 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 464 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 465 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 466 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 467 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 468 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 469 | // Case 3: parent's local transform affects child and grandchild |
| 470 | gfx::Transform parent_layer_transform; |
| 471 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 472 | gfx::Transform parent_translation_to_anchor; |
| 473 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 474 | gfx::Transform parent_composite_transform = |
| 475 | parent_translation_to_anchor * parent_layer_transform * |
| 476 | Inverse(parent_translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 477 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 478 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 479 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 480 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 481 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 482 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 483 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 484 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 485 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 486 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 487 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 488 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 489 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 490 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 491 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 492 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 493 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 494 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 495 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 496 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 497 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 498 | } |
| 499 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 500 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 501 | LayerImpl* root = root_layer(); |
| 502 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 503 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 504 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 505 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 507 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 508 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 509 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 510 | true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 511 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 512 | // Child is set up so that a new render surface should be created. |
| 513 | child->SetOpacity(0.5f); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 514 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 515 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 516 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 517 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 518 | gfx::Transform parent_translation_to_anchor; |
| 519 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 520 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 521 | gfx::Transform parent_composite_transform = |
| 522 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 523 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 524 | gfx::Vector2dF parent_composite_scale = |
| 525 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 526 | 1.f); |
| 527 | gfx::Transform surface_sublayer_transform; |
| 528 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 529 | parent_composite_scale.y()); |
| 530 | gfx::Transform surface_sublayer_composite_transform = |
| 531 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 532 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 533 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 534 | gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(), |
| 535 | gfx::Size(100, 120), true, false, false); |
| 536 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 537 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 538 | true); |
| 539 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 540 | gfx::PointF(), gfx::Size(8, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 541 | false); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 542 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 544 | // Render surface should have been created now. |
| 545 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 546 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 547 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 548 | // The child layer's draw transform should refer to its new render surface. |
| 549 | // The screen-space transform, however, should still refer to the root. |
| 550 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 551 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 552 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 553 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 554 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 555 | // Because the grand_child is the only drawable content, the child's render |
| 556 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 557 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 558 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 559 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 560 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 561 | // The screen space is the same as the target since the child surface draws |
| 562 | // into the root. |
| 563 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 564 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 565 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 566 | } |
| 567 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 568 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
| 569 | LayerImpl* root = root_layer(); |
| 570 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 571 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 572 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 573 | grand_child->SetDrawsContent(true); |
| 574 | |
| 575 | gfx::Transform identity_matrix; |
| 576 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 577 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 578 | true); |
| 579 | |
| 580 | gfx::Transform parent_transform; |
| 581 | parent_transform.Translate(10.0, 10.0); |
| 582 | |
| 583 | gfx::Transform child_transform; |
| 584 | child_transform.Rotate(45.0); |
| 585 | |
| 586 | // child gets a render surface when surfaces are enabled. |
| 587 | SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(), |
| 588 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 589 | false); |
| 590 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 591 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 592 | true); |
| 593 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 594 | gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true, |
| 595 | false, false); |
| 596 | |
| 597 | gfx::Transform expected_grand_child_screen_space_transform; |
| 598 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 599 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 600 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 601 | |
| 602 | // First compute draw properties with separate surfaces enabled. |
| 603 | ExecuteCalculateDrawProperties(root); |
| 604 | |
| 605 | // The grand child's draw transform should be its offset wrt the child. |
| 606 | gfx::Transform expected_grand_child_draw_transform; |
| 607 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 608 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 609 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 610 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 611 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 612 | |
| 613 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 614 | |
| 615 | // With separate surfaces disabled, the grand child's draw transform should be |
| 616 | // the same as its screen space transform. |
| 617 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 618 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 619 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 620 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 623 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 624 | LayerImpl* root = root_layer(); |
| 625 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 626 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 627 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 628 | grand_child->SetDrawsContent(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 629 | std::unique_ptr<LayerImpl> child_replica = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 630 | LayerImpl::Create(host_impl()->active_tree(), 100); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 631 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 632 | // One-time setup of root layer |
| 633 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 634 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 635 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 636 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 637 | |
| 638 | // Child is set up so that a new render surface should be created. |
| 639 | child->SetOpacity(0.5f); |
| 640 | |
| 641 | gfx::Transform parent_layer_transform; |
| 642 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 643 | gfx::Transform parent_translation_to_anchor; |
| 644 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 645 | gfx::Transform parent_composite_transform = |
| 646 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 647 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 648 | gfx::Transform replica_layer_transform; |
| 649 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 650 | gfx::Vector2dF parent_composite_scale = |
| 651 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 652 | 1.f); |
| 653 | gfx::Transform surface_sublayer_transform; |
| 654 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 655 | parent_composite_scale.y()); |
| 656 | gfx::Transform replica_composite_transform = |
| 657 | parent_composite_transform * replica_layer_transform * |
| 658 | Inverse(surface_sublayer_transform); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 659 | child_replica->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | // Child's render surface should not exist yet. |
| 661 | ASSERT_FALSE(child->render_surface()); |
| 662 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 663 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 664 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 665 | gfx::Size(10, 12), true, false, false); |
| 666 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 667 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 668 | true); |
| 669 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 670 | gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true, |
| 671 | false, false); |
| 672 | SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform, |
| 673 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 674 | false, false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 675 | child->SetReplicaLayer(std::move(child_replica)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 676 | |
| 677 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 678 | |
| 679 | // Render surface should have been created now. |
| 680 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 681 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 682 | |
| 683 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 684 | replica_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 685 | child->render_target()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 687 | child->render_target() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 688 | ->replica_screen_space_transform()); |
| 689 | } |
| 690 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 691 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 692 | // This test creates a more complex tree and verifies it all at once. This |
| 693 | // covers the following cases: |
| 694 | // - layers that are described w.r.t. a render surface: should have draw |
| 695 | // transforms described w.r.t. that surface |
| 696 | // - A render surface described w.r.t. an ancestor render surface: should |
| 697 | // have a draw transform described w.r.t. that ancestor surface |
| 698 | // - Replicas of a render surface are described w.r.t. the replica's |
| 699 | // transform around its anchor, along with the surface itself. |
| 700 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 701 | // a render surface that is described w.r.t. an ancestor render surface. |
| 702 | // - verifying that each layer has a reference to the correct render surface |
| 703 | // and render target values. |
| 704 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 705 | LayerImpl* root = root_layer(); |
| 706 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 707 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 708 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 709 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 710 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 711 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 712 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 713 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 714 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 715 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 716 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 717 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 718 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 719 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 720 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 721 | grand_child_of_rs1->SetDrawsContent(true); |
| 722 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 723 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 724 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 725 | std::unique_ptr<LayerImpl> replica_of_rs1 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 726 | LayerImpl::Create(host_impl()->active_tree(), 101); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 727 | std::unique_ptr<LayerImpl> replica_of_rs2 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 728 | LayerImpl::Create(host_impl()->active_tree(), 102); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 729 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 730 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 731 | // to have a new render surface. |
| 732 | render_surface1->SetOpacity(0.5f); |
| 733 | render_surface2->SetOpacity(0.33f); |
| 734 | |
| 735 | // One-time setup of root layer |
| 736 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 737 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 738 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 739 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 740 | |
| 741 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 742 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 743 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 744 | gfx::Transform translation_to_anchor; |
| 745 | translation_to_anchor.Translate(2.5, 0.0); |
| 746 | gfx::Transform layer_transform; |
| 747 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 748 | gfx::Transform replica_layer_transform; |
| 749 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 750 | |
| 751 | gfx::Transform A = |
| 752 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 753 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 754 | Inverse(translation_to_anchor); |
| 755 | |
| 756 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 757 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 758 | gfx::Transform surface1_sublayer_transform; |
| 759 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 760 | surface1_parent_transform_scale.y()); |
| 761 | |
| 762 | // SS1 = transform given to the subtree of render_surface1 |
| 763 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 764 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 765 | // the owning layer |
| 766 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 767 | |
| 768 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 769 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 770 | gfx::Transform surface2_sublayer_transform; |
| 771 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 772 | surface2_parent_transform_scale.y()); |
| 773 | |
| 774 | // SS2 = transform given to the subtree of render_surface2 |
| 775 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 776 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 777 | // the owning layer |
| 778 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 779 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 780 | SetLayerPropertiesForTesting(parent, layer_transform, |
| 781 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 782 | gfx::Size(10, 10), true, false, false); |
| 783 | SetLayerPropertiesForTesting(render_surface1, layer_transform, |
| 784 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 785 | gfx::Size(10, 10), true, false, true); |
| 786 | SetLayerPropertiesForTesting(render_surface2, layer_transform, |
| 787 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 788 | gfx::Size(10, 10), true, false, true); |
| 789 | SetLayerPropertiesForTesting(child_of_root, layer_transform, |
| 790 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 791 | gfx::Size(10, 10), true, false, false); |
| 792 | SetLayerPropertiesForTesting(child_of_rs1, layer_transform, |
| 793 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 794 | gfx::Size(10, 10), true, false, false); |
| 795 | SetLayerPropertiesForTesting(child_of_rs2, 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_root, layer_transform, |
| 799 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 800 | gfx::Size(10, 10), true, false, false); |
| 801 | SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform, |
| 802 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 803 | gfx::Size(10, 10), true, false, false); |
| 804 | SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform, |
| 805 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 806 | gfx::Size(10, 10), true, false, false); |
| 807 | SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform, |
| 808 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 809 | gfx::Size(), true, false, false); |
| 810 | SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform, |
| 811 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 812 | gfx::Size(), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 813 | |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 814 | // We need to set parent on replica layers for property tree building. |
| 815 | replica_of_rs1->SetParent(render_surface1); |
| 816 | replica_of_rs2->SetParent(render_surface2); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 817 | render_surface1->SetReplicaLayer(std::move(replica_of_rs1)); |
| 818 | render_surface2->SetReplicaLayer(std::move(replica_of_rs2)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 819 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 820 | |
| 821 | // Only layers that are associated with render surfaces should have an actual |
| 822 | // RenderSurface() value. |
| 823 | ASSERT_TRUE(root->render_surface()); |
| 824 | ASSERT_FALSE(child_of_root->render_surface()); |
| 825 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 826 | |
| 827 | ASSERT_TRUE(render_surface1->render_surface()); |
| 828 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 829 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 830 | |
| 831 | ASSERT_TRUE(render_surface2->render_surface()); |
| 832 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 833 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 834 | |
| 835 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 836 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 837 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 838 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 839 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 840 | EXPECT_EQ(render_surface1->render_surface(), |
| 841 | render_surface1->render_target()); |
| 842 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 843 | EXPECT_EQ(render_surface1->render_surface(), |
| 844 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 845 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 846 | EXPECT_EQ(render_surface2->render_surface(), |
| 847 | render_surface2->render_target()); |
| 848 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 849 | EXPECT_EQ(render_surface2->render_surface(), |
| 850 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 851 | |
| 852 | // Verify layer draw transforms note that draw transforms are described with |
| 853 | // respect to the nearest ancestor render surface but screen space transforms |
| 854 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 855 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 856 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 857 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 858 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 859 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 860 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 861 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 862 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 863 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 864 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 865 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 866 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 867 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 868 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 869 | |
| 870 | // Verify layer screen-space transforms |
| 871 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 872 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 873 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 874 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 875 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 876 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 877 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 878 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 879 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 880 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 881 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 882 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 883 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 884 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 885 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 886 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 887 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 888 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 889 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 890 | |
| 891 | // Verify render surface transforms. |
| 892 | // |
| 893 | // Draw transform of render surface 1 is described with respect to root. |
| 894 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 895 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 896 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 897 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 898 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 899 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 900 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 901 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 902 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 903 | // Draw transform of render surface 2 is described with respect to render |
| 904 | // surface 1. |
| 905 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 906 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 907 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 908 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 909 | render_surface2->render_surface()->replica_draw_transform()); |
| 910 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 911 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 912 | render_surface2->render_surface()->screen_space_transform()); |
| 913 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 914 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 915 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 916 | |
| 917 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 918 | // is expected that we correctly set up transforms so that the y-component of |
| 919 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 920 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 921 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 922 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 923 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 924 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 925 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 926 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 927 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 928 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 929 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 930 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 931 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 932 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 933 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 934 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 936 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 937 | } |
| 938 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 939 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 940 | // For layers that flatten their subtree, there should be an orthographic |
| 941 | // projection (for x and y values) in the middle of the transform sequence. |
| 942 | // Note that the way the code is currently implemented, it is not expected to |
| 943 | // use a canonical orthographic projection. |
| 944 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 945 | LayerImpl* root = root_layer(); |
| 946 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 947 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 948 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 949 | grand_child->SetDrawsContent(true); |
| 950 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 951 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 952 | |
| 953 | gfx::Transform rotation_about_y_axis; |
| 954 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 955 | |
| 956 | const gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 957 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 958 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 959 | true); |
| 960 | SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(), |
| 961 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 962 | true); |
| 963 | SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis, |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 964 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 965 | true, false, false); |
| 966 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 967 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 968 | true, false, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 970 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 971 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 972 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 973 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 974 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 975 | |
| 976 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 977 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 978 | gfx::Transform expected_grand_child_draw_transform = |
| 979 | rotation_about_y_axis; // draws onto child's render surface |
| 980 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 981 | flattened_rotation_about_y.FlattenTo2d(); |
| 982 | gfx::Transform expected_grand_child_screen_space_transform = |
| 983 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 984 | gfx::Transform expected_great_grand_child_draw_transform = |
| 985 | flattened_rotation_about_y; |
| 986 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 987 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 988 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 989 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 990 | |
| 991 | // The child's draw transform should have been taken by its surface. |
| 992 | ASSERT_TRUE(child->render_surface()); |
| 993 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 994 | child->render_surface()->draw_transform()); |
| 995 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 996 | expected_child_screen_space_transform, |
| 997 | child->render_surface()->screen_space_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 998 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 999 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1000 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1002 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1003 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1004 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1005 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1006 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1007 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1008 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1009 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1010 | } |
| 1011 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1012 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1013 | LayerImpl* root = root_layer(); |
| 1014 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1015 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1016 | |
| 1017 | gfx::Transform child_transform; |
| 1018 | child_transform.Translate(50.0, 50.0); |
| 1019 | child_transform.RotateAboutZAxis(30.0); |
| 1020 | |
| 1021 | gfx::Transform grand_child_transform; |
| 1022 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1023 | |
| 1024 | const gfx::Transform identity_matrix; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1025 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1026 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 1027 | true); |
| 1028 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 1029 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1030 | false); |
| 1031 | SetLayerPropertiesForTesting(grand_child, grand_child_transform, |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1032 | gfx::Point3F(), gfx::PointF(), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1033 | gfx::Size(100, 100), true, false, false); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1034 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1035 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1036 | grand_child->SetDrawsContent(true); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1037 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1038 | ExecuteCalculateDrawProperties(root); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1039 | |
| 1040 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1041 | // that is fully contained within the target's bounds, so grand_child should |
| 1042 | // be considered fully visible. |
| 1043 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1044 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1045 | } |
| 1046 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1047 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1048 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1049 | // skipping a necessary translation. Without that translation, the coordinate |
| 1050 | // space of the layer's draw transform is incorrect. |
| 1051 | // |
| 1052 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1053 | // but if that layer becomes a render surface, then its draw transform is |
| 1054 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1055 | // incorrectly as a result. |
| 1056 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1057 | LayerImpl* root = root_layer(); |
| 1058 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1059 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1060 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1061 | |
| 1062 | // The child height is zero, but has non-zero width that should be accounted |
| 1063 | // for while computing draw transforms. |
| 1064 | const gfx::Transform identity_matrix; |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1065 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1066 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1067 | true); |
| 1068 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1069 | gfx::PointF(), gfx::Size(10, 0), true, false, |
| 1070 | true); |
| 1071 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1072 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1073 | false); |
| 1074 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1075 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1077 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1078 | // This is the real test, the rest are sanity checks. |
| 1079 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1080 | child->render_surface()->draw_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1081 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1083 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1084 | } |
| 1085 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1086 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
| 1087 | const gfx::Transform identity_matrix; |
| 1088 | LayerImpl* root = root_layer(); |
| 1089 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1090 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1091 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1092 | |
| 1093 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1094 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1095 | true); |
| 1096 | gfx::Transform translate; |
| 1097 | translate.Translate3d(5, 5, 5); |
| 1098 | SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(), |
| 1099 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1100 | true); |
| 1101 | SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(), |
| 1102 | gfx::Size(100, 100), true, false, false); |
| 1103 | SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(), |
| 1104 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1105 | false); |
| 1106 | grand_child->SetDrawsContent(true); |
| 1107 | |
| 1108 | // render_surface will have a sublayer scale because of device scale factor. |
| 1109 | float device_scale_factor = 2.0f; |
| 1110 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1111 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1112 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1113 | inputs.device_scale_factor = device_scale_factor; |
| 1114 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1115 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1116 | |
| 1117 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1118 | // by a factor of 2. |
| 1119 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1120 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1121 | expected_translation); |
| 1122 | } |
| 1123 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1124 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1125 | // Transformations applied at the root of the tree should be forwarded |
| 1126 | // to child layers instead of applied to the root RenderSurface. |
| 1127 | const gfx::Transform identity_matrix; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1128 | LayerImpl* root = root_layer(); |
| 1129 | root->SetDrawsContent(true); |
| 1130 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1131 | child->SetDrawsContent(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1132 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1133 | child->SetScrollClipLayer(root->id()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1134 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1135 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1136 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1137 | true); |
| 1138 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1139 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1140 | false); |
| 1141 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1142 | gfx::Transform translate; |
| 1143 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1144 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1145 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1146 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1147 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1148 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1149 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1150 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1151 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1152 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1153 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1154 | |
| 1155 | gfx::Transform scale; |
| 1156 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1157 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1158 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1159 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1160 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1161 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1162 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1163 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1164 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1165 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1166 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1167 | |
| 1168 | gfx::Transform rotate; |
| 1169 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1170 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1171 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1172 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1173 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1174 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1175 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&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; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1187 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1188 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1189 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1190 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1191 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1192 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1193 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1194 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1195 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1196 | // Verify it composes correctly with device scale. |
| 1197 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1198 | |
| 1199 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1200 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1201 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1202 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1203 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1204 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1205 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1206 | gfx::Transform device_scaled_translate = translate; |
| 1207 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1208 | EXPECT_EQ(device_scaled_translate, |
| 1209 | root->draw_properties().target_space_transform); |
| 1210 | EXPECT_EQ(device_scaled_translate, |
| 1211 | child->draw_properties().target_space_transform); |
| 1212 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1213 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1214 | |
| 1215 | // Verify it composes correctly with page scale. |
| 1216 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1217 | |
| 1218 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1219 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1220 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1221 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1222 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1223 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1224 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1225 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1226 | gfx::Transform page_scaled_translate = translate; |
| 1227 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1228 | EXPECT_EQ(page_scaled_translate, |
| 1229 | root->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1230 | EXPECT_EQ(page_scaled_translate, |
| 1231 | child->draw_properties().target_space_transform); |
| 1232 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1233 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1234 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1235 | // Verify that it composes correctly with transforms directly on root layer. |
| 1236 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1237 | |
| 1238 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1239 | LayerImplList render_surface_layer_list_impl; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1240 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1241 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1242 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1243 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1244 | gfx::Transform compositeSquared = composite; |
| 1245 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1246 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1247 | compositeSquared, root->draw_properties().target_space_transform); |
| 1248 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1249 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1250 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1251 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1252 | } |
| 1253 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1254 | TEST_F(LayerTreeHostCommonTest, |
| 1255 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1256 | LayerImpl* parent = root_layer(); |
| 1257 | parent->SetMasksToBounds(true); |
| 1258 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1259 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1260 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1261 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1262 | const gfx::Transform identity_matrix; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1263 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1264 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1265 | true); |
| 1266 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1267 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1268 | true); |
| 1269 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1270 | gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true, |
| 1271 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1272 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1273 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1274 | |
| 1275 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1276 | // the intermediate render surface should not be listed here, even if it was |
| 1277 | // forced to be created. Render surfaces without children or visible content |
| 1278 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1279 | // of size 0). |
| 1280 | ASSERT_TRUE(parent->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1281 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1282 | } |
| 1283 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1284 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1285 | LayerImpl* parent = root_layer(); |
| 1286 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1287 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1288 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1290 | const gfx::Transform identity_matrix; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1291 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1292 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1293 | true); |
| 1294 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1295 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1296 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1297 | render_surface1->SetOpacity(0.f); |
| 1298 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1299 | LayerImplList render_surface_layer_list; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1300 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1301 | parent, parent->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1302 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1303 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1304 | |
| 1305 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1306 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1307 | // have been extended by the children. |
| 1308 | ASSERT_TRUE(parent->render_surface()); |
| 1309 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1310 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1311 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1312 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1313 | } |
| 1314 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1315 | TEST_F(LayerTreeHostCommonTest, |
| 1316 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
| 1317 | LayerImpl* parent = root_layer(); |
| 1318 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1319 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1320 | child->SetDrawsContent(true); |
| 1321 | |
| 1322 | const gfx::Transform identity_matrix; |
| 1323 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1324 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1325 | true); |
| 1326 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1327 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1328 | true); |
| 1329 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1330 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1331 | false); |
| 1332 | render_surface1->SetOpacity(0.f); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1333 | render_surface1->SetDrawsContent(true); |
| 1334 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1335 | FilterOperations filters; |
| 1336 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
| 1337 | render_surface1->SetBackgroundFilters(filters); |
| 1338 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1339 | { |
| 1340 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1341 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1342 | parent, parent->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1343 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1344 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1345 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1346 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1347 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1348 | // shouldn't be skipped and should be drawn. |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1349 | ASSERT_TRUE(parent->render_surface()); |
| 1350 | EXPECT_EQ(1U, parent->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1351 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
| 1352 | parent->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1353 | EffectTree& effect_tree = |
| 1354 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 1355 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1356 | EXPECT_TRUE(node->data.is_drawn); |
| 1357 | |
| 1358 | // When parent is transparent, the layer should not be drawn. |
| 1359 | parent->OnOpacityAnimated(0.f); |
| 1360 | render_surface1->OnOpacityAnimated(1.f); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1361 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1362 | { |
| 1363 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1364 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1365 | parent, parent->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1366 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1367 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1371 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1372 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1373 | } |
| 1374 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1375 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
| 1376 | LayerImpl* root = root_layer(); |
| 1377 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1378 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1379 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1380 | child1->SetDrawsContent(true); |
| 1381 | child2->SetDrawsContent(true); |
| 1382 | |
| 1383 | const gfx::Transform identity_matrix; |
| 1384 | gfx::Transform scale_matrix; |
| 1385 | scale_matrix.Scale(2.0f, 2.0f); |
| 1386 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1387 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1388 | true); |
| 1389 | SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(), |
| 1390 | gfx::PointF(), gfx::Size(), true, false, true); |
| 1391 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1392 | gfx::PointF(0, 0), gfx::Size(25, 25), true, |
| 1393 | false, true); |
| 1394 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1395 | gfx::PointF(25, 25), gfx::Size(25, 25), true, |
| 1396 | false, true); |
| 1397 | FilterOperations filters; |
| 1398 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
| 1399 | parent->SetFilters(filters); |
| 1400 | |
| 1401 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1402 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1403 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1404 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1405 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1406 | |
| 1407 | ASSERT_TRUE(parent->render_surface()); |
| 1408 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1409 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 6797dde | 2016-05-20 18:59:55 | [diff] [blame] | 1410 | EXPECT_EQ(gfx::RectF(-30, -30, 160, 160), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1411 | parent->render_surface()->DrawableContentRect()); |
| 1412 | } |
| 1413 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1414 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1415 | LayerImpl* parent = root_layer(); |
| 1416 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1417 | child->SetDrawsContent(true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1418 | |
| 1419 | const gfx::Transform identity_matrix; |
| 1420 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1421 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1422 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1423 | true); |
| 1424 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1425 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1426 | true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1427 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1428 | child->SetBlendMode(blend_mode); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1429 | child->SetOpacity(0.5f); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1430 | |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1431 | ExecuteCalculateDrawProperties(parent); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1432 | |
| 1433 | // Since the child layer has a blend mode other than normal, it should get |
| 1434 | // its own render surface. Also, layer's draw_properties should contain the |
| 1435 | // default blend mode, since the render surface becomes responsible for |
| 1436 | // applying the blend mode. |
| 1437 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1438 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1439 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1440 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1441 | } |
| 1442 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1443 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
| 1444 | LayerImpl* root = root_layer(); |
| 1445 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1446 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1447 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1448 | |
| 1449 | const gfx::Transform identity_matrix; |
| 1450 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1451 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1452 | true); |
| 1453 | SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(), |
| 1454 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1455 | true); |
| 1456 | SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(), |
| 1457 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1458 | false); |
| 1459 | SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(), |
| 1460 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1461 | true); |
| 1462 | surface1->SetDrawsContent(true); |
| 1463 | surface2->SetDrawsContent(true); |
| 1464 | |
| 1465 | surface1->SetOpacity(0.5f); |
| 1466 | not_surface->SetOpacity(0.5f); |
| 1467 | surface2->SetOpacity(0.5f); |
| 1468 | |
| 1469 | ExecuteCalculateDrawProperties(root); |
| 1470 | |
| 1471 | ASSERT_TRUE(surface1->render_surface()); |
| 1472 | ASSERT_FALSE(not_surface->render_surface()); |
| 1473 | ASSERT_TRUE(surface2->render_surface()); |
| 1474 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1475 | // surface2's draw opacity should include the opacity of not-surface and |
| 1476 | // itself, but not the opacity of surface1. |
| 1477 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1478 | } |
| 1479 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1480 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1481 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1482 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1483 | // (Rendering will still be incorrect in situations where we really do need |
| 1484 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1485 | // ancestor whose opacity is <1.) |
| 1486 | LayerImpl* root = root_layer(); |
| 1487 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1488 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1489 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1490 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1491 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1492 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1493 | |
| 1494 | root->SetDrawsContent(true); |
| 1495 | parent->SetDrawsContent(true); |
| 1496 | child1->SetDrawsContent(true); |
| 1497 | child2->SetDrawsContent(true); |
| 1498 | grand_child->SetDrawsContent(true); |
| 1499 | leaf_node1->SetDrawsContent(true); |
| 1500 | leaf_node2->SetDrawsContent(true); |
| 1501 | |
| 1502 | const gfx::Transform identity_matrix; |
| 1503 | |
| 1504 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1505 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1506 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1507 | true); |
| 1508 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1509 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1510 | false); |
| 1511 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1512 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1513 | true); |
| 1514 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1515 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1516 | false); |
| 1517 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1518 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1519 | true); |
| 1520 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1521 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1522 | false); |
| 1523 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1524 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1525 | false); |
| 1526 | |
| 1527 | child1->SetOpacity(0.5f); |
| 1528 | grand_child->SetOpacity(0.5f); |
| 1529 | leaf_node1->SetOpacity(0.5f); |
| 1530 | leaf_node2->SetOpacity(0.5f); |
| 1531 | |
| 1532 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1533 | // opacities on the path from the layer to its render target, not including |
| 1534 | // the opacity of the layer that owns the target surface (since that opacity |
| 1535 | // is applied by the surface). |
| 1536 | ExecuteCalculateDrawProperties(root); |
| 1537 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1538 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1539 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1540 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1541 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1542 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1543 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1544 | |
| 1545 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1546 | // opacities on the path from the layer to the root. |
| 1547 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1548 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1549 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1550 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1551 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1552 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1553 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1554 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1555 | } |
| 1556 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1557 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1558 | LayerImpl* parent = root_layer(); |
| 1559 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1560 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1561 | |
| 1562 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1563 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1564 | gfx::PointF(), gfx::Size(10, 10), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1565 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1566 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1567 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1568 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1569 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1570 | child->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1571 | render_surface1->test_properties()->force_render_surface = true; |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1572 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1573 | { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1574 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1575 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1576 | // The root layer always creates a render surface |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1577 | EXPECT_TRUE(parent->has_render_surface()); |
| 1578 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1579 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1581 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1582 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1583 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1584 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1585 | EXPECT_TRUE(parent->has_render_surface()); |
| 1586 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1587 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1588 | } |
| 1589 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1590 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1591 | // Render surfaces act as a flattening point for their subtree, so should |
| 1592 | // always flatten the target-to-screen space transform seen by descendants. |
| 1593 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1594 | LayerImpl* root = root_layer(); |
| 1595 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1596 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1597 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1598 | |
| 1599 | child->SetDrawsContent(true); |
| 1600 | grand_child->SetDrawsContent(true); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1601 | |
| 1602 | gfx::Transform rotation_about_y_axis; |
| 1603 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1604 | // Make |parent| have a render surface. |
| 1605 | parent->SetOpacity(0.9f); |
| 1606 | |
| 1607 | const gfx::Transform identity_matrix; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1608 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1609 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1610 | true); |
| 1611 | SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(), |
| 1612 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1613 | true); |
| 1614 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1615 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1616 | false); |
| 1617 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1618 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1619 | false); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1620 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1621 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1622 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1623 | // Only grand_child should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1624 | EXPECT_TRUE(root->test_properties()->should_flatten_transform); |
| 1625 | EXPECT_TRUE(parent->test_properties()->should_flatten_transform); |
| 1626 | EXPECT_TRUE(child->test_properties()->should_flatten_transform); |
| 1627 | EXPECT_FALSE(grand_child->test_properties()->should_flatten_transform); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1628 | |
| 1629 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1630 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1631 | |
| 1632 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1633 | flattened_rotation_about_y.FlattenTo2d(); |
| 1634 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1635 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1636 | |
| 1637 | EXPECT_TRUE(parent->render_surface()); |
| 1638 | EXPECT_FALSE(child->render_surface()); |
| 1639 | EXPECT_FALSE(grand_child->render_surface()); |
| 1640 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1641 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1642 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1643 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1644 | |
| 1645 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1646 | // have been flattened at their render target. In particular, the fact that |
| 1647 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1648 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1649 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1650 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1651 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1652 | } |
| 1653 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1654 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1655 | // The entire subtree of layers that are outside the clip rect should be |
| 1656 | // culled away, and should not affect the render_surface_layer_list. |
| 1657 | // |
| 1658 | // The test tree is set up as follows: |
| 1659 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1660 | // that have something to draw. |
| 1661 | // - parent is a large container layer. |
| 1662 | // - child has masksToBounds=true to cause clipping. |
| 1663 | // - grand_child is positioned outside of the child's bounds |
| 1664 | // - great_grand_child is also kept outside child's bounds. |
| 1665 | // |
| 1666 | // In this configuration, grand_child and great_grand_child are completely |
| 1667 | // outside the clip rect, and they should never get scheduled on the list of |
| 1668 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1669 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1670 | LayerImpl* parent = root_layer(); |
| 1671 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1672 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1673 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1674 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1675 | // leaf_node1 ensures that parent and child are kept on the |
| 1676 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1677 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1678 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
| 1679 | leaf_node1->SetDrawsContent(true); |
| 1680 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
| 1681 | leaf_node2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1682 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1683 | const gfx::Transform identity_matrix; |
| 1684 | |
| 1685 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1686 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 1687 | true); |
| 1688 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1689 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1690 | true); |
| 1691 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1692 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 1693 | false, false); |
| 1694 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 1695 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1696 | true, false, false); |
| 1697 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1698 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1699 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1700 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1701 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1702 | false); |
| 1703 | |
| 1704 | child->SetMasksToBounds(true); |
| 1705 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1706 | grand_child->SetOpacity(0.5f); |
| 1707 | great_grand_child->SetOpacity(0.4f); |
| 1708 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1709 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1710 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1711 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
| 1712 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
| 1713 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1714 | } |
| 1715 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1716 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1717 | // 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] | 1718 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1719 | |
| 1720 | // The test tree is set up as follows: |
| 1721 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1722 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1723 | // the parent. |
| 1724 | // - grand_child is a render surface, and the only visible content in child. |
| 1725 | // It is positioned outside of the clip rect from parent. |
| 1726 | |
| 1727 | // In this configuration, grand_child should be outside the clipped |
| 1728 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1729 | // render_surface_layer_list. |
| 1730 | |
| 1731 | LayerImpl* parent = root_layer(); |
| 1732 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1733 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1734 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 1735 | leaf_node->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1736 | |
| 1737 | const gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1738 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1739 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1740 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1741 | true); |
| 1742 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1743 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1744 | true); |
| 1745 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1746 | gfx::PointF(200.f, 200.f), gfx::Size(10, 10), |
| 1747 | true, false, true); |
| 1748 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 1749 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1750 | false); |
| 1751 | |
| 1752 | parent->SetMasksToBounds(true); |
| 1753 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | grand_child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1755 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1756 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1757 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1758 | // We should cull child and grand_child from the |
| 1759 | // render_surface_layer_list. |
| 1760 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
| 1761 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1762 | } |
| 1763 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1764 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1765 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1766 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1767 | // - the layer is clipped by an ancestor that contributes to the same |
| 1768 | // render target, |
| 1769 | // - a surface is clipped by an ancestor that contributes to the same |
| 1770 | // render target. |
| 1771 | // |
| 1772 | // In particular, for a layer that owns a render surface: |
| 1773 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1774 | // pass that clipped status to the layer itself. |
| 1775 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1776 | // and propagates the clip to the subtree. |
| 1777 | |
| 1778 | const gfx::Transform identity_matrix; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1779 | LayerImpl* root = root_layer(); |
| 1780 | LayerImpl* parent = AddChild<LayerImpl>(root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1781 | parent->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1782 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1783 | child1->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1784 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1785 | child2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1786 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1787 | grand_child->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1788 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1789 | leaf_node1->SetDrawsContent(true); |
| 1790 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1791 | leaf_node2->SetDrawsContent(true); |
| 1792 | |
| 1793 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1794 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1795 | true); |
| 1796 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1797 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1798 | false); |
| 1799 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1800 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1801 | false); |
| 1802 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1803 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1804 | true); |
| 1805 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1806 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1807 | false); |
| 1808 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1809 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1810 | false); |
| 1811 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1812 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1813 | false); |
| 1814 | |
| 1815 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1816 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1817 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1818 | ASSERT_TRUE(root->render_surface()); |
| 1819 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1820 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1821 | EXPECT_FALSE(root->is_clipped()); |
| 1822 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1823 | EXPECT_FALSE(parent->is_clipped()); |
| 1824 | EXPECT_FALSE(child1->is_clipped()); |
| 1825 | EXPECT_FALSE(child2->is_clipped()); |
| 1826 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1827 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1828 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1829 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1830 | |
| 1831 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1832 | // surface are clipped. But layers that contribute to child2's surface are |
| 1833 | // not clipped explicitly because child2's surface already accounts for |
| 1834 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1835 | parent->SetMasksToBounds(true); |
| 1836 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1837 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1838 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1839 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1840 | ASSERT_TRUE(root->render_surface()); |
| 1841 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1842 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1843 | EXPECT_FALSE(root->is_clipped()); |
| 1844 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1845 | EXPECT_TRUE(parent->is_clipped()); |
| 1846 | EXPECT_TRUE(child1->is_clipped()); |
| 1847 | EXPECT_FALSE(child2->is_clipped()); |
| 1848 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1849 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1850 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1851 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1852 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1853 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1854 | |
| 1855 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1856 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1857 | child2->SetMasksToBounds(true); |
| 1858 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1859 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1860 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1861 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1862 | ASSERT_TRUE(root->render_surface()); |
| 1863 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1864 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1865 | EXPECT_FALSE(root->is_clipped()); |
| 1866 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1867 | EXPECT_FALSE(parent->is_clipped()); |
| 1868 | EXPECT_FALSE(child1->is_clipped()); |
| 1869 | EXPECT_TRUE(child2->is_clipped()); |
| 1870 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1871 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1872 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1873 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1874 | } |
| 1875 | |
| 1876 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1877 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1878 | // correct value. |
| 1879 | LayerImpl* root = root_layer(); |
| 1880 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1881 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1882 | |
| 1883 | root->SetDrawsContent(true); |
| 1884 | parent->SetDrawsContent(true); |
| 1885 | child->SetDrawsContent(true); |
| 1886 | |
| 1887 | const gfx::Transform identity_matrix; |
| 1888 | |
| 1889 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1890 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1891 | true); |
| 1892 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1893 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1894 | false); |
| 1895 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1896 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1897 | false); |
| 1898 | child->SetMasksToBounds(true); |
| 1899 | |
| 1900 | ExecuteCalculateDrawProperties(root); |
| 1901 | |
| 1902 | EXPECT_FALSE(root->is_clipped()); |
| 1903 | EXPECT_FALSE(parent->is_clipped()); |
| 1904 | EXPECT_TRUE(child->is_clipped()); |
| 1905 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1906 | |
| 1907 | parent->SetMasksToBounds(true); |
| 1908 | child->SetPosition(gfx::PointF(100, 100)); |
| 1909 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1910 | |
| 1911 | ExecuteCalculateDrawProperties(root); |
| 1912 | |
| 1913 | EXPECT_FALSE(root->is_clipped()); |
| 1914 | EXPECT_TRUE(parent->is_clipped()); |
| 1915 | EXPECT_TRUE(child->is_clipped()); |
| 1916 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1917 | } |
| 1918 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1919 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1920 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1921 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1922 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1923 | // that can reset is_clipped). |
| 1924 | LayerImpl* root = root_layer(); |
| 1925 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1926 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1927 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1928 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1929 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1930 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1931 | |
| 1932 | root->SetDrawsContent(true); |
| 1933 | parent->SetDrawsContent(true); |
| 1934 | child1->SetDrawsContent(true); |
| 1935 | child2->SetDrawsContent(true); |
| 1936 | grand_child->SetDrawsContent(true); |
| 1937 | leaf_node1->SetDrawsContent(true); |
| 1938 | leaf_node2->SetDrawsContent(true); |
| 1939 | |
| 1940 | const gfx::Transform identity_matrix; |
| 1941 | |
| 1942 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1943 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1944 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1945 | true); |
| 1946 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1947 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1948 | false); |
| 1949 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1950 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1951 | true); |
| 1952 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1953 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1954 | false); |
| 1955 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1956 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1957 | true); |
| 1958 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1959 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1960 | false); |
| 1961 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1962 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1963 | false); |
| 1964 | |
| 1965 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1966 | // or without surfaces. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1967 | root->SetHasRenderSurface(true); |
| 1968 | child1->SetHasRenderSurface(true); |
| 1969 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1970 | ExecuteCalculateDrawProperties(root); |
| 1971 | EXPECT_FALSE(root->is_clipped()); |
| 1972 | EXPECT_FALSE(parent->is_clipped()); |
| 1973 | EXPECT_FALSE(child1->is_clipped()); |
| 1974 | EXPECT_FALSE(child2->is_clipped()); |
| 1975 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1976 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1977 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1978 | |
| 1979 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1980 | EXPECT_FALSE(root->is_clipped()); |
| 1981 | EXPECT_FALSE(parent->is_clipped()); |
| 1982 | EXPECT_FALSE(child1->is_clipped()); |
| 1983 | EXPECT_FALSE(child2->is_clipped()); |
| 1984 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1985 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1986 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1987 | |
| 1988 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 1989 | // next render surface. Without surfaces, the entire tree is clipped. |
| 1990 | root->SetMasksToBounds(true); |
| 1991 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1992 | root->SetHasRenderSurface(true); |
| 1993 | child1->SetHasRenderSurface(true); |
| 1994 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1995 | ExecuteCalculateDrawProperties(root); |
| 1996 | EXPECT_TRUE(root->is_clipped()); |
| 1997 | EXPECT_TRUE(parent->is_clipped()); |
| 1998 | EXPECT_FALSE(child1->is_clipped()); |
| 1999 | EXPECT_TRUE(child2->is_clipped()); |
| 2000 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2001 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2002 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2003 | |
| 2004 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2005 | EXPECT_TRUE(root->is_clipped()); |
| 2006 | EXPECT_TRUE(parent->is_clipped()); |
| 2007 | EXPECT_TRUE(child1->is_clipped()); |
| 2008 | EXPECT_TRUE(child2->is_clipped()); |
| 2009 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2010 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2011 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2012 | |
| 2013 | root->SetMasksToBounds(false); |
| 2014 | |
| 2015 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2016 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2017 | // clipped. |
| 2018 | parent->SetMasksToBounds(true); |
| 2019 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2020 | root->SetHasRenderSurface(true); |
| 2021 | child1->SetHasRenderSurface(true); |
| 2022 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2023 | ExecuteCalculateDrawProperties(root); |
| 2024 | EXPECT_FALSE(root->is_clipped()); |
| 2025 | EXPECT_TRUE(parent->is_clipped()); |
| 2026 | EXPECT_FALSE(child1->is_clipped()); |
| 2027 | EXPECT_TRUE(child2->is_clipped()); |
| 2028 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2029 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2030 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2031 | |
| 2032 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2033 | EXPECT_FALSE(root->is_clipped()); |
| 2034 | EXPECT_TRUE(parent->is_clipped()); |
| 2035 | EXPECT_TRUE(child1->is_clipped()); |
| 2036 | EXPECT_TRUE(child2->is_clipped()); |
| 2037 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2038 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2039 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2040 | |
| 2041 | parent->SetMasksToBounds(false); |
| 2042 | |
| 2043 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2044 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2045 | // clipped. |
| 2046 | child1->SetMasksToBounds(true); |
| 2047 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2048 | root->SetHasRenderSurface(true); |
| 2049 | child1->SetHasRenderSurface(true); |
| 2050 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2051 | ExecuteCalculateDrawProperties(root); |
| 2052 | EXPECT_FALSE(root->is_clipped()); |
| 2053 | EXPECT_FALSE(parent->is_clipped()); |
| 2054 | EXPECT_TRUE(child1->is_clipped()); |
| 2055 | EXPECT_FALSE(child2->is_clipped()); |
| 2056 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2057 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2058 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2059 | |
| 2060 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2061 | EXPECT_FALSE(root->is_clipped()); |
| 2062 | EXPECT_FALSE(parent->is_clipped()); |
| 2063 | EXPECT_TRUE(child1->is_clipped()); |
| 2064 | EXPECT_FALSE(child2->is_clipped()); |
| 2065 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2066 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2067 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2068 | |
| 2069 | child1->SetMasksToBounds(false); |
| 2070 | |
| 2071 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2072 | // surfaces is the same. |
| 2073 | leaf_node1->SetMasksToBounds(true); |
| 2074 | leaf_node2->SetMasksToBounds(true); |
| 2075 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2076 | root->SetHasRenderSurface(true); |
| 2077 | child1->SetHasRenderSurface(true); |
| 2078 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2079 | ExecuteCalculateDrawProperties(root); |
| 2080 | EXPECT_FALSE(root->is_clipped()); |
| 2081 | EXPECT_FALSE(parent->is_clipped()); |
| 2082 | EXPECT_FALSE(child1->is_clipped()); |
| 2083 | EXPECT_FALSE(child2->is_clipped()); |
| 2084 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2085 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2086 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2087 | |
| 2088 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2089 | EXPECT_FALSE(root->is_clipped()); |
| 2090 | EXPECT_FALSE(parent->is_clipped()); |
| 2091 | EXPECT_FALSE(child1->is_clipped()); |
| 2092 | EXPECT_FALSE(child2->is_clipped()); |
| 2093 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2094 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2095 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2096 | } |
| 2097 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2098 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2099 | // Verify that layers get the appropriate DrawableContentRect when their |
| 2100 | // parent masksToBounds is true. |
| 2101 | // |
| 2102 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2103 | // be the layer rect expressed in target space. |
| 2104 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 2105 | // will be the intersection of layer bounds and the mask region. |
| 2106 | // grand_child3 - partially clipped and masksToBounds; the |
| 2107 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2108 | // the mask region. |
| 2109 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2110 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2111 | |
| 2112 | const gfx::Transform identity_matrix; |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2113 | LayerImpl* parent = root_layer(); |
| 2114 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2115 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2116 | grand_child1->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2117 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2118 | grand_child2->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2119 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2120 | grand_child3->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2121 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2122 | grand_child4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2123 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2124 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2125 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2126 | true); |
| 2127 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2128 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2129 | true); |
| 2130 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2131 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2132 | false, false); |
| 2133 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2134 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2135 | false, false); |
| 2136 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2137 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2138 | false, false); |
| 2139 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2140 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2141 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2142 | |
| 2143 | child->SetMasksToBounds(true); |
| 2144 | grand_child3->SetMasksToBounds(true); |
| 2145 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2146 | // Force child to be a render surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2147 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2148 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2149 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2150 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2151 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2152 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2153 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2154 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2155 | } |
| 2156 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2157 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2158 | // Verify that render surfaces (and their layers) get the appropriate |
| 2159 | // clip rects when their parent masksToBounds is true. |
| 2160 | // |
| 2161 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2162 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2163 | // They may still have a clip rect of their own layer bounds, however, if |
| 2164 | // masksToBounds was true. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2165 | LayerImpl* parent = root_layer(); |
| 2166 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2167 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2168 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2169 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2170 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2171 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2172 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2173 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 2174 | leaf_node1->SetDrawsContent(true); |
| 2175 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 2176 | leaf_node2->SetDrawsContent(true); |
| 2177 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
| 2178 | leaf_node3->SetDrawsContent(true); |
| 2179 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
| 2180 | leaf_node4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2181 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2182 | const gfx::Transform identity_matrix; |
| 2183 | |
| 2184 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2185 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2186 | true); |
| 2187 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2188 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2189 | true); |
| 2190 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2191 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2192 | false, true); |
| 2193 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2194 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2195 | false, true); |
| 2196 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2197 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2198 | false, true); |
| 2199 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2200 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2201 | false, true); |
| 2202 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2203 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2204 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2205 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2206 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2207 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2208 | SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(), |
| 2209 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2210 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2211 | SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(), |
| 2212 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2213 | false); |
| 2214 | |
| 2215 | child->SetMasksToBounds(true); |
| 2216 | grand_child3->SetMasksToBounds(true); |
| 2217 | grand_child4->SetMasksToBounds(true); |
| 2218 | |
| 2219 | // Force everyone to be a render surface. |
| 2220 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2221 | grand_child1->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2222 | grand_child2->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2223 | grand_child3->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2224 | grand_child4->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2225 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2226 | ExecuteCalculateDrawProperties(parent); |
| 2227 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2228 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2229 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2230 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2231 | |
| 2232 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2233 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2234 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2235 | grand_child1->render_surface()->clip_rect()); |
| 2236 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2237 | grand_child2->render_surface()->clip_rect()); |
| 2238 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2239 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | } |
| 2241 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2242 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2243 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2244 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2245 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2246 | // subtree (since there are no render surfaces that can reset the clip_rect). |
| 2247 | LayerImpl* root = root_layer(); |
| 2248 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2249 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2250 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2251 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2252 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2253 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2254 | |
| 2255 | root->SetDrawsContent(true); |
| 2256 | parent->SetDrawsContent(true); |
| 2257 | child1->SetDrawsContent(true); |
| 2258 | child2->SetDrawsContent(true); |
| 2259 | grand_child->SetDrawsContent(true); |
| 2260 | leaf_node1->SetDrawsContent(true); |
| 2261 | leaf_node2->SetDrawsContent(true); |
| 2262 | |
| 2263 | const gfx::Transform identity_matrix; |
| 2264 | |
| 2265 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 2266 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2267 | gfx::PointF(), gfx::Size(100, 100), true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2268 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2269 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2270 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2271 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 2272 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2273 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2274 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 2275 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2276 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2277 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2278 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2279 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2280 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2281 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2282 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2283 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2284 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2285 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2286 | |
| 2287 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2288 | // bounds in target space. The only thing that changes when surfaces are |
| 2289 | // disabled is that target space is always screen space. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2290 | root->test_properties()->force_render_surface = true; |
| 2291 | child1->test_properties()->force_render_surface = true; |
| 2292 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2293 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2294 | EXPECT_TRUE(root->has_render_surface()); |
| 2295 | EXPECT_FALSE(parent->has_render_surface()); |
| 2296 | EXPECT_TRUE(child1->has_render_surface()); |
| 2297 | EXPECT_FALSE(child2->has_render_surface()); |
| 2298 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2299 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2300 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2301 | EXPECT_FALSE(root->is_clipped()); |
| 2302 | EXPECT_FALSE(parent->is_clipped()); |
| 2303 | EXPECT_FALSE(child1->is_clipped()); |
| 2304 | EXPECT_FALSE(child2->is_clipped()); |
| 2305 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2306 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2307 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2308 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2309 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2310 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2311 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2312 | |
| 2313 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2314 | EXPECT_FALSE(root->is_clipped()); |
| 2315 | EXPECT_FALSE(parent->is_clipped()); |
| 2316 | EXPECT_FALSE(child1->is_clipped()); |
| 2317 | EXPECT_FALSE(child2->is_clipped()); |
| 2318 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2319 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2320 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2321 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2322 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2323 | |
| 2324 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2325 | // render surface are clipped by the root's bounds. |
| 2326 | root->SetMasksToBounds(true); |
| 2327 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2328 | root->test_properties()->force_render_surface = true; |
| 2329 | child1->test_properties()->force_render_surface = true; |
| 2330 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2331 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2332 | EXPECT_TRUE(root->has_render_surface()); |
| 2333 | EXPECT_FALSE(parent->has_render_surface()); |
| 2334 | EXPECT_TRUE(child1->has_render_surface()); |
| 2335 | EXPECT_FALSE(child2->has_render_surface()); |
| 2336 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2337 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2338 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2339 | EXPECT_TRUE(root->is_clipped()); |
| 2340 | EXPECT_TRUE(parent->is_clipped()); |
| 2341 | EXPECT_FALSE(child1->is_clipped()); |
| 2342 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2343 | EXPECT_TRUE(child2->is_clipped()); |
| 2344 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2345 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2346 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2347 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2348 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2349 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2350 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2351 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2352 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2353 | |
| 2354 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2355 | EXPECT_TRUE(root->is_clipped()); |
| 2356 | EXPECT_TRUE(parent->is_clipped()); |
| 2357 | EXPECT_TRUE(child1->is_clipped()); |
| 2358 | EXPECT_TRUE(child2->is_clipped()); |
| 2359 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2360 | EXPECT_TRUE(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()); |
| 2364 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2365 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2366 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2367 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2368 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2369 | |
| 2370 | root->SetMasksToBounds(false); |
| 2371 | |
| 2372 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2373 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2374 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2375 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2376 | // child is a render surface. However, without surfaces, these clip rects |
| 2377 | // contribute to all descendants. |
| 2378 | parent->SetMasksToBounds(true); |
| 2379 | child1->SetMasksToBounds(true); |
| 2380 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2381 | root->test_properties()->force_render_surface = true; |
| 2382 | child1->test_properties()->force_render_surface = true; |
| 2383 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2384 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2385 | EXPECT_TRUE(root->has_render_surface()); |
| 2386 | EXPECT_FALSE(parent->has_render_surface()); |
| 2387 | EXPECT_TRUE(child1->has_render_surface()); |
| 2388 | EXPECT_FALSE(child2->has_render_surface()); |
| 2389 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2390 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2391 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2392 | EXPECT_FALSE(root->is_clipped()); |
| 2393 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2394 | EXPECT_TRUE(parent->is_clipped()); |
| 2395 | EXPECT_TRUE(child1->is_clipped()); |
| 2396 | EXPECT_TRUE(child2->is_clipped()); |
| 2397 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2398 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2399 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2400 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2401 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2402 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2403 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2404 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2405 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2406 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2407 | |
| 2408 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2409 | EXPECT_FALSE(root->is_clipped()); |
| 2410 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2411 | EXPECT_TRUE(parent->is_clipped()); |
| 2412 | EXPECT_TRUE(child1->is_clipped()); |
| 2413 | EXPECT_TRUE(child2->is_clipped()); |
| 2414 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2415 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2416 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2417 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2418 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2419 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2420 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2421 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2422 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2423 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2424 | } |
| 2425 | |
| 2426 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2427 | // Tests that draw properties are computed correctly when we disable and then |
| 2428 | // re-enable separate surfaces. |
| 2429 | LayerImpl* root = root_layer(); |
| 2430 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2431 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2432 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2433 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2434 | |
| 2435 | root->SetDrawsContent(true); |
| 2436 | parent->SetDrawsContent(true); |
| 2437 | child->SetDrawsContent(true); |
| 2438 | grand_child->SetDrawsContent(true); |
| 2439 | leaf_node->SetDrawsContent(true); |
| 2440 | |
| 2441 | const gfx::Transform identity_matrix; |
| 2442 | |
| 2443 | // child and grand_child get render surfaces when surfaces are enabled. |
| 2444 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2445 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2446 | true); |
| 2447 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2448 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 2449 | false, false); |
| 2450 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2451 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 2452 | false, true); |
| 2453 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2454 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 2455 | true, false, true); |
| 2456 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 2457 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 2458 | true, false, false); |
| 2459 | |
| 2460 | parent->SetMasksToBounds(true); |
| 2461 | child->SetMasksToBounds(true); |
| 2462 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2463 | root->SetHasRenderSurface(true); |
| 2464 | child->SetHasRenderSurface(true); |
| 2465 | grand_child->SetHasRenderSurface(true); |
| 2466 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2467 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2468 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2469 | |
| 2470 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2471 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2472 | |
| 2473 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2474 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2475 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2476 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2477 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2478 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2479 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2480 | root->SetHasRenderSurface(true); |
| 2481 | child->SetHasRenderSurface(true); |
| 2482 | grand_child->SetHasRenderSurface(true); |
| 2483 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2484 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2485 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2486 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2487 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
| 2488 | EXPECT_EQ(expected_leaf_draw_transform_without_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2489 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2490 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2491 | root->SetHasRenderSurface(true); |
| 2492 | child->SetHasRenderSurface(true); |
| 2493 | grand_child->SetHasRenderSurface(true); |
| 2494 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2495 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2496 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2497 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2498 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2499 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2500 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2501 | } |
| 2502 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2503 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2504 | LayerImpl* parent = root_layer(); |
| 2505 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2506 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2507 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2508 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2509 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2510 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2511 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2512 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2513 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2514 | parent->SetDrawsContent(true); |
| 2515 | render_surface1->SetDrawsContent(true); |
| 2516 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2517 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2518 | render_surface2->SetDrawsContent(true); |
| 2519 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2520 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2521 | child_of_root->SetDrawsContent(true); |
| 2522 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2523 | |
| 2524 | gfx::Transform layer_transform; |
| 2525 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2526 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2527 | SetLayerPropertiesForTesting( |
| 2528 | parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2529 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2530 | SetLayerPropertiesForTesting( |
| 2531 | render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2532 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2533 | SetLayerPropertiesForTesting( |
| 2534 | render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2535 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2536 | SetLayerPropertiesForTesting( |
| 2537 | child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2538 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2539 | SetLayerPropertiesForTesting( |
| 2540 | child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2541 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2542 | SetLayerPropertiesForTesting( |
| 2543 | child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2544 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2545 | SetLayerPropertiesForTesting( |
| 2546 | grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2547 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2548 | SetLayerPropertiesForTesting( |
| 2549 | grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2550 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2551 | SetLayerPropertiesForTesting( |
| 2552 | grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2553 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2554 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2555 | parent->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 2556 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2557 | // Put an animated opacity on the render surface. |
| 2558 | AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(), |
| 2559 | 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2560 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2561 | // Also put an animated opacity on a layer without descendants. |
| 2562 | AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(), |
| 2563 | timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2564 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2565 | // Put a transform animation on the render surface. |
| 2566 | AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(), |
| 2567 | 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2568 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2569 | // Also put transform animations on grand_child_of_root, and |
| 2570 | // grand_child_of_rs2 |
| 2571 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), |
| 2572 | timeline_impl(), 10.0, 30, 0); |
| 2573 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), |
| 2574 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2575 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2576 | parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2577 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2578 | |
| 2579 | // Only layers that are associated with render surfaces should have an actual |
| 2580 | // RenderSurface() value. |
| 2581 | ASSERT_TRUE(parent->render_surface()); |
| 2582 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2583 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2584 | |
| 2585 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2586 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2587 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2588 | |
| 2589 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2590 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2591 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2592 | |
| 2593 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2594 | EXPECT_EQ(parent->render_surface(), parent->render_target()); |
| 2595 | EXPECT_EQ(parent->render_surface(), child_of_root->render_target()); |
| 2596 | EXPECT_EQ(parent->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2597 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2598 | EXPECT_EQ(render_surface1->render_surface(), |
| 2599 | render_surface1->render_target()); |
| 2600 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2601 | EXPECT_EQ(render_surface1->render_surface(), |
| 2602 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2603 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2604 | EXPECT_EQ(render_surface2->render_surface(), |
| 2605 | render_surface2->render_target()); |
| 2606 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2607 | EXPECT_EQ(render_surface2->render_surface(), |
| 2608 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2609 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | // Verify screen_space_transform_is_animating values |
| 2611 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2612 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2613 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2614 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2615 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2616 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2617 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2618 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2619 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2620 | |
| 2621 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2622 | // It is expected that we correctly set up transforms so that the y-component |
| 2623 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2624 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2625 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2626 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2627 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2628 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2629 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2630 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2631 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2632 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2633 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2634 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2635 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2636 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2637 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2638 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2639 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2640 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2641 | } |
| 2642 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2643 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
| 2644 | LayerImpl* parent = root_layer(); |
| 2645 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2646 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2647 | |
| 2648 | grand_child->SetDrawsContent(true); |
| 2649 | |
| 2650 | gfx::Transform large_transform; |
| 2651 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2652 | |
| 2653 | gfx::Transform identity; |
| 2654 | |
| 2655 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2656 | gfx::Size(10, 10), true, false, true); |
| 2657 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
| 2658 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2659 | false); |
| 2660 | SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(), |
| 2661 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2662 | false); |
| 2663 | ExecuteCalculateDrawProperties(parent); |
| 2664 | |
| 2665 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2666 | } |
| 2667 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2668 | TEST_F(LayerTreeHostCommonTest, |
| 2669 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
| 2670 | LayerImpl* parent = root_layer(); |
| 2671 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2672 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2673 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2674 | |
| 2675 | parent->SetDrawsContent(true); |
| 2676 | child->SetDrawsContent(true); |
| 2677 | grand_child->SetDrawsContent(true); |
| 2678 | great_grand_child->SetDrawsContent(true); |
| 2679 | |
| 2680 | gfx::Transform identity; |
| 2681 | |
| 2682 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2683 | gfx::Size(10, 10), true, false, true); |
| 2684 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 2685 | gfx::Size(10, 10), true, false, false); |
| 2686 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 2687 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2688 | false); |
| 2689 | SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(), |
| 2690 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2691 | false); |
| 2692 | |
| 2693 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2694 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2695 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2696 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2697 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2698 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2699 | AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(), |
| 2700 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2701 | ExecuteCalculateDrawProperties(parent); |
| 2702 | |
| 2703 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2704 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2705 | |
| 2706 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2707 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2708 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2709 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2710 | } |
| 2711 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2712 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2713 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2714 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2715 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2716 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | gfx::Transform layer_to_surface_transform; |
| 2718 | |
| 2719 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2720 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2721 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2722 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2723 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2724 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2725 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2726 | EXPECT_EQ(expected_drawable_content_rect, |
| 2727 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2728 | |
| 2729 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2730 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2731 | expected_visible_layer_rect = gfx::Rect(); |
| 2732 | expected_drawable_content_rect = gfx::Rect(); |
| 2733 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2734 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2735 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2736 | EXPECT_EQ(expected_drawable_content_rect, |
| 2737 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 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); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2741 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2742 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2743 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2744 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2745 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2746 | EXPECT_EQ(expected_drawable_content_rect, |
| 2747 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2748 | } |
| 2749 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2750 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2751 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2752 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2753 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2754 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2755 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2756 | gfx::Transform layer_to_surface_transform; |
| 2757 | |
| 2758 | // Case 1: Layer is contained within the surface. |
| 2759 | layer_to_surface_transform.MakeIdentity(); |
| 2760 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2761 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2762 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2763 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2764 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2765 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2766 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2767 | EXPECT_EQ(expected_drawable_content_rect, |
| 2768 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | |
| 2770 | // Case 2: Layer is outside the surface rect. |
| 2771 | layer_to_surface_transform.MakeIdentity(); |
| 2772 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2773 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2774 | expected_visible_layer_rect = gfx::Rect(); |
| 2775 | expected_drawable_content_rect = gfx::Rect(); |
| 2776 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2777 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2778 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2779 | EXPECT_EQ(expected_drawable_content_rect, |
| 2780 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2781 | |
| 2782 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2783 | // the layer is oriented diagonally, with the left half outside of the render |
| 2784 | // surface. In this case, the g should still be the entire layer |
| 2785 | // (remember the g is computed in layer space); both the top-left |
| 2786 | // and bottom-right corners of the layer are still visible. |
| 2787 | layer_to_surface_transform.MakeIdentity(); |
| 2788 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2789 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2790 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 2791 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2792 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2793 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2794 | EXPECT_EQ(expected_drawable_content_rect, |
| 2795 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | |
| 2797 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2798 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2799 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2800 | // surface overlaps the right side of the layer. The g should be |
| 2801 | // the layer's right half. |
| 2802 | layer_to_surface_transform.MakeIdentity(); |
| 2803 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2804 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2805 | // Right half of layer bounds. |
| 2806 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2807 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2808 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2809 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2810 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2811 | EXPECT_EQ(expected_drawable_content_rect, |
| 2812 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2813 | } |
| 2814 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2815 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2816 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2817 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2818 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2819 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2820 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2821 | gfx::Transform layer_to_surface_transform; |
| 2822 | |
| 2823 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2824 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2825 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2826 | layer_to_surface_transform.MakeIdentity(); |
| 2827 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2828 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2829 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2830 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2831 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2832 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2833 | EXPECT_EQ(expected_drawable_content_rect, |
| 2834 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2835 | |
| 2836 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2837 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2838 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2839 | // 50 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] | 2840 | SkMScalar half_width_of_rotated_layer = |
| 2841 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2842 | layer_to_surface_transform.MakeIdentity(); |
| 2843 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2844 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2845 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2846 | // Tight half of the layer. |
| 2847 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2848 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2849 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2850 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2851 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2852 | EXPECT_EQ(expected_drawable_content_rect, |
| 2853 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | } |
| 2855 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2856 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2857 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2858 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2859 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2860 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2861 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2862 | gfx::Transform layer_to_surface_transform; |
| 2863 | |
| 2864 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2865 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2866 | // its translated more than the perspective amount. |
| 2867 | layer_to_surface_transform.MakeIdentity(); |
| 2868 | |
| 2869 | // The following sequence of transforms applies the perspective about the |
| 2870 | // center of the surface. |
| 2871 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2872 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2873 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2874 | |
| 2875 | // This translate places the layer in front of the surface's projection plane. |
| 2876 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2877 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2878 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2879 | // offset by layer position. |
| 2880 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2881 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2882 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2883 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2884 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2885 | EXPECT_EQ(expected_drawable_content_rect, |
| 2886 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2887 | |
| 2888 | // Case 2: same projection as before, except that the layer is also translated |
| 2889 | // to the side, so that only the right half of the layer should be visible. |
| 2890 | // |
| 2891 | // Explanation of expected result: The perspective ratio is (z distance |
| 2892 | // between layer and camera origin) / (z distance between projection plane and |
| 2893 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2894 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2895 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2896 | // -25 == -100 in the layer's units. |
| 2897 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 2898 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 2899 | // space and is moved by 25. |
| 2900 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 2901 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 2902 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2903 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2904 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2905 | EXPECT_EQ(expected_drawable_content_rect, |
| 2906 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2907 | } |
| 2908 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2909 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2910 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[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 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2927 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 2928 | // space. |
| 2929 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2930 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 2931 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2932 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2933 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2934 | EXPECT_EQ(expected_drawable_content_rect, |
| 2935 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2936 | } |
| 2937 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2938 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 2939 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 2940 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2941 | // when projecting a surface onto a layer, but the layer is partially behind |
| 2942 | // the camera (not just behind the projection plane). In this case, the |
| 2943 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 2944 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 2945 | // coordinates before converting to cartesian coordinates. The drawable |
| 2946 | // content rect would be entire surface rect because layer is rotated at the |
| 2947 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2948 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2949 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 2950 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2951 | gfx::Transform layer_to_surface_transform; |
| 2952 | |
| 2953 | // The layer is positioned so that the right half of the layer should be in |
| 2954 | // front of the camera, while the other half is behind the surface's |
| 2955 | // projection plane. The following sequence of transforms applies the |
| 2956 | // perspective and rotation about the center of the layer. |
| 2957 | layer_to_surface_transform.MakeIdentity(); |
| 2958 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2959 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 2960 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 2961 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2962 | |
| 2963 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2964 | // transform, otherwise this code is not testing the intended scenario. |
| 2965 | bool clipped; |
| 2966 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2967 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2968 | &clipped); |
| 2969 | ASSERT_TRUE(clipped); |
| 2970 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2971 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 2972 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 2973 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2974 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2975 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2976 | EXPECT_EQ(expected_drawable_content_rect, |
| 2977 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2978 | } |
| 2979 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2980 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2981 | // To determine visible rect in layer space, there needs to be an |
| 2982 | // un-projection from surface space to layer space. When the original |
| 2983 | // transform was a perspective projection that was clipped, it returns a rect |
| 2984 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2985 | // clipping again. |
| 2986 | |
| 2987 | // This sequence of transforms causes one corner of the layer to protrude |
| 2988 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2989 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 2990 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2991 | gfx::Transform layer_to_surface_transform; |
| 2992 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2993 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2994 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2995 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2996 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2997 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2998 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2999 | |
| 3000 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 3001 | // code is not testing the intended scenario. |
| 3002 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3003 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 3004 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3005 | MathUtil::ProjectQuad( |
| 3006 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 3007 | ASSERT_TRUE(clipped); |
| 3008 | |
| 3009 | // Only the corner of the layer is not visible on the surface because of being |
| 3010 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 3011 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3012 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 3013 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3014 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3015 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3016 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3017 | EXPECT_EQ(expected_drawable_content_rect, |
| 3018 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3019 | } |
| 3020 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3021 | TEST_F(LayerTreeHostCommonTest, |
| 3022 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3023 | LayerImpl* root = root_layer(); |
| 3024 | root->SetDrawsContent(true); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3025 | |
| 3026 | gfx::Transform identity_matrix; |
| 3027 | // Root layer is positioned at (60, 70). The default device viewport size |
| 3028 | // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 3029 | // 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] | 3030 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3031 | gfx::PointF(60, 70), gfx::Size(100, 100), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3032 | false, true); |
| 3033 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3034 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3035 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3036 | root->render_surface()->DrawableContentRect()); |
| 3037 | // In target space, not clipped. |
| 3038 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3039 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3040 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3041 | } |
| 3042 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3043 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3044 | LayerImpl* root = root_layer(); |
| 3045 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
| 3046 | child1_layer->SetDrawsContent(true); |
| 3047 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
| 3048 | child2_layer->SetDrawsContent(true); |
| 3049 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
| 3050 | child3_layer->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3051 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3052 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3053 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3054 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3055 | true); |
| 3056 | SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), |
| 3057 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3058 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3059 | SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), |
| 3060 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3061 | false, false); |
| 3062 | SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), |
| 3063 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3064 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3065 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3066 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3067 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3068 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3069 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3070 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3071 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3072 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3073 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3074 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3075 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3076 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3077 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3078 | |
| 3079 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3080 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3081 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3082 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3083 | } |
| 3084 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3085 | TEST_F(LayerTreeHostCommonTest, |
| 3086 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3087 | LayerImpl* root = root_layer(); |
| 3088 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3089 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 3090 | grand_child1->SetDrawsContent(true); |
| 3091 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 3092 | grand_child2->SetDrawsContent(true); |
| 3093 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 3094 | grand_child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3095 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3096 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3097 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3098 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3099 | true); |
| 3100 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 3101 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3102 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3103 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3104 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3105 | false, false); |
| 3106 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3107 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3108 | false, false); |
| 3109 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 3110 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3111 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3112 | |
| 3113 | child->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3114 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3115 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3116 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3117 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3118 | |
| 3119 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3120 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3121 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3122 | |
| 3123 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3124 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3125 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3126 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3127 | |
| 3128 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3129 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3130 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3131 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3132 | } |
| 3133 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3134 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3135 | LayerImpl* root = root_layer(); |
| 3136 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3137 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3138 | |
| 3139 | gfx::Transform identity_matrix; |
| 3140 | gfx::Transform child_scale_matrix; |
| 3141 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3142 | gfx::Transform grand_child_scale_matrix; |
| 3143 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3144 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3145 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3146 | true); |
| 3147 | SetLayerPropertiesForTesting(child, child_scale_matrix, gfx::Point3F(), |
| 3148 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 3149 | false); |
| 3150 | SetLayerPropertiesForTesting(grand_child, grand_child_scale_matrix, |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3151 | gfx::Point3F(), gfx::PointF(), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3152 | gfx::Size(100, 100), true, false, false); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3153 | |
| 3154 | child->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3155 | grand_child->SetDrawsContent(true); |
| 3156 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3157 | |
| 3158 | // The visible rect is expanded to integer coordinates in target space before |
| 3159 | // being projected back to layer space, where it is once again expanded to |
| 3160 | // integer coordinates. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3161 | EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3162 | } |
| 3163 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3164 | TEST_F(LayerTreeHostCommonTest, |
| 3165 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3166 | LayerImpl* root = root_layer(); |
| 3167 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3168 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3169 | child1->SetDrawsContent(true); |
| 3170 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3171 | child2->SetDrawsContent(true); |
| 3172 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3173 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3175 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3176 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3177 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3178 | true); |
| 3179 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3180 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3181 | true); |
| 3182 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3183 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3184 | false, false); |
| 3185 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3186 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3187 | false, false); |
| 3188 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3189 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3190 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3191 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3192 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3193 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3194 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3195 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3196 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3197 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3198 | |
| 3199 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3200 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3201 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3202 | |
| 3203 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3204 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3205 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3206 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3207 | |
| 3208 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3209 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3210 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3211 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3212 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3213 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3214 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3215 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3216 | } |
| 3217 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3218 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3219 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
| 3220 | LayerImpl* root = root_layer(); |
| 3221 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3222 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3223 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3224 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3225 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3226 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3227 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3228 | |
| 3229 | root->SetDrawsContent(true); |
| 3230 | parent->SetDrawsContent(true); |
| 3231 | child1->SetDrawsContent(true); |
| 3232 | child2->SetDrawsContent(true); |
| 3233 | grand_child1->SetDrawsContent(true); |
| 3234 | grand_child2->SetDrawsContent(true); |
| 3235 | leaf_node1->SetDrawsContent(true); |
| 3236 | leaf_node2->SetDrawsContent(true); |
| 3237 | |
| 3238 | const gfx::Transform identity_matrix; |
| 3239 | |
| 3240 | // child1 and child2 get render surfaces when surfaces are enabled. |
| 3241 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3242 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3243 | true); |
| 3244 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 3245 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 3246 | false, false); |
| 3247 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3248 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 3249 | false, true); |
| 3250 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3251 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
| 3252 | false, true); |
| 3253 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3254 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 3255 | true, false, false); |
| 3256 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3257 | gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500), |
| 3258 | true, false, false); |
| 3259 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 3260 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 3261 | true, false, false); |
| 3262 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 3263 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
| 3264 | true, false, false); |
| 3265 | |
| 3266 | // Case 1: No layers clip. Visible rects are clipped by the viewport, but the |
| 3267 | // viewport clip doesn't apply to layers that draw into unclipped surfaces. |
| 3268 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3269 | // thing that changes with surfaces disabled is that target space is always |
| 3270 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3271 | root->SetHasRenderSurface(true); |
| 3272 | child1->SetHasRenderSurface(true); |
| 3273 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3274 | ExecuteCalculateDrawProperties(root); |
| 3275 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
| 3277 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3279 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect()); |
| 3280 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3281 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect()); |
| 3282 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect()); |
| 3283 | |
| 3284 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3285 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3286 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3287 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3288 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3289 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3290 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3291 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3292 | |
| 3293 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3294 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3300 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3301 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3302 | |
| 3303 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3304 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3305 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3307 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3308 | grand_child1->drawable_content_rect()); |
| 3309 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3310 | grand_child2->drawable_content_rect()); |
| 3311 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3312 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3313 | |
| 3314 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3315 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3316 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3317 | // rects are clipped only until the next render surface is reached, so |
| 3318 | // descendants of parent have their drawable content rects clipped only when |
| 3319 | // surfaces are disabled. |
| 3320 | parent->SetMasksToBounds(true); |
| 3321 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3322 | root->SetHasRenderSurface(true); |
| 3323 | child1->SetHasRenderSurface(true); |
| 3324 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3325 | ExecuteCalculateDrawProperties(root); |
| 3326 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3328 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3329 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3330 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3331 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3332 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3333 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3334 | |
| 3335 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3336 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3337 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3338 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3339 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3340 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3341 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3342 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3343 | |
| 3344 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3345 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3346 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3347 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3348 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3349 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3350 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3351 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3352 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3353 | |
| 3354 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3355 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3356 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3357 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3358 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3359 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3360 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3361 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3362 | |
| 3363 | parent->SetMasksToBounds(false); |
| 3364 | |
| 3365 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
| 3366 | // layers have their visible rects clipped by them; without surfaces, these |
| 3367 | // rects are also clipped by the viewport. Similarly, descendants of these |
| 3368 | // layers have their drawable content rects clipped by them. |
| 3369 | child1->SetMasksToBounds(true); |
| 3370 | grand_child2->SetMasksToBounds(true); |
| 3371 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3372 | root->SetHasRenderSurface(true); |
| 3373 | child1->SetHasRenderSurface(true); |
| 3374 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3375 | ExecuteCalculateDrawProperties(root); |
| 3376 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3377 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3378 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3379 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3380 | EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); |
| 3381 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3382 | EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); |
| 3383 | EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); |
| 3384 | |
| 3385 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3386 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3387 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3388 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3389 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3390 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3391 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3392 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3393 | |
| 3394 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3395 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3396 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3397 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3398 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3399 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3400 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3401 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3402 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3403 | |
| 3404 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3405 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3406 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3407 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3408 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3409 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3410 | grand_child2->drawable_content_rect()); |
| 3411 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3412 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3413 | } |
| 3414 | |
| 3415 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3416 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3417 | LayerImpl* root = root_layer(); |
| 3418 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3419 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3420 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
| 3421 | child1->SetDrawsContent(true); |
| 3422 | child2->SetDrawsContent(true); |
| 3423 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3424 | |
| 3425 | gfx::Transform identity_matrix; |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3426 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3427 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3428 | true); |
| 3429 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3430 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3431 | false, false); |
| 3432 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3433 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3434 | false, false); |
| 3435 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3436 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3437 | true, false, false); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3438 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3439 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3440 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3441 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3442 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3443 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3444 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3445 | ASSERT_TRUE(root->render_surface()); |
| 3446 | EXPECT_FALSE(root->is_clipped()); |
| 3447 | |
| 3448 | gfx::Rect empty; |
| 3449 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3450 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3451 | |
| 3452 | // Visible content rect calculation will check if the target surface is |
| 3453 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3454 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3455 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3456 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3457 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3461 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3462 | LayerImpl* root = root_layer(); |
| 3463 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3464 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3465 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3466 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3467 | gfx::Transform identity_matrix; |
| 3468 | 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] | 3469 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3470 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3471 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3472 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3473 | true); |
| 3474 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3475 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3476 | false, false); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3477 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3478 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3479 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3480 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3481 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3482 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3483 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3484 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3485 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3486 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3487 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3488 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3489 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3490 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3491 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3492 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3493 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3494 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3495 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3496 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3497 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3498 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3499 | uninvertible_matrix.MakeIdentity(); |
| 3500 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3501 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3502 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3503 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3504 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3505 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3506 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3507 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3508 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3509 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3510 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3511 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3512 | } |
| 3513 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3514 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3515 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
| 3516 | LayerImpl* root = root_layer(); |
| 3517 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3518 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 3519 | child->SetDrawsContent(true); |
| 3520 | grand_child->SetDrawsContent(true); |
| 3521 | |
| 3522 | gfx::Transform identity_matrix; |
| 3523 | |
| 3524 | gfx::Transform perspective; |
| 3525 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3526 | |
| 3527 | gfx::Transform rotation; |
| 3528 | rotation.RotateAboutYAxis(45.0); |
| 3529 | |
| 3530 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3531 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3532 | true); |
| 3533 | SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(), |
| 3534 | gfx::PointF(10.f, 10.f), gfx::Size(100, 100), |
| 3535 | false, true, false); |
| 3536 | SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(), |
| 3537 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 3538 | false); |
| 3539 | |
| 3540 | ExecuteCalculateDrawProperties(root); |
| 3541 | |
| 3542 | // Though all layers have invertible transforms, matrix multiplication using |
| 3543 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3544 | EXPECT_FALSE(root->layer_tree_impl() |
| 3545 | ->property_trees() |
| 3546 | ->transform_tree.Node(grand_child->transform_tree_index()) |
| 3547 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3548 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3549 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3550 | // uninvertible |
| 3551 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | TEST_F(LayerTreeHostCommonTest, |
| 3555 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3556 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3557 | TestSharedBitmapManager shared_bitmap_manager; |
| 3558 | TestTaskGraphRunner task_graph_runner; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3559 | std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3560 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3561 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3562 | std::unique_ptr<LayerImpl> root = |
| 3563 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3564 | std::unique_ptr<LayerImpl> child = |
| 3565 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3566 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3567 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3568 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3569 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 3570 | child->SetDrawsContent(true); |
| 3571 | grand_child->SetDrawsContent(true); |
| 3572 | occluding_child->SetDrawsContent(true); |
| 3573 | occluding_child->SetContentsOpaque(true); |
| 3574 | |
| 3575 | gfx::Transform identity_matrix; |
| 3576 | gfx::Transform perspective; |
| 3577 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3578 | |
| 3579 | gfx::Transform rotation; |
| 3580 | rotation.RotateAboutYAxis(45.0); |
| 3581 | |
| 3582 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3583 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3584 | false, true); |
| 3585 | SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(), |
| 3586 | gfx::PointF(10.f, 10.f), gfx::Size(300, 300), |
| 3587 | false, true, false); |
| 3588 | SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(), |
| 3589 | gfx::PointF(), gfx::Size(200, 200), false, true, |
| 3590 | false); |
| 3591 | SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix, |
| 3592 | gfx::Point3F(), gfx::PointF(), |
| 3593 | gfx::Size(200, 200), false, false, false); |
| 3594 | |
| 3595 | host_impl.SetViewportSize(root->bounds()); |
| 3596 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3597 | child->AddChild(std::move(grand_child)); |
| 3598 | root->AddChild(std::move(child)); |
| 3599 | root->AddChild(std::move(occluding_child)); |
| 3600 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3601 | host_impl.SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3602 | host_impl.InitializeRenderer(output_surface.get()); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 3603 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3604 | bool update_lcd_text = false; |
| 3605 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3606 | |
| 3607 | LayerImpl* grand_child_ptr = |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3608 | host_impl.active_tree()->root_layer()->children()[0]->children()[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3609 | |
| 3610 | // Though all layers have invertible transforms, matrix multiplication using |
| 3611 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3612 | EXPECT_FALSE( |
| 3613 | host_impl.active_tree() |
| 3614 | ->property_trees() |
| 3615 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
| 3616 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3617 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3618 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3619 | // skipped so |
| 3620 | // that we are not computing its occlusion_in_content_space. |
| 3621 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3622 | EXPECT_EQ( |
| 3623 | layer_bounds, |
| 3624 | grand_child_ptr->draw_properties() |
| 3625 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3626 | } |
| 3627 | |
| 3628 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3629 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3630 | LayerImpl* root = root_layer(); |
| 3631 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3632 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3633 | child1->SetDrawsContent(true); |
| 3634 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3635 | child2->SetDrawsContent(true); |
| 3636 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3637 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3638 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3639 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3640 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3641 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3642 | true); |
| 3643 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3644 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3645 | true); |
| 3646 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3647 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3648 | false, false); |
| 3649 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3650 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3651 | false, false); |
| 3652 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3653 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3654 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3655 | |
| 3656 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3657 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3658 | ExecuteCalculateDrawProperties(root); |
| 3659 | |
| 3660 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3661 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3662 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3663 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3664 | |
| 3665 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3666 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3667 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3668 | |
| 3669 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3670 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3671 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3672 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3673 | |
| 3674 | // All layers that draw content into the surface have their visible content |
| 3675 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3676 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3677 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3678 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3679 | |
| 3680 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3681 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3682 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3683 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3684 | } |
| 3685 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3686 | TEST_F(LayerTreeHostCommonTest, |
| 3687 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3688 | // Check that clipping does not propagate down surfaces. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3689 | LayerImpl* root = root_layer(); |
| 3690 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3691 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3692 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
| 3693 | child1->SetDrawsContent(true); |
| 3694 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 3695 | child2->SetDrawsContent(true); |
| 3696 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
| 3697 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3698 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3699 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3700 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3701 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3702 | true); |
| 3703 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3704 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3705 | true); |
| 3706 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3707 | gfx::PointF(), gfx::Size(7, 13), true, false, |
| 3708 | true); |
| 3709 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3710 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3711 | false, false); |
| 3712 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3713 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3714 | false, false); |
| 3715 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3716 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3717 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3718 | |
| 3719 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3720 | |
| 3721 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3722 | |
| 3723 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3724 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3725 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3726 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3727 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3728 | |
| 3729 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3730 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3731 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3732 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3733 | |
| 3734 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3735 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3736 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3737 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3738 | |
| 3739 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3740 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3741 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3742 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3743 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3744 | |
| 3745 | // All layers that draw content into render_surface2 think they are unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3746 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3747 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3748 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3749 | |
| 3750 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3751 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3752 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3753 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3754 | } |
| 3755 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3756 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3757 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
| 3758 | LayerImpl* root = root_layer(); |
| 3759 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3760 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3761 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3762 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
| 3763 | child1->SetDrawsContent(true); |
| 3764 | child2->SetDrawsContent(true); |
| 3765 | render_surface2->SetDrawsContent(true); |
| 3766 | |
| 3767 | gfx::Transform identity_matrix; |
| 3768 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3769 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3770 | true); |
| 3771 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3772 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3773 | true); |
| 3774 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3775 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 3776 | false); |
| 3777 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3778 | gfx::PointF(), gfx::Size(700, 700), true, false, |
| 3779 | false); |
| 3780 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3781 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3782 | false, true); |
| 3783 | |
| 3784 | child1->SetMasksToBounds(true); |
| 3785 | child2->SetMasksToBounds(true); |
| 3786 | |
| 3787 | ExecuteCalculateDrawProperties(root); |
| 3788 | EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); |
| 3789 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3790 | } |
| 3791 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3792 | TEST_F(LayerTreeHostCommonTest, |
| 3793 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
| 3794 | LayerImpl* root = root_layer(); |
| 3795 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3796 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3797 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3798 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3799 | |
| 3800 | render_surface1->SetDrawsContent(true); |
| 3801 | render_surface2->SetDrawsContent(true); |
| 3802 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3803 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3804 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3805 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3806 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3807 | |
| 3808 | gfx::Transform identity_matrix; |
| 3809 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3810 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3811 | true); |
| 3812 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3813 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3814 | false); |
| 3815 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3816 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3817 | true); |
| 3818 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3819 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3820 | false); |
| 3821 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3822 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3823 | true); |
| 3824 | clip_parent->SetMasksToBounds(true); |
| 3825 | render_surface1->SetMasksToBounds(true); |
| 3826 | |
| 3827 | ExecuteCalculateDrawProperties(root); |
| 3828 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3829 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3830 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3831 | } |
| 3832 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3833 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
| 3834 | LayerImpl* root = root_layer(); |
| 3835 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3836 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3837 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3838 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3839 | |
| 3840 | render_surface1->SetDrawsContent(true); |
| 3841 | render_surface2->SetDrawsContent(true); |
| 3842 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3843 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3844 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3845 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3846 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3847 | |
| 3848 | gfx::Transform identity_matrix; |
| 3849 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3850 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3851 | true); |
| 3852 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3853 | gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true, |
| 3854 | false, false); |
| 3855 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3856 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3857 | true); |
| 3858 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3859 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3860 | false); |
| 3861 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3862 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3863 | true); |
| 3864 | clip_parent->SetMasksToBounds(true); |
| 3865 | render_surface1->SetMasksToBounds(true); |
| 3866 | |
| 3867 | ExecuteCalculateDrawProperties(root); |
| 3868 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3869 | } |
| 3870 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3871 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3872 | // Test that only drawn layers contribute to render surface content rect. |
| 3873 | LayerImpl* root = root_layer(); |
| 3874 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3875 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3876 | |
| 3877 | test_layer->SetDrawsContent(false); |
| 3878 | surface->SetDrawsContent(true); |
| 3879 | gfx::Transform identity_matrix; |
| 3880 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3881 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 3882 | true); |
| 3883 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 3884 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3885 | true); |
| 3886 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 3887 | gfx::PointF(), gfx::Size(150, 150), true, false, |
| 3888 | false); |
| 3889 | |
| 3890 | ExecuteCalculateDrawProperties(root); |
| 3891 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3892 | |
| 3893 | test_layer->SetDrawsContent(true); |
| 3894 | ExecuteCalculateDrawProperties(root); |
| 3895 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3896 | } |
| 3897 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3898 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3899 | // Tests visible rects computation when we have unclipped_surface-> |
| 3900 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3901 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3902 | // clipped_surface below it. |
| 3903 | LayerImpl* root = root_layer(); |
| 3904 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3905 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3906 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3907 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3908 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3909 | |
| 3910 | unclipped_surface->SetDrawsContent(true); |
| 3911 | unclipped_desc_surface->SetDrawsContent(true); |
| 3912 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3913 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3914 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3915 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3916 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3917 | |
| 3918 | gfx::Transform identity_matrix; |
| 3919 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3920 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3921 | true); |
| 3922 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3923 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 3924 | true, false, true); |
| 3925 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3926 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3927 | false); |
| 3928 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3929 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 3930 | true, false, true); |
| 3931 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3932 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3933 | false); |
| 3934 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 3935 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3936 | true); |
| 3937 | clip_parent->SetMasksToBounds(true); |
| 3938 | |
| 3939 | ExecuteCalculateDrawProperties(root); |
| 3940 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3941 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3942 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3943 | } |
| 3944 | |
| 3945 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3946 | // Tests visible rects computation when we have unclipped_surface-> |
| 3947 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3948 | // of root propagate to the clipped_surface. |
| 3949 | LayerImpl* root = root_layer(); |
| 3950 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3951 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3952 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3953 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3954 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3955 | |
| 3956 | unclipped_surface->SetDrawsContent(true); |
| 3957 | unclipped_desc_surface->SetDrawsContent(true); |
| 3958 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3959 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3960 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3961 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3962 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3963 | |
| 3964 | gfx::Transform identity_matrix; |
| 3965 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3966 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 3967 | true); |
| 3968 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3969 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 3970 | true, false, true); |
| 3971 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3972 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3973 | false); |
| 3974 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3975 | gfx::Point3F(), gfx::PointF(), |
| 3976 | gfx::Size(100, 100), true, false, true); |
| 3977 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3978 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3979 | false); |
| 3980 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 3981 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3982 | true); |
| 3983 | clip_parent->SetMasksToBounds(true); |
| 3984 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3985 | |
| 3986 | ExecuteCalculateDrawProperties(root); |
| 3987 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 3988 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3989 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3990 | } |
| 3991 | |
| 3992 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3993 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3994 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3995 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3996 | LayerImpl* root = root_layer(); |
| 3997 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3998 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3999 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4000 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4001 | gfx::Transform identity_matrix; |
| 4002 | gfx::Transform child_rotation; |
| 4003 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4004 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4005 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4006 | true); |
| 4007 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4008 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4009 | true); |
| 4010 | SetLayerPropertiesForTesting( |
| 4011 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4012 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4013 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4014 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4015 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4016 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4017 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4018 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4019 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4020 | |
| 4021 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4022 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4023 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4024 | |
| 4025 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4026 | // regions of the subtree. |
| 4027 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4028 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4029 | gfx::Rect(50 - diagonal_radius, |
| 4030 | 50 - diagonal_radius, |
| 4031 | diagonal_radius * 2, |
| 4032 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4033 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4034 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4035 | |
| 4036 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4037 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4038 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4039 | } |
| 4040 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4041 | TEST_F(LayerTreeHostCommonTest, |
| 4042 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4044 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4045 | LayerImpl* root = root_layer(); |
| 4046 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4047 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4048 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4049 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4050 | gfx::Transform identity_matrix; |
| 4051 | gfx::Transform child_rotation; |
| 4052 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4053 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4054 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4055 | true); |
| 4056 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4057 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4058 | true); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4059 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4060 | SetLayerPropertiesForTesting( |
| 4061 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4062 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | |
| 4064 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4065 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4066 | ExecuteCalculateDrawProperties(root); |
| 4067 | |
| 4068 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4069 | |
| 4070 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4071 | // rotated layer. |
| 4072 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4073 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4074 | 50 - diagonal_radius, |
| 4075 | diagonal_radius * 2, |
| 4076 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4077 | gfx::RectF expected_surface_drawable_content( |
| 4078 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4079 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4080 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4081 | |
| 4082 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4083 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4084 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4085 | // |
| 4086 | // Given the floating point math, this number is a little bit fuzzy. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4087 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4088 | |
| 4089 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4090 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4091 | } |
| 4092 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4093 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4094 | LayerImpl* root = root_layer(); |
| 4095 | FakePictureLayerImpl* render_surface1 = |
| 4096 | AddChildToRoot<FakePictureLayerImpl>(); |
| 4097 | render_surface1->SetDrawsContent(true); |
| 4098 | FakePictureLayerImpl* render_surface2 = |
| 4099 | AddChild<FakePictureLayerImpl>(render_surface1); |
| 4100 | render_surface2->SetDrawsContent(true); |
| 4101 | FakePictureLayerImpl* child1 = |
| 4102 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4103 | child1->SetDrawsContent(true); |
| 4104 | FakePictureLayerImpl* child2 = |
| 4105 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4106 | child2->SetDrawsContent(true); |
| 4107 | FakePictureLayerImpl* child3 = |
| 4108 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4109 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4110 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4111 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4112 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4113 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4114 | true); |
| 4115 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 4116 | gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true, |
| 4117 | false, true); |
| 4118 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 4119 | gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true, |
| 4120 | false, true); |
| 4121 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4122 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 4123 | false, false); |
| 4124 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4125 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 4126 | false, false); |
| 4127 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 4128 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 4129 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4130 | |
| 4131 | float device_scale_factor = 2.f; |
| 4132 | |
| 4133 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4134 | |
| 4135 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4136 | |
| 4137 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4138 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4139 | |
| 4140 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4141 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4142 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4143 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4144 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4145 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4146 | |
| 4147 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4148 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4149 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4150 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4151 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4152 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4153 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4154 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4155 | |
| 4156 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4157 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4158 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4159 | // All layer visible content rects are not expressed in content space of each |
| 4160 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4161 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4162 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4163 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 4164 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 4165 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4166 | } |
| 4167 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4168 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4169 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4170 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4171 | // "flattened" to each parent layer according to current W3C spec. |
| 4172 | |
| 4173 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4174 | LayerImpl* parent = root_layer(); |
| 4175 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4176 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4177 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4178 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4179 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4180 | AddChild<LayerImpl>(front_facing_surface); |
| 4181 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4182 | AddChild<LayerImpl>(front_facing_surface); |
| 4183 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4184 | AddChild<LayerImpl>(back_facing_surface); |
| 4185 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4186 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4187 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4188 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4189 | front_facing_child->test_properties()->double_sided = false; |
| 4190 | back_facing_child->test_properties()->double_sided = false; |
| 4191 | front_facing_surface->test_properties()->double_sided = false; |
| 4192 | back_facing_surface->test_properties()->double_sided = false; |
| 4193 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4194 | false; |
| 4195 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4196 | false; |
| 4197 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4198 | false; |
| 4199 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4200 | false; |
| 4201 | |
| 4202 | // Everything draws content. |
| 4203 | front_facing_child->SetDrawsContent(true); |
| 4204 | back_facing_child->SetDrawsContent(true); |
| 4205 | front_facing_surface->SetDrawsContent(true); |
| 4206 | back_facing_surface->SetDrawsContent(true); |
| 4207 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4208 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4209 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4210 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4211 | |
| 4212 | gfx::Transform backface_matrix; |
| 4213 | backface_matrix.Translate(50.0, 50.0); |
| 4214 | backface_matrix.RotateAboutYAxis(180.0); |
| 4215 | backface_matrix.Translate(-50.0, -50.0); |
| 4216 | |
| 4217 | // Having a descendant and opacity will force these to have render surfaces. |
| 4218 | front_facing_surface->SetOpacity(0.5f); |
| 4219 | back_facing_surface->SetOpacity(0.5f); |
| 4220 | |
| 4221 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 4222 | // these layers should blindly use their own local transforms to determine |
| 4223 | // back-face culling. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4224 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4225 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4226 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
| 4227 | gfx::Point3F(), gfx::PointF(), |
| 4228 | gfx::Size(100, 100), true, false); |
| 4229 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
| 4230 | gfx::Point3F(), gfx::PointF(), |
| 4231 | gfx::Size(100, 100), true, false); |
| 4232 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
| 4233 | gfx::Point3F(), gfx::PointF(), |
| 4234 | gfx::Size(100, 100), true, false); |
| 4235 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
| 4236 | gfx::Point3F(), gfx::PointF(), |
| 4237 | gfx::Size(100, 100), true, false); |
| 4238 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
| 4239 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4240 | gfx::Size(100, 100), true, false); |
| 4241 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
| 4242 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4243 | gfx::Size(100, 100), true, false); |
| 4244 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
| 4245 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4246 | gfx::Size(100, 100), true, false); |
| 4247 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
| 4248 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4249 | gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4250 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4251 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4252 | |
| 4253 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4254 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4255 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4256 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4257 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4258 | EXPECT_FALSE( |
| 4259 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4260 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4261 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4262 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4263 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4264 | EXPECT_EQ(4u, update_layer_list_impl()->size()); |
| 4265 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4266 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4267 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4268 | front_facing_child_of_front_facing_surface->id())); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4269 | EXPECT_TRUE(UpdateLayerListImplContains( |
| 4270 | front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4271 | } |
| 4272 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4273 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4274 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4275 | // is used. |
| 4276 | |
| 4277 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4278 | LayerImpl* parent = root_layer(); |
| 4279 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4280 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4281 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4282 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4283 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4284 | AddChild<LayerImpl>(front_facing_surface); |
| 4285 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4286 | AddChild<LayerImpl>(front_facing_surface); |
| 4287 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4288 | AddChild<LayerImpl>(back_facing_surface); |
| 4289 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4290 | AddChild<LayerImpl>(back_facing_surface); |
| 4291 | // Opacity will not force creation of render surfaces in this case because of |
| 4292 | // the preserve-3d transform style. Instead, an example of when a surface |
| 4293 | // would be created with preserve-3d is when there is a replica layer. |
| 4294 | LayerImpl* dummy_replica_layer1 = |
| 4295 | AddReplicaLayer<LayerImpl>(front_facing_surface); |
| 4296 | LayerImpl* dummy_replica_layer2 = |
| 4297 | AddReplicaLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4298 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4299 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4300 | front_facing_child->test_properties()->double_sided = false; |
| 4301 | back_facing_child->test_properties()->double_sided = false; |
| 4302 | front_facing_surface->test_properties()->double_sided = false; |
| 4303 | back_facing_surface->test_properties()->double_sided = false; |
| 4304 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4305 | false; |
| 4306 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4307 | false; |
| 4308 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4309 | false; |
| 4310 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4311 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4312 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4313 | // Everything draws content. |
| 4314 | front_facing_child->SetDrawsContent(true); |
| 4315 | back_facing_child->SetDrawsContent(true); |
| 4316 | front_facing_surface->SetDrawsContent(true); |
| 4317 | back_facing_surface->SetDrawsContent(true); |
| 4318 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4319 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4320 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4321 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4322 | dummy_replica_layer1->SetDrawsContent(true); |
| 4323 | dummy_replica_layer2->SetDrawsContent(true); |
| 4324 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4325 | gfx::Transform backface_matrix; |
| 4326 | backface_matrix.Translate(50.0, 50.0); |
| 4327 | backface_matrix.RotateAboutYAxis(180.0); |
| 4328 | backface_matrix.Translate(-50.0, -50.0); |
| 4329 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4330 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4331 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4332 | // rendering context should use the transform with respect to that context. |
| 4333 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4334 | // and (b) the layer's transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4335 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4336 | gfx::PointF(), gfx::Size(100, 100), true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | false); // parent transform style is flat. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4338 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4339 | gfx::Point3F(), gfx::PointF(), |
| 4340 | gfx::Size(100, 100), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4341 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4342 | gfx::Point3F(), gfx::PointF(), |
| 4343 | gfx::Size(100, 100), true, false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4344 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4345 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4346 | gfx::Point3F(), gfx::PointF(), |
| 4347 | gfx::Size(100, 100), false, true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4348 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4349 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4350 | gfx::Point3F(), gfx::PointF(), |
| 4351 | gfx::Size(100, 100), false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4352 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4353 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4354 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4355 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4356 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4357 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4358 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4359 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4360 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4361 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4362 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4363 | gfx::Size(100, 100), true, true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4364 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4365 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4366 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4367 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4368 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4369 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4370 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4371 | // We expect that a has_render_surface was created but not used. |
| 4372 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4373 | EXPECT_FALSE( |
| 4374 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4375 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4376 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4377 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4378 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4379 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4380 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4381 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4382 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4383 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4384 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4385 | } |
| 4386 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4387 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4388 | // Verify that layers are appropriately culled when their back face is showing |
| 4389 | // and they are not double sided, while animations are going on. |
| 4390 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4391 | // Even layers that are animating get culled if their back face is showing and |
| 4392 | // they are not double sided. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4393 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4394 | LayerImpl* parent = root_layer(); |
| 4395 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4396 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4397 | LayerImpl* child_of_animating_surface = |
| 4398 | AddChild<LayerImpl>(animating_surface); |
| 4399 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4400 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4401 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4402 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4403 | child->test_properties()->double_sided = false; |
| 4404 | child2->test_properties()->double_sided = false; |
| 4405 | animating_surface->test_properties()->double_sided = false; |
| 4406 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4407 | animating_child->test_properties()->double_sided = false; |
| 4408 | |
| 4409 | // Everything draws content. |
| 4410 | child->SetDrawsContent(true); |
| 4411 | child2->SetDrawsContent(true); |
| 4412 | animating_surface->SetDrawsContent(true); |
| 4413 | child_of_animating_surface->SetDrawsContent(true); |
| 4414 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4415 | |
| 4416 | gfx::Transform backface_matrix; |
| 4417 | backface_matrix.Translate(50.0, 50.0); |
| 4418 | backface_matrix.RotateAboutYAxis(180.0); |
| 4419 | backface_matrix.Translate(-50.0, -50.0); |
| 4420 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4421 | // Animate the transform on the render surface. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4422 | AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), |
| 4423 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4424 | // This is just an animating layer, not a surface. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4425 | AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline_impl(), |
| 4426 | 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4427 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4428 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4429 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4430 | SetLayerPropertiesForTesting(child, backface_matrix, gfx::Point3F(), |
| 4431 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4432 | SetLayerPropertiesForTesting(animating_surface, backface_matrix, |
| 4433 | gfx::Point3F(), gfx::PointF(), |
| 4434 | gfx::Size(100, 100), true, false, true); |
| 4435 | SetLayerPropertiesForTesting(child_of_animating_surface, backface_matrix, |
| 4436 | gfx::Point3F(), gfx::PointF(), |
| 4437 | gfx::Size(100, 100), true, false); |
| 4438 | SetLayerPropertiesForTesting(animating_child, backface_matrix, gfx::Point3F(), |
| 4439 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4440 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4441 | gfx::PointF(), gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4442 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4443 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4444 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4445 | EXPECT_FALSE(child->has_render_surface()); |
| 4446 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4447 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4448 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4449 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4450 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4451 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4452 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4453 | // The back facing layers are culled from the layer list, and have an empty |
| 4454 | // visible rect. |
| 4455 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4456 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4457 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4458 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4459 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4460 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4461 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4462 | } |
| 4463 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4464 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4465 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4466 | // Verify the behavior of back-face culling for a render surface that is |
| 4467 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4468 | |
| 4469 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4470 | LayerImpl* parent = root_layer(); |
| 4471 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4472 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4473 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4474 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4476 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4477 | front_facing_surface->test_properties()->double_sided = false; |
| 4478 | back_facing_surface->test_properties()->double_sided = false; |
| 4479 | |
| 4480 | // Everything draws content. |
| 4481 | front_facing_surface->SetDrawsContent(true); |
| 4482 | back_facing_surface->SetDrawsContent(true); |
| 4483 | child1->SetDrawsContent(true); |
| 4484 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | |
| 4486 | gfx::Transform backface_matrix; |
| 4487 | backface_matrix.Translate(50.0, 50.0); |
| 4488 | backface_matrix.RotateAboutYAxis(180.0); |
| 4489 | backface_matrix.Translate(-50.0, -50.0); |
| 4490 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4491 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4492 | gfx::PointF(), gfx::Size(100, 100), false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4493 | true); // parent transform style is preserve3d. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4494 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
| 4495 | gfx::Point3F(), gfx::PointF(), |
| 4496 | gfx::Size(100, 100), true, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4497 | true); // surface transform style is flat. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4498 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
| 4499 | gfx::Point3F(), gfx::PointF(), |
| 4500 | gfx::Size(100, 100), true, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4501 | true); // surface transform style is flat. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4502 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4503 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4504 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4505 | gfx::PointF(), gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4507 | front_facing_surface->Set3dSortingContextId(1); |
| 4508 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4509 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4510 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4511 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4512 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4513 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4514 | |
| 4515 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4516 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4517 | EXPECT_FALSE(child1->has_render_surface()); |
| 4518 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4519 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4520 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4521 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4522 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4523 | } |
| 4524 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4525 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4526 | // Verify draw and screen space transforms of layers not in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4527 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4528 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4529 | LayerImpl* parent = root_layer(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4530 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4531 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4532 | gfx::PointF(), gfx::Size(100, 100), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4533 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4534 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4535 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4536 | child->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4537 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4538 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4539 | true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4540 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4541 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
| 4542 | child2->SetDrawsContent(true); |
| 4543 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4544 | gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false, |
| 4545 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4546 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4547 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4548 | gfx::Size viewport_size(100, 100); |
| 4549 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4550 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4551 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent); |
| 4552 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4553 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4554 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4555 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4556 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4557 | // Verify parent transforms |
| 4558 | gfx::Transform expected_parent_transform; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4559 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4560 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4561 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4562 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4563 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4564 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4565 | // Verify results of transformed parent rects |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4566 | gfx::RectF parent_bounds(gfx::SizeF(parent->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4567 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4568 | gfx::RectF parent_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4569 | MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4570 | gfx::RectF parent_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4571 | MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4572 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4573 | gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4574 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4575 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4576 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4577 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4578 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4579 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4580 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4581 | expected_child_transform.Translate(child->position().x(), |
| 4582 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4583 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4584 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4585 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4586 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4587 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4588 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4589 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4590 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4591 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4592 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4593 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4594 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4595 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4596 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4597 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4598 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4599 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4600 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4601 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4602 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4603 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4604 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4605 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4606 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4607 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4608 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4609 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4610 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4611 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4612 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4613 | } |
| 4614 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4615 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4616 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4617 | gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | gfx::Transform perspective_matrix; |
| 4619 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4620 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4621 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4622 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4623 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4624 | LayerImpl* root = root_layer(); |
| 4625 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4626 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4627 | false); |
| 4628 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4629 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4630 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4631 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4632 | false); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4633 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4634 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
| 4635 | SetLayerPropertiesForTesting(perspective_surface, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | perspective_matrix * scale_small_matrix, |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4637 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4638 | gfx::Size(10, 10), false, true, true); |
| 4639 | perspective_surface->SetDrawsContent(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4640 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4641 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
| 4642 | SetLayerPropertiesForTesting(scale_surface, scale_small_matrix, |
| 4643 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4644 | gfx::Size(10, 10), false, true, true); |
| 4645 | scale_surface->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4646 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4647 | float device_scale_factor = 2.5f; |
| 4648 | float page_scale_factor = 3.f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4649 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4650 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4651 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4652 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4653 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4654 | perspective_surface); |
| 4655 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4656 | // the nearest render target. Here this includes the layer transform as well |
| 4657 | // as the device and page scale factors. |
| 4658 | gfx::Transform transform = scale_small_matrix; |
| 4659 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4660 | device_scale_factor * page_scale_factor); |
| 4661 | gfx::Vector2dF scales = |
| 4662 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4663 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4664 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4665 | |
| 4666 | // The ideal scale will draw 1:1 with its render target space along |
| 4667 | // the larger-scale axis. |
| 4668 | gfx::Vector2dF target_space_transform_scales = |
| 4669 | MathUtil::ComputeTransform2dScaleComponents( |
| 4670 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4671 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4672 | std::max(target_space_transform_scales.x(), |
| 4673 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4674 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4675 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4676 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4677 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4678 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4679 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4680 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4681 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4682 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4683 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4684 | // with the screen, and then scaled during drawing. |
| 4685 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4686 | expected_perspective_surface_draw_transform.Translate( |
| 4687 | device_scale_factor * page_scale_factor * |
| 4688 | perspective_surface->position().x(), |
| 4689 | device_scale_factor * page_scale_factor * |
| 4690 | perspective_surface->position().y()); |
| 4691 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4692 | perspective_matrix); |
| 4693 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4694 | scale_small_matrix); |
| 4695 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4696 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4697 | device_scale_factor * page_scale_factor, |
| 4698 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4699 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4700 | expected_perspective_surface_draw_transform, |
| 4701 | perspective_surface->render_surface()->draw_transform()); |
| 4702 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4703 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4704 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4705 | } |
| 4706 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4707 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4708 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4709 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4710 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4711 | |
| 4712 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4713 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4714 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4715 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4716 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4717 | root->SetBounds(gfx::Size(100, 100)); |
| 4718 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4719 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4720 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4721 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4722 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4723 | false); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4724 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4725 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4726 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4727 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4728 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4729 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4730 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4731 | float device_scale_factor = 2.5f; |
| 4732 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4733 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4734 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4735 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4736 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4737 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4738 | // The ideal scale is able to go below 1. |
| 4739 | float expected_ideal_scale = |
| 4740 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4741 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4742 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4743 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4744 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4745 | initial_parent_scale * initial_child_scale; |
| 4746 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4747 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4748 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4749 | } |
| 4750 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4751 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4753 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4754 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4755 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4756 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4757 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4758 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4759 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4760 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4761 | root->SetBounds(gfx::Size(100, 100)); |
| 4762 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4763 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4764 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4765 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4766 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4767 | false); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4768 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4769 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4770 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4771 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4772 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4773 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4774 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4775 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4776 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4777 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4778 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 4779 | // Animating layers compute ideal scale in the same way as when |
| 4780 | // they are static. |
| 4781 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 4782 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4783 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4784 | } |
| 4785 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4786 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4787 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4788 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4789 | LayerImpl* parent = root_layer(); |
| 4790 | parent->SetDrawsContent(true); |
| 4791 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4792 | gfx::PointF(), gfx::Size(30, 30), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4793 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4794 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4795 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4796 | child->SetDrawsContent(true); |
| 4797 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4798 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4799 | true, true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4800 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4801 | gfx::Transform replica_transform; |
| 4802 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4803 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4804 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4805 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 4806 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 4807 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4808 | true, false); |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 4809 | // We need to set parent on replica layer for property tree building. |
| 4810 | replica->SetParent(child); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 4811 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4812 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4813 | // This layer should end up in the same surface as child, with the same draw |
| 4814 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4815 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
| 4816 | duplicate_child_non_owner->SetDrawsContent(true); |
| 4817 | SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix, |
| 4818 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 4819 | false, true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4820 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4821 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4822 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4823 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4824 | // We should have two render surfaces. The root's render surface and child's |
| 4825 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4826 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4827 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4828 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4829 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4830 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4831 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4832 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4833 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4835 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4836 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4837 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4838 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4839 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4840 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4841 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4842 | device_scale_factor); |
| 4843 | expected_screen_space_transform.Translate(child->position().x(), |
| 4844 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4845 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4846 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4847 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4848 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4849 | child->DrawTransform(); |
| 4850 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(), |
| 4851 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4852 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4853 | child->ScreenSpaceTransform(), |
| 4854 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4855 | EXPECT_EQ(child->drawable_content_rect(), |
| 4856 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4857 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4858 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4859 | gfx::Transform expected_render_surface_draw_transform; |
| 4860 | expected_render_surface_draw_transform.Translate( |
| 4861 | device_scale_factor * child->position().x(), |
| 4862 | device_scale_factor * child->position().y()); |
| 4863 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4864 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4865 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4866 | gfx::Transform expected_surface_draw_transform; |
| 4867 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4868 | device_scale_factor * 2.f); |
| 4869 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4870 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4871 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4872 | gfx::Transform expected_surface_screen_space_transform; |
| 4873 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4874 | device_scale_factor * 2.f); |
| 4875 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4876 | expected_surface_screen_space_transform, |
| 4877 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4878 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4879 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4880 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 4881 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 4882 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4883 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4884 | expected_replica_draw_transform, |
| 4885 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4887 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4888 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 4889 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 4890 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4891 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4892 | expected_replica_screen_space_transform, |
| 4893 | child->render_surface()->replica_screen_space_transform()); |
| 4894 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4895 | expected_replica_screen_space_transform, |
| 4896 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4897 | } |
| 4898 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4899 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4900 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4901 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4902 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4903 | LayerImpl* parent = root_layer(); |
| 4904 | parent->SetDrawsContent(true); |
| 4905 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4906 | gfx::PointF(), gfx::Size(33, 31), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4907 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4908 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4909 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4910 | child->SetDrawsContent(true); |
| 4911 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4912 | gfx::PointF(), gfx::Size(13, 11), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4913 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4915 | gfx::Transform replica_transform; |
| 4916 | replica_transform.Scale(1.0, -1.0); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4917 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4918 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 4919 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 4920 | gfx::PointF(), gfx::Size(13, 11), false, true, |
| 4921 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 4922 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4923 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 4924 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4925 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4926 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4927 | // We should have two render surfaces. The root's render surface and child's |
| 4928 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4929 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4930 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4931 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4932 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 4933 | child->render_surface()->draw_transform()); |
| 4934 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 4935 | child->render_surface()->draw_transform()); |
| 4936 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4937 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4938 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4939 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4940 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4941 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4942 | expected_replica_draw_transform, |
| 4943 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4944 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4945 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4946 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4947 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4948 | expected_replica_screen_space_transform, |
| 4949 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4950 | } |
| 4951 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4952 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 4953 | scoped_refptr<Layer> root = Layer::Create(); |
| 4954 | scoped_refptr<Layer> child = Layer::Create(); |
| 4955 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 4956 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 4957 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4958 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4959 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 4960 | child->AddChild(grand_child.get()); |
| 4961 | child->SetMaskLayer(mask_layer.get()); |
| 4962 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4963 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4964 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4965 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | int nonexistent_id = -1; |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 4967 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 4968 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 4969 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 4970 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 4971 | EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id())); |
| 4972 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4973 | } |
| 4974 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4975 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4976 | LayerImpl* root = root_layer(); |
| 4977 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 4978 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 4979 | grand_child->SetDrawsContent(true); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4980 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4981 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4982 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4983 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4984 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4985 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 4986 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 4987 | gfx::PointF(), gfx::Size(10, 10), true, false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4988 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4989 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4990 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4991 | ExecuteCalculateDrawProperties(root); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4992 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4993 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 4994 | } |
| 4995 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4996 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 4997 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4998 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 4999 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5000 | FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, |
| 5001 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5002 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5003 | std::unique_ptr<LayerImpl> root = |
| 5004 | LayerImpl::Create(host_impl.pending_tree(), 1); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5005 | |
| 5006 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5007 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5008 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5009 | false); |
| 5010 | root->SetDrawsContent(true); |
| 5011 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5012 | std::unique_ptr<LayerImpl> child = |
| 5013 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5014 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5015 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5016 | false); |
| 5017 | child->SetDrawsContent(true); |
| 5018 | child->SetOpacity(0.0f); |
| 5019 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5020 | const int child_id = child->id(); |
| 5021 | root->AddChild(std::move(child)); |
| 5022 | root->SetHasRenderSurface(true); |
| 5023 | LayerImpl* root_layer = root.get(); |
| 5024 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
| 5025 | host_impl.pending_tree()->BuildPropertyTreesForTesting(); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5026 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5027 | scoped_refptr<AnimationTimeline> timeline = |
| 5028 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5029 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5030 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5031 | AddOpacityTransitionToLayerWithPlayer(child_id, timeline, 10.0, 0.0f, 1.0f, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5032 | false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5033 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5034 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5035 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5036 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5037 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5038 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5039 | |
| 5040 | // We should have one render surface and two layers. The child |
| 5041 | // layer should be included even though it is transparent. |
| 5042 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5043 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5044 | |
| 5045 | // If the root itself is hidden, the child should not be drawn even if it has |
| 5046 | // an animating opacity. |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5047 | root_layer->SetOpacity(0.0f); |
| 5048 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5049 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5050 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5051 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5052 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5053 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5054 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5055 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5056 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5057 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5058 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
| 5059 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5060 | |
| 5061 | // A layer should be drawn and it should contribute to drawn surface when |
| 5062 | // it has animating opacity even if it has opacity 0. |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5063 | root_layer->SetOpacity(1.0f); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5064 | child_ptr->SetOpacity(0.0f); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5065 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5066 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5067 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5068 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5069 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5070 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5071 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5072 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 5073 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5074 | node = tree.Node(child_ptr->effect_tree_index()); |
| 5075 | EXPECT_TRUE(node->data.is_drawn); |
| 5076 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5077 | |
| 5078 | // But if the opacity of the layer remains 0 after activation, it should not |
| 5079 | // be drawn. |
| 5080 | host_impl.ActivateSyncTree(); |
| 5081 | LayerImpl* active_root = host_impl.active_tree()->root_layer(); |
| 5082 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 5083 | |
| 5084 | EffectTree& active_effect_tree = |
| 5085 | host_impl.active_tree()->property_trees()->effect_tree; |
| 5086 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 5087 | |
| 5088 | ExecuteCalculateDrawProperties(active_root); |
| 5089 | |
| 5090 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
| 5091 | EXPECT_FALSE(node->data.is_drawn); |
| 5092 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 5093 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5094 | } |
| 5095 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5096 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 5097 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 5098 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5099 | public: |
| 5100 | LCDTextTest() |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5101 | : LayerTreeHostCommonTestBase(LayerTreeSettings()), |
| 5102 | host_impl_(&task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5103 | &shared_bitmap_manager_, |
| 5104 | &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5105 | root_(nullptr), |
| 5106 | child_(nullptr), |
| 5107 | grand_child_(nullptr) {} |
| 5108 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5109 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5110 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5111 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5112 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5113 | timeline_ = |
| 5114 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5115 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5116 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5117 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5118 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5119 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5120 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5121 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5122 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5123 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5124 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5125 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5126 | |
| 5127 | // Stash raw pointers to look at later. |
| 5128 | root_ = root_ptr.get(); |
| 5129 | child_ = child_ptr.get(); |
| 5130 | grand_child_ = grand_child_ptr.get(); |
| 5131 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5132 | child_->AddChild(std::move(grand_child_ptr)); |
| 5133 | root_->AddChild(std::move(child_ptr)); |
| 5134 | host_impl_.active_tree()->SetRootLayer(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5135 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5136 | root_->SetContentsOpaque(true); |
| 5137 | child_->SetContentsOpaque(true); |
| 5138 | grand_child_->SetContentsOpaque(true); |
| 5139 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5140 | root_->SetDrawsContent(true); |
| 5141 | child_->SetDrawsContent(true); |
| 5142 | grand_child_->SetDrawsContent(true); |
| 5143 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5144 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5145 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5146 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5147 | true); |
| 5148 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5149 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5150 | std::tr1::get<2>(GetParam())); |
| 5151 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5152 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5153 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5154 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5155 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5156 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5157 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5158 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5159 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5160 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5161 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5162 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5163 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5164 | |
| 5165 | LayerImpl* root_; |
| 5166 | LayerImpl* child_; |
| 5167 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5168 | }; |
| 5169 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5170 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5171 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5172 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5173 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5174 | // Case 1: Identity transform. |
| 5175 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5176 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5177 | layers_always_allowed_lcd_text_); |
| 5178 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5179 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5180 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5181 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5182 | // Case 2: Integral translation. |
| 5183 | gfx::Transform integral_translation; |
| 5184 | integral_translation.Translate(1.0, 2.0); |
| 5185 | child_->SetTransform(integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5186 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5187 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5188 | layers_always_allowed_lcd_text_); |
| 5189 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5190 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5191 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5192 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5193 | // Case 3: Non-integral translation. |
| 5194 | gfx::Transform non_integral_translation; |
| 5195 | non_integral_translation.Translate(1.5, 2.5); |
| 5196 | child_->SetTransform(non_integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5197 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5198 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5199 | layers_always_allowed_lcd_text_); |
| 5200 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5201 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5202 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5203 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5204 | // Case 4: Rotation. |
| 5205 | gfx::Transform rotation; |
| 5206 | rotation.Rotate(10.0); |
| 5207 | child_->SetTransform(rotation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5208 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5209 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5210 | layers_always_allowed_lcd_text_); |
| 5211 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5212 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5213 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5214 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5215 | // Case 5: Scale. |
| 5216 | gfx::Transform scale; |
| 5217 | scale.Scale(2.0, 2.0); |
| 5218 | child_->SetTransform(scale); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5219 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5220 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5221 | layers_always_allowed_lcd_text_); |
| 5222 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5223 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5224 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5225 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5226 | // Case 6: Skew. |
| 5227 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5228 | skew.Skew(10.0, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5229 | child_->SetTransform(skew); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5230 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5231 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5232 | layers_always_allowed_lcd_text_); |
| 5233 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5234 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5235 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5237 | // Case 7: Translucent. |
| 5238 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5239 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5240 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5241 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5242 | layers_always_allowed_lcd_text_); |
| 5243 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5244 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5245 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5246 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5247 | // Case 8: Sanity check: restore transform and opacity. |
| 5248 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5249 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5250 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5251 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5252 | layers_always_allowed_lcd_text_); |
| 5253 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5254 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5255 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5256 | |
| 5257 | // Case 9: Non-opaque content. |
| 5258 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5259 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5260 | layers_always_allowed_lcd_text_); |
| 5261 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5262 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5263 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5264 | |
| 5265 | // Case 10: Sanity check: restore content opaqueness. |
| 5266 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5267 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5268 | layers_always_allowed_lcd_text_); |
| 5269 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5270 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5271 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5272 | } |
| 5273 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5274 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5275 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5276 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5277 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5278 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5279 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5280 | layers_always_allowed_lcd_text_); |
| 5281 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5282 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5283 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5284 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5285 | // Add opacity animation. |
| 5286 | child_->SetOpacity(0.9f); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5287 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5288 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5289 | 0.1f, false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5290 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5291 | layers_always_allowed_lcd_text_); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5292 | // Text LCD should be adjusted while animation is active. |
| 5293 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5294 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5295 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
| 5296 | } |
| 5297 | |
| 5298 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5299 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5300 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5301 | |
| 5302 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5303 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5304 | layers_always_allowed_lcd_text_); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5305 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5306 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5307 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5308 | |
| 5309 | // Mark contents non-opaque within the first animation frame. |
| 5310 | child_->SetContentsOpaque(false); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5311 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5312 | 0.1f, false); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5313 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5314 | layers_always_allowed_lcd_text_); |
| 5315 | // LCD text should be disabled for non-opaque layers even during animations. |
| 5316 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5317 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5318 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5322 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5323 | testing::Combine(testing::Bool(), |
| 5324 | testing::Bool(), |
| 5325 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5326 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5327 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5328 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5329 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5330 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5331 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5332 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5333 | host_impl.CreatePendingTree(); |
| 5334 | const gfx::Transform identity_matrix; |
| 5335 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5336 | std::unique_ptr<LayerImpl> root = |
| 5337 | LayerImpl::Create(host_impl.pending_tree(), 1); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5338 | LayerImpl* root_layer = root.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5339 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5340 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5341 | false); |
| 5342 | root->SetDrawsContent(true); |
| 5343 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5344 | std::unique_ptr<LayerImpl> child = |
| 5345 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5346 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5347 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5348 | false); |
| 5349 | child->SetDrawsContent(true); |
| 5350 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5351 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5352 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5353 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5354 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5355 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5356 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5357 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5358 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5359 | child->AddChild(std::move(grand_child)); |
| 5360 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5361 | root->SetHasRenderSurface(true); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5362 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5363 | |
| 5364 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5365 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5366 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5367 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5368 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5369 | |
| 5370 | // We should have one render surface and two layers. The grand child has |
| 5371 | // hidden itself. |
| 5372 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5373 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5374 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5375 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5376 | } |
| 5377 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5378 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5379 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5380 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5381 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5382 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5383 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5384 | host_impl.CreatePendingTree(); |
| 5385 | const gfx::Transform identity_matrix; |
| 5386 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5387 | std::unique_ptr<LayerImpl> root = |
| 5388 | LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5389 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5390 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5391 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5392 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5393 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5394 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5395 | std::unique_ptr<LayerImpl> child = |
| 5396 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5397 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5398 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5399 | false); |
| 5400 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5401 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5402 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5403 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5404 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5405 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5406 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5407 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5408 | grand_child->SetDrawsContent(true); |
| 5409 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5410 | child->AddChild(std::move(grand_child)); |
| 5411 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5412 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5413 | |
| 5414 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5415 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5416 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5417 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5418 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5419 | |
| 5420 | // We should have one render surface and one layers. The child has |
| 5421 | // hidden itself and the grand child. |
| 5422 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5423 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5424 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5425 | } |
| 5426 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5427 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5428 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5429 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5430 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5431 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5432 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5433 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5434 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5435 | host_impl.CreatePendingTree(); |
| 5436 | const gfx::Transform identity_matrix; |
| 5437 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5438 | std::unique_ptr<LayerImpl> root = |
| 5439 | LayerImpl::Create(host_impl.pending_tree(), 1); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5440 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5441 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5442 | true); |
| 5443 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5444 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5445 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5446 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5447 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5448 | SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix, |
| 5449 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 5450 | true, false, false); |
| 5451 | copy_grand_parent->SetDrawsContent(true); |
| 5452 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5453 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5454 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5455 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5456 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5457 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5458 | true, false, true); |
| 5459 | copy_parent->SetDrawsContent(true); |
| 5460 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5461 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5462 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5463 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5464 | SetLayerPropertiesForTesting(copy_request.get(), identity_matrix, |
| 5465 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5466 | true, false, true); |
| 5467 | copy_request->SetDrawsContent(true); |
| 5468 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5469 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5470 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5471 | LayerImpl::Create(host_impl.pending_tree(), 5); |
| 5472 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5473 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5474 | true, false, false); |
| 5475 | copy_child->SetDrawsContent(true); |
| 5476 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5477 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5478 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5479 | LayerImpl::Create(host_impl.pending_tree(), 6); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5480 | SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix, |
| 5481 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5482 | true, false, false); |
| 5483 | copy_child->SetDrawsContent(true); |
| 5484 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5485 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5486 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5487 | LayerImpl::Create(host_impl.pending_tree(), 7); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5488 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5489 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5490 | gfx::Size(40, 40), true, false, false); |
| 5491 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5492 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5493 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5494 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5495 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5496 | LayerImpl::Create(host_impl.pending_tree(), 8); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5497 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5498 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5499 | gfx::Size(40, 40), true, false, false); |
| 5500 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5501 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5502 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5503 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5504 | copy_child->AddChild(std::move(copy_grand_child)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5505 | copy_request->AddChild(std::move(copy_child)); |
| 5506 | copy_parent->AddChild(std::move(copy_request)); |
| 5507 | copy_grand_parent->AddChild(std::move(copy_parent)); |
| 5508 | root->AddChild(std::move(copy_grand_parent_sibling_before)); |
| 5509 | root->AddChild(std::move(copy_grand_parent)); |
| 5510 | root->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5511 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5512 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5513 | // 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] | 5514 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5515 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5516 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5517 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5518 | ->hide_layer_and_subtree = true; |
| 5519 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5520 | ->hide_layer_and_subtree = true; |
| 5521 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5522 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5523 | std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5524 | copy_requests.push_back( |
| 5525 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5526 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5527 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5528 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5529 | LayerImplList render_surface_layer_list; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5530 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5531 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5532 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5533 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5534 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5535 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5536 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5537 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5538 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5539 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5540 | // We should have four render surfaces, one for the root, one for the grand |
| 5541 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5542 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5543 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5544 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5545 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5546 | render_surface_layer_list.at(1)->id()); |
| 5547 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5548 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5549 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5550 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5551 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5552 | EXPECT_EQ(root_layer->id(), |
| 5553 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5554 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5555 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5556 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5557 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5558 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5559 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5560 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5561 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5562 | |
| 5563 | // The copy_layer's render surface should have two contributing layers. |
| 5564 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5565 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5566 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5567 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5568 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5569 | |
| 5570 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5571 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5572 | // copy grand child should not be drawn as its hidden even in the copy |
| 5573 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 5574 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5575 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5576 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
| 5577 | EXPECT_FALSE(node->data.is_drawn); |
| 5578 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
| 5579 | EXPECT_FALSE(node->data.is_drawn); |
| 5580 | node = tree.Node(copy_layer->effect_tree_index()); |
| 5581 | EXPECT_TRUE(node->data.is_drawn); |
| 5582 | node = tree.Node(copy_child_layer->effect_tree_index()); |
| 5583 | EXPECT_TRUE(node->data.is_drawn); |
| 5584 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
| 5585 | EXPECT_FALSE(node->data.is_drawn); |
| 5586 | |
| 5587 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5588 | // actually hidden. |
| 5589 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5590 | } |
| 5591 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5592 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5593 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5594 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5595 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5596 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5597 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5598 | host_impl.CreatePendingTree(); |
| 5599 | const gfx::Transform identity_matrix; |
| 5600 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5601 | std::unique_ptr<LayerImpl> root = |
| 5602 | LayerImpl::Create(host_impl.pending_tree(), 1); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5603 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5604 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5605 | true); |
| 5606 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5607 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5608 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5609 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5610 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5611 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 5612 | false, false); |
| 5613 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5614 | copy_parent->SetMasksToBounds(true); |
| 5615 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5616 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5617 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5618 | SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix, |
| 5619 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5620 | true, false, true); |
| 5621 | copy_layer->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5622 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5623 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5624 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5625 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5626 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5627 | true, false, false); |
| 5628 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5629 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5630 | std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5631 | copy_requests.push_back( |
| 5632 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5633 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5634 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5635 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5636 | copy_layer->AddChild(std::move(copy_child)); |
| 5637 | copy_parent->AddChild(std::move(copy_layer)); |
| 5638 | root->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5639 | |
| 5640 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5641 | LayerImpl* root_layer = root.get(); |
| 5642 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5643 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5644 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5645 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5646 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5647 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5648 | // We should have two render surface, as the others are clipped out. |
| 5649 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5650 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5651 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5652 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5653 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5654 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5655 | EXPECT_EQ(root_layer->id(), |
| 5656 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5657 | } |
| 5658 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5659 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5660 | LayerImpl* root = root_layer(); |
| 5661 | LayerImpl* surface = AddChild<LayerImpl>(root); |
| 5662 | LayerImpl* surface_child = AddChild<LayerImpl>(surface); |
| 5663 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5664 | const gfx::Transform identity_matrix; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5665 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 5666 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5667 | true); |
| 5668 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 5669 | gfx::PointF(-10, 20), gfx::Size(), true, false, |
| 5670 | true); |
| 5671 | SetLayerPropertiesForTesting(surface_child, identity_matrix, gfx::Point3F(), |
| 5672 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5673 | false); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5674 | root->SetDrawsContent(true); |
| 5675 | surface_child->SetDrawsContent(true); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5676 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5677 | ExecuteCalculateDrawProperties(root); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5678 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 5679 | // The visible_layer_rect for the |surface_child| should not be clipped by |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5680 | // the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5681 | EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5682 | } |
| 5683 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5684 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5685 | // Ensure that a transform between the layer and its render surface is not a |
| 5686 | // problem. Constructs the following layer tree. |
| 5687 | // |
| 5688 | // root (a render surface) |
| 5689 | // + render_surface |
| 5690 | // + clip_parent (scaled) |
| 5691 | // + intervening_clipping_layer |
| 5692 | // + clip_child |
| 5693 | // |
| 5694 | // The render surface should be resized correctly and the clip child should |
| 5695 | // inherit the right clip rect. |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5696 | LayerImpl* root = root_layer(); |
| 5697 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5698 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5699 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5700 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5701 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5702 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5703 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5704 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5705 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5706 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5707 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5708 | |
| 5709 | intervening->SetMasksToBounds(true); |
| 5710 | clip_parent->SetMasksToBounds(true); |
| 5711 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5712 | gfx::Transform scale_transform; |
| 5713 | scale_transform.Scale(2, 2); |
| 5714 | |
| 5715 | gfx::Transform identity_transform; |
| 5716 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5717 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5718 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5719 | true); |
| 5720 | SetLayerPropertiesForTesting(render_surface, identity_transform, |
| 5721 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5722 | true, false, true); |
| 5723 | SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(), |
| 5724 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5725 | false, false); |
| 5726 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5727 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5728 | false, false); |
| 5729 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5730 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5731 | false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5732 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5733 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5734 | |
| 5735 | ASSERT_TRUE(root->render_surface()); |
| 5736 | ASSERT_TRUE(render_surface->render_surface()); |
| 5737 | |
| 5738 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5739 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5740 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5741 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5742 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5743 | |
| 5744 | // Ensure that the render surface reports a content rect that has been grown |
| 5745 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5746 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5747 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5748 | |
| 5749 | // The above check implies the two below, but they nicely demonstrate that |
| 5750 | // we've grown, despite the intervening layer's clip. |
| 5751 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5752 | render_surface->render_surface()->content_rect())); |
| 5753 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5754 | render_surface->render_surface()->content_rect())); |
| 5755 | } |
| 5756 | |
| 5757 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5758 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5759 | // case. In the following tree, both render surfaces should be resized to |
| 5760 | // accomodate for the clip child, despite an intervening clip. |
| 5761 | // |
| 5762 | // root (a render surface) |
| 5763 | // + clip_parent (masks to bounds) |
| 5764 | // + render_surface1 (sets opacity) |
| 5765 | // + intervening (masks to bounds) |
| 5766 | // + render_surface2 (also sets opacity) |
| 5767 | // + clip_child |
| 5768 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5769 | LayerImpl* root = root_layer(); |
| 5770 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5771 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5772 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5773 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5774 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5775 | render_surface1->SetDrawsContent(true); |
| 5776 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5777 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5778 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5779 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5780 | |
| 5781 | intervening->SetMasksToBounds(true); |
| 5782 | clip_parent->SetMasksToBounds(true); |
| 5783 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5784 | gfx::Transform translation_transform; |
| 5785 | translation_transform.Translate(2, 2); |
| 5786 | |
| 5787 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5788 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5789 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5790 | true); |
| 5791 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5792 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5793 | gfx::Size(40, 40), true, false, false); |
| 5794 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5795 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5796 | true, false, true); |
| 5797 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5798 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5799 | false, false); |
| 5800 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5801 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5802 | true, false, true); |
| 5803 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5804 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 5805 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5806 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5807 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5808 | |
| 5809 | EXPECT_TRUE(root->render_surface()); |
| 5810 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5811 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5812 | |
| 5813 | // Since the render surfaces could have expanded, they should not clip (their |
| 5814 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5815 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5816 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5817 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5818 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5819 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5820 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5821 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5822 | |
| 5823 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5824 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5825 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5826 | |
| 5827 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5828 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5829 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5830 | |
| 5831 | // The content rects of both render surfaces should both have expanded to |
| 5832 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5833 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5834 | render_surface1->render_surface()->content_rect()); |
| 5835 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5836 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5837 | |
| 5838 | // The clip child should have inherited the clip parent's clip (projected to |
| 5839 | // the right space, of course), and should have the correctly sized visible |
| 5840 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5841 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5842 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5843 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5844 | } |
| 5845 | |
| 5846 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5847 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5848 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5849 | // of transform. |
| 5850 | // |
| 5851 | // root (a render surface) |
| 5852 | // + clip_parent (masks to bounds) |
| 5853 | // + render_surface1 (sets opacity) |
| 5854 | // + intervening (masks to bounds AND scrolls) |
| 5855 | // + render_surface2 (also sets opacity) |
| 5856 | // + clip_child |
| 5857 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5858 | LayerImpl* root = root_layer(); |
| 5859 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5860 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5861 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5862 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5863 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5864 | render_surface1->SetDrawsContent(true); |
| 5865 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5866 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5867 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5868 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5869 | |
| 5870 | intervening->SetMasksToBounds(true); |
| 5871 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5872 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5873 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5874 | |
| 5875 | gfx::Transform translation_transform; |
| 5876 | translation_transform.Translate(2, 2); |
| 5877 | |
| 5878 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5879 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5880 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5881 | true); |
| 5882 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5883 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5884 | gfx::Size(40, 40), true, false, false); |
| 5885 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5886 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5887 | true, false, true); |
| 5888 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5889 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5890 | false, false); |
| 5891 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5892 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5893 | true, false, true); |
| 5894 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5895 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 5896 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5897 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5898 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5899 | |
| 5900 | EXPECT_TRUE(root->render_surface()); |
| 5901 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5902 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5903 | |
| 5904 | // Since the render surfaces could have expanded, they should not clip (their |
| 5905 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5906 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5907 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5908 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5909 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5910 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5911 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5912 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5913 | |
| 5914 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5915 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5916 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5917 | |
| 5918 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5919 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5920 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5921 | |
| 5922 | // The content rects of both render surfaces should both have expanded to |
| 5923 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5924 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5925 | render_surface1->render_surface()->content_rect()); |
| 5926 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 5927 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5928 | |
| 5929 | // The clip child should have inherited the clip parent's clip (projected to |
| 5930 | // the right space, of course), and should have the correctly sized visible |
| 5931 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5932 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 5933 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5934 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5935 | } |
| 5936 | |
| 5937 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 5938 | // Ensures that descendants of the clip child inherit the correct clip. |
| 5939 | // |
| 5940 | // root (a render surface) |
| 5941 | // + clip_parent (masks to bounds) |
| 5942 | // + intervening (masks to bounds) |
| 5943 | // + clip_child |
| 5944 | // + child |
| 5945 | // |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5946 | LayerImpl* root = root_layer(); |
| 5947 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 5948 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 5949 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5950 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5951 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5952 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5953 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5954 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5955 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5956 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5957 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5958 | |
| 5959 | intervening->SetMasksToBounds(true); |
| 5960 | clip_parent->SetMasksToBounds(true); |
| 5961 | |
| 5962 | gfx::Transform identity_transform; |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5963 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5964 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5965 | true); |
| 5966 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 5967 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5968 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5969 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5970 | gfx::PointF(), gfx::Size(5, 5), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5971 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5972 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5973 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5974 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5975 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 5976 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5977 | false); |
| 5978 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 5979 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5980 | |
| 5981 | EXPECT_TRUE(root->render_surface()); |
| 5982 | |
| 5983 | // Neither the clip child nor its descendant should have inherited the clip |
| 5984 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5985 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5986 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5987 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5988 | EXPECT_TRUE(child->is_clipped()); |
| 5989 | } |
| 5990 | |
| 5991 | TEST_F(LayerTreeHostCommonTest, |
| 5992 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 5993 | // Ensures that non-descendant clip children in the tree do not affect |
| 5994 | // render surfaces. |
| 5995 | // |
| 5996 | // root (a render surface) |
| 5997 | // + clip_parent (masks to bounds) |
| 5998 | // + render_surface1 |
| 5999 | // + clip_child |
| 6000 | // + render_surface2 |
| 6001 | // + non_clip_child |
| 6002 | // |
| 6003 | // In this example render_surface2 should be unaffected by clip_child. |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6004 | LayerImpl* root = root_layer(); |
| 6005 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6006 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6007 | render_surface1->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6008 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 6009 | clip_child->SetDrawsContent(true); |
| 6010 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6011 | render_surface2->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6012 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
| 6013 | non_clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6014 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6015 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6016 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6017 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6018 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6019 | |
| 6020 | clip_parent->SetMasksToBounds(true); |
| 6021 | render_surface1->SetMasksToBounds(true); |
| 6022 | |
| 6023 | gfx::Transform identity_transform; |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6024 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6025 | gfx::PointF(), gfx::Size(15, 15), true, false, |
| 6026 | true); |
| 6027 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6028 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6029 | false); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6030 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6031 | gfx::Point3F(), gfx::PointF(5, 5), |
| 6032 | gfx::Size(5, 5), true, false, true); |
| 6033 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6034 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6035 | true, false, true); |
| 6036 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6037 | gfx::PointF(-1, 1), gfx::Size(10, 10), true, |
| 6038 | false, false); |
| 6039 | SetLayerPropertiesForTesting(non_clip_child, identity_transform, |
| 6040 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6041 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6042 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6043 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6044 | |
| 6045 | EXPECT_TRUE(root->render_surface()); |
| 6046 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6047 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6048 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6049 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6050 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6051 | |
| 6052 | // The render surface should not clip (it has unclipped descendants), instead |
| 6053 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6054 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 6055 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6056 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6057 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6058 | // That said, it should have grown to accomodate the unclipped descendant and |
| 6059 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6060 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 6061 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6062 | |
| 6063 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6064 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 6065 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6066 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 6067 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6068 | |
| 6069 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6070 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 6071 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6072 | |
| 6073 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 6074 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 6075 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6076 | } |
| 6077 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6078 | TEST_F(LayerTreeHostCommonTest, |
| 6079 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 6080 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 6081 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6082 | LayerImpl* root = root_layer(); |
| 6083 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 6084 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 6085 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 6086 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6087 | |
| 6088 | const gfx::Transform identity_matrix; |
| 6089 | gfx::Point3F transform_origin; |
| 6090 | gfx::PointF position; |
| 6091 | gfx::Size bounds(100, 100); |
| 6092 | |
| 6093 | SetLayerPropertiesForTesting(root, identity_matrix, transform_origin, |
| 6094 | position, bounds, true, false); |
| 6095 | SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin, |
| 6096 | position, bounds, false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6097 | child1->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6098 | SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin, |
| 6099 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6100 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6101 | SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin, |
| 6102 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6103 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6104 | |
| 6105 | child2->Set3dSortingContextId(1); |
| 6106 | child3->Set3dSortingContextId(1); |
| 6107 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6108 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6109 | |
| 6110 | // Verify which render surfaces were created. |
| 6111 | EXPECT_TRUE(root->has_render_surface()); |
| 6112 | EXPECT_FALSE(child1->has_render_surface()); |
| 6113 | EXPECT_TRUE(child2->has_render_surface()); |
| 6114 | EXPECT_FALSE(child3->has_render_surface()); |
| 6115 | } |
| 6116 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6117 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6118 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6119 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6120 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6121 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6122 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6123 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6124 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6125 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6126 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6127 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6128 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6129 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6130 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6131 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6132 | |
| 6133 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6134 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6135 | gfx::PointF position; |
| 6136 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6137 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6138 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6139 | root->SetDrawsContent(true); |
| 6140 | |
| 6141 | // This layer structure normally forces render surface due to preserves3d |
| 6142 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6143 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6144 | position, bounds, false, true, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6145 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6146 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6147 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6148 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6149 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 6150 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6151 | child3->SetDrawsContent(true); |
| 6152 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6153 | child2->Set3dSortingContextId(1); |
| 6154 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6155 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 6156 | child2->AddChild(std::move(child3)); |
| 6157 | child1->AddChild(std::move(child2)); |
| 6158 | root->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6159 | LayerImpl* root_layer = root.get(); |
| 6160 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6161 | |
| 6162 | { |
| 6163 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6164 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6165 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6166 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6167 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6168 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6169 | |
| 6170 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6171 | |
| 6172 | int count_represents_target_render_surface = 0; |
| 6173 | int count_represents_contributing_render_surface = 0; |
| 6174 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6175 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6176 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6177 | it != end; ++it) { |
| 6178 | if (it.represents_target_render_surface()) |
| 6179 | count_represents_target_render_surface++; |
| 6180 | if (it.represents_contributing_render_surface()) |
| 6181 | count_represents_contributing_render_surface++; |
| 6182 | if (it.represents_itself()) |
| 6183 | count_represents_itself++; |
| 6184 | } |
| 6185 | |
| 6186 | // Two render surfaces. |
| 6187 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6188 | // Second render surface contributes to root render surface. |
| 6189 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6190 | // All 4 layers represent itself. |
| 6191 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6192 | } |
| 6193 | |
| 6194 | { |
| 6195 | LayerImplList render_surface_layer_list; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6196 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6197 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6198 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6199 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6200 | |
| 6201 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6202 | |
| 6203 | int count_represents_target_render_surface = 0; |
| 6204 | int count_represents_contributing_render_surface = 0; |
| 6205 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6206 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6207 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6208 | it != end; ++it) { |
| 6209 | if (it.represents_target_render_surface()) |
| 6210 | count_represents_target_render_surface++; |
| 6211 | if (it.represents_contributing_render_surface()) |
| 6212 | count_represents_contributing_render_surface++; |
| 6213 | if (it.represents_itself()) |
| 6214 | count_represents_itself++; |
| 6215 | } |
| 6216 | |
| 6217 | // Only root layer has a render surface. |
| 6218 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6219 | // No layer contributes a render surface to root render surface. |
| 6220 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6221 | // All 4 layers represent itself. |
| 6222 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6223 | } |
| 6224 | } |
| 6225 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6226 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6227 | LayerImpl* root = root_layer(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6228 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6229 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6230 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6231 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6232 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 6233 | child1->SetDrawsContent(true); |
| 6234 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6235 | |
| 6236 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6237 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6238 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6239 | true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6240 | SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(), |
| 6241 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6242 | false); |
| 6243 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6244 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6245 | false, true, true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6246 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6247 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6248 | false, true, true); |
| 6249 | SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(), |
| 6250 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 6251 | false); |
| 6252 | SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(), |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6253 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6254 | false); |
| 6255 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6256 | root->test_properties()->should_flatten_transform = false; |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6257 | root->Set3dSortingContextId(1); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6258 | back_facing->Set3dSortingContextId(1); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6259 | back_facing->test_properties()->should_flatten_transform = false; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6260 | render_surface1->test_properties()->double_sided = false; |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6261 | render_surface2->Set3dSortingContextId(2); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6262 | render_surface2->test_properties()->double_sided = false; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6263 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6264 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6265 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6266 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6267 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6268 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6269 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6270 | ->at(0) |
| 6271 | ->render_surface() |
| 6272 | ->layer_list() |
| 6273 | .size()); |
| 6274 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6275 | ->at(1) |
| 6276 | ->render_surface() |
| 6277 | ->layer_list() |
| 6278 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6279 | |
| 6280 | gfx::Transform rotation_transform = identity_transform; |
| 6281 | rotation_transform.RotateAboutXAxis(180.0); |
| 6282 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6283 | back_facing->SetTransform(rotation_transform); |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6284 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6285 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6286 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6287 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6288 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6289 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6290 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6291 | // context. |
| 6292 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6293 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6294 | ->at(0) |
| 6295 | ->render_surface() |
| 6296 | ->layer_list() |
| 6297 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6298 | } |
| 6299 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6300 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
| 6301 | LayerImpl* root = root_layer(); |
| 6302 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6303 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 6304 | grand_child->SetDrawsContent(true); |
| 6305 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6306 | child->test_properties()->double_sided = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6307 | grand_child->SetUseParentBackfaceVisibility(true); |
| 6308 | |
| 6309 | gfx::Transform identity_transform; |
| 6310 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6311 | gfx::PointF(), gfx::Size(50, 50), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6312 | true); |
| 6313 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6314 | gfx::PointF(), gfx::Size(30, 30), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6315 | false); |
| 6316 | SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6317 | gfx::PointF(), gfx::Size(20, 20), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6318 | false); |
| 6319 | |
| 6320 | ExecuteCalculateDrawProperties(root); |
| 6321 | |
| 6322 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6323 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6324 | ->at(0) |
| 6325 | ->render_surface() |
| 6326 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6327 | |
| 6328 | // As all layers have identity transform, we shouldn't check for backface |
| 6329 | // visibility. |
| 6330 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6331 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6332 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6333 | // As there are no 3d rendering contexts, all layers should use their local |
| 6334 | // transform for backface visibility. |
| 6335 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6336 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6337 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6338 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6339 | gfx::Transform rotation_transform = identity_transform; |
| 6340 | rotation_transform.RotateAboutXAxis(180.0); |
| 6341 | |
| 6342 | child->SetTransform(rotation_transform); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6343 | child->Set3dSortingContextId(1); |
| 6344 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6345 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6346 | |
| 6347 | ExecuteCalculateDrawProperties(root); |
| 6348 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6349 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6350 | ->at(0) |
| 6351 | ->render_surface() |
| 6352 | ->layer_list() |
| 6353 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6354 | |
| 6355 | // We should check for backface visibilty of child as it has a rotation |
| 6356 | // transform. We should also check for grand_child as it uses the backface |
| 6357 | // visibility of its parent. |
| 6358 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6359 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6360 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6361 | // child uses its local transform for backface visibility as it is the root of |
| 6362 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6363 | // the root, but it derives its backface visibility from its parent which uses |
| 6364 | // its local transform. |
| 6365 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6366 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6367 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6368 | |
| 6369 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6370 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6371 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6372 | |
| 6373 | ExecuteCalculateDrawProperties(root); |
| 6374 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6375 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6376 | ->at(0) |
| 6377 | ->render_surface() |
| 6378 | ->layer_list() |
| 6379 | .size()); |
| 6380 | |
| 6381 | // We should check the backface visibility of child as it has a rotation |
| 6382 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6383 | // the root of it. |
| 6384 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6385 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6386 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6387 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6388 | // local transform for backface visibility. |
| 6389 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6390 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6391 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6392 | } |
| 6393 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6394 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
| 6395 | LayerImpl* root = root_layer(); |
| 6396 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6397 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6398 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6399 | |
| 6400 | gfx::Transform identity_transform; |
| 6401 | gfx::Transform rotate_about_y; |
| 6402 | rotate_about_y.RotateAboutYAxis(180.0); |
| 6403 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6404 | gfx::PointF(), gfx::Size(50, 50), false, true, |
| 6405 | true); |
| 6406 | SetLayerPropertiesForTesting(back_facing, rotate_about_y, gfx::Point3F(), |
| 6407 | gfx::PointF(), gfx::Size(50, 50), false, true, |
| 6408 | false); |
| 6409 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6410 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6411 | false, true, true); |
| 6412 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6413 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6414 | false, true, true); |
| 6415 | |
| 6416 | render_surface1->test_properties()->double_sided = false; |
| 6417 | render_surface2->test_properties()->double_sided = false; |
| 6418 | |
| 6419 | ExecuteCalculateDrawProperties(root); |
| 6420 | |
| 6421 | const EffectTree& tree = |
| 6422 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6423 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
| 6424 | ->data.hidden_by_backface_visibility); |
| 6425 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6426 | ->data.hidden_by_backface_visibility); |
| 6427 | |
| 6428 | back_facing->OnTransformAnimated(identity_transform); |
| 6429 | render_surface2->OnTransformAnimated(rotate_about_y); |
| 6430 | ExecuteCalculateDrawProperties(root); |
| 6431 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
| 6432 | ->data.hidden_by_backface_visibility); |
| 6433 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6434 | ->data.hidden_by_backface_visibility); |
| 6435 | |
| 6436 | render_surface1->OnTransformAnimated(rotate_about_y); |
| 6437 | ExecuteCalculateDrawProperties(root); |
| 6438 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
| 6439 | ->data.hidden_by_backface_visibility); |
| 6440 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6441 | ->data.hidden_by_backface_visibility); |
| 6442 | } |
| 6443 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6444 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6445 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6446 | // have been processed before you anyhow) results in the right clips. |
| 6447 | // |
| 6448 | // + root |
| 6449 | // + scroll_parent_border |
| 6450 | // | + scroll_parent_clip |
| 6451 | // | + scroll_parent |
| 6452 | // + scroll_child |
| 6453 | // |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6454 | LayerImpl* root = root_layer(); |
| 6455 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6456 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6457 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6458 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6459 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6460 | scroll_parent->SetDrawsContent(true); |
| 6461 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6462 | scroll_parent_clip->SetMasksToBounds(true); |
| 6463 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6464 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6465 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6466 | new std::set<LayerImpl*>); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6467 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6468 | scroll_parent->test_properties()->scroll_children.reset( |
| 6469 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6470 | |
| 6471 | gfx::Transform identity_transform; |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6472 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6473 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6474 | true); |
| 6475 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6476 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6477 | true, false, false); |
| 6478 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6479 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6480 | true, false, false); |
| 6481 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6482 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6483 | true, false, false); |
| 6484 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6485 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6486 | false); |
| 6487 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6488 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6489 | |
| 6490 | EXPECT_TRUE(root->render_surface()); |
| 6491 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6492 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6493 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6494 | } |
| 6495 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6496 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6497 | // Tests the computation of draw transform for the scroll child when its |
| 6498 | // target is different from its scroll parent's target. |
| 6499 | LayerImpl* root = root_layer(); |
| 6500 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6501 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6502 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6503 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6504 | |
| 6505 | scroll_parent->SetDrawsContent(true); |
| 6506 | scroll_child->SetDrawsContent(true); |
| 6507 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6508 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6509 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6510 | new std::set<LayerImpl*>); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6511 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6512 | scroll_parent->test_properties()->scroll_children.reset( |
| 6513 | scroll_children.release()); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6514 | |
| 6515 | gfx::Transform identity_transform; |
| 6516 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6517 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6518 | true); |
| 6519 | SetLayerPropertiesForTesting(scroll_child_target, identity_transform, |
| 6520 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6521 | true, false, true); |
| 6522 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6523 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6524 | false); |
| 6525 | SetLayerPropertiesForTesting(scroll_parent_target, identity_transform, |
| 6526 | gfx::Point3F(), gfx::PointF(10, 10), |
| 6527 | gfx::Size(50, 50), true, false, true); |
| 6528 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6529 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6530 | true, false, false); |
| 6531 | scroll_parent_target->SetMasksToBounds(true); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6532 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6533 | float device_scale_factor = 1.5f; |
| 6534 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6535 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6536 | root, root->bounds(), identity_transform, |
| 6537 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6538 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6539 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6540 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6541 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6542 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6543 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6544 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6545 | gfx::Transform scale; |
| 6546 | scale.Scale(1.5f, 1.5f); |
| 6547 | EXPECT_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6548 | } |
| 6549 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6550 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6551 | LayerImpl* root = root_layer(); |
| 6552 | root->SetDrawsContent(true); |
| 6553 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 6554 | parent->SetDrawsContent(true); |
| 6555 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 6556 | child->SetDrawsContent(true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6557 | |
| 6558 | gfx::Transform identity_transform; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6559 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6560 | gfx::PointF(), gfx::Size(50, 50), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6561 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6562 | SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(), |
| 6563 | gfx::PointF(), gfx::Size(30, 30), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6564 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6565 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6566 | gfx::PointF(), gfx::Size(20, 20), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6567 | true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6568 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6569 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6570 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6571 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6572 | |
| 6573 | gfx::Transform singular_transform; |
| 6574 | singular_transform.Scale3d( |
| 6575 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6576 | |
| 6577 | child->SetTransform(singular_transform); |
| 6578 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6579 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6580 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6581 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6582 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6583 | |
| 6584 | // Ensure that the entire subtree under a layer with singular transform does |
| 6585 | // not get rendered. |
| 6586 | parent->SetTransform(singular_transform); |
| 6587 | child->SetTransform(identity_transform); |
| 6588 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6589 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6590 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6591 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6592 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6593 | } |
| 6594 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6595 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6596 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6597 | // still results in correct clipping. |
| 6598 | // |
| 6599 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6600 | // + scroll_parent_border |
| 6601 | // + scroll_parent_clip |
| 6602 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6603 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6604 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6605 | LayerImpl* root = root_layer(); |
| 6606 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6607 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6608 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6609 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6610 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6611 | scroll_parent->SetDrawsContent(true); |
| 6612 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6613 | |
| 6614 | scroll_parent_clip->SetMasksToBounds(true); |
| 6615 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6616 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6617 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6618 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6619 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6620 | scroll_parent->test_properties()->scroll_children.reset( |
| 6621 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6622 | |
| 6623 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6624 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6625 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6626 | true); |
| 6627 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6628 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6629 | true, false, false); |
| 6630 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6631 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6632 | true, false, false); |
| 6633 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6634 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6635 | true, false, false); |
| 6636 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6637 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6638 | false); |
| 6639 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6640 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6641 | |
| 6642 | EXPECT_TRUE(root->render_surface()); |
| 6643 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6644 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6645 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6646 | } |
| 6647 | |
| 6648 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6649 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6650 | // you in paint order still results in correct clipping. |
| 6651 | // |
| 6652 | // + root |
| 6653 | // + scroll_child |
| 6654 | // + scroll_parent_border |
| 6655 | // | + scroll_parent_clip |
| 6656 | // | + scroll_parent |
| 6657 | // + scroll_grandparent_border |
| 6658 | // + scroll_grandparent_clip |
| 6659 | // + scroll_grandparent |
| 6660 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6661 | LayerImpl* root = root_layer(); |
| 6662 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6663 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6664 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6665 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6666 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6667 | LayerImpl* scroll_grandparent_clip = |
| 6668 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6669 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6670 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6671 | scroll_parent->SetDrawsContent(true); |
| 6672 | scroll_grandparent->SetDrawsContent(true); |
| 6673 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6674 | |
| 6675 | scroll_parent_clip->SetMasksToBounds(true); |
| 6676 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6677 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6678 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6679 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6680 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6681 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6682 | scroll_parent->test_properties()->scroll_children.reset( |
| 6683 | scroll_children.release()); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6684 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6685 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6686 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6687 | scroll_children->insert(scroll_parent_border); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6688 | scroll_grandparent->test_properties()->scroll_children.reset( |
| 6689 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6690 | |
| 6691 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6692 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6693 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6694 | true); |
| 6695 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6696 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6697 | true, false, false); |
| 6698 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6699 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6700 | true, false, false); |
| 6701 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6702 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6703 | true, false, false); |
| 6704 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6705 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6706 | true, false, false); |
| 6707 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6708 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6709 | true, false, false); |
| 6710 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6711 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6712 | true, false, false); |
| 6713 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6714 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6715 | false); |
| 6716 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6717 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6718 | |
| 6719 | EXPECT_TRUE(root->render_surface()); |
| 6720 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6721 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6722 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6723 | |
| 6724 | // Despite the fact that we visited the above layers out of order to get the |
| 6725 | // correct clip, the layer lists should be unaffected. |
| 6726 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6727 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6728 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6729 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6733 | // 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] | 6734 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6735 | // + root |
| 6736 | // + scroll_child |
| 6737 | // + scroll_parent_border |
| 6738 | // + scroll_parent_clip |
| 6739 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6740 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6741 | // + scroll_grandparent_border |
| 6742 | // + scroll_grandparent_clip |
| 6743 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6744 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6745 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6746 | LayerImpl* root = root_layer(); |
| 6747 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6748 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6749 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6750 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6751 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6752 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6753 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6754 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6755 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6756 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6757 | LayerImpl* scroll_grandparent_clip = |
| 6758 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6759 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6760 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6761 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6762 | scroll_parent->SetDrawsContent(true); |
| 6763 | render_surface1->SetDrawsContent(true); |
| 6764 | scroll_grandparent->SetDrawsContent(true); |
| 6765 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6766 | |
| 6767 | scroll_parent_clip->SetMasksToBounds(true); |
| 6768 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6769 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6770 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6771 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6772 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6773 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6774 | scroll_parent->test_properties()->scroll_children.reset( |
| 6775 | scroll_children.release()); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6776 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6777 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6778 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6779 | scroll_children->insert(scroll_parent_border); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6780 | scroll_grandparent->test_properties()->scroll_children.reset( |
| 6781 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6782 | |
| 6783 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6784 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6785 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6786 | true); |
| 6787 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6788 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6789 | true, false, false); |
| 6790 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6791 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6792 | true, false, false); |
| 6793 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6794 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6795 | true, false, false); |
| 6796 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6797 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6798 | true, false, true); |
| 6799 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6800 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6801 | true, false, false); |
| 6802 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6803 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6804 | true, false, false); |
| 6805 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6806 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6807 | true, false, false); |
| 6808 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6809 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6810 | true, false, true); |
| 6811 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6812 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6813 | false); |
| 6814 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6815 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6816 | |
| 6817 | EXPECT_TRUE(root->render_surface()); |
| 6818 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6819 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6820 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6821 | |
| 6822 | // Despite the fact that we had to process the layers out of order to get the |
| 6823 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6824 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6825 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6826 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6827 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6828 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6829 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6830 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6831 | } |
| 6832 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6833 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6834 | // Ensures that when we have a render surface between a fixed position layer |
| 6835 | // and its container, we compute the fixed position layer's draw transform |
| 6836 | // with respect to that intervening render surface, not with respect to its |
| 6837 | // container's render target. |
| 6838 | // |
| 6839 | // + root |
| 6840 | // + render_surface |
| 6841 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6842 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6843 | // |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6844 | LayerImpl* root = root_layer(); |
| 6845 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6846 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6847 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6848 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6849 | render_surface->SetDrawsContent(true); |
| 6850 | fixed->SetDrawsContent(true); |
| 6851 | child->SetDrawsContent(true); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6852 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6853 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6854 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6855 | |
| 6856 | LayerPositionConstraint constraint; |
| 6857 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6858 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6859 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6860 | SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6861 | gfx::PointF(), gfx::Size(50, 50), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6862 | SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(), |
| 6863 | gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true, |
| 6864 | false); |
| 6865 | SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6866 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 6867 | false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6868 | SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(), |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6869 | gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, |
| 6870 | false); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6871 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6872 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6873 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6874 | TransformTree& tree = |
| 6875 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6876 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6877 | gfx::Transform expected_fixed_draw_transform; |
| 6878 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6879 | EXPECT_EQ(expected_fixed_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6880 | draw_property_utils::DrawTransform(fixed, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6881 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6882 | gfx::Transform expected_fixed_screen_space_transform; |
| 6883 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
| 6884 | EXPECT_EQ(expected_fixed_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6885 | draw_property_utils::ScreenSpaceTransform(fixed, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6886 | |
| 6887 | gfx::Transform expected_child_draw_transform; |
| 6888 | expected_child_draw_transform.Translate(11.f, 17.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6889 | EXPECT_EQ(expected_child_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6890 | draw_property_utils::DrawTransform(child, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6891 | |
| 6892 | gfx::Transform expected_child_screen_space_transform; |
| 6893 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
| 6894 | EXPECT_EQ(expected_child_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6895 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6896 | } |
| 6897 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6898 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 6899 | // This test verifies that a scrolling layer that gets snapped to |
| 6900 | // integer coordinates doesn't move a fixed position child. |
| 6901 | // |
| 6902 | // + root |
| 6903 | // + container |
| 6904 | // + scroller |
| 6905 | // + fixed |
| 6906 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6907 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6908 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6909 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6910 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6911 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6912 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6913 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6914 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 6915 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6916 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6917 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 6918 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6919 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6920 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 6921 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6922 | std::unique_ptr<LayerImpl> fixed = |
| 6923 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6924 | LayerImpl* fixed_layer = fixed.get(); |
| 6925 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6926 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6927 | |
| 6928 | LayerPositionConstraint constraint; |
| 6929 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6930 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6931 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6932 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6933 | |
| 6934 | gfx::Transform identity_transform; |
| 6935 | gfx::Transform container_transform; |
| 6936 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 6937 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 6938 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6939 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6940 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6941 | true); |
| 6942 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 6943 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6944 | true, false, false); |
| 6945 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 6946 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6947 | true, false, false); |
| 6948 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 6949 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6950 | false); |
| 6951 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6952 | root->SetDrawsContent(true); |
| 6953 | container->SetDrawsContent(true); |
| 6954 | scroller->SetDrawsContent(true); |
| 6955 | fixed->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 6956 | scroller->AddChild(std::move(fixed)); |
| 6957 | container->AddChild(std::move(scroller)); |
| 6958 | root->AddChild(std::move(container)); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6959 | |
| 6960 | // Rounded to integers already. |
| 6961 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6962 | root->layer_tree_impl()->SetRootLayer(std::move(root_ptr)); |
| 6963 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 6964 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6965 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6966 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6967 | |
| 6968 | LayerImplList render_surface_layer_list; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6969 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6970 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6971 | root->layer_tree_impl() |
| 6972 | ->property_trees() |
| 6973 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6974 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6975 | |
| 6976 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6977 | container_layer->draw_properties().screen_space_transform, |
| 6978 | fixed_layer->draw_properties().screen_space_transform); |
| 6979 | EXPECT_VECTOR_EQ( |
| 6980 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 6981 | container_offset); |
| 6982 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 6983 | .screen_space_transform.To2dTranslation(), |
| 6984 | container_offset - scroll_delta); |
| 6985 | } |
| 6986 | |
| 6987 | // Scroll delta requiring rounding. |
| 6988 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6989 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 6990 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6991 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 6992 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6993 | |
| 6994 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 6995 | |
| 6996 | LayerImplList render_surface_layer_list; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 6997 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6998 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6999 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7000 | |
| 7001 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7002 | container_layer->draw_properties().screen_space_transform, |
| 7003 | fixed_layer->draw_properties().screen_space_transform); |
| 7004 | EXPECT_VECTOR_EQ( |
| 7005 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7006 | container_offset); |
| 7007 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7008 | .screen_space_transform.To2dTranslation(), |
| 7009 | container_offset - rounded_scroll_delta); |
| 7010 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7011 | |
| 7012 | // Scale is applied earlier in the tree. |
| 7013 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7014 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7015 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7016 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7017 | container_layer->SetTransform(scaled_container_transform); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7018 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7019 | root->layer_tree_impl()->BuildPropertyTreesForTesting(); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7020 | |
| 7021 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7022 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7023 | |
| 7024 | LayerImplList render_surface_layer_list; |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7025 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7026 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7027 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7028 | |
| 7029 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7030 | container_layer->draw_properties().screen_space_transform, |
| 7031 | fixed_layer->draw_properties().screen_space_transform); |
| 7032 | EXPECT_VECTOR_EQ( |
| 7033 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7034 | container_offset); |
| 7035 | |
| 7036 | container_layer->SetTransform(container_transform); |
| 7037 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7038 | } |
| 7039 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7040 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7041 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 7042 | // This test verifies that a scrolling layer whose screen space transform is |
| 7043 | // animating doesn't get snapped to integer coordinates. |
| 7044 | // |
| 7045 | // + root |
| 7046 | // + animated layer |
| 7047 | // + surface |
| 7048 | // + container |
| 7049 | // + scroller |
| 7050 | // |
| 7051 | LayerImpl* root = root_layer(); |
| 7052 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 7053 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 7054 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 7055 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
| 7056 | scroller->SetScrollClipLayer(container->id()); |
| 7057 | scroller->SetDrawsContent(true); |
| 7058 | |
| 7059 | gfx::Transform identity_transform; |
| 7060 | gfx::Transform start_scale; |
| 7061 | start_scale.Scale(1.5f, 1.5f); |
| 7062 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 7063 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7064 | true); |
| 7065 | SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(), |
| 7066 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7067 | false); |
| 7068 | SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(), |
| 7069 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7070 | true); |
| 7071 | SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(), |
| 7072 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7073 | false); |
| 7074 | SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(), |
| 7075 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 7076 | false); |
| 7077 | |
| 7078 | gfx::Transform end_scale; |
| 7079 | end_scale.Scale(2.f, 2.f); |
| 7080 | TransformOperations start_operations; |
| 7081 | start_operations.AppendMatrix(start_scale); |
| 7082 | TransformOperations end_operations; |
| 7083 | end_operations.AppendMatrix(end_scale); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7084 | AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(), |
| 7085 | 1.0, start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7086 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7087 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7088 | |
| 7089 | ExecuteCalculateDrawProperties(root); |
| 7090 | |
| 7091 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 7092 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7093 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7094 | } |
| 7095 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7096 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7097 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7098 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7099 | LayerTreeImpl* tree_impl, |
| 7100 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7101 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7102 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7103 | } |
| 7104 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7105 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7106 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7107 | private: |
| 7108 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7109 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7110 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7111 | SetDrawsContent(true); |
| 7112 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7113 | }; |
| 7114 | |
| 7115 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7116 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7117 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7118 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7119 | LayerTreeSettings settings = host()->settings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7120 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7121 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7122 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7123 | gfx::Transform identity_matrix; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7124 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7125 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7126 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7127 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7128 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7129 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7130 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7131 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7132 | |
| 7133 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7134 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7135 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7136 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7137 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7138 | child->AddChild(std::move(grand_child)); |
| 7139 | parent->AddChild(std::move(child)); |
| 7140 | grand_parent->AddChild(std::move(parent)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7141 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7142 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7143 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7144 | true, false, true); |
| 7145 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7146 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7147 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7148 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7149 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7150 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7151 | |
| 7152 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7153 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7154 | false); |
| 7155 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7156 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
| 7157 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7158 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7159 | |
| 7160 | // No layers have animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7161 | EXPECT_EQ( |
| 7162 | 0.f, |
| 7163 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7164 | EXPECT_EQ(0.f, |
| 7165 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7166 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7167 | EXPECT_EQ( |
| 7168 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7169 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7170 | EXPECT_EQ( |
| 7171 | 0.f, |
| 7172 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7173 | EXPECT_EQ(0.f, |
| 7174 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7175 | EXPECT_EQ(0.f, |
| 7176 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7177 | EXPECT_EQ( |
| 7178 | 0.f, |
| 7179 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7180 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7181 | TransformOperations translation; |
| 7182 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7183 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7184 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7185 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7186 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7187 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7188 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7189 | TransformOperations(), translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7190 | |
| 7191 | // No layers have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7192 | EXPECT_EQ( |
| 7193 | 0.f, |
| 7194 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7195 | EXPECT_EQ(0.f, |
| 7196 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7197 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7198 | EXPECT_EQ( |
| 7199 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7200 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7201 | EXPECT_EQ( |
| 7202 | 0.f, |
| 7203 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7204 | EXPECT_EQ(0.f, |
| 7205 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7206 | EXPECT_EQ(0.f, |
| 7207 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7208 | EXPECT_EQ( |
| 7209 | 0.f, |
| 7210 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7211 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7212 | TransformOperations scale; |
| 7213 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7214 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7215 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7216 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7217 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7218 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7219 | |
| 7220 | // Only |child| has a scale-affecting animation. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7221 | EXPECT_EQ( |
| 7222 | 0.f, |
| 7223 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7224 | EXPECT_EQ(0.f, |
| 7225 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7226 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7227 | EXPECT_EQ( |
| 7228 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7229 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7230 | EXPECT_EQ( |
| 7231 | 0.f, |
| 7232 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7233 | EXPECT_EQ(0.f, |
| 7234 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7235 | EXPECT_EQ(1.f, |
| 7236 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7237 | EXPECT_EQ( |
| 7238 | 1.f, |
| 7239 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7240 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7241 | AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7242 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7243 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7244 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7245 | |
| 7246 | // |grand_parent| and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7247 | EXPECT_EQ( |
| 7248 | 5.f, |
| 7249 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7250 | EXPECT_EQ(5.f, |
| 7251 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7252 | // We don't support combining animated scales from two nodes; 0.f means |
| 7253 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7254 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7255 | EXPECT_EQ( |
| 7256 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7257 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7258 | EXPECT_EQ( |
| 7259 | 1.f, |
| 7260 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7261 | EXPECT_EQ(1.f, |
| 7262 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7263 | EXPECT_EQ(0.f, |
| 7264 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7265 | EXPECT_EQ( |
| 7266 | 0.f, |
| 7267 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7268 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7269 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7270 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7271 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7272 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7273 | |
| 7274 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7275 | EXPECT_EQ( |
| 7276 | 5.f, |
| 7277 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7278 | EXPECT_EQ(0.f, |
| 7279 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7280 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7281 | EXPECT_EQ( |
| 7282 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7283 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7284 | EXPECT_EQ( |
| 7285 | 1.f, |
| 7286 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7287 | EXPECT_EQ(0.f, |
| 7288 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7289 | EXPECT_EQ(0.f, |
| 7290 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7291 | EXPECT_EQ( |
| 7292 | 0.f, |
| 7293 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7294 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7295 | AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7296 | TargetProperty::TRANSFORM); |
| 7297 | AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline, |
| 7298 | TargetProperty::TRANSFORM); |
| 7299 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7300 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7301 | |
| 7302 | TransformOperations perspective; |
| 7303 | perspective.AppendPerspective(10.f); |
| 7304 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7305 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7306 | TransformOperations(), perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7307 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7308 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7309 | |
| 7310 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7311 | // animation is not supported. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7312 | EXPECT_EQ( |
| 7313 | 0.f, |
| 7314 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7315 | EXPECT_EQ(0.f, |
| 7316 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7317 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7318 | EXPECT_EQ( |
| 7319 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7320 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7321 | EXPECT_EQ( |
| 7322 | 0.f, |
| 7323 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7324 | EXPECT_EQ(0.f, |
| 7325 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7326 | EXPECT_EQ(0.f, |
| 7327 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7328 | EXPECT_EQ( |
| 7329 | 0.f, |
| 7330 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7331 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7332 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7333 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7334 | gfx::Transform scale_matrix; |
| 7335 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7336 | grand_parent_raw->SetTransform(scale_matrix); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7337 | parent_raw->SetTransform(scale_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7338 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7339 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7340 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7341 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7342 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7343 | |
| 7344 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7345 | // animation with maximum scale 5.f. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7346 | EXPECT_EQ( |
| 7347 | 0.f, |
| 7348 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7349 | EXPECT_EQ(10.f, |
| 7350 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7351 | EXPECT_EQ(10.f, |
| 7352 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 7353 | EXPECT_EQ( |
| 7354 | 10.f, |
| 7355 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7356 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7357 | EXPECT_EQ( |
| 7358 | 0.f, |
| 7359 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7360 | EXPECT_EQ(2.f, |
| 7361 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7362 | EXPECT_EQ(2.f, |
| 7363 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7364 | EXPECT_EQ( |
| 7365 | 2.f, |
| 7366 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7367 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7368 | gfx::Transform perspective_matrix; |
| 7369 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 7370 | child_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7371 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7372 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7373 | |
| 7374 | // |child| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7375 | EXPECT_EQ( |
| 7376 | 0.f, |
| 7377 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7378 | EXPECT_EQ(10.f, |
| 7379 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7380 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7381 | EXPECT_EQ( |
| 7382 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7383 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7384 | EXPECT_EQ( |
| 7385 | 0.f, |
| 7386 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7387 | EXPECT_EQ(2.f, |
| 7388 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7389 | EXPECT_EQ(0.f, |
| 7390 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7391 | EXPECT_EQ( |
| 7392 | 0.f, |
| 7393 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7394 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7395 | parent_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7396 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7397 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7398 | |
| 7399 | // |parent| and |child| have transforms that are neither translations nor |
| 7400 | // scales. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7401 | EXPECT_EQ( |
| 7402 | 0.f, |
| 7403 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7404 | EXPECT_EQ(0.f, |
| 7405 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7406 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7407 | EXPECT_EQ( |
| 7408 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7409 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7410 | EXPECT_EQ( |
| 7411 | 0.f, |
| 7412 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7413 | EXPECT_EQ(0.f, |
| 7414 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7415 | EXPECT_EQ(0.f, |
| 7416 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7417 | EXPECT_EQ( |
| 7418 | 0.f, |
| 7419 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7420 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7421 | parent_raw->SetTransform(identity_matrix); |
| 7422 | child_raw->SetTransform(identity_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7423 | grand_parent_raw->SetTransform(perspective_matrix); |
| 7424 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7425 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7426 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7427 | |
| 7428 | // |grand_parent| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7429 | EXPECT_EQ( |
| 7430 | 0.f, |
| 7431 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7432 | EXPECT_EQ(0.f, |
| 7433 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7434 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7435 | EXPECT_EQ( |
| 7436 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7437 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7438 | EXPECT_EQ( |
| 7439 | 0.f, |
| 7440 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7441 | EXPECT_EQ(0.f, |
| 7442 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7443 | EXPECT_EQ(0.f, |
| 7444 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7445 | EXPECT_EQ( |
| 7446 | 0.f, |
| 7447 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7448 | } |
| 7449 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7450 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 7451 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7452 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7453 | end = LayerIterator::End(rsll); |
| 7454 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7455 | LayerImpl* layer = *it; |
| 7456 | if (it.represents_itself()) |
| 7457 | drawn_layers->insert(layer); |
| 7458 | |
| 7459 | if (!it.represents_contributing_render_surface()) |
| 7460 | continue; |
| 7461 | |
| 7462 | if (layer->mask_layer()) |
| 7463 | drawn_layers->insert(layer->mask_layer()); |
| 7464 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 7465 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 7466 | } |
| 7467 | } |
| 7468 | |
| 7469 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7470 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7471 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7472 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7473 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7474 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7475 | gfx::Transform identity_matrix; |
| 7476 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7477 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7478 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7479 | std::unique_ptr<LayerImpl> parent = |
| 7480 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7481 | std::unique_ptr<LayerImpl> child = |
| 7482 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7483 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7484 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7485 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7486 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7487 | |
| 7488 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7489 | LayerImpl* parent_raw = parent.get(); |
| 7490 | LayerImpl* child_raw = child.get(); |
| 7491 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7492 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7493 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7494 | child->AddChild(std::move(grand_child1)); |
| 7495 | child->AddChild(std::move(grand_child2)); |
| 7496 | parent->AddChild(std::move(child)); |
| 7497 | grand_parent->AddChild(std::move(parent)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7498 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7499 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7500 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 7501 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7502 | true, false, true); |
| 7503 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7504 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7505 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7506 | |
| 7507 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7508 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7509 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7510 | |
| 7511 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 7512 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7513 | true, false, false); |
| 7514 | |
| 7515 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 7516 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7517 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7518 | |
| 7519 | // Start with nothing being drawn. |
| 7520 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7521 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7522 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7523 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7524 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7525 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7526 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7527 | |
| 7528 | std::set<LayerImpl*> expected; |
| 7529 | std::set<LayerImpl*> actual; |
| 7530 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7531 | EXPECT_EQ(expected, actual); |
| 7532 | |
| 7533 | // If we force render surface, but none of the layers are in the layer list, |
| 7534 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7535 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7536 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7537 | |
| 7538 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7539 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7540 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7541 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7542 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7543 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7544 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7545 | |
| 7546 | expected.clear(); |
| 7547 | actual.clear(); |
| 7548 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7549 | EXPECT_EQ(expected, actual); |
| 7550 | |
| 7551 | // However, if we say that this layer also draws content, it will appear in |
| 7552 | // RSLL. |
| 7553 | grand_child1_raw->SetDrawsContent(true); |
| 7554 | |
| 7555 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7556 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7557 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7558 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7559 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7560 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7561 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7562 | |
| 7563 | expected.clear(); |
| 7564 | expected.insert(grand_child1_raw); |
| 7565 | |
| 7566 | actual.clear(); |
| 7567 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7568 | EXPECT_EQ(expected, actual); |
| 7569 | |
| 7570 | // Now child is forced to have a render surface, and one if its children draws |
| 7571 | // content. |
| 7572 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7573 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7574 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7575 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7576 | grand_child2_raw->SetDrawsContent(true); |
| 7577 | |
| 7578 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7579 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7580 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7581 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7582 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7583 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7584 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7585 | |
| 7586 | expected.clear(); |
| 7587 | expected.insert(grand_child2_raw); |
| 7588 | |
| 7589 | actual.clear(); |
| 7590 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7591 | EXPECT_EQ(expected, actual); |
| 7592 | |
| 7593 | // Add a mask layer to child. |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7594 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7595 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7596 | |
| 7597 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7598 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7599 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7600 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7601 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7602 | EXPECT_TRUE( |
| 7603 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7604 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7605 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7606 | |
| 7607 | expected.clear(); |
| 7608 | expected.insert(grand_child2_raw); |
| 7609 | expected.insert(child_raw->mask_layer()); |
| 7610 | |
| 7611 | expected.clear(); |
| 7612 | expected.insert(grand_child2_raw); |
| 7613 | expected.insert(child_raw->mask_layer()); |
| 7614 | |
| 7615 | actual.clear(); |
| 7616 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7617 | EXPECT_EQ(expected, actual); |
| 7618 | |
| 7619 | // Add replica mask layer. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7620 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7621 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 7622 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7623 | child_raw->SetReplicaLayer(std::move(replica_layer)); |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 7624 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7625 | |
| 7626 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7627 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7628 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7629 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7630 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7631 | EXPECT_TRUE( |
| 7632 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7633 | EXPECT_TRUE(child_raw->replica_layer() |
| 7634 | ->mask_layer() |
| 7635 | ->is_drawn_render_surface_layer_list_member()); |
| 7636 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7637 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7638 | |
| 7639 | expected.clear(); |
| 7640 | expected.insert(grand_child2_raw); |
| 7641 | expected.insert(child_raw->mask_layer()); |
| 7642 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 7643 | |
| 7644 | actual.clear(); |
| 7645 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7646 | EXPECT_EQ(expected, actual); |
| 7647 | |
| 7648 | child_raw->TakeReplicaLayer(); |
| 7649 | |
| 7650 | // With nothing drawing, we should have no layers. |
| 7651 | grand_child2_raw->SetDrawsContent(false); |
| 7652 | |
| 7653 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7654 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7655 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7656 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7657 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7658 | EXPECT_FALSE( |
| 7659 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7660 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7661 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7662 | |
| 7663 | expected.clear(); |
| 7664 | actual.clear(); |
| 7665 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7666 | EXPECT_EQ(expected, actual); |
| 7667 | |
| 7668 | // Child itself draws means that we should have the child and the mask in the |
| 7669 | // list. |
| 7670 | child_raw->SetDrawsContent(true); |
| 7671 | |
| 7672 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7673 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7674 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7675 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7676 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7677 | EXPECT_TRUE( |
| 7678 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7679 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7680 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7681 | |
| 7682 | expected.clear(); |
| 7683 | expected.insert(child_raw); |
| 7684 | expected.insert(child_raw->mask_layer()); |
| 7685 | actual.clear(); |
| 7686 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7687 | EXPECT_EQ(expected, actual); |
| 7688 | |
| 7689 | child_raw->TakeMaskLayer(); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7690 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7691 | |
| 7692 | // Now everyone's a member! |
| 7693 | grand_parent_raw->SetDrawsContent(true); |
| 7694 | parent_raw->SetDrawsContent(true); |
| 7695 | child_raw->SetDrawsContent(true); |
| 7696 | grand_child1_raw->SetDrawsContent(true); |
| 7697 | grand_child2_raw->SetDrawsContent(true); |
| 7698 | |
| 7699 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7700 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7701 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7702 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7703 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7704 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7705 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7706 | |
| 7707 | expected.clear(); |
| 7708 | expected.insert(grand_parent_raw); |
| 7709 | expected.insert(parent_raw); |
| 7710 | expected.insert(child_raw); |
| 7711 | expected.insert(grand_child1_raw); |
| 7712 | expected.insert(grand_child2_raw); |
| 7713 | |
| 7714 | actual.clear(); |
| 7715 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7716 | EXPECT_EQ(expected, actual); |
| 7717 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7718 | |
| 7719 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7720 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7721 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7722 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7723 | LayerTreeSettings settings = host()->settings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7724 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7725 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7726 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7727 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7728 | std::unique_ptr<LayerImpl> root = |
| 7729 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7730 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7731 | std::unique_ptr<LayerImpl> child1 = |
| 7732 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7733 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7734 | std::unique_ptr<LayerImpl> child2 = |
| 7735 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7736 | LayerImpl* child2_layer = child2.get(); |
| 7737 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7738 | root->AddChild(std::move(child1)); |
| 7739 | root->AddChild(std::move(child2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7740 | root->test_properties()->force_render_surface = true; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7741 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7742 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7743 | |
| 7744 | gfx::Transform identity_matrix, scale_transform_child1, |
| 7745 | scale_transform_child2; |
| 7746 | scale_transform_child1.Scale(2, 3); |
| 7747 | scale_transform_child2.Scale(4, 5); |
| 7748 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7749 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 7750 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 7751 | true); |
| 7752 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7753 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7754 | true, false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7755 | |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7756 | child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7757 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7758 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7759 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7760 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7761 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7762 | child1_layer->SetReplicaLayer(std::move(replica_layer)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7763 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7764 | |
| 7765 | ExecuteCalculateDrawProperties(root_layer); |
| 7766 | |
| 7767 | TransformOperations scale; |
| 7768 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7769 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7770 | scoped_refptr<AnimationTimeline> timeline = |
| 7771 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7772 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7773 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7774 | AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0, |
| 7775 | TransformOperations(), scale); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7776 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7777 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7778 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7779 | true, false, false); |
| 7780 | child2_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7781 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7782 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7783 | ExecuteCalculateDrawProperties(root_layer); |
| 7784 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7785 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7786 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
| 7787 | EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
| 7788 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7789 | |
| 7790 | EXPECT_FLOAT_EQ( |
| 7791 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7792 | EXPECT_FLOAT_EQ( |
| 7793 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7794 | EXPECT_FLOAT_EQ(0.f, |
| 7795 | child1_layer->mask_layer() |
| 7796 | ->draw_properties() |
| 7797 | .maximum_animation_contents_scale); |
| 7798 | EXPECT_FLOAT_EQ(0.f, |
| 7799 | child1_layer->replica_layer() |
| 7800 | ->mask_layer() |
| 7801 | ->draw_properties() |
| 7802 | .maximum_animation_contents_scale); |
| 7803 | EXPECT_FLOAT_EQ( |
| 7804 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7805 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7806 | // Changing page-scale would affect ideal_contents_scale and |
| 7807 | // maximum_animation_contents_scale. |
| 7808 | |
| 7809 | float page_scale_factor = 3.f; |
| 7810 | float device_scale_factor = 1.0f; |
| 7811 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7812 | gfx::Size device_viewport_size = |
| 7813 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7814 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7815 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7816 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7817 | |
| 7818 | inputs.page_scale_factor = page_scale_factor; |
| 7819 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7820 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7821 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7822 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7823 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7824 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
| 7825 | EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7826 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7827 | 9.f, |
| 7828 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 7829 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7830 | |
| 7831 | EXPECT_FLOAT_EQ( |
| 7832 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7833 | EXPECT_FLOAT_EQ( |
| 7834 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7835 | EXPECT_FLOAT_EQ(0.f, |
| 7836 | child1_layer->mask_layer() |
| 7837 | ->draw_properties() |
| 7838 | .maximum_animation_contents_scale); |
| 7839 | EXPECT_FLOAT_EQ(0.f, |
| 7840 | child1_layer->replica_layer() |
| 7841 | ->mask_layer() |
| 7842 | ->draw_properties() |
| 7843 | .maximum_animation_contents_scale); |
| 7844 | EXPECT_FLOAT_EQ( |
| 7845 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7846 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7847 | // Changing device-scale would affect ideal_contents_scale and |
| 7848 | // maximum_animation_contents_scale. |
| 7849 | |
| 7850 | device_scale_factor = 4.0f; |
| 7851 | inputs.device_scale_factor = device_scale_factor; |
| 7852 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7853 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7854 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7855 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7856 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7857 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
| 7858 | EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7859 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7860 | 36.f, |
| 7861 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 7862 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7863 | |
| 7864 | EXPECT_FLOAT_EQ( |
| 7865 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7866 | EXPECT_FLOAT_EQ( |
| 7867 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7868 | EXPECT_FLOAT_EQ(0.f, |
| 7869 | child1_layer->mask_layer() |
| 7870 | ->draw_properties() |
| 7871 | .maximum_animation_contents_scale); |
| 7872 | EXPECT_FLOAT_EQ(0.f, |
| 7873 | child1_layer->replica_layer() |
| 7874 | ->mask_layer() |
| 7875 | ->draw_properties() |
| 7876 | .maximum_animation_contents_scale); |
| 7877 | EXPECT_FLOAT_EQ( |
| 7878 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7879 | } |
| 7880 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7881 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7882 | LayerImpl* root = root_layer(); |
| 7883 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 7884 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7885 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7886 | const gfx::Transform identity_matrix; |
| 7887 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 7888 | gfx::PointF(), gfx::Size(768 / 2, 3000), true, |
| 7889 | false, true); |
| 7890 | SetLayerPropertiesForTesting(clip, identity_matrix, gfx::Point3F(), |
| 7891 | gfx::PointF(), gfx::Size(768 / 2, 10000), true, |
| 7892 | false, false); |
| 7893 | SetLayerPropertiesForTesting(content, identity_matrix, gfx::Point3F(), |
| 7894 | gfx::PointF(), gfx::Size(768 / 2, 10000), true, |
| 7895 | false, true); |
| 7896 | root->SetDrawsContent(true); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7897 | clip->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7898 | content->SetDrawsContent(true); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7899 | |
| 7900 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7901 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7902 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7903 | root, device_viewport_size, identity_matrix, |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7904 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7905 | inputs.device_scale_factor = 2.f; |
| 7906 | inputs.page_scale_factor = 1.f; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7907 | inputs.page_scale_layer = NULL; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7908 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7909 | |
| 7910 | // Layers in the root render surface have their visible content rect clipped |
| 7911 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7912 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7913 | |
| 7914 | // Layers drawing to a child render surface should still have their visible |
| 7915 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7916 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7917 | } |
| 7918 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7919 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7920 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7921 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7922 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7923 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7924 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7925 | |
| 7926 | // Set two layers: the root layer clips it's child, |
| 7927 | // the child draws its content. |
| 7928 | |
| 7929 | gfx::Size root_size = gfx::Size(300, 500); |
| 7930 | |
| 7931 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 7932 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 7933 | |
| 7934 | // Device viewport accomidated the root and the top controls. |
| 7935 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 7936 | gfx::Transform identity_matrix; |
| 7937 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 7938 | host_impl.SetViewportSize(device_viewport_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7939 | host_impl.active_tree()->SetRootLayer( |
| 7940 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 7941 | |
| 7942 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 7943 | SetLayerPropertiesForTesting(root, |
| 7944 | identity_matrix, |
| 7945 | gfx::Point3F(), |
| 7946 | gfx::PointF(), |
| 7947 | root_size, |
| 7948 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7949 | false, |
| 7950 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7951 | root->SetMasksToBounds(true); |
| 7952 | |
| 7953 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 7954 | |
| 7955 | LayerImpl* sublayer = root->child_at(0); |
| 7956 | SetLayerPropertiesForTesting(sublayer, |
| 7957 | identity_matrix, |
| 7958 | gfx::Point3F(), |
| 7959 | gfx::PointF(), |
| 7960 | sublayer_size, |
| 7961 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7962 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7963 | false); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7964 | sublayer->SetDrawsContent(true); |
| 7965 | |
| 7966 | LayerImplList layer_impl_list; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7967 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7968 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7969 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7970 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7971 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7972 | |
| 7973 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7974 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7975 | |
| 7976 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 7977 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 7978 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 7979 | } |
| 7980 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 7981 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 7982 | scoped_refptr<Layer> root = Layer::Create(); |
| 7983 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 7984 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 7985 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 7986 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 7987 | |
| 7988 | root->AddChild(inner_viewport_container_layer); |
| 7989 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 7990 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 7991 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 7992 | |
| 7993 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 7994 | inner_viewport_container_layer->id()); |
| 7995 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 7996 | outer_viewport_container_layer->id()); |
| 7997 | |
| 7998 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 7999 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8000 | |
| 8001 | host()->SetRootLayer(root); |
| 8002 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 8003 | outer_viewport_scroll_layer); |
| 8004 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8005 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8006 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8007 | |
| 8008 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8009 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8010 | |
| 8011 | LayerPositionConstraint fixed_to_right; |
| 8012 | fixed_to_right.set_is_fixed_position(true); |
| 8013 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8014 | |
| 8015 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8016 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8017 | |
| 8018 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8019 | |
| 8020 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8021 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8022 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8023 | |
| 8024 | LayerPositionConstraint fixed_to_left; |
| 8025 | fixed_to_left.set_is_fixed_position(true); |
| 8026 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8027 | |
| 8028 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8029 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8030 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8031 | |
| 8032 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8033 | |
| 8034 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8035 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8036 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8037 | } |
| 8038 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8039 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8040 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8041 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8042 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8043 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8044 | |
| 8045 | root->AddChild(animated); |
| 8046 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8047 | host()->SetRootLayer(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8048 | |
| 8049 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8050 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8051 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8052 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8053 | |
| 8054 | root->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8055 | root->SetForceRenderSurfaceForTesting(true); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8056 | animated->SetOpacity(0.f); |
| 8057 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8058 | AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f, |
| 8059 | 1.f, false); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8060 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8061 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8062 | EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8063 | } |
| 8064 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8065 | TEST_F(LayerTreeHostCommonTest, |
| 8066 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
| 8067 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8068 | scoped_refptr<Layer> root = Layer::Create(); |
| 8069 | scoped_refptr<Layer> clip = Layer::Create(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8070 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8071 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8072 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8073 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8074 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8075 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8076 | |
| 8077 | root->AddChild(clip); |
| 8078 | clip->AddChild(animated); |
| 8079 | animated->AddChild(surface); |
| 8080 | surface->AddChild(descendant_of_animation); |
| 8081 | |
| 8082 | clip->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8083 | surface->SetForceRenderSurfaceForTesting(true); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8084 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8085 | host()->SetRootLayer(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8086 | |
| 8087 | gfx::Transform uninvertible_matrix; |
| 8088 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8089 | |
| 8090 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8091 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8092 | SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 8093 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8094 | SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix, |
| 8095 | gfx::Point3F(), gfx::PointF(), |
| 8096 | gfx::Size(120, 120), true, false); |
| 8097 | SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 8098 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8099 | SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix, |
| 8100 | gfx::Point3F(), gfx::PointF(), |
| 8101 | gfx::Size(200, 200), true, false); |
| 8102 | |
| 8103 | TransformOperations start_transform_operations; |
| 8104 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8105 | TransformOperations end_transform_operations; |
| 8106 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8107 | AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0, |
| 8108 | start_transform_operations, |
| 8109 | end_transform_operations); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8110 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8111 | |
| 8112 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8113 | // clipped target space, so is treated as fully visible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8114 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8115 | |
| 8116 | // The singular transform on |animated| is flattened when inherited by |
| 8117 | // |surface|, and this happens to make it invertible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8118 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing()); |
| 8119 | EXPECT_EQ(gfx::Rect(2, 2), |
| 8120 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8121 | |
| 8122 | gfx::Transform zero_matrix; |
| 8123 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8124 | SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(), |
| 8125 | gfx::PointF(), gfx::Size(120, 120), true, false); |
| 8126 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8127 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8128 | |
| 8129 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8130 | // treated as having an empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8131 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8132 | |
| 8133 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8134 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8135 | // |surface| and layers that draw into it as having empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8136 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing()); |
| 8137 | EXPECT_EQ(gfx::Rect(), |
| 8138 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8139 | } |
| 8140 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8141 | // Verify that having an animated filter (but no current filter, as these |
| 8142 | // are mutually exclusive) correctly creates a render surface. |
| 8143 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8144 | LayerImpl* root = root_layer(); |
| 8145 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8146 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8147 | |
| 8148 | gfx::Transform identity_transform; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8149 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8150 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8151 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8152 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8153 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8154 | gfx::PointF(), gfx::Size(50, 50), true, false); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8155 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8156 | AddAnimatedFilterToLayerWithPlayer(child->id(), timeline_impl(), 10.0, 0.1f, |
| 8157 | 0.2f); |
| 8158 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8159 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8160 | EXPECT_TRUE(root->has_render_surface()); |
| 8161 | EXPECT_TRUE(child->has_render_surface()); |
| 8162 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8163 | |
| 8164 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8165 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8166 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8167 | |
| 8168 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8169 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8170 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8171 | } |
| 8172 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8173 | // Verify that having a filter animation with a delayed start time creates a |
| 8174 | // render surface. |
| 8175 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8176 | LayerImpl* root = root_layer(); |
| 8177 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8178 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8179 | |
| 8180 | gfx::Transform identity_transform; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8181 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8182 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8183 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8184 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8185 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8186 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8187 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8188 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8189 | KeyframedFilterAnimationCurve::Create()); |
| 8190 | FilterOperations start_filters; |
| 8191 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8192 | FilterOperations end_filters; |
| 8193 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8194 | curve->AddKeyframe( |
| 8195 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8196 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8197 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8198 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8199 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8200 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8201 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8202 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8203 | AddAnimationToLayerWithPlayer(child->id(), timeline_impl(), |
| 8204 | std::move(animation)); |
| 8205 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8206 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8207 | EXPECT_TRUE(root->has_render_surface()); |
| 8208 | EXPECT_TRUE(child->has_render_surface()); |
| 8209 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8210 | |
| 8211 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8212 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8213 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8214 | |
| 8215 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8216 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8217 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8218 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8219 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8220 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8221 | } |
| 8222 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8223 | // Ensures that the property tree code accounts for offsets between fixed |
| 8224 | // position layers and their respective containers. |
| 8225 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8226 | LayerImpl* root = root_layer(); |
| 8227 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8228 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8229 | |
| 8230 | gfx::Transform identity_transform; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8231 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8232 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8233 | true); |
| 8234 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8235 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8236 | false, false); |
| 8237 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8238 | gfx::PointF(-1000, -1000), gfx::Size(50, 50), |
| 8239 | true, false, false); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8240 | |
| 8241 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8242 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8243 | LayerPositionConstraint constraint; |
| 8244 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8245 | grandchild->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8246 | grandchild->SetDrawsContent(true); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8247 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8248 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8249 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8250 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8251 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8252 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8253 | } |
| 8254 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8255 | // Ensures that the property tree code accounts for offsets between fixed |
| 8256 | // position containers and their transform tree parents, when a fixed position |
| 8257 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8258 | // own transform tree node. |
| 8259 | TEST_F(LayerTreeHostCommonTest, |
| 8260 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8261 | LayerImpl* root = root_layer(); |
| 8262 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8263 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8264 | |
| 8265 | gfx::Transform identity_transform; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8266 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8267 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8268 | true); |
| 8269 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8270 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8271 | false, false); |
| 8272 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8273 | gfx::PointF(-1000, -1000), gfx::Size(50, 50), |
| 8274 | true, false, false); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8275 | |
| 8276 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8277 | child->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8278 | LayerPositionConstraint constraint; |
| 8279 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8280 | grandchild->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8281 | grandchild->SetDrawsContent(true); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8282 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8283 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8284 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8285 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8286 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8287 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8288 | } |
| 8289 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8290 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8291 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8292 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8293 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8294 | // test ensures that happens. |
| 8295 | |
| 8296 | gfx::Transform rotate; |
| 8297 | rotate.Rotate(5); |
| 8298 | gfx::Transform identity; |
| 8299 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8300 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8301 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8302 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8303 | false); |
| 8304 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8305 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8306 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8307 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8308 | false); |
| 8309 | frame_clip->SetMasksToBounds(true); |
| 8310 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8311 | scoped_refptr<Layer> rotated = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8312 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8313 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8314 | gfx::Size(2500, 500), true, false); |
| 8315 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8316 | scoped_refptr<Layer> surface = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8317 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8318 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8319 | false); |
| 8320 | surface->SetOpacity(0.5); |
| 8321 | |
| 8322 | scoped_refptr<LayerWithForcedDrawsContent> container = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8323 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8324 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8325 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8326 | |
| 8327 | scoped_refptr<LayerWithForcedDrawsContent> box = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8328 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8329 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8330 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8331 | |
| 8332 | root->AddChild(frame_clip); |
| 8333 | frame_clip->AddChild(rotated); |
| 8334 | rotated->AddChild(surface); |
| 8335 | surface->AddChild(container); |
| 8336 | surface->AddChild(box); |
| 8337 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8338 | host()->SetRootLayer(root); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8339 | |
| 8340 | ExecuteCalculateDrawProperties(root.get()); |
| 8341 | } |
| 8342 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8343 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8344 | LayerImpl* root = root_layer(); |
| 8345 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8346 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8347 | gfx::Transform identity; |
| 8348 | gfx::Transform translate_z; |
| 8349 | translate_z.Translate3d(0, 0, 10); |
| 8350 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8351 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8352 | gfx::Size(800, 800), true, false, true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8353 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8354 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8355 | SetLayerPropertiesForTesting(frame_clip, translate_z, gfx::Point3F(), |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8356 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8357 | false, false); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8358 | frame_clip->SetMasksToBounds(true); |
| 8359 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8360 | SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), gfx::PointF(), |
| 8361 | gfx::Size(1000, 1000), true, false, false); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8362 | |
| 8363 | LayerPositionConstraint constraint; |
| 8364 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8365 | fixed->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8366 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8367 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8368 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8369 | |
| 8370 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8371 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8372 | } |
| 8373 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8374 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8375 | LayerImpl* root = root_layer(); |
| 8376 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8377 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8378 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8379 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8380 | gfx::Transform identity; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8381 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8382 | gfx::Size(800, 800), true, false, true); |
| 8383 | SetLayerPropertiesForTesting(frame_clip, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8384 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8385 | false, false); |
| 8386 | SetLayerPropertiesForTesting(scroller, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8387 | gfx::PointF(), gfx::Size(1000, 1000), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8388 | false, false); |
| 8389 | SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8390 | gfx::PointF(100, 100), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8391 | false, true); |
| 8392 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8393 | root->test_properties()->is_container_for_fixed_position_layers = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8394 | root->SetDrawsContent(true); |
| 8395 | |
| 8396 | frame_clip->SetMasksToBounds(true); |
| 8397 | frame_clip->SetDrawsContent(true); |
| 8398 | |
| 8399 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8400 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8401 | scroller->SetDrawsContent(true); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8402 | |
| 8403 | LayerPositionConstraint constraint; |
| 8404 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8405 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8406 | fixed->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8407 | fixed->SetDrawsContent(true); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8408 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8409 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8410 | |
| 8411 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8412 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8413 | } |
| 8414 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8415 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
| 8416 | gfx::Transform identity; |
| 8417 | gfx::Transform translate; |
| 8418 | gfx::Transform rotate; |
| 8419 | |
| 8420 | translate.Translate(10, 10); |
| 8421 | rotate.Rotate(45); |
| 8422 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8423 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8424 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8425 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8426 | root->SetIsContainerForFixedPositionLayers(true); |
| 8427 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8428 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8429 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8430 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8431 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8432 | |
| 8433 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8434 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8435 | |
| 8436 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8437 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8438 | } |
| 8439 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8440 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8441 | LayerImpl* root = root_layer(); |
| 8442 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8443 | |
| 8444 | gfx::Transform identity_matrix; |
| 8445 | gfx::Transform scale_matrix; |
| 8446 | scale_matrix.Scale(2.f, 2.f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8447 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 8448 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8449 | true); |
| 8450 | SetLayerPropertiesForTesting(child, scale_matrix, gfx::Point3F(), |
| 8451 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8452 | false); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8453 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8454 | root->SetDrawsContent(true); |
| 8455 | child->SetDrawsContent(true); |
| 8456 | |
| 8457 | ExecuteCalculateDrawProperties(root); |
| 8458 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8459 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8460 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8461 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8462 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8463 | ExecuteCalculateDrawProperties(root); |
| 8464 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8465 | } |
| 8466 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8467 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8468 | LayerImpl* root = root_layer(); |
| 8469 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8470 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8471 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8472 | scroll_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8473 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8474 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 8475 | new std::set<LayerImpl*>); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8476 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8477 | scroll_parent->test_properties()->scroll_children.reset( |
| 8478 | scroll_children.release()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8479 | scroll_parent->SetDrawsContent(true); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8480 | |
| 8481 | gfx::Transform identity_transform; |
| 8482 | gfx::Transform scale; |
| 8483 | scale.Scale(2.f, 2.f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8484 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8485 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8486 | true); |
| 8487 | SetLayerPropertiesForTesting(scroll_child, scale, gfx::Point3F(), |
| 8488 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 8489 | false); |
| 8490 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8491 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8492 | true, false, false); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8493 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8494 | ExecuteCalculateDrawProperties(root); |
| 8495 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8496 | |
| 8497 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8498 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8499 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8500 | ExecuteCalculateDrawProperties(root); |
| 8501 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8502 | } |
| 8503 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8504 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8505 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8506 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8507 | // If the layer has a node in effect_tree, the return value of |
| 8508 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8509 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8510 | // to be the value of its nearest ancestor that owns an effect node and |
| 8511 | // greater than or equal to the actual number of copy requests in the |
| 8512 | // sub-layer_tree. |
| 8513 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8514 | scoped_refptr<Layer> root = Layer::Create(); |
| 8515 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8516 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8517 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8518 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8519 | |
| 8520 | root->AddChild(child1); |
| 8521 | root->AddChild(child2); |
| 8522 | child1->AddChild(grandchild); |
| 8523 | grandchild->AddChild(greatgrandchild); |
| 8524 | host()->SetRootLayer(root); |
| 8525 | |
| 8526 | child1->RequestCopyOfOutput( |
| 8527 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8528 | greatgrandchild->RequestCopyOfOutput( |
| 8529 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8530 | child2->SetOpacity(0.f); |
| 8531 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8532 | |
| 8533 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8534 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8535 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8536 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8537 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8538 | } |
| 8539 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8540 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
| 8541 | gfx::Transform identity; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8542 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8543 | FakeContentLayerClient client; |
| 8544 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8545 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8546 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8547 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8548 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8549 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8550 | FakePictureLayer::Create(&client)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8551 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8552 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8553 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8554 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8555 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8556 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8557 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 8558 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8559 | |
| 8560 | root->AddChild(child); |
| 8561 | child->AddChild(grandchild); |
| 8562 | grandchild->AddChild(greatgrandchild); |
| 8563 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8564 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8565 | |
| 8566 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8567 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8568 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8569 | |
| 8570 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8571 | // and we will configure |child| in several ways that should force the subtree |
| 8572 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8573 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8574 | grandchild->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8575 | gfx::Transform singular; |
| 8576 | singular.matrix().set(0, 0, 0); |
| 8577 | |
| 8578 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8579 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8580 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8581 | child->SetTransform(identity); |
| 8582 | |
| 8583 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8584 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8585 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8586 | child->SetHideLayerAndSubtree(false); |
| 8587 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8588 | gfx::Transform zero_z_scale; |
| 8589 | zero_z_scale.Scale3d(1, 1, 0); |
| 8590 | child->SetTransform(zero_z_scale); |
| 8591 | |
| 8592 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8593 | // a singular transform, the subtree should still get processed. |
| 8594 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8595 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8596 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8597 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8598 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8599 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8600 | AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8601 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8602 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8603 | grandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8604 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8605 | RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(), |
| 8606 | animation_id); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8607 | child->SetTransform(identity); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8608 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8609 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8610 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8611 | |
| 8612 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8613 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8614 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8615 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8616 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8617 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8618 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8619 | greatgrandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8620 | |
| 8621 | // Add an opacity animation with a start delay. |
| 8622 | animation_id = 1; |
| 8623 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8624 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8625 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8626 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8627 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8628 | AddAnimationToLayerWithExistingPlayer(child->id(), timeline(), |
| 8629 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8630 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8631 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8632 | } |
| 8633 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8634 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8635 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8636 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8637 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8638 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8639 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8640 | |
| 8641 | gfx::Transform identity; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8642 | std::unique_ptr<LayerImpl> root = |
| 8643 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8644 | std::unique_ptr<LayerImpl> child = |
| 8645 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8646 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8647 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8648 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8649 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8650 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8651 | |
| 8652 | child->SetDrawsContent(true); |
| 8653 | grandchild->SetDrawsContent(true); |
| 8654 | greatgrandchild->SetDrawsContent(true); |
| 8655 | |
| 8656 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8657 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8658 | true); |
| 8659 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8660 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8661 | false); |
| 8662 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8663 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8664 | false); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8665 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8666 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8667 | LayerImpl* child_ptr = child.get(); |
| 8668 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8669 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8670 | child->AddChild(std::move(grandchild)); |
| 8671 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8672 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8673 | |
| 8674 | // Check the non-skipped case. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8675 | // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8676 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8677 | |
| 8678 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8679 | // and we will configure |child| in several ways that should force the subtree |
| 8680 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8681 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8682 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8683 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8684 | gfx::Transform singular; |
| 8685 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8686 | // This line is used to make the results of skipping and not skipping layers |
| 8687 | // different. |
| 8688 | singular.matrix().set(0, 1, 1); |
| 8689 | |
| 8690 | gfx::Transform rotate; |
| 8691 | rotate.Rotate(90); |
| 8692 | |
| 8693 | gfx::Transform rotate_back_and_translate; |
| 8694 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8695 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8696 | |
| 8697 | child_ptr->SetTransform(singular); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8698 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8699 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8700 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8701 | child_ptr->SetTransform(identity); |
| 8702 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8703 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8704 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8705 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8706 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8707 | |
| 8708 | child_ptr->SetOpacity(0.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8709 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8710 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8711 | child_ptr->SetOpacity(1.f); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8712 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8713 | root_ptr->SetTransform(singular); |
| 8714 | // Force transform tree to have a node for child, so that ancestor's |
| 8715 | // invertible transform can be tested. |
| 8716 | child_ptr->SetTransform(rotate); |
| 8717 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8718 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8719 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
| 8720 | root_ptr->SetTransform(identity); |
| 8721 | child_ptr->SetTransform(identity); |
| 8722 | |
| 8723 | root_ptr->SetOpacity(0.f); |
| 8724 | child_ptr->SetOpacity(0.7f); |
| 8725 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8726 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8727 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
| 8728 | root_ptr->SetOpacity(1.f); |
| 8729 | |
| 8730 | child_ptr->SetOpacity(0.f); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8731 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8732 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8733 | // processed anyhow. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8734 | std::vector<std::unique_ptr<CopyOutputRequest>> requests; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8735 | requests.push_back(CopyOutputRequest::CreateEmptyRequest()); |
| 8736 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8737 | grandchild_ptr->PassCopyRequests(&requests); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8738 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8739 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8740 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8741 | requests.clear(); |
| 8742 | grandchild_ptr->PassCopyRequests(&requests); |
| 8743 | child_ptr->SetOpacity(1.f); |
| 8744 | |
| 8745 | // A double sided render surface with backface visible should not be skipped |
| 8746 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8747 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8748 | child_ptr->test_properties()->double_sided = true; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8749 | child_ptr->SetTransform(rotate_back_and_translate); |
| 8750 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8751 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8752 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8753 | child_ptr->SetTransform(identity); |
| 8754 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8755 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8756 | KeyframedTransformAnimationCurve::Create()); |
| 8757 | TransformOperations start; |
| 8758 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8759 | gfx::Transform transform; |
| 8760 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8761 | TransformOperations operation; |
| 8762 | operation.AppendMatrix(transform); |
| 8763 | curve->AddKeyframe( |
| 8764 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8765 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8766 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8767 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8768 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8769 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8770 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8771 | root_ptr->id(), player.get()); |
| 8772 | host_impl.active_tree() |
| 8773 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8774 | ->GetElementAnimationsForElementId(root_ptr->id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8775 | ->AddAnimation(std::move(transform_animation)); |
| 8776 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8777 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
| 8778 | root_ptr->SetTransform(singular); |
| 8779 | child_ptr->SetTransform(singular); |
| 8780 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8781 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8782 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8783 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8784 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8785 | root_ptr->id(), player.get()); |
| 8786 | } |
| 8787 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8788 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
| 8789 | LayerImpl* root = root_layer(); |
| 8790 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8791 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 8792 | |
| 8793 | gfx::Transform identity; |
| 8794 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8795 | gfx::Size(10, 10), true, false, true); |
| 8796 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 8797 | gfx::Size(10, 10), true, false, false); |
| 8798 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 8799 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8800 | false); |
| 8801 | |
| 8802 | gfx::Transform singular; |
| 8803 | singular.matrix().set(0, 0, 0); |
| 8804 | singular.matrix().set(0, 1, 1); |
| 8805 | |
| 8806 | child->SetTransform(singular); |
| 8807 | child->SetDrawsContent(true); |
| 8808 | grand_child->SetDrawsContent(true); |
| 8809 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8810 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8811 | KeyframedTransformAnimationCurve::Create()); |
| 8812 | TransformOperations start; |
| 8813 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8814 | gfx::Transform transform; |
| 8815 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8816 | TransformOperations operation; |
| 8817 | operation.AppendMatrix(transform); |
| 8818 | curve->AddKeyframe( |
| 8819 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8820 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8821 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8822 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8823 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8824 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8825 | host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8826 | grand_child->id(), player.get()); |
| 8827 | host_impl() |
| 8828 | ->active_tree() |
| 8829 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8830 | ->GetElementAnimationsForElementId(grand_child->id()) |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8831 | ->AddAnimation(std::move(transform_animation)); |
| 8832 | |
| 8833 | ExecuteCalculateDrawProperties(root); |
| 8834 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 8835 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 8836 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8837 | host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8838 | grand_child->id(), player.get()); |
| 8839 | } |
| 8840 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8841 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8842 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8843 | TestSharedBitmapManager shared_bitmap_manager; |
| 8844 | TestTaskGraphRunner task_graph_runner; |
| 8845 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 8846 | &task_graph_runner); |
| 8847 | |
| 8848 | gfx::Transform identity; |
| 8849 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8850 | std::unique_ptr<LayerImpl> root = |
| 8851 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8852 | std::unique_ptr<LayerImpl> child = |
| 8853 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8854 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8855 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8856 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8857 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8858 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8859 | |
| 8860 | child->SetDrawsContent(true); |
| 8861 | grandchild->SetDrawsContent(true); |
| 8862 | greatgrandchild->SetDrawsContent(true); |
| 8863 | |
| 8864 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8865 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8866 | true); |
| 8867 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8868 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8869 | false); |
| 8870 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8871 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8872 | false); |
| 8873 | |
| 8874 | LayerImpl* root_ptr = root.get(); |
| 8875 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 8876 | |
| 8877 | child->AddChild(std::move(grandchild)); |
| 8878 | root->AddChild(std::move(child)); |
| 8879 | |
| 8880 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
| 8881 | |
| 8882 | // Check the non-skipped case. |
| 8883 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8884 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8885 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8886 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8887 | KeyframedFloatAnimationCurve::Create()); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8888 | std::unique_ptr<TimingFunction> func = EaseTimingFunction::Create(); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8889 | curve->AddKeyframe( |
| 8890 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 8891 | curve->AddKeyframe( |
| 8892 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8893 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8894 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 8895 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8896 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8897 | root_ptr->id(), player.get()); |
| 8898 | host_impl.active_tree() |
| 8899 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8900 | ->GetElementAnimationsForElementId(root_ptr->id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8901 | ->AddAnimation(std::move(animation)); |
| 8902 | root_ptr->SetOpacity(0); |
| 8903 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8904 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8905 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8906 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8907 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8908 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8909 | root_ptr->id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8910 | } |
| 8911 | |
| 8912 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
| 8913 | gfx::Transform identity; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8914 | LayerImpl* root = root_layer(); |
| 8915 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8916 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8917 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8918 | gfx::Size(100, 100), true, false, true); |
| 8919 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 8920 | gfx::Size(10, 10), true, false, false); |
| 8921 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8922 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8923 | ExecuteCalculateDrawProperties(root); |
| 8924 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8925 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8926 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8927 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8928 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8929 | ExecuteCalculateDrawProperties(root); |
| 8930 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8931 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8932 | |
| 8933 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8934 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8935 | ExecuteCalculateDrawProperties(root); |
| 8936 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8937 | child->SetBounds(gfx::Size(10, 10)); |
| 8938 | |
| 8939 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8940 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8941 | rotate.RotateAboutXAxis(180.f); |
| 8942 | child->SetTransform(rotate); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8943 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8944 | ExecuteCalculateDrawProperties(root); |
| 8945 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8946 | child->test_properties()->double_sided = true; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8947 | child->SetTransform(identity); |
| 8948 | |
| 8949 | child->SetOpacity(0.f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8950 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8951 | ExecuteCalculateDrawProperties(root); |
| 8952 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8953 | } |
| 8954 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8955 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 8956 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 8957 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8958 | scoped_refptr<Layer> root = Layer::Create(); |
| 8959 | scoped_refptr<Layer> parent = Layer::Create(); |
| 8960 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8961 | |
| 8962 | root->AddChild(parent); |
| 8963 | parent->AddChild(child); |
| 8964 | |
| 8965 | child->SetClipParent(root.get()); |
| 8966 | |
| 8967 | gfx::Transform identity; |
| 8968 | |
| 8969 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8970 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8971 | SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(), |
| 8972 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8973 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8974 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8975 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8976 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8977 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8978 | child->RequestCopyOfOutput( |
| 8979 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8980 | |
| 8981 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8982 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 8983 | |
| 8984 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 8985 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8986 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 8987 | } |
| 8988 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8989 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
| 8990 | gfx::Transform identity; |
| 8991 | gfx::Transform translate_z; |
| 8992 | translate_z.Translate3d(0, 0, 10); |
| 8993 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8994 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8995 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8996 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8997 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8998 | scoped_refptr<Layer> child = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 8999 | SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(), |
| 9000 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9001 | |
| 9002 | root->AddChild(child); |
| 9003 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9004 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9005 | |
| 9006 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9007 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9008 | |
| 9009 | child->RemoveFromParent(); |
| 9010 | |
| 9011 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9012 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9013 | } |
| 9014 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9015 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9016 | // Ensure that a Clip Node is added when a render surface applies clip. |
| 9017 | LayerImpl* root = root_layer(); |
| 9018 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9019 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9020 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9021 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9022 | |
| 9023 | const gfx::Transform identity_matrix; |
| 9024 | // This transform should be a significant one so that a transform node is |
| 9025 | // formed for it. |
| 9026 | gfx::Transform transform1; |
| 9027 | transform1.RotateAboutYAxis(45); |
| 9028 | transform1.RotateAboutXAxis(30); |
| 9029 | // This transform should be a 3d transform as we want the render surface |
| 9030 | // to flatten the transform |
| 9031 | gfx::Transform transform2; |
| 9032 | transform2.Translate3d(10, 10, 10); |
| 9033 | |
| 9034 | layer_clips_subtree->SetMasksToBounds(true); |
| 9035 | test_layer->SetDrawsContent(true); |
| 9036 | |
| 9037 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9038 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9039 | SetLayerPropertiesForTesting(significant_transform, transform1, |
| 9040 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9041 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9042 | SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix, |
| 9043 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9044 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9045 | SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9046 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9047 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9048 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9049 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9050 | root->test_properties()->force_render_surface = true; |
| 9051 | significant_transform->test_properties()->force_render_surface = false; |
| 9052 | layer_clips_subtree->test_properties()->force_render_surface = true; |
| 9053 | render_surface->test_properties()->force_render_surface = true; |
| 9054 | test_layer->test_properties()->force_render_surface = false; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9055 | ExecuteCalculateDrawProperties(root); |
| 9056 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 9057 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9058 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9059 | TransformNode* transform_node = |
| 9060 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9061 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9062 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9063 | EXPECT_TRUE(root->has_render_surface()); |
| 9064 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9065 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9066 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9067 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9068 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 9069 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9070 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9071 | EXPECT_FALSE(clip_node->data.applies_local_clip); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9072 | EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9073 | } |
| 9074 | |
| 9075 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9076 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9077 | // clip node's target, clip is 'projected' from parent space to current |
| 9078 | // target space and visible rects are calculated correctly. |
| 9079 | LayerImpl* root = root_layer(); |
| 9080 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9081 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9082 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9083 | |
| 9084 | const gfx::Transform identity_matrix; |
| 9085 | gfx::Transform transform; |
| 9086 | transform.RotateAboutYAxis(45); |
| 9087 | clip_layer->SetMasksToBounds(true); |
| 9088 | target_layer->SetMasksToBounds(true); |
| 9089 | test_layer->SetDrawsContent(true); |
| 9090 | |
| 9091 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9092 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9093 | true); |
| 9094 | SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(), |
| 9095 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9096 | false); |
| 9097 | SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), |
| 9098 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9099 | true); |
| 9100 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9101 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9102 | false); |
| 9103 | ExecuteCalculateDrawProperties(root); |
| 9104 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9105 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9106 | } |
| 9107 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9108 | TEST_F(LayerTreeHostCommonTest, |
| 9109 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9110 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9111 | // descendants. |
| 9112 | LayerImpl* root = root_layer(); |
| 9113 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9114 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9115 | LayerImpl* render_surface = |
| 9116 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9117 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9118 | |
| 9119 | const gfx::Transform identity_matrix; |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9120 | gfx::Transform translate; |
| 9121 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9122 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9123 | clip_parent->SetMasksToBounds(true); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9124 | test_layer->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9125 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9126 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | e9d0970 | 2015-09-15 01:26:41 | [diff] [blame] | 9127 | clip_children->insert(render_surface); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9128 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9129 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9130 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9131 | true); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9132 | SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(), |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9133 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9134 | false); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9135 | SetLayerPropertiesForTesting(between_clip_parent_and_child, translate, |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9136 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 9137 | true, false, false); |
| 9138 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9139 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9140 | true); |
| 9141 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9142 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9143 | false); |
| 9144 | |
| 9145 | ExecuteCalculateDrawProperties(root); |
| 9146 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9147 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9148 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9149 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9150 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9151 | } |
| 9152 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9153 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9154 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9155 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9156 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9157 | // a clip. |
| 9158 | LayerImpl* root = root_layer(); |
| 9159 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9160 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9161 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9162 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9163 | |
| 9164 | const gfx::Transform identity_matrix; |
| 9165 | |
| 9166 | clip_child->SetDrawsContent(true); |
| 9167 | child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9168 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9169 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9170 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9171 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9172 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9173 | gfx::PointF(), gfx::Size(30, 10), true, false, |
| 9174 | true); |
| 9175 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9176 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9177 | false); |
| 9178 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9179 | gfx::PointF(), gfx::Size(10, 15), true, false, |
| 9180 | true); |
| 9181 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9182 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9183 | false); |
| 9184 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 9185 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 9186 | false); |
| 9187 | |
| 9188 | ExecuteCalculateDrawProperties(root); |
| 9189 | EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect()); |
| 9190 | } |
| 9191 | |
| 9192 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9193 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
| 9194 | LayerImpl* root = root_layer(); |
| 9195 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9196 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9197 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9198 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9199 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9200 | |
| 9201 | const gfx::Transform identity_matrix; |
| 9202 | root->SetMasksToBounds(true); |
| 9203 | render_surface->SetMasksToBounds(true); |
| 9204 | render_surface->SetDrawsContent(true); |
| 9205 | clip_child->SetDrawsContent(true); |
| 9206 | test_layer1->SetDrawsContent(true); |
| 9207 | test_layer2->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9208 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9209 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9210 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9211 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9212 | |
| 9213 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9214 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9215 | true); |
| 9216 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9217 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9218 | false); |
| 9219 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9220 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9221 | true); |
| 9222 | SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(), |
| 9223 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9224 | false); |
| 9225 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9226 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9227 | false); |
| 9228 | SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(), |
| 9229 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9230 | false); |
| 9231 | |
| 9232 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9233 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9234 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9235 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9236 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9237 | } |
| 9238 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9239 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
| 9240 | LayerImpl* root = root_layer(); |
| 9241 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9242 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9243 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9244 | |
| 9245 | const gfx::Transform identity_matrix; |
| 9246 | clip_parent->SetDrawsContent(true); |
| 9247 | render_surface->SetMasksToBounds(true); |
| 9248 | render_surface->SetDrawsContent(true); |
| 9249 | clip_child->SetDrawsContent(true); |
| 9250 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9251 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9252 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9253 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9254 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9255 | |
| 9256 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9257 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9258 | true); |
| 9259 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9260 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9261 | false); |
| 9262 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9263 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9264 | true); |
| 9265 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9266 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9267 | false); |
| 9268 | |
| 9269 | ExecuteCalculateDrawProperties(root); |
| 9270 | |
| 9271 | // The clip child should inherit its clip parent's clipping state, not its |
| 9272 | // tree parent's clipping state. |
| 9273 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9274 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9275 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9276 | } |
| 9277 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9278 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9279 | // Tests the value of render surface content rect when we have multiple types |
| 9280 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9281 | // clipped surfaces. |
| 9282 | LayerImpl* root = root_layer(); |
| 9283 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9284 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9285 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9286 | LayerImpl* unclipped_desc_surface2 = |
| 9287 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9288 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9289 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9290 | |
| 9291 | unclipped_surface->SetDrawsContent(true); |
| 9292 | unclipped_desc_surface->SetDrawsContent(true); |
| 9293 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9294 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9295 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9296 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9297 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9298 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9299 | |
| 9300 | gfx::Transform identity_matrix; |
| 9301 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9302 | gfx::PointF(), gfx::Size(80, 80), true, false, |
| 9303 | true); |
| 9304 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 9305 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 9306 | true, false, true); |
| 9307 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9308 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9309 | false); |
| 9310 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9311 | gfx::Point3F(), gfx::PointF(), |
| 9312 | gfx::Size(100, 100), true, false, true); |
| 9313 | SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix, |
| 9314 | gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60), |
| 9315 | true, false, true); |
| 9316 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9317 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9318 | false); |
| 9319 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 9320 | gfx::PointF(), gfx::Size(70, 70), true, false, |
| 9321 | true); |
| 9322 | clip_parent->SetMasksToBounds(true); |
| 9323 | unclipped_surface->SetMasksToBounds(true); |
| 9324 | unclipped_desc_surface->SetMasksToBounds(true); |
| 9325 | |
| 9326 | ExecuteCalculateDrawProperties(root); |
| 9327 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9328 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9329 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9330 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9331 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9332 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9333 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9334 | clipped_surface->render_surface()->content_rect()); |
| 9335 | } |
| 9336 | |
| 9337 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9338 | // Tests the value of render surface content rect when we have a layer that |
| 9339 | // clips between the clip parent's target and clip child's target. |
| 9340 | LayerImpl* root = root_layer(); |
| 9341 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9342 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9343 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9344 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9345 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9346 | |
| 9347 | clip_child->SetDrawsContent(true); |
| 9348 | unclipped_desc_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9349 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9350 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9351 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9352 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9353 | |
| 9354 | gfx::Transform identity_matrix; |
| 9355 | gfx::Transform translate; |
| 9356 | translate.Translate(10, 10); |
| 9357 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9358 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9359 | true); |
| 9360 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 9361 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9362 | true); |
| 9363 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9364 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9365 | false); |
| 9366 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9367 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9368 | false); |
| 9369 | SetLayerPropertiesForTesting(unclipped_desc_surface, translate, |
| 9370 | gfx::Point3F(), gfx::PointF(), |
| 9371 | gfx::Size(100, 100), true, false, true); |
| 9372 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9373 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9374 | false); |
| 9375 | surface->SetMasksToBounds(true); |
| 9376 | clip_layer->SetMasksToBounds(true); |
| 9377 | |
| 9378 | ExecuteCalculateDrawProperties(root); |
| 9379 | |
| 9380 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9381 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9382 | } |
| 9383 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9384 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
| 9385 | LayerImpl* root = root_layer(); |
| 9386 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9387 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9388 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9389 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9390 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9391 | |
| 9392 | clip_child->SetDrawsContent(true); |
| 9393 | unclipped_desc_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9394 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9395 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9396 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9397 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9398 | |
| 9399 | gfx::Transform identity_matrix; |
| 9400 | gfx::Transform scale; |
| 9401 | scale.Scale(2, 2); |
| 9402 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9403 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9404 | true); |
| 9405 | SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(), |
| 9406 | gfx::Size(100, 100), true, false, true); |
| 9407 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9408 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9409 | false); |
| 9410 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9411 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9412 | false); |
| 9413 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9414 | gfx::Point3F(), gfx::PointF(), |
| 9415 | gfx::Size(100, 100), true, false, true); |
| 9416 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9417 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9418 | false); |
| 9419 | surface->SetMasksToBounds(true); |
| 9420 | clip_layer->SetMasksToBounds(true); |
| 9421 | |
| 9422 | ExecuteCalculateDrawProperties(root); |
| 9423 | |
| 9424 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9425 | } |
| 9426 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9427 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
| 9428 | LayerImpl* root = root_layer(); |
| 9429 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9430 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9431 | |
| 9432 | const gfx::Transform identity_matrix; |
| 9433 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9434 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9435 | true); |
| 9436 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9437 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9438 | true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9439 | gfx::Transform translation; |
| 9440 | translation.Translate(10, 10); |
| 9441 | SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(), |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9442 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9443 | false); |
| 9444 | |
| 9445 | render_surface->SetMasksToBounds(true); |
| 9446 | test_layer->SetDrawsContent(true); |
| 9447 | test_layer->SetOpacity(0); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9448 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9449 | |
| 9450 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9451 | EXPECT_EQ(translation, test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9452 | } |
| 9453 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9454 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
| 9455 | LayerImpl* root = root_layer(); |
| 9456 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9457 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9458 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9459 | |
| 9460 | const gfx::Transform identity_matrix; |
| 9461 | clip_parent->SetMasksToBounds(true); |
| 9462 | render_surface->SetMasksToBounds(true); |
| 9463 | render_surface->SetDrawsContent(true); |
| 9464 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9465 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9466 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9467 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9468 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9469 | |
| 9470 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9471 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9472 | true); |
| 9473 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9474 | gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true, |
| 9475 | false, false); |
| 9476 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9477 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9478 | true); |
| 9479 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9480 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9481 | false); |
| 9482 | |
| 9483 | ExecuteCalculateDrawProperties(root); |
| 9484 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect()); |
| 9485 | } |
| 9486 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9487 | TEST_F(LayerTreeHostCommonTest, |
| 9488 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
| 9489 | LayerImpl* root = root_layer(); |
| 9490 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9491 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9492 | const gfx::Transform identity_matrix; |
| 9493 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9494 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9495 | true); |
| 9496 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9497 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9498 | true); |
| 9499 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9500 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9501 | false); |
| 9502 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9503 | root->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9504 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9505 | render_surface->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9506 | test_layer->SetMasksToBounds(true); |
| 9507 | test_layer->SetDrawsContent(true); |
| 9508 | ExecuteCalculateDrawProperties(root); |
| 9509 | |
| 9510 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9511 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9512 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9513 | } |
| 9514 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9515 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9516 | // Tests that subtree is hidden is updated. |
| 9517 | LayerImpl* root = root_layer(); |
| 9518 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9519 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9520 | |
| 9521 | const gfx::Transform identity_matrix; |
| 9522 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9523 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9524 | true); |
| 9525 | SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(), |
| 9526 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9527 | false, true); |
| 9528 | SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(), |
| 9529 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9530 | true); |
| 9531 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9532 | hidden->test_properties()->hide_layer_and_subtree = true; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9533 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9534 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9535 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9536 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9537 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9538 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9539 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9540 | } |
| 9541 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9542 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
| 9543 | LayerImpl* root = root_layer(); |
| 9544 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9545 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9546 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9547 | |
| 9548 | const gfx::Transform identity_matrix; |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9549 | clip_child->test_properties()->clip_parent = root; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9550 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9551 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9552 | root->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9553 | root->SetMasksToBounds(true); |
| 9554 | render_surface1->SetDrawsContent(true); |
| 9555 | render_surface2->SetDrawsContent(true); |
| 9556 | |
| 9557 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9558 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9559 | true); |
| 9560 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 9561 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9562 | false, true); |
| 9563 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9564 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9565 | true); |
| 9566 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9567 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9568 | false); |
| 9569 | ExecuteCalculateDrawProperties(root); |
| 9570 | |
| 9571 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9572 | // A clip node is created for every render surface and for layers that have |
| 9573 | // local clip. So, here it should be craeted for every layer. |
| 9574 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9575 | } |
| 9576 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9577 | TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) { |
| 9578 | // Tests that the mask layer gets its owning layer's screen space transform. |
| 9579 | LayerImpl* root = root_layer(); |
| 9580 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9581 | |
| 9582 | const gfx::Transform identity_matrix; |
| 9583 | gfx::Transform transform; |
| 9584 | transform.Translate(10, 10); |
| 9585 | |
| 9586 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9587 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9588 | true); |
| 9589 | SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(), |
| 9590 | gfx::Size(30, 30), true, false, false); |
| 9591 | root->SetDrawsContent(true); |
| 9592 | child->SetDrawsContent(false); |
| 9593 | child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9594 | ExecuteCalculateDrawProperties(root); |
| 9595 | |
| 9596 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9597 | child->mask_layer()->ScreenSpaceTransform()); |
| 9598 | transform.Translate(10, 10); |
| 9599 | child->SetTransform(transform); |
| 9600 | child->SetDrawsContent(true); |
| 9601 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9602 | ExecuteCalculateDrawProperties(root); |
| 9603 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9604 | child->mask_layer()->ScreenSpaceTransform()); |
| 9605 | } |
| 9606 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9607 | TEST_F(LayerTreeHostCommonTest, |
| 9608 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
| 9609 | LayerImpl* root = root_layer(); |
| 9610 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9611 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9612 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9613 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
| 9614 | const gfx::Transform identity_matrix; |
| 9615 | test_layer->SetDrawsContent(true); |
| 9616 | |
| 9617 | gfx::Transform scale; |
| 9618 | scale.Scale(2.f, 2.f); |
| 9619 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9620 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9621 | true); |
| 9622 | SetLayerPropertiesForTesting(render_surface1, scale, gfx::Point3F(), |
| 9623 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9624 | true); |
| 9625 | SetLayerPropertiesForTesting(between_targets, identity_matrix, gfx::Point3F(), |
| 9626 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9627 | false); |
| 9628 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9629 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9630 | true); |
| 9631 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9632 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9633 | false); |
| 9634 | // We want layer between the two targets to create a clip node and transform |
| 9635 | // node but it shouldn't create a render surface. |
| 9636 | between_targets->SetMasksToBounds(true); |
| 9637 | between_targets->Set3dSortingContextId(2); |
| 9638 | |
| 9639 | ExecuteCalculateDrawProperties(root); |
| 9640 | |
| 9641 | TransformTree& tree = |
| 9642 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9643 | TransformNode* node = tree.Node(render_surface1->transform_tree_index()); |
| 9644 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f)); |
| 9645 | |
| 9646 | node = tree.Node(between_targets->transform_tree_index()); |
| 9647 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); |
| 9648 | |
| 9649 | node = tree.Node(render_surface2->transform_tree_index()); |
| 9650 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f)); |
| 9651 | |
| 9652 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9653 | } |
| 9654 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9655 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
| 9656 | LayerImpl* root = root_layer(); |
| 9657 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9658 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9659 | |
| 9660 | const gfx::Transform identity_matrix; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9661 | child->SetDrawsContent(true); |
| 9662 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9663 | |
| 9664 | gfx::Transform large_transform; |
| 9665 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9666 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9667 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9668 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9669 | |
| 9670 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9671 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9672 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9673 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9674 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9675 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9676 | // TODO(sunxd): we make child have no render surface, because if the |
| 9677 | // child has one, the large transform applied to child will result in NaNs in |
| 9678 | // the draw_transform of the render_surface, thus make draw property updates |
| 9679 | // skip the child layer. We need further investigation into this to know |
| 9680 | // what exactly happens here. |
| 9681 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9682 | gfx::PointF(), gfx::Size(30, 30), true, false, |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9683 | false); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9684 | |
| 9685 | ExecuteCalculateDrawProperties(root); |
| 9686 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9687 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9688 | render_surface1->render_surface()->DrawableContentRect()); |
| 9689 | |
| 9690 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9691 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9692 | EXPECT_TRUE(is_inf_or_nan); |
| 9693 | |
| 9694 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9695 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9696 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9697 | |
| 9698 | std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); |
| 9699 | bool root_in_rsll = |
| 9700 | std::find(rsll->begin(), rsll->end(), root) != rsll->end(); |
| 9701 | EXPECT_TRUE(root_in_rsll); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9702 | } |
| 9703 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9704 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
| 9705 | const gfx::Transform identity_matrix; |
| 9706 | scoped_refptr<Layer> root = Layer::Create(); |
| 9707 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9708 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9709 | root->AddChild(child); |
| 9710 | |
| 9711 | host()->SetRootLayer(root); |
| 9712 | |
| 9713 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9714 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9715 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 9716 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9717 | |
| 9718 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9719 | |
| 9720 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9721 | // property trees as a new effect node will be created. |
| 9722 | child->SetOpacity(0.5f); |
| 9723 | PropertyTrees* property_trees = host()->property_trees(); |
| 9724 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9725 | |
| 9726 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9727 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9728 | property_trees->effect_id_to_index_map.end()); |
| 9729 | |
| 9730 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9731 | // a property trees rebuild. |
| 9732 | child->SetOpacity(0.8f); |
| 9733 | property_trees = host()->property_trees(); |
| 9734 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 9735 | |
| 9736 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9737 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9738 | property_trees->effect_id_to_index_map.end()); |
| 9739 | |
| 9740 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 9741 | // property trees as the effect node may no longer be needed. |
| 9742 | child->SetOpacity(1.f); |
| 9743 | property_trees = host()->property_trees(); |
| 9744 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9745 | |
| 9746 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9747 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 9748 | property_trees->effect_id_to_index_map.end()); |
| 9749 | } |
| 9750 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9751 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
| 9752 | const gfx::Transform identity_matrix; |
| 9753 | scoped_refptr<Layer> root = Layer::Create(); |
| 9754 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9755 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9756 | root->AddChild(animated); |
| 9757 | |
| 9758 | host()->SetRootLayer(root); |
| 9759 | |
| 9760 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9761 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9762 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 9763 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9764 | |
| 9765 | root->SetForceRenderSurfaceForTesting(true); |
| 9766 | animated->SetOpacity(0.f); |
| 9767 | |
| 9768 | scoped_refptr<AnimationPlayer> player = |
| 9769 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9770 | timeline()->AttachPlayer(player); |
| 9771 | player->AttachElement(animated->id()); |
| 9772 | |
| 9773 | int animation_id = 0; |
| 9774 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9775 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9776 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9777 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9778 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9779 | Animation* animation_ptr = animation.get(); |
| 9780 | AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(), |
| 9781 | std::move(animation)); |
| 9782 | |
| 9783 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9784 | |
| 9785 | EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
| 9786 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
| 9787 | EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9788 | EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9789 | |
| 9790 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9791 | root->layer_tree_host()->AnimateLayers( |
| 9792 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9793 | node = tree.Node(animated->effect_tree_index()); |
| 9794 | EXPECT_TRUE(node->data.is_currently_animating_opacity); |
| 9795 | EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9796 | |
| 9797 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9798 | node = tree.Node(animated->effect_tree_index()); |
| 9799 | EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9800 | EXPECT_FALSE(node->data.has_potential_opacity_animation); |
| 9801 | } |
| 9802 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9803 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
| 9804 | const gfx::Transform identity_matrix; |
| 9805 | scoped_refptr<Layer> root = Layer::Create(); |
| 9806 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9807 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9808 | root->AddChild(animated); |
| 9809 | |
| 9810 | host()->SetRootLayer(root); |
| 9811 | |
| 9812 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9813 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9814 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 9815 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9816 | |
| 9817 | root->SetForceRenderSurfaceForTesting(true); |
| 9818 | |
| 9819 | scoped_refptr<AnimationPlayer> player = |
| 9820 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9821 | timeline()->AttachPlayer(player); |
| 9822 | player->AttachElement(animated->id()); |
| 9823 | |
| 9824 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 9825 | KeyframedTransformAnimationCurve::Create()); |
| 9826 | TransformOperations start; |
| 9827 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9828 | gfx::Transform transform; |
| 9829 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9830 | TransformOperations operation; |
| 9831 | operation.AppendMatrix(transform); |
| 9832 | curve->AddKeyframe( |
| 9833 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9834 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9835 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 9836 | std::unique_ptr<Animation> animation( |
| 9837 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9838 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 9839 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9840 | Animation* animation_ptr = animation.get(); |
| 9841 | AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(), |
| 9842 | std::move(animation)); |
| 9843 | |
| 9844 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9845 | |
| 9846 | TransformTree& tree = |
| 9847 | root->layer_tree_host()->property_trees()->transform_tree; |
| 9848 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
| 9849 | EXPECT_FALSE(node->data.is_currently_animating); |
| 9850 | EXPECT_TRUE(node->data.has_potential_animation); |
| 9851 | |
| 9852 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9853 | root->layer_tree_host()->AnimateLayers( |
| 9854 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9855 | node = tree.Node(animated->transform_tree_index()); |
| 9856 | EXPECT_TRUE(node->data.is_currently_animating); |
| 9857 | EXPECT_TRUE(node->data.has_potential_animation); |
| 9858 | |
| 9859 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 9860 | false /*needs_completion*/); |
| 9861 | node = tree.Node(animated->transform_tree_index()); |
| 9862 | EXPECT_FALSE(node->data.is_currently_animating); |
| 9863 | EXPECT_FALSE(node->data.has_potential_animation); |
| 9864 | } |
| 9865 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9866 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9867 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9868 | scroll.layer_id = 2; |
| 9869 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9870 | |
| 9871 | proto::ScrollUpdateInfo proto; |
| 9872 | scroll.ToProtobuf(&proto); |
| 9873 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9874 | new_scroll.FromProtobuf(proto); |
| 9875 | |
| 9876 | EXPECT_EQ(scroll, new_scroll); |
| 9877 | } |
| 9878 | |
| 9879 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9880 | ScrollAndScaleSet scroll_and_scale_set; |
| 9881 | |
| 9882 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9883 | scroll1.layer_id = 1; |
| 9884 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9885 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9886 | scroll2.layer_id = 2; |
| 9887 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9888 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9889 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9890 | |
| 9891 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9892 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 9893 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 9894 | |
| 9895 | proto::ScrollAndScaleSet proto; |
| 9896 | scroll_and_scale_set.ToProtobuf(&proto); |
| 9897 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 9898 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 9899 | |
| 9900 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 9901 | } |
| 9902 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9903 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9904 | // Test the behavior of scroll tree builder |
| 9905 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9906 | // +root1(1)[inner_viewport_container_layer] |
| 9907 | // +-page_scale_layer |
| 9908 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9909 | // scrollable, inner_viewport_scroll_layer] |
| 9910 | // +------child6(6)[kScrollbarScrolling] |
| 9911 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9912 | // +----parent3(3) |
| 9913 | // +------child7(7)[scrollable] |
| 9914 | // +------child8(8)[scroll_parent=7] |
| 9915 | // +--------grand_child11(11)[scrollable] |
| 9916 | // +----parent4(4) |
| 9917 | // +------child9(9) |
| 9918 | // +--------grand_child12(12) |
| 9919 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9920 | // |
| 9921 | // Expected scroll tree topology: |
| 9922 | // +property_tree_root---owner:-1 |
| 9923 | // +--root---owner:1, id:1 |
| 9924 | // +----node---owner:2, id:2 |
| 9925 | // +------node---owner:6, id:3 |
| 9926 | // +----node---owner:7, id:4 |
| 9927 | // +------node---owner:11, id:5 |
| 9928 | // +----node---owner:5, id:6 |
| 9929 | // |
| 9930 | // Extra check: |
| 9931 | // scroll_tree_index() of: |
| 9932 | // grand_child10:3 |
| 9933 | // parent3:1 |
| 9934 | // child8:4 |
| 9935 | // parent4:1 |
| 9936 | // child9:1 |
| 9937 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9938 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 9939 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 9940 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 9941 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 9942 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 9943 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 9944 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 9945 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 9946 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 9947 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 9948 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 9949 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 9950 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9951 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9952 | root1->AddChild(page_scale_layer); |
| 9953 | page_scale_layer->AddChild(parent2); |
| 9954 | page_scale_layer->AddChild(parent3); |
| 9955 | page_scale_layer->AddChild(parent4); |
| 9956 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9957 | parent2->AddChild(child6); |
| 9958 | parent3->AddChild(child7); |
| 9959 | parent3->AddChild(child8); |
| 9960 | parent4->AddChild(child9); |
| 9961 | child6->AddChild(grand_child10); |
| 9962 | child8->AddChild(grand_child11); |
| 9963 | child9->AddChild(grand_child12); |
| 9964 | host()->SetRootLayer(root1); |
| 9965 | |
| 9966 | parent2->AddMainThreadScrollingReasons( |
| 9967 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 9968 | parent2->AddMainThreadScrollingReasons( |
| 9969 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9970 | parent2->SetScrollClipLayerId(root1->id()); |
| 9971 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 9972 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9973 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 9974 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9975 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9976 | child7->SetScrollClipLayerId(parent3->id()); |
| 9977 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9978 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9979 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9980 | |
| 9981 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9982 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9983 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 9984 | host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9985 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 9986 | |
| 9987 | const int kInvalidPropertyTreeNodeId = -1; |
| 9988 | const int kRootPropertyTreeNodeId = 0; |
| 9989 | |
| 9990 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 9991 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 9992 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 9993 | property_trees.is_main_thread = true; |
| 9994 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame^] | 9995 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9996 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 9997 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 9998 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 9999 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
| 10000 | property_tree_root->data.scrollable = false; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10001 | property_tree_root->data.main_thread_scrolling_reasons = |
| 10002 | MainThreadScrollingReason::kNotScrollingOnMain; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10003 | property_tree_root->data.contains_non_fast_scrollable_region = false; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10004 | property_tree_root->data.transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10005 | |
| 10006 | // The node owned by root1 |
| 10007 | ScrollNode scroll_root1; |
| 10008 | scroll_root1.id = 1; |
| 10009 | scroll_root1.owner_id = root1->id(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10010 | scroll_root1.data.user_scrollable_horizontal = true; |
| 10011 | scroll_root1.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10012 | scroll_root1.data.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10013 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10014 | |
| 10015 | // The node owned by parent2 |
| 10016 | ScrollNode scroll_parent2; |
| 10017 | scroll_parent2.id = 2; |
| 10018 | scroll_parent2.owner_id = parent2->id(); |
| 10019 | scroll_parent2.data.scrollable = true; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10020 | scroll_parent2.data.main_thread_scrolling_reasons = |
| 10021 | parent2->main_thread_scrolling_reasons(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10022 | scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds(); |
| 10023 | scroll_parent2.data.bounds = parent2->bounds(); |
| 10024 | scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true; |
| 10025 | scroll_parent2.data.is_inner_viewport_scroll_layer = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10026 | scroll_parent2.data.user_scrollable_horizontal = true; |
| 10027 | scroll_parent2.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10028 | scroll_parent2.data.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10029 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10030 | |
| 10031 | // The node owned by child6 |
| 10032 | ScrollNode scroll_child6; |
| 10033 | scroll_child6.id = 3; |
| 10034 | scroll_child6.owner_id = child6->id(); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10035 | scroll_child6.data.main_thread_scrolling_reasons = |
| 10036 | child6->main_thread_scrolling_reasons(); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10037 | scroll_child6.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10038 | scroll_child6.data.user_scrollable_horizontal = true; |
| 10039 | scroll_child6.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10040 | scroll_child6.data.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10041 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10042 | |
| 10043 | // The node owned by child7, child7 also owns a transform node |
| 10044 | ScrollNode scroll_child7; |
| 10045 | scroll_child7.id = 4; |
| 10046 | scroll_child7.owner_id = child7->id(); |
| 10047 | scroll_child7.data.scrollable = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10048 | scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds(); |
| 10049 | scroll_child7.data.bounds = child7->bounds(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10050 | scroll_child7.data.user_scrollable_horizontal = true; |
| 10051 | scroll_child7.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10052 | scroll_child7.data.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10053 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10054 | |
| 10055 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10056 | ScrollNode scroll_grand_child11; |
| 10057 | scroll_grand_child11.id = 5; |
| 10058 | scroll_grand_child11.owner_id = grand_child11->id(); |
| 10059 | scroll_grand_child11.data.scrollable = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10060 | scroll_grand_child11.data.user_scrollable_horizontal = true; |
| 10061 | scroll_grand_child11.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10062 | scroll_grand_child11.data.transform_id = |
| 10063 | grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10064 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10065 | |
| 10066 | // The node owned by parent5 |
| 10067 | ScrollNode scroll_parent5; |
| 10068 | scroll_parent5.id = 8; |
| 10069 | scroll_parent5.owner_id = parent5->id(); |
| 10070 | scroll_parent5.data.contains_non_fast_scrollable_region = true; |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10071 | scroll_parent5.data.bounds = gfx::Size(10, 10); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10072 | scroll_parent5.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10073 | scroll_parent5.data.user_scrollable_horizontal = true; |
| 10074 | scroll_parent5.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10075 | scroll_parent5.data.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10076 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10077 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10078 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10079 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10080 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10081 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10082 | expected_scroll_tree.set_needs_update(false); |
| 10083 | |
| 10084 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10085 | |
| 10086 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10087 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10088 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10089 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10090 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10091 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10092 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10093 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10094 | } |
| 10095 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10096 | } // namespace |
| 10097 | } // namespace cc |