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" |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 49 | #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 50 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 51 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 52 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 53 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 54 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | namespace { |
| 56 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 57 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 58 | public: |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 59 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 61 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 62 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 63 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 64 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | }; |
| 66 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 67 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 68 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 69 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 70 | public: |
| 71 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 72 | ~MockContentLayerClient() override {} |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 73 | gfx::Rect PaintableRegion() override { return gfx::Rect(); } |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 74 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 75 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 76 | NOTIMPLEMENTED(); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 77 | return nullptr; |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 78 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 79 | bool FillsBoundsCompletely() const override { return false; } |
jbroman | 9f60f1a | 2015-07-16 21:40:32 | [diff] [blame] | 80 | size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 81 | }; |
| 82 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 83 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 84 | do { \ |
| 85 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 86 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 87 | } while (false) |
| 88 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 89 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 90 | do { \ |
| 91 | EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \ |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 92 | } while (false) |
| 93 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 94 | class LayerTreeSettingsScaleContent : public LayerTreeSettings { |
| 95 | public: |
| 96 | LayerTreeSettingsScaleContent() { |
| 97 | layer_transforms_should_scale_layer_contents = true; |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest { |
| 102 | public: |
| 103 | LayerTreeHostCommonScalingTest() |
| 104 | : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {} |
| 105 | }; |
| 106 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 107 | class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest { |
| 108 | public: |
| 109 | LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {} |
| 110 | |
| 111 | LayerImpl* TestVisibleRectAndDrawableContentRect( |
| 112 | const gfx::Rect& target_rect, |
| 113 | const gfx::Transform& layer_transform, |
| 114 | const gfx::Rect& layer_rect) { |
| 115 | LayerImpl* root = root_layer(); |
| 116 | LayerImpl* target = AddChild<LayerImpl>(root); |
| 117 | LayerImpl* drawing_layer = AddChild<LayerImpl>(target); |
| 118 | |
| 119 | root->SetDrawsContent(true); |
| 120 | target->SetDrawsContent(true); |
| 121 | target->SetMasksToBounds(true); |
| 122 | drawing_layer->SetDrawsContent(true); |
| 123 | |
| 124 | gfx::Transform identity; |
| 125 | |
| 126 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 127 | gfx::Size(500, 500), true, false, true); |
| 128 | SetLayerPropertiesForTesting(target, identity, gfx::Point3F(), |
| 129 | gfx::PointF(target_rect.origin()), |
| 130 | target_rect.size(), true, false, true); |
| 131 | SetLayerPropertiesForTesting(drawing_layer, layer_transform, gfx::Point3F(), |
| 132 | gfx::PointF(layer_rect.origin()), |
| 133 | layer_rect.size(), true, false, false); |
| 134 | |
| 135 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 136 | ExecuteCalculateDrawProperties(root); |
| 137 | |
| 138 | return drawing_layer; |
| 139 | } |
| 140 | }; |
| 141 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 142 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 143 | // Sanity check: For layers positioned at zero, with zero size, |
| 144 | // and with identity transforms, then the draw transform, |
| 145 | // screen space transform, and the hierarchy passed on to children |
| 146 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 147 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 148 | LayerImpl* parent = root_layer(); |
| 149 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 150 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 151 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 152 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 153 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 154 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 155 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 156 | gfx::PointF(), gfx::Size(), true, false); |
| 157 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 158 | gfx::PointF(), gfx::Size(), true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 159 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 160 | ExecuteCalculateDrawProperties(parent); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 161 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 162 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 163 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 164 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 165 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 166 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 167 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 168 | grand_child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 169 | } |
| 170 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 171 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 172 | // Tests that effect tree node gets a valid transform id when a layer |
| 173 | // has opacity but doesn't create a render surface. |
| 174 | LayerImpl* parent = root_layer(); |
| 175 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 176 | child->SetDrawsContent(true); |
| 177 | |
| 178 | gfx::Transform identity_matrix; |
| 179 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 180 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 181 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 182 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
| 183 | false); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 184 | child->test_properties()->opacity = 0.f; |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 185 | ExecuteCalculateDrawProperties(parent); |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 186 | EffectTree& effect_tree = |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 187 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 188 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 189 | const int transform_tree_size = parent->layer_tree_impl() |
| 190 | ->property_trees() |
| 191 | ->transform_tree.next_available_id(); |
| 192 | EXPECT_LT(node->data.transform_id, transform_tree_size); |
| 193 | } |
| 194 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 195 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 196 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 197 | LayerImpl* root = root_layer(); |
| 198 | LayerImpl* layer = AddChild<LayerImpl>(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 199 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 200 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 201 | gfx::PointF(), gfx::Size(1, 2), true, false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 202 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 203 | TransformTree& tree = |
| 204 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 205 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 206 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 207 | // transform or the screenspace transform. |
| 208 | gfx::Transform translation_to_center; |
| 209 | translation_to_center.Translate(5.0, 6.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 210 | SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 211 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 212 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 213 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 214 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 215 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 216 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 217 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 218 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 219 | // no effect on the transforms. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 220 | SetLayerPropertiesForTesting(layer, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 221 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 222 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 223 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 224 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 225 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 226 | identity_matrix, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 227 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 228 | identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 229 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 230 | // Case 4: A change in actual position affects both the draw transform and |
| 231 | // screen space transform. |
| 232 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 233 | position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 234 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 235 | layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 236 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 237 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 238 | ExecuteCalculateDrawProperties(root); |
| 239 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 240 | position_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 241 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 242 | position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 243 | draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 244 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 245 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 246 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 247 | // scale transform, because scale and translation are not commutative. |
| 248 | gfx::Transform layer_transform; |
| 249 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 250 | SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 251 | gfx::PointF(), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 252 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 253 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 254 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 255 | layer_transform, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 256 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 257 | layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 258 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 259 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 260 | gfx::Transform translation_to_anchor; |
| 261 | translation_to_anchor.Translate(5.0, 0.0); |
| 262 | gfx::Transform expected_result = |
| 263 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 264 | SetLayerPropertiesForTesting(layer, layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 265 | gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(), |
| 266 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 267 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 268 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 269 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 270 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 271 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 272 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 273 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 274 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 275 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 276 | // it is still worth testing to detect accidental regressions. |
| 277 | expected_result = position_transform * translation_to_anchor * |
| 278 | layer_transform * Inverse(translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 279 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 280 | layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 281 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 282 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 283 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 284 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 285 | expected_result, draw_property_utils::DrawTransform(layer, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 286 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 287 | expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 288 | } |
| 289 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 290 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 291 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 292 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 293 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 294 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 295 | -kScrollOffset.y()); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 296 | float page_scale = 0.888f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 297 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 298 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 299 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 300 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 301 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 302 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 303 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 304 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 305 | gfx::Transform identity_matrix; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 306 | std::unique_ptr<LayerImpl> sublayer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 307 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 308 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 309 | sublayer->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 310 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 311 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 312 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 313 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 314 | std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 315 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 316 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 317 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 318 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 319 | false); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 320 | std::unique_ptr<LayerImpl> clip_layer_scoped_ptr( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 321 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 322 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 323 | |
| 324 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 325 | clip_layer->SetBounds( |
| 326 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 327 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 328 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 329 | SetScrollOffsetDelta(scroll_layer, kScrollDelta); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 330 | gfx::Transform impl_transform; |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 331 | scroll_layer->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 332 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 333 | clip_layer->AddChild(std::move(scroll_layer_scoped_ptr)); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 334 | scroll_layer_raw_ptr->layer_tree_impl() |
| 335 | ->property_trees() |
| 336 | ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(), |
| 337 | kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 338 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 339 | std::unique_ptr<LayerImpl> root( |
| 340 | LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 341 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 342 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 343 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 344 | root->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 345 | root->SetHasRenderSurface(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 346 | LayerImpl* root_layer = root.get(); |
| 347 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 348 | |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 349 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 350 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 351 | gfx::Transform expected_transform = identity_matrix; |
| 352 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 353 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 354 | page_scale * kDeviceScale), |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 355 | MathUtil::Round(sub_layer_screen_position.y() * |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 356 | page_scale * kDeviceScale)); |
| 357 | expected_transform.Scale(page_scale * kDeviceScale, |
| 358 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 359 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 360 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 361 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 362 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 364 | gfx::Transform arbitrary_translate; |
| 365 | const float kTranslateX = 10.6f; |
| 366 | const float kTranslateY = 20.6f; |
| 367 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 368 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 369 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 370 | true, false, false); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 371 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 372 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 373 | scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 374 | expected_transform.MakeIdentity(); |
| 375 | expected_transform.Translate( |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 376 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 377 | sub_layer_screen_position.x() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 378 | kDeviceScale), |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 379 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 380 | sub_layer_screen_position.y() * page_scale * |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 381 | kDeviceScale)); |
jaydasika | a534a47 | 2016-03-31 01:12:16 | [diff] [blame] | 382 | expected_transform.Scale(page_scale * kDeviceScale, |
| 383 | page_scale * kDeviceScale); |
| 384 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 385 | sublayer->DrawTransform()); |
| 386 | |
| 387 | // Test that page scale is updated even when we don't rebuild property trees. |
| 388 | page_scale = 1.888f; |
| 389 | root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 390 | Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID, |
| 391 | Layer::INVALID_ID); |
| 392 | root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 393 | EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 394 | ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 395 | scroll_layer->parent()); |
| 396 | |
| 397 | expected_transform.MakeIdentity(); |
| 398 | expected_transform.Translate( |
| 399 | MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 400 | sub_layer_screen_position.x() * page_scale * |
| 401 | kDeviceScale), |
| 402 | MathUtil::Round(kTranslateY * page_scale * kDeviceScale + |
| 403 | sub_layer_screen_position.y() * page_scale * |
| 404 | kDeviceScale)); |
| 405 | expected_transform.Scale(page_scale * kDeviceScale, |
| 406 | page_scale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 407 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 408 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 411 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 412 | gfx::Transform identity_matrix; |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 413 | LayerImpl* root = root_layer(); |
| 414 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 415 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 416 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 417 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 418 | // One-time setup of root layer |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 419 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 420 | gfx::PointF(), gfx::Size(1, 2), true, false); |
| 421 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 422 | TransformTree& tree = |
| 423 | host_impl()->active_tree()->property_trees()->transform_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 425 | // Case 1: parent's anchor point should not affect child or grand_child. |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 426 | SetLayerPropertiesForTesting(parent, identity_matrix, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 427 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 428 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 429 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 430 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 431 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 432 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 433 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 434 | |
| 435 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 436 | identity_matrix, draw_property_utils::DrawTransform(child, tree)); |
| 437 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 438 | identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree)); |
| 439 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 440 | identity_matrix, draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 441 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 442 | identity_matrix, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 443 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 444 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 445 | // Case 2: parent's position affects child and grand_child. |
| 446 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 447 | parent_position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 448 | SetLayerPropertiesForTesting( |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 449 | parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 450 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 451 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 452 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 453 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 454 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 455 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 456 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 457 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 458 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 459 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 460 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 461 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 462 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 463 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 464 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 465 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 466 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 467 | parent_position_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 468 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 469 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 470 | // Case 3: parent's local transform affects child and grandchild |
| 471 | gfx::Transform parent_layer_transform; |
| 472 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 473 | gfx::Transform parent_translation_to_anchor; |
| 474 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 475 | gfx::Transform parent_composite_transform = |
| 476 | parent_translation_to_anchor * parent_layer_transform * |
| 477 | Inverse(parent_translation_to_anchor); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 478 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 479 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 480 | gfx::Size(10, 12), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 481 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 482 | gfx::PointF(), gfx::Size(16, 18), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 483 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 484 | gfx::PointF(), gfx::Size(76, 78), true, false); |
| 485 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 486 | ExecuteCalculateDrawProperties(root); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 487 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 488 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 489 | draw_property_utils::DrawTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 490 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 491 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 492 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 493 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 494 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 495 | draw_property_utils::DrawTransform(grand_child, tree)); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 496 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 497 | parent_composite_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 498 | draw_property_utils::ScreenSpaceTransform(grand_child, tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 501 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 502 | LayerImpl* root = root_layer(); |
| 503 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 504 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 505 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 506 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 508 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 509 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 510 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 511 | true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 513 | // Child is set up so that a new render surface should be created. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 514 | child->test_properties()->opacity = 0.5f; |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 515 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 516 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 517 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 518 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 519 | gfx::Transform parent_translation_to_anchor; |
| 520 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 521 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 522 | gfx::Transform parent_composite_transform = |
| 523 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 524 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 525 | gfx::Vector2dF parent_composite_scale = |
| 526 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 527 | 1.f); |
| 528 | gfx::Transform surface_sublayer_transform; |
| 529 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 530 | parent_composite_scale.y()); |
| 531 | gfx::Transform surface_sublayer_composite_transform = |
| 532 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 533 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 534 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 535 | gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(), |
| 536 | gfx::Size(100, 120), true, false, false); |
| 537 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 538 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 539 | true); |
| 540 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 541 | gfx::PointF(), gfx::Size(8, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 542 | false); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 543 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 544 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 545 | // Render surface should have been created now. |
| 546 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 547 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 548 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 549 | // The child layer's draw transform should refer to its new render surface. |
| 550 | // The screen-space transform, however, should still refer to the root. |
| 551 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 552 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 554 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 555 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 556 | // Because the grand_child is the only drawable content, the child's render |
| 557 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 558 | // surface's subtree is drawn must be removed from the composite transform. |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 559 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform, |
| 560 | child->render_target()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 562 | // The screen space is the same as the target since the child surface draws |
| 563 | // into the root. |
| 564 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 565 | surface_sublayer_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 566 | child->render_target()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 567 | } |
| 568 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 569 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
| 570 | LayerImpl* root = root_layer(); |
| 571 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 572 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 573 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 574 | grand_child->SetDrawsContent(true); |
| 575 | |
| 576 | gfx::Transform identity_matrix; |
| 577 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 578 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 579 | true); |
| 580 | |
| 581 | gfx::Transform parent_transform; |
| 582 | parent_transform.Translate(10.0, 10.0); |
| 583 | |
| 584 | gfx::Transform child_transform; |
| 585 | child_transform.Rotate(45.0); |
| 586 | |
| 587 | // child gets a render surface when surfaces are enabled. |
| 588 | SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(), |
| 589 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 590 | false); |
| 591 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 592 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 593 | true); |
| 594 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 595 | gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true, |
| 596 | false, false); |
| 597 | |
| 598 | gfx::Transform expected_grand_child_screen_space_transform; |
| 599 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 600 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 601 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 602 | |
| 603 | // First compute draw properties with separate surfaces enabled. |
| 604 | ExecuteCalculateDrawProperties(root); |
| 605 | |
| 606 | // The grand child's draw transform should be its offset wrt the child. |
| 607 | gfx::Transform expected_grand_child_draw_transform; |
| 608 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 609 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 610 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 611 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 612 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 613 | |
| 614 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 615 | |
| 616 | // With separate surfaces disabled, the grand child's draw transform should be |
| 617 | // the same as its screen space transform. |
| 618 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 619 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 620 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 621 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 622 | } |
| 623 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 624 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 625 | LayerImpl* root = root_layer(); |
| 626 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 627 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 628 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 629 | grand_child->SetDrawsContent(true); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 630 | std::unique_ptr<LayerImpl> child_replica = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 631 | LayerImpl::Create(host_impl()->active_tree(), 100); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 633 | // One-time setup of root layer |
| 634 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 635 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 636 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 637 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 638 | |
| 639 | // Child is set up so that a new render surface should be created. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 640 | child->test_properties()->opacity = 0.5f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 641 | |
| 642 | gfx::Transform parent_layer_transform; |
| 643 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 644 | gfx::Transform parent_translation_to_anchor; |
| 645 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 646 | gfx::Transform parent_composite_transform = |
| 647 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 648 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 649 | gfx::Transform replica_layer_transform; |
| 650 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 651 | gfx::Vector2dF parent_composite_scale = |
| 652 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 653 | 1.f); |
| 654 | gfx::Transform surface_sublayer_transform; |
| 655 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 656 | parent_composite_scale.y()); |
| 657 | gfx::Transform replica_composite_transform = |
| 658 | parent_composite_transform * replica_layer_transform * |
| 659 | Inverse(surface_sublayer_transform); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 660 | child_replica->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 661 | // Child's render surface should not exist yet. |
| 662 | ASSERT_FALSE(child->render_surface()); |
| 663 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 664 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 665 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 666 | gfx::Size(10, 12), true, false, false); |
| 667 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 668 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 669 | true); |
| 670 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 671 | gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true, |
| 672 | false, false); |
| 673 | SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform, |
| 674 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 675 | false, false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 676 | child->SetReplicaLayer(std::move(child_replica)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 677 | |
| 678 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 679 | |
| 680 | // Render surface should have been created now. |
| 681 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 682 | ASSERT_EQ(child->render_surface(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 683 | |
| 684 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 685 | replica_composite_transform, |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 686 | child->render_target()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 687 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 688 | child->render_target() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 689 | ->replica_screen_space_transform()); |
| 690 | } |
| 691 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 692 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 693 | // This test creates a more complex tree and verifies it all at once. This |
| 694 | // covers the following cases: |
| 695 | // - layers that are described w.r.t. a render surface: should have draw |
| 696 | // transforms described w.r.t. that surface |
| 697 | // - A render surface described w.r.t. an ancestor render surface: should |
| 698 | // have a draw transform described w.r.t. that ancestor surface |
| 699 | // - Replicas of a render surface are described w.r.t. the replica's |
| 700 | // transform around its anchor, along with the surface itself. |
| 701 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 702 | // a render surface that is described w.r.t. an ancestor render surface. |
| 703 | // - verifying that each layer has a reference to the correct render surface |
| 704 | // and render target values. |
| 705 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 706 | LayerImpl* root = root_layer(); |
| 707 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 708 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 709 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 710 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 711 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 712 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 713 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 714 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 715 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 716 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 717 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 718 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 719 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 720 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 721 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 722 | grand_child_of_rs1->SetDrawsContent(true); |
| 723 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 724 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 725 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 726 | std::unique_ptr<LayerImpl> replica_of_rs1 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 727 | LayerImpl::Create(host_impl()->active_tree(), 101); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 728 | std::unique_ptr<LayerImpl> replica_of_rs2 = |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 729 | LayerImpl::Create(host_impl()->active_tree(), 102); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 730 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 731 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 732 | // to have a new render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 733 | render_surface1->test_properties()->opacity = 0.5f; |
| 734 | render_surface2->test_properties()->opacity = 0.33f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 735 | |
| 736 | // One-time setup of root layer |
| 737 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 738 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 739 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 740 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 741 | |
| 742 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 743 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 744 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 745 | gfx::Transform translation_to_anchor; |
| 746 | translation_to_anchor.Translate(2.5, 0.0); |
| 747 | gfx::Transform layer_transform; |
| 748 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 749 | gfx::Transform replica_layer_transform; |
| 750 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 751 | |
| 752 | gfx::Transform A = |
| 753 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 754 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 755 | Inverse(translation_to_anchor); |
| 756 | |
| 757 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 758 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 759 | gfx::Transform surface1_sublayer_transform; |
| 760 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 761 | surface1_parent_transform_scale.y()); |
| 762 | |
| 763 | // SS1 = transform given to the subtree of render_surface1 |
| 764 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 765 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 766 | // the owning layer |
| 767 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 768 | |
| 769 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 770 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 771 | gfx::Transform surface2_sublayer_transform; |
| 772 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 773 | surface2_parent_transform_scale.y()); |
| 774 | |
| 775 | // SS2 = transform given to the subtree of render_surface2 |
| 776 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 777 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 778 | // the owning layer |
| 779 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 780 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 781 | SetLayerPropertiesForTesting(parent, layer_transform, |
| 782 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 783 | gfx::Size(10, 10), true, false, false); |
| 784 | SetLayerPropertiesForTesting(render_surface1, layer_transform, |
| 785 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 786 | gfx::Size(10, 10), true, false, true); |
| 787 | SetLayerPropertiesForTesting(render_surface2, layer_transform, |
| 788 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 789 | gfx::Size(10, 10), true, false, true); |
| 790 | SetLayerPropertiesForTesting(child_of_root, layer_transform, |
| 791 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 792 | gfx::Size(10, 10), true, false, false); |
| 793 | SetLayerPropertiesForTesting(child_of_rs1, layer_transform, |
| 794 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 795 | gfx::Size(10, 10), true, false, false); |
| 796 | SetLayerPropertiesForTesting(child_of_rs2, layer_transform, |
| 797 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 798 | gfx::Size(10, 10), true, false, false); |
| 799 | SetLayerPropertiesForTesting(grand_child_of_root, layer_transform, |
| 800 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 801 | gfx::Size(10, 10), true, false, false); |
| 802 | SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform, |
| 803 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 804 | gfx::Size(10, 10), true, false, false); |
| 805 | SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform, |
| 806 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 807 | gfx::Size(10, 10), true, false, false); |
| 808 | SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform, |
| 809 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 810 | gfx::Size(), true, false, false); |
| 811 | SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform, |
| 812 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 813 | gfx::Size(), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 814 | |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 815 | // We need to set parent on replica layers for property tree building. |
| 816 | replica_of_rs1->SetParent(render_surface1); |
| 817 | replica_of_rs2->SetParent(render_surface2); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 818 | render_surface1->SetReplicaLayer(std::move(replica_of_rs1)); |
| 819 | render_surface2->SetReplicaLayer(std::move(replica_of_rs2)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 820 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 821 | |
| 822 | // Only layers that are associated with render surfaces should have an actual |
| 823 | // RenderSurface() value. |
| 824 | ASSERT_TRUE(root->render_surface()); |
| 825 | ASSERT_FALSE(child_of_root->render_surface()); |
| 826 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 827 | |
| 828 | ASSERT_TRUE(render_surface1->render_surface()); |
| 829 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 830 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 831 | |
| 832 | ASSERT_TRUE(render_surface2->render_surface()); |
| 833 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 834 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 835 | |
| 836 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 837 | EXPECT_EQ(root->render_surface(), parent->render_target()); |
| 838 | EXPECT_EQ(root->render_surface(), child_of_root->render_target()); |
| 839 | EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 840 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 841 | EXPECT_EQ(render_surface1->render_surface(), |
| 842 | render_surface1->render_target()); |
| 843 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 844 | EXPECT_EQ(render_surface1->render_surface(), |
| 845 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 846 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 847 | EXPECT_EQ(render_surface2->render_surface(), |
| 848 | render_surface2->render_target()); |
| 849 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 850 | EXPECT_EQ(render_surface2->render_surface(), |
| 851 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 852 | |
| 853 | // Verify layer draw transforms note that draw transforms are described with |
| 854 | // respect to the nearest ancestor render surface but screen space transforms |
| 855 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 856 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 857 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 858 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 859 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 860 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 861 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 862 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 863 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 864 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 865 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 866 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 867 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 868 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 869 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 870 | |
| 871 | // Verify layer screen-space transforms |
| 872 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 873 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 874 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 875 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 876 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 877 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 878 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 879 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 880 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 881 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 882 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 883 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 884 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 885 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 886 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 887 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 888 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 889 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 890 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 891 | |
| 892 | // Verify render surface transforms. |
| 893 | // |
| 894 | // Draw transform of render surface 1 is described with respect to root. |
| 895 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 896 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 897 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 898 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 899 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 900 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 901 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 902 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 903 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 904 | // Draw transform of render surface 2 is described with respect to render |
| 905 | // surface 1. |
| 906 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 907 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 908 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 909 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 910 | render_surface2->render_surface()->replica_draw_transform()); |
| 911 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 912 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 913 | render_surface2->render_surface()->screen_space_transform()); |
| 914 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 915 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 917 | |
| 918 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 919 | // is expected that we correctly set up transforms so that the y-component of |
| 920 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 921 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 922 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 923 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 924 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 925 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 926 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 927 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 928 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 929 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 930 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 931 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 932 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 933 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 934 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 935 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 936 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 937 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 938 | } |
| 939 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 940 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 941 | // For layers that flatten their subtree, there should be an orthographic |
| 942 | // projection (for x and y values) in the middle of the transform sequence. |
| 943 | // Note that the way the code is currently implemented, it is not expected to |
| 944 | // use a canonical orthographic projection. |
| 945 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 946 | LayerImpl* root = root_layer(); |
| 947 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 948 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 949 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 950 | grand_child->SetDrawsContent(true); |
| 951 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 952 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 953 | |
| 954 | gfx::Transform rotation_about_y_axis; |
| 955 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 956 | |
| 957 | const gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 958 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 959 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 960 | true); |
| 961 | SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(), |
| 962 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 963 | true); |
| 964 | SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis, |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 965 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 966 | true, false, false); |
| 967 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 968 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 969 | true, false, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 970 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 971 | // No layers in this test should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 972 | ASSERT_TRUE(root->test_properties()->should_flatten_transform); |
| 973 | ASSERT_TRUE(child->test_properties()->should_flatten_transform); |
| 974 | ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform); |
| 975 | ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 976 | |
| 977 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 978 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 979 | gfx::Transform expected_grand_child_draw_transform = |
| 980 | rotation_about_y_axis; // draws onto child's render surface |
| 981 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 982 | flattened_rotation_about_y.FlattenTo2d(); |
| 983 | gfx::Transform expected_grand_child_screen_space_transform = |
| 984 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 985 | gfx::Transform expected_great_grand_child_draw_transform = |
| 986 | flattened_rotation_about_y; |
| 987 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 988 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 989 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 990 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | |
| 992 | // The child's draw transform should have been taken by its surface. |
| 993 | ASSERT_TRUE(child->render_surface()); |
| 994 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 995 | child->render_surface()->draw_transform()); |
| 996 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 997 | expected_child_screen_space_transform, |
| 998 | child->render_surface()->screen_space_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 999 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1001 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1002 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1003 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1004 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1005 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1006 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1007 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1008 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1009 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1010 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1011 | } |
| 1012 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1013 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1014 | LayerImpl* root = root_layer(); |
| 1015 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1016 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1017 | |
| 1018 | gfx::Transform child_transform; |
| 1019 | child_transform.Translate(50.0, 50.0); |
| 1020 | child_transform.RotateAboutZAxis(30.0); |
| 1021 | |
| 1022 | gfx::Transform grand_child_transform; |
| 1023 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1024 | |
| 1025 | const gfx::Transform identity_matrix; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1026 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1027 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 1028 | true); |
| 1029 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 1030 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1031 | false); |
| 1032 | SetLayerPropertiesForTesting(grand_child, grand_child_transform, |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1033 | gfx::Point3F(), gfx::PointF(), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1034 | gfx::Size(100, 100), true, false, false); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1035 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1036 | grand_child->test_properties()->should_flatten_transform = false; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1037 | grand_child->SetDrawsContent(true); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1038 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1039 | ExecuteCalculateDrawProperties(root); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1040 | |
| 1041 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1042 | // that is fully contained within the target's bounds, so grand_child should |
| 1043 | // be considered fully visible. |
| 1044 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 1045 | grand_child->visible_layer_rect()); |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1046 | } |
| 1047 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1048 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1049 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1050 | // skipping a necessary translation. Without that translation, the coordinate |
| 1051 | // space of the layer's draw transform is incorrect. |
| 1052 | // |
| 1053 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1054 | // but if that layer becomes a render surface, then its draw transform is |
| 1055 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1056 | // incorrectly as a result. |
| 1057 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1058 | LayerImpl* root = root_layer(); |
| 1059 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1060 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1061 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | |
| 1063 | // The child height is zero, but has non-zero width that should be accounted |
| 1064 | // for while computing draw transforms. |
| 1065 | const gfx::Transform identity_matrix; |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1066 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1067 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1068 | true); |
| 1069 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1070 | gfx::PointF(), gfx::Size(10, 0), true, false, |
| 1071 | true); |
| 1072 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1073 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1074 | false); |
| 1075 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1076 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1077 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1078 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1079 | // This is the real test, the rest are sanity checks. |
| 1080 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1081 | child->render_surface()->draw_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1083 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1084 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1085 | } |
| 1086 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1087 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
| 1088 | const gfx::Transform identity_matrix; |
| 1089 | LayerImpl* root = root_layer(); |
| 1090 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1091 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1092 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1093 | |
| 1094 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1095 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1096 | true); |
| 1097 | gfx::Transform translate; |
| 1098 | translate.Translate3d(5, 5, 5); |
| 1099 | SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(), |
| 1100 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1101 | true); |
| 1102 | SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(), |
| 1103 | gfx::Size(100, 100), true, false, false); |
| 1104 | SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(), |
| 1105 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1106 | false); |
| 1107 | grand_child->SetDrawsContent(true); |
| 1108 | |
| 1109 | // render_surface will have a sublayer scale because of device scale factor. |
| 1110 | float device_scale_factor = 2.0f; |
| 1111 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1112 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1113 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1114 | inputs.device_scale_factor = device_scale_factor; |
| 1115 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1116 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1117 | |
| 1118 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1119 | // by a factor of 2. |
| 1120 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1121 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1122 | expected_translation); |
| 1123 | } |
| 1124 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1125 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1126 | // Transformations applied at the root of the tree should be forwarded |
| 1127 | // to child layers instead of applied to the root RenderSurface. |
| 1128 | const gfx::Transform identity_matrix; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1129 | LayerImpl* root = root_layer(); |
| 1130 | root->SetDrawsContent(true); |
| 1131 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1132 | child->SetDrawsContent(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1133 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1134 | child->SetScrollClipLayer(root->id()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1135 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1136 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1137 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1138 | true); |
| 1139 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1140 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1141 | false); |
| 1142 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1143 | gfx::Transform translate; |
| 1144 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1145 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1146 | LayerImplList render_surface_layer_list_impl; |
| 1147 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1148 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1149 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1150 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1151 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1152 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1153 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1154 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1155 | |
| 1156 | gfx::Transform scale; |
| 1157 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1158 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1159 | LayerImplList render_surface_layer_list_impl; |
| 1160 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1161 | root, root->bounds(), scale, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1162 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1163 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1164 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1165 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1166 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1167 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1168 | |
| 1169 | gfx::Transform rotate; |
| 1170 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1171 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1172 | LayerImplList render_surface_layer_list_impl; |
| 1173 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1174 | root, root->bounds(), rotate, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1175 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1176 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1177 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1178 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1179 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1180 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1181 | |
| 1182 | gfx::Transform composite; |
| 1183 | composite.ConcatTransform(translate); |
| 1184 | composite.ConcatTransform(scale); |
| 1185 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1186 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1187 | LayerImplList render_surface_layer_list_impl; |
| 1188 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1189 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1190 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1191 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1192 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1193 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1194 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1195 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1196 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1197 | // Verify it composes correctly with device scale. |
| 1198 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1199 | |
| 1200 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1201 | LayerImplList render_surface_layer_list_impl; |
| 1202 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1203 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1204 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1205 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1206 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1207 | gfx::Transform device_scaled_translate = translate; |
| 1208 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1209 | EXPECT_EQ(device_scaled_translate, |
| 1210 | root->draw_properties().target_space_transform); |
| 1211 | EXPECT_EQ(device_scaled_translate, |
| 1212 | child->draw_properties().target_space_transform); |
| 1213 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1214 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1215 | |
| 1216 | // Verify it composes correctly with page scale. |
| 1217 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1218 | |
| 1219 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1220 | LayerImplList render_surface_layer_list_impl; |
| 1221 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1222 | root, root->bounds(), translate, &render_surface_layer_list_impl); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1223 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1224 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1225 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1226 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1227 | gfx::Transform page_scaled_translate = translate; |
| 1228 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1229 | EXPECT_EQ(page_scaled_translate, |
| 1230 | root->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1231 | EXPECT_EQ(page_scaled_translate, |
| 1232 | child->draw_properties().target_space_transform); |
| 1233 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1234 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1235 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1236 | // Verify that it composes correctly with transforms directly on root layer. |
| 1237 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1238 | |
| 1239 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1240 | LayerImplList render_surface_layer_list_impl; |
| 1241 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1242 | root, root->bounds(), composite, &render_surface_layer_list_impl); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1243 | inputs.property_trees->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1244 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1245 | gfx::Transform compositeSquared = composite; |
| 1246 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1247 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1248 | compositeSquared, root->draw_properties().target_space_transform); |
| 1249 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1250 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1251 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1252 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1253 | } |
| 1254 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1255 | TEST_F(LayerTreeHostCommonTest, |
| 1256 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1257 | LayerImpl* parent = root_layer(); |
| 1258 | parent->SetMasksToBounds(true); |
| 1259 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1260 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1261 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1263 | const gfx::Transform identity_matrix; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1264 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1265 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1266 | true); |
| 1267 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1268 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1269 | true); |
| 1270 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1271 | gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true, |
| 1272 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1273 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1274 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1275 | |
| 1276 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1277 | // the intermediate render surface should not be listed here, even if it was |
| 1278 | // forced to be created. Render surfaces without children or visible content |
| 1279 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1280 | // of size 0). |
| 1281 | ASSERT_TRUE(parent->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1282 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1283 | } |
| 1284 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1285 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1286 | LayerImpl* parent = root_layer(); |
| 1287 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1288 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1289 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1290 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1291 | const gfx::Transform identity_matrix; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1292 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1293 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1294 | true); |
| 1295 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1296 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1297 | false); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1298 | render_surface1->test_properties()->opacity = 0.f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1299 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1300 | LayerImplList render_surface_layer_list; |
| 1301 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1302 | parent, parent->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1303 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1304 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1305 | |
| 1306 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1307 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1308 | // have been extended by the children. |
| 1309 | ASSERT_TRUE(parent->render_surface()); |
| 1310 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1311 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1312 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1313 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1314 | } |
| 1315 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1316 | TEST_F(LayerTreeHostCommonTest, |
| 1317 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
| 1318 | LayerImpl* parent = root_layer(); |
| 1319 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1320 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1321 | child->SetDrawsContent(true); |
| 1322 | |
| 1323 | const gfx::Transform identity_matrix; |
| 1324 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1325 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1326 | true); |
| 1327 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1328 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1329 | true); |
| 1330 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1331 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1332 | false); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1333 | render_surface1->test_properties()->opacity = 0.f; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1334 | render_surface1->SetDrawsContent(true); |
| 1335 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1336 | FilterOperations filters; |
| 1337 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
| 1338 | render_surface1->SetBackgroundFilters(filters); |
| 1339 | |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1340 | { |
| 1341 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1342 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1343 | parent, parent->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1344 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1345 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1346 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1347 | } |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1348 | // The layer is fully transparent, but has a background filter, so it |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1349 | // shouldn't be skipped and should be drawn. |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1350 | ASSERT_TRUE(parent->render_surface()); |
| 1351 | EXPECT_EQ(1U, parent->render_surface()->layer_list().size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1352 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
| 1353 | parent->render_surface()->DrawableContentRect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1354 | EffectTree& effect_tree = |
| 1355 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 1356 | EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1357 | EXPECT_TRUE(node->data.is_drawn); |
| 1358 | |
| 1359 | // When parent is transparent, the layer should not be drawn. |
| 1360 | parent->OnOpacityAnimated(0.f); |
| 1361 | render_surface1->OnOpacityAnimated(1.f); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1362 | render_surface1->set_visible_layer_rect(gfx::Rect()); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1363 | { |
| 1364 | LayerImplList render_surface_layer_list; |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1365 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1366 | parent, parent->bounds(), &render_surface_layer_list); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1367 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1368 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 369c24b | 2016-04-06 23:44:16 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | node = effect_tree.Node(render_surface1->effect_tree_index()); |
| 1372 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 1373 | EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1374 | } |
| 1375 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1376 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
| 1377 | LayerImpl* root = root_layer(); |
| 1378 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1379 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1380 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1381 | child1->SetDrawsContent(true); |
| 1382 | child2->SetDrawsContent(true); |
| 1383 | |
| 1384 | const gfx::Transform identity_matrix; |
| 1385 | gfx::Transform scale_matrix; |
| 1386 | scale_matrix.Scale(2.0f, 2.0f); |
| 1387 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1388 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1389 | true); |
| 1390 | SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(), |
| 1391 | gfx::PointF(), gfx::Size(), true, false, true); |
| 1392 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1393 | gfx::PointF(0, 0), gfx::Size(25, 25), true, |
| 1394 | false, true); |
| 1395 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1396 | gfx::PointF(25, 25), gfx::Size(25, 25), true, |
| 1397 | false, true); |
| 1398 | FilterOperations filters; |
| 1399 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
| 1400 | parent->SetFilters(filters); |
| 1401 | |
| 1402 | LayerImplList render_surface_layer_list; |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1403 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 1404 | root, root->bounds(), &render_surface_layer_list); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1405 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 1406 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1407 | |
| 1408 | ASSERT_TRUE(parent->render_surface()); |
| 1409 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1410 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1411 | |
| 1412 | // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the |
| 1413 | // blur (-30,-30 110x110), and then scaled by the scale matrix |
| 1414 | // (-60,-60 220x220). |
| 1415 | EXPECT_EQ(gfx::RectF(-60, -60, 220, 220), |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1416 | parent->render_surface()->DrawableContentRect()); |
| 1417 | } |
| 1418 | |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 1419 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) { |
| 1420 | LayerImpl* root = root_layer(); |
| 1421 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1422 | child->SetDrawsContent(true); |
| 1423 | |
| 1424 | SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(), |
| 1425 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1426 | true); |
| 1427 | SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(), |
| 1428 | gfx::PointF(), gfx::Size(25, 25), true, false, |
| 1429 | true); |
| 1430 | |
| 1431 | FilterOperations filters; |
| 1432 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1433 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
| 1434 | child->SetFilters(filters); |
| 1435 | |
| 1436 | ExecuteCalculateDrawProperties(root); |
| 1437 | |
| 1438 | // The render surface's size should be unaffected by the offset image filter; |
| 1439 | // it need only have a drawable content rect large enough to contain the |
| 1440 | // contents (at the new offset). |
| 1441 | ASSERT_TRUE(child->render_surface()); |
| 1442 | EXPECT_EQ(gfx::RectF(50, 50, 25, 25), |
| 1443 | child->render_surface()->DrawableContentRect()); |
| 1444 | } |
| 1445 | |
| 1446 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) { |
| 1447 | const float device_scale_factor = 2.0f; |
| 1448 | |
| 1449 | LayerImpl* root = root_layer(); |
| 1450 | root->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
| 1451 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1452 | child->SetDrawsContent(true); |
| 1453 | |
| 1454 | SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(), |
| 1455 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1456 | true); |
| 1457 | SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(), |
| 1458 | gfx::PointF(), gfx::Size(25, 25), true, false, |
| 1459 | true); |
| 1460 | |
| 1461 | FilterOperations filters; |
| 1462 | filters.Append(FilterOperation::CreateReferenceFilter( |
| 1463 | SkOffsetImageFilter::Make(50, 50, nullptr))); |
| 1464 | child->SetFilters(filters); |
| 1465 | |
| 1466 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
| 1467 | |
| 1468 | // The render surface's size should be unaffected by the offset image filter; |
| 1469 | // it need only have a drawable content rect large enough to contain the |
| 1470 | // contents (at the new offset). All coordinates should be scaled by 2, |
| 1471 | // corresponding to the device scale factor. |
| 1472 | ASSERT_TRUE(child->render_surface()); |
| 1473 | EXPECT_EQ(gfx::RectF(100, 100, 50, 50), |
| 1474 | child->render_surface()->DrawableContentRect()); |
| 1475 | } |
| 1476 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1477 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1478 | LayerImpl* parent = root_layer(); |
| 1479 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1480 | child->SetDrawsContent(true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1481 | |
| 1482 | const gfx::Transform identity_matrix; |
| 1483 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1484 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1485 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1486 | true); |
| 1487 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1488 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1489 | true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1490 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1491 | child->SetBlendMode(blend_mode); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1492 | child->test_properties()->opacity = 0.5f; |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1493 | |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1494 | ExecuteCalculateDrawProperties(parent); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1495 | |
| 1496 | // Since the child layer has a blend mode other than normal, it should get |
| 1497 | // its own render surface. Also, layer's draw_properties should contain the |
| 1498 | // default blend mode, since the render surface becomes responsible for |
| 1499 | // applying the blend mode. |
| 1500 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1501 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1502 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1503 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1504 | } |
| 1505 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1506 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
| 1507 | LayerImpl* root = root_layer(); |
| 1508 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1509 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1510 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1511 | |
| 1512 | const gfx::Transform identity_matrix; |
| 1513 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1514 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1515 | true); |
| 1516 | SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(), |
| 1517 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1518 | true); |
| 1519 | SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(), |
| 1520 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1521 | false); |
| 1522 | SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(), |
| 1523 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1524 | true); |
| 1525 | surface1->SetDrawsContent(true); |
| 1526 | surface2->SetDrawsContent(true); |
| 1527 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1528 | surface1->test_properties()->opacity = 0.5f; |
| 1529 | not_surface->test_properties()->opacity = 0.5f; |
| 1530 | surface2->test_properties()->opacity = 0.5f; |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1531 | |
| 1532 | ExecuteCalculateDrawProperties(root); |
| 1533 | |
| 1534 | ASSERT_TRUE(surface1->render_surface()); |
| 1535 | ASSERT_FALSE(not_surface->render_surface()); |
| 1536 | ASSERT_TRUE(surface2->render_surface()); |
| 1537 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1538 | // surface2's draw opacity should include the opacity of not-surface and |
| 1539 | // itself, but not the opacity of surface1. |
| 1540 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1541 | } |
| 1542 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1543 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1544 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1545 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1546 | // (Rendering will still be incorrect in situations where we really do need |
| 1547 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1548 | // ancestor whose opacity is <1.) |
| 1549 | LayerImpl* root = root_layer(); |
| 1550 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1551 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1552 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1553 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1554 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1555 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1556 | |
| 1557 | root->SetDrawsContent(true); |
| 1558 | parent->SetDrawsContent(true); |
| 1559 | child1->SetDrawsContent(true); |
| 1560 | child2->SetDrawsContent(true); |
| 1561 | grand_child->SetDrawsContent(true); |
| 1562 | leaf_node1->SetDrawsContent(true); |
| 1563 | leaf_node2->SetDrawsContent(true); |
| 1564 | |
| 1565 | const gfx::Transform identity_matrix; |
| 1566 | |
| 1567 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1568 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1569 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1570 | true); |
| 1571 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1572 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1573 | false); |
| 1574 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1575 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1576 | true); |
| 1577 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1578 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1579 | false); |
| 1580 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1581 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1582 | true); |
| 1583 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1584 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1585 | false); |
| 1586 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1587 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1588 | false); |
| 1589 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1590 | child1->test_properties()->opacity = 0.5f; |
| 1591 | grand_child->test_properties()->opacity = 0.5f; |
| 1592 | leaf_node1->test_properties()->opacity = 0.5f; |
| 1593 | leaf_node2->test_properties()->opacity = 0.5f; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1594 | |
| 1595 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1596 | // opacities on the path from the layer to its render target, not including |
| 1597 | // the opacity of the layer that owns the target surface (since that opacity |
| 1598 | // is applied by the surface). |
| 1599 | ExecuteCalculateDrawProperties(root); |
| 1600 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1601 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1602 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1603 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1604 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1605 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1606 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1607 | |
| 1608 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1609 | // opacities on the path from the layer to the root. |
| 1610 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1611 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1612 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1613 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1614 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1615 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1616 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1617 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1618 | } |
| 1619 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1620 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1621 | LayerImpl* parent = root_layer(); |
| 1622 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1623 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1624 | |
| 1625 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1626 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1627 | gfx::PointF(), gfx::Size(10, 10), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1628 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1629 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1630 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1631 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1632 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1633 | child->SetDrawsContent(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1634 | render_surface1->test_properties()->force_render_surface = true; |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1635 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1636 | { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1637 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1638 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1639 | // The root layer always creates a render surface |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1640 | EXPECT_TRUE(parent->has_render_surface()); |
| 1641 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1642 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1643 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1644 | { |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 1645 | render_surface1->test_properties()->force_render_surface = false; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1646 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1647 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1648 | EXPECT_TRUE(parent->has_render_surface()); |
| 1649 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1650 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1651 | } |
| 1652 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1653 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1654 | // Render surfaces act as a flattening point for their subtree, so should |
| 1655 | // always flatten the target-to-screen space transform seen by descendants. |
| 1656 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1657 | LayerImpl* root = root_layer(); |
| 1658 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1659 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1660 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1661 | |
| 1662 | child->SetDrawsContent(true); |
| 1663 | grand_child->SetDrawsContent(true); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1664 | |
| 1665 | gfx::Transform rotation_about_y_axis; |
| 1666 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1667 | // Make |parent| have a render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1668 | parent->test_properties()->opacity = 0.9f; |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1669 | |
| 1670 | const gfx::Transform identity_matrix; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1671 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1672 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1673 | true); |
| 1674 | SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(), |
| 1675 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1676 | true); |
| 1677 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1678 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1679 | false); |
| 1680 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1681 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1682 | false); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1683 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1684 | grand_child->test_properties()->should_flatten_transform = false; |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1685 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1686 | // Only grand_child should preserve 3d. |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 1687 | EXPECT_TRUE(root->test_properties()->should_flatten_transform); |
| 1688 | EXPECT_TRUE(parent->test_properties()->should_flatten_transform); |
| 1689 | EXPECT_TRUE(child->test_properties()->should_flatten_transform); |
| 1690 | EXPECT_FALSE(grand_child->test_properties()->should_flatten_transform); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1691 | |
| 1692 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1693 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1694 | |
| 1695 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1696 | flattened_rotation_about_y.FlattenTo2d(); |
| 1697 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1698 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1699 | |
| 1700 | EXPECT_TRUE(parent->render_surface()); |
| 1701 | EXPECT_FALSE(child->render_surface()); |
| 1702 | EXPECT_FALSE(grand_child->render_surface()); |
| 1703 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1704 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1705 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1706 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1707 | |
| 1708 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1709 | // have been flattened at their render target. In particular, the fact that |
| 1710 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1711 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1712 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1713 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1714 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1715 | } |
| 1716 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1717 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1718 | // The entire subtree of layers that are outside the clip rect should be |
| 1719 | // culled away, and should not affect the render_surface_layer_list. |
| 1720 | // |
| 1721 | // The test tree is set up as follows: |
| 1722 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1723 | // that have something to draw. |
| 1724 | // - parent is a large container layer. |
| 1725 | // - child has masksToBounds=true to cause clipping. |
| 1726 | // - grand_child is positioned outside of the child's bounds |
| 1727 | // - great_grand_child is also kept outside child's bounds. |
| 1728 | // |
| 1729 | // In this configuration, grand_child and great_grand_child are completely |
| 1730 | // outside the clip rect, and they should never get scheduled on the list of |
| 1731 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1732 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1733 | LayerImpl* parent = root_layer(); |
| 1734 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1735 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1736 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1737 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1738 | // leaf_node1 ensures that parent and child are kept on the |
| 1739 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1740 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1741 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
| 1742 | leaf_node1->SetDrawsContent(true); |
| 1743 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
| 1744 | leaf_node2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1745 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1746 | const gfx::Transform identity_matrix; |
| 1747 | |
| 1748 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1749 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 1750 | true); |
| 1751 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1752 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1753 | true); |
| 1754 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1755 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 1756 | false, false); |
| 1757 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 1758 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1759 | true, false, false); |
| 1760 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1761 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1762 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1763 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1764 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | false); |
| 1766 | |
| 1767 | child->SetMasksToBounds(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1768 | child->test_properties()->opacity = 0.4f; |
| 1769 | grand_child->test_properties()->opacity = 0.5f; |
| 1770 | great_grand_child->test_properties()->opacity = 0.4f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1771 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1772 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1773 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1774 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
| 1775 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
| 1776 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1777 | } |
| 1778 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1779 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1780 | // 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] | 1781 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1782 | |
| 1783 | // The test tree is set up as follows: |
| 1784 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1785 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1786 | // the parent. |
| 1787 | // - grand_child is a render surface, and the only visible content in child. |
| 1788 | // It is positioned outside of the clip rect from parent. |
| 1789 | |
| 1790 | // In this configuration, grand_child should be outside the clipped |
| 1791 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1792 | // render_surface_layer_list. |
| 1793 | |
| 1794 | LayerImpl* parent = root_layer(); |
| 1795 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1796 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1797 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 1798 | leaf_node->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | |
| 1800 | const gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1801 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1802 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1803 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1804 | true); |
| 1805 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1806 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1807 | true); |
| 1808 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1809 | gfx::PointF(200.f, 200.f), gfx::Size(10, 10), |
| 1810 | true, false, true); |
| 1811 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 1812 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1813 | false); |
| 1814 | |
| 1815 | parent->SetMasksToBounds(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 1816 | child->test_properties()->opacity = 0.4f; |
| 1817 | grand_child->test_properties()->opacity = 0.4f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1818 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1819 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1820 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1821 | // We should cull child and grand_child from the |
| 1822 | // render_surface_layer_list. |
| 1823 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
| 1824 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1825 | } |
| 1826 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1827 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1828 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1829 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1830 | // - the layer is clipped by an ancestor that contributes to the same |
| 1831 | // render target, |
| 1832 | // - a surface is clipped by an ancestor that contributes to the same |
| 1833 | // render target. |
| 1834 | // |
| 1835 | // In particular, for a layer that owns a render surface: |
| 1836 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1837 | // pass that clipped status to the layer itself. |
| 1838 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1839 | // and propagates the clip to the subtree. |
| 1840 | |
| 1841 | const gfx::Transform identity_matrix; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1842 | LayerImpl* root = root_layer(); |
| 1843 | LayerImpl* parent = AddChild<LayerImpl>(root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1844 | parent->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1845 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1846 | child1->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1847 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1848 | child2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1849 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1850 | grand_child->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1851 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1852 | leaf_node1->SetDrawsContent(true); |
| 1853 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1854 | leaf_node2->SetDrawsContent(true); |
| 1855 | |
| 1856 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1857 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1858 | true); |
| 1859 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1860 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1861 | false); |
| 1862 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1863 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1864 | false); |
| 1865 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1866 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1867 | true); |
| 1868 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1869 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1870 | false); |
| 1871 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1872 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1873 | false); |
| 1874 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1875 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1876 | false); |
| 1877 | |
| 1878 | // Case 1: nothing is clipped except the root render surface. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1879 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1880 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1881 | ASSERT_TRUE(root->render_surface()); |
| 1882 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1883 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1884 | EXPECT_FALSE(root->is_clipped()); |
| 1885 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1886 | EXPECT_FALSE(parent->is_clipped()); |
| 1887 | EXPECT_FALSE(child1->is_clipped()); |
| 1888 | EXPECT_FALSE(child2->is_clipped()); |
| 1889 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1890 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1891 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1892 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1893 | |
| 1894 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1895 | // surface are clipped. But layers that contribute to child2's surface are |
| 1896 | // not clipped explicitly because child2's surface already accounts for |
| 1897 | // that clip. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1898 | parent->SetMasksToBounds(true); |
| 1899 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1900 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1901 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1902 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1903 | ASSERT_TRUE(root->render_surface()); |
| 1904 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1905 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1906 | EXPECT_FALSE(root->is_clipped()); |
| 1907 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1908 | EXPECT_TRUE(parent->is_clipped()); |
| 1909 | EXPECT_TRUE(child1->is_clipped()); |
| 1910 | EXPECT_FALSE(child2->is_clipped()); |
| 1911 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1912 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1913 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1914 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1915 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1916 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1917 | |
| 1918 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1919 | // child2's render surface is not clipped. |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1920 | child2->SetMasksToBounds(true); |
| 1921 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1922 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1923 | ExecuteCalculateDrawProperties(root); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1924 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1925 | ASSERT_TRUE(root->render_surface()); |
| 1926 | ASSERT_TRUE(child2->render_surface()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1927 | |
weiliangc | e3f09a61 | 2016-03-16 17:02:52 | [diff] [blame] | 1928 | EXPECT_FALSE(root->is_clipped()); |
| 1929 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1930 | EXPECT_FALSE(parent->is_clipped()); |
| 1931 | EXPECT_FALSE(child1->is_clipped()); |
| 1932 | EXPECT_TRUE(child2->is_clipped()); |
| 1933 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1934 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1935 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1936 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1937 | } |
| 1938 | |
| 1939 | TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) { |
| 1940 | // Tests that when as long as layer is clipped, it's clip rect is set to |
| 1941 | // correct value. |
| 1942 | LayerImpl* root = root_layer(); |
| 1943 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1944 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1945 | |
| 1946 | root->SetDrawsContent(true); |
| 1947 | parent->SetDrawsContent(true); |
| 1948 | child->SetDrawsContent(true); |
| 1949 | |
| 1950 | const gfx::Transform identity_matrix; |
| 1951 | |
| 1952 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1953 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1954 | true); |
| 1955 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1956 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1957 | false); |
| 1958 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1959 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1960 | false); |
| 1961 | child->SetMasksToBounds(true); |
| 1962 | |
| 1963 | ExecuteCalculateDrawProperties(root); |
| 1964 | |
| 1965 | EXPECT_FALSE(root->is_clipped()); |
| 1966 | EXPECT_FALSE(parent->is_clipped()); |
| 1967 | EXPECT_TRUE(child->is_clipped()); |
| 1968 | EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect()); |
| 1969 | |
| 1970 | parent->SetMasksToBounds(true); |
| 1971 | child->SetPosition(gfx::PointF(100, 100)); |
| 1972 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1973 | |
| 1974 | ExecuteCalculateDrawProperties(root); |
| 1975 | |
| 1976 | EXPECT_FALSE(root->is_clipped()); |
| 1977 | EXPECT_TRUE(parent->is_clipped()); |
| 1978 | EXPECT_TRUE(child->is_clipped()); |
| 1979 | EXPECT_EQ(gfx::Rect(), child->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1980 | } |
| 1981 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1982 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1983 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1984 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1985 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1986 | // that can reset is_clipped). |
| 1987 | LayerImpl* root = root_layer(); |
| 1988 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1989 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1990 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1991 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1992 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1993 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1994 | |
| 1995 | root->SetDrawsContent(true); |
| 1996 | parent->SetDrawsContent(true); |
| 1997 | child1->SetDrawsContent(true); |
| 1998 | child2->SetDrawsContent(true); |
| 1999 | grand_child->SetDrawsContent(true); |
| 2000 | leaf_node1->SetDrawsContent(true); |
| 2001 | leaf_node2->SetDrawsContent(true); |
| 2002 | |
| 2003 | const gfx::Transform identity_matrix; |
| 2004 | |
| 2005 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 2006 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2007 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2008 | true); |
| 2009 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2010 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2011 | false); |
| 2012 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 2013 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2014 | true); |
| 2015 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 2016 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2017 | false); |
| 2018 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2019 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2020 | true); |
| 2021 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2022 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2023 | false); |
| 2024 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2025 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2026 | false); |
| 2027 | |
| 2028 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 2029 | // or without surfaces. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2030 | root->SetHasRenderSurface(true); |
| 2031 | child1->SetHasRenderSurface(true); |
| 2032 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2033 | ExecuteCalculateDrawProperties(root); |
| 2034 | EXPECT_FALSE(root->is_clipped()); |
| 2035 | EXPECT_FALSE(parent->is_clipped()); |
| 2036 | EXPECT_FALSE(child1->is_clipped()); |
| 2037 | EXPECT_FALSE(child2->is_clipped()); |
| 2038 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2039 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2040 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2041 | |
| 2042 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2043 | EXPECT_FALSE(root->is_clipped()); |
| 2044 | EXPECT_FALSE(parent->is_clipped()); |
| 2045 | EXPECT_FALSE(child1->is_clipped()); |
| 2046 | EXPECT_FALSE(child2->is_clipped()); |
| 2047 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2048 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2049 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2050 | |
| 2051 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 2052 | // next render surface. Without surfaces, the entire tree is clipped. |
| 2053 | root->SetMasksToBounds(true); |
| 2054 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2055 | root->SetHasRenderSurface(true); |
| 2056 | child1->SetHasRenderSurface(true); |
| 2057 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2058 | ExecuteCalculateDrawProperties(root); |
| 2059 | EXPECT_TRUE(root->is_clipped()); |
| 2060 | EXPECT_TRUE(parent->is_clipped()); |
| 2061 | EXPECT_FALSE(child1->is_clipped()); |
| 2062 | EXPECT_TRUE(child2->is_clipped()); |
| 2063 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2064 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2065 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2066 | |
| 2067 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2068 | EXPECT_TRUE(root->is_clipped()); |
| 2069 | EXPECT_TRUE(parent->is_clipped()); |
| 2070 | EXPECT_TRUE(child1->is_clipped()); |
| 2071 | EXPECT_TRUE(child2->is_clipped()); |
| 2072 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2073 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2074 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2075 | |
| 2076 | root->SetMasksToBounds(false); |
| 2077 | |
| 2078 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 2079 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 2080 | // clipped. |
| 2081 | parent->SetMasksToBounds(true); |
| 2082 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2083 | root->SetHasRenderSurface(true); |
| 2084 | child1->SetHasRenderSurface(true); |
| 2085 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2086 | ExecuteCalculateDrawProperties(root); |
| 2087 | EXPECT_FALSE(root->is_clipped()); |
| 2088 | EXPECT_TRUE(parent->is_clipped()); |
| 2089 | EXPECT_FALSE(child1->is_clipped()); |
| 2090 | EXPECT_TRUE(child2->is_clipped()); |
| 2091 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2092 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2093 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2094 | |
| 2095 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2096 | EXPECT_FALSE(root->is_clipped()); |
| 2097 | EXPECT_TRUE(parent->is_clipped()); |
| 2098 | EXPECT_TRUE(child1->is_clipped()); |
| 2099 | EXPECT_TRUE(child2->is_clipped()); |
| 2100 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2101 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2102 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2103 | |
| 2104 | parent->SetMasksToBounds(false); |
| 2105 | |
| 2106 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2107 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2108 | // clipped. |
| 2109 | child1->SetMasksToBounds(true); |
| 2110 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2111 | root->SetHasRenderSurface(true); |
| 2112 | child1->SetHasRenderSurface(true); |
| 2113 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2114 | ExecuteCalculateDrawProperties(root); |
| 2115 | EXPECT_FALSE(root->is_clipped()); |
| 2116 | EXPECT_FALSE(parent->is_clipped()); |
| 2117 | EXPECT_TRUE(child1->is_clipped()); |
| 2118 | EXPECT_FALSE(child2->is_clipped()); |
| 2119 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2120 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2121 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2122 | |
| 2123 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2124 | EXPECT_FALSE(root->is_clipped()); |
| 2125 | EXPECT_FALSE(parent->is_clipped()); |
| 2126 | EXPECT_TRUE(child1->is_clipped()); |
| 2127 | EXPECT_FALSE(child2->is_clipped()); |
| 2128 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2129 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2130 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2131 | |
| 2132 | child1->SetMasksToBounds(false); |
| 2133 | |
| 2134 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2135 | // surfaces is the same. |
| 2136 | leaf_node1->SetMasksToBounds(true); |
| 2137 | leaf_node2->SetMasksToBounds(true); |
| 2138 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2139 | root->SetHasRenderSurface(true); |
| 2140 | child1->SetHasRenderSurface(true); |
| 2141 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2142 | ExecuteCalculateDrawProperties(root); |
| 2143 | EXPECT_FALSE(root->is_clipped()); |
| 2144 | EXPECT_FALSE(parent->is_clipped()); |
| 2145 | EXPECT_FALSE(child1->is_clipped()); |
| 2146 | EXPECT_FALSE(child2->is_clipped()); |
| 2147 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2148 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2149 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2150 | |
| 2151 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2152 | EXPECT_FALSE(root->is_clipped()); |
| 2153 | EXPECT_FALSE(parent->is_clipped()); |
| 2154 | EXPECT_FALSE(child1->is_clipped()); |
| 2155 | EXPECT_FALSE(child2->is_clipped()); |
| 2156 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2157 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2158 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2159 | } |
| 2160 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2161 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2162 | // Verify that layers get the appropriate DrawableContentRect when their |
| 2163 | // parent masksToBounds is true. |
| 2164 | // |
| 2165 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2166 | // be the layer rect expressed in target space. |
| 2167 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 2168 | // will be the intersection of layer bounds and the mask region. |
| 2169 | // grand_child3 - partially clipped and masksToBounds; the |
| 2170 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2171 | // the mask region. |
| 2172 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2173 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2174 | |
| 2175 | const gfx::Transform identity_matrix; |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2176 | LayerImpl* parent = root_layer(); |
| 2177 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2178 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2179 | grand_child1->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2180 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2181 | grand_child2->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2182 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2183 | grand_child3->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2184 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2185 | grand_child4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2186 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2187 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2188 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2189 | true); |
| 2190 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2191 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2192 | true); |
| 2193 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2194 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2195 | false, false); |
| 2196 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2197 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2198 | false, false); |
| 2199 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2200 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2201 | false, false); |
| 2202 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2203 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2204 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2205 | |
| 2206 | child->SetMasksToBounds(true); |
| 2207 | grand_child3->SetMasksToBounds(true); |
| 2208 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2209 | // Force child to be a render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2210 | child->test_properties()->opacity = 0.4f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2211 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2212 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2213 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2214 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2215 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2216 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2217 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2218 | } |
| 2219 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2220 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2221 | // Verify that render surfaces (and their layers) get the appropriate |
| 2222 | // clip rects when their parent masksToBounds is true. |
| 2223 | // |
| 2224 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2225 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2226 | // They may still have a clip rect of their own layer bounds, however, if |
| 2227 | // masksToBounds was true. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2228 | LayerImpl* parent = root_layer(); |
| 2229 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2230 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2231 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2232 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2233 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2234 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2235 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2236 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 2237 | leaf_node1->SetDrawsContent(true); |
| 2238 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 2239 | leaf_node2->SetDrawsContent(true); |
| 2240 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
| 2241 | leaf_node3->SetDrawsContent(true); |
| 2242 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
| 2243 | leaf_node4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2244 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2245 | const gfx::Transform identity_matrix; |
| 2246 | |
| 2247 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2248 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2249 | true); |
| 2250 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2251 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2252 | true); |
| 2253 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2254 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2255 | false, true); |
| 2256 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2257 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2258 | false, true); |
| 2259 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2260 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2261 | false, true); |
| 2262 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2263 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2264 | false, true); |
| 2265 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2266 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2267 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2268 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2269 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2270 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2271 | SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(), |
| 2272 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2273 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2274 | SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(), |
| 2275 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2276 | false); |
| 2277 | |
| 2278 | child->SetMasksToBounds(true); |
| 2279 | grand_child3->SetMasksToBounds(true); |
| 2280 | grand_child4->SetMasksToBounds(true); |
| 2281 | |
| 2282 | // Force everyone to be a render surface. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 2283 | child->test_properties()->opacity = 0.4f; |
| 2284 | grand_child1->test_properties()->opacity = 0.5f; |
| 2285 | grand_child2->test_properties()->opacity = 0.5f; |
| 2286 | grand_child3->test_properties()->opacity = 0.5f; |
| 2287 | grand_child4->test_properties()->opacity = 0.5f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2288 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2289 | ExecuteCalculateDrawProperties(parent); |
| 2290 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2291 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2292 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2293 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2294 | |
| 2295 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2296 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2297 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2298 | grand_child1->render_surface()->clip_rect()); |
| 2299 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2300 | grand_child2->render_surface()->clip_rect()); |
| 2301 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2302 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2303 | } |
| 2304 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2305 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2306 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2307 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2308 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2309 | // subtree (since there are no render surfaces that can reset the clip_rect). |
| 2310 | LayerImpl* root = root_layer(); |
| 2311 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2312 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2313 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2314 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2315 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2316 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2317 | |
| 2318 | root->SetDrawsContent(true); |
| 2319 | parent->SetDrawsContent(true); |
| 2320 | child1->SetDrawsContent(true); |
| 2321 | child2->SetDrawsContent(true); |
| 2322 | grand_child->SetDrawsContent(true); |
| 2323 | leaf_node1->SetDrawsContent(true); |
| 2324 | leaf_node2->SetDrawsContent(true); |
| 2325 | |
| 2326 | const gfx::Transform identity_matrix; |
| 2327 | |
| 2328 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 2329 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2330 | gfx::PointF(), gfx::Size(100, 100), true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2331 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2332 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2333 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2334 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 2335 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2336 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2337 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 2338 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2339 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2340 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2341 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2342 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2343 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2344 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2345 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2346 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2347 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2348 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2349 | |
| 2350 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2351 | // bounds in target space. The only thing that changes when surfaces are |
| 2352 | // disabled is that target space is always screen space. |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2353 | root->test_properties()->force_render_surface = true; |
| 2354 | child1->test_properties()->force_render_surface = true; |
| 2355 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2356 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2357 | EXPECT_TRUE(root->has_render_surface()); |
| 2358 | EXPECT_FALSE(parent->has_render_surface()); |
| 2359 | EXPECT_TRUE(child1->has_render_surface()); |
| 2360 | EXPECT_FALSE(child2->has_render_surface()); |
| 2361 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2362 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2363 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2364 | EXPECT_FALSE(root->is_clipped()); |
| 2365 | EXPECT_FALSE(parent->is_clipped()); |
| 2366 | EXPECT_FALSE(child1->is_clipped()); |
| 2367 | EXPECT_FALSE(child2->is_clipped()); |
| 2368 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2369 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2370 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2371 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2372 | EXPECT_FALSE(child1->render_surface()->is_clipped()); |
| 2373 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2374 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2375 | |
| 2376 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2377 | EXPECT_FALSE(root->is_clipped()); |
| 2378 | EXPECT_FALSE(parent->is_clipped()); |
| 2379 | EXPECT_FALSE(child1->is_clipped()); |
| 2380 | EXPECT_FALSE(child2->is_clipped()); |
| 2381 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2382 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2383 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2384 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2385 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2386 | |
| 2387 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2388 | // render surface are clipped by the root's bounds. |
| 2389 | root->SetMasksToBounds(true); |
| 2390 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2391 | root->test_properties()->force_render_surface = true; |
| 2392 | child1->test_properties()->force_render_surface = true; |
| 2393 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2394 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2395 | EXPECT_TRUE(root->has_render_surface()); |
| 2396 | EXPECT_FALSE(parent->has_render_surface()); |
| 2397 | EXPECT_TRUE(child1->has_render_surface()); |
| 2398 | EXPECT_FALSE(child2->has_render_surface()); |
| 2399 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2400 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2401 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2402 | EXPECT_TRUE(root->is_clipped()); |
| 2403 | EXPECT_TRUE(parent->is_clipped()); |
| 2404 | EXPECT_FALSE(child1->is_clipped()); |
| 2405 | EXPECT_TRUE(child1->render_surface()->is_clipped()); |
| 2406 | EXPECT_TRUE(child2->is_clipped()); |
| 2407 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2408 | EXPECT_FALSE(grand_child->render_surface()->is_clipped()); |
| 2409 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2410 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2411 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2412 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2413 | EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2414 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2415 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2416 | |
| 2417 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2418 | EXPECT_TRUE(root->is_clipped()); |
| 2419 | EXPECT_TRUE(parent->is_clipped()); |
| 2420 | EXPECT_TRUE(child1->is_clipped()); |
| 2421 | EXPECT_TRUE(child2->is_clipped()); |
| 2422 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2423 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2424 | EXPECT_TRUE(leaf_node2->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2425 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2426 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2427 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2428 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2429 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2430 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2431 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2432 | |
| 2433 | root->SetMasksToBounds(false); |
| 2434 | |
| 2435 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2436 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2437 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2438 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2439 | // child is a render surface. However, without surfaces, these clip rects |
| 2440 | // contribute to all descendants. |
| 2441 | parent->SetMasksToBounds(true); |
| 2442 | child1->SetMasksToBounds(true); |
| 2443 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 2444 | root->test_properties()->force_render_surface = true; |
| 2445 | child1->test_properties()->force_render_surface = true; |
| 2446 | grand_child->test_properties()->force_render_surface = true; |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2447 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2448 | EXPECT_TRUE(root->has_render_surface()); |
| 2449 | EXPECT_FALSE(parent->has_render_surface()); |
| 2450 | EXPECT_TRUE(child1->has_render_surface()); |
| 2451 | EXPECT_FALSE(child2->has_render_surface()); |
| 2452 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2453 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2454 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2455 | EXPECT_FALSE(root->is_clipped()); |
| 2456 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2457 | EXPECT_TRUE(parent->is_clipped()); |
| 2458 | EXPECT_TRUE(child1->is_clipped()); |
| 2459 | EXPECT_TRUE(child2->is_clipped()); |
| 2460 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2461 | EXPECT_TRUE(grand_child->render_surface()->is_clipped()); |
| 2462 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2463 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2464 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2465 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2466 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2467 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2468 | EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2469 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2470 | |
| 2471 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2472 | EXPECT_FALSE(root->is_clipped()); |
| 2473 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2474 | EXPECT_TRUE(parent->is_clipped()); |
| 2475 | EXPECT_TRUE(child1->is_clipped()); |
| 2476 | EXPECT_TRUE(child2->is_clipped()); |
| 2477 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2478 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2479 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2480 | EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2481 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2482 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2483 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2484 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2485 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2486 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2487 | } |
| 2488 | |
jaydasika | 8d0064f | 2016-06-02 23:34:54 | [diff] [blame] | 2489 | TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) { |
| 2490 | LayerImpl* root = root_layer(); |
| 2491 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2492 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2493 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2494 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2495 | |
| 2496 | root->SetDrawsContent(true); |
| 2497 | parent->SetDrawsContent(true); |
| 2498 | child->SetDrawsContent(true); |
| 2499 | grand_child->SetDrawsContent(true); |
| 2500 | leaf_node->SetDrawsContent(true); |
| 2501 | |
| 2502 | const gfx::Transform identity_matrix; |
| 2503 | |
| 2504 | // child and grand_child will get render surfaces if surfaces are enabled. |
| 2505 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2506 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2507 | true); |
| 2508 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2509 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 2510 | false, false); |
| 2511 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2512 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 2513 | false, true); |
| 2514 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2515 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 2516 | true, false, true); |
| 2517 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 2518 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 2519 | true, false, false); |
| 2520 | |
| 2521 | parent->SetMasksToBounds(true); |
| 2522 | child->SetMasksToBounds(true); |
| 2523 | |
| 2524 | root->SetHasRenderSurface(true); |
| 2525 | child->SetHasRenderSurface(true); |
| 2526 | grand_child->SetHasRenderSurface(true); |
| 2527 | |
| 2528 | host_impl()->set_resourceless_software_draw_for_testing(); |
| 2529 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2530 | gfx::PointF test_point(90.f, 90.f); |
| 2531 | LayerImpl* result_layer = |
| 2532 | root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point); |
| 2533 | ASSERT_TRUE(result_layer); |
| 2534 | EXPECT_EQ(leaf_node, result_layer); |
| 2535 | } |
| 2536 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2537 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2538 | // Tests that draw properties are computed correctly when we disable and then |
| 2539 | // re-enable separate surfaces. |
| 2540 | LayerImpl* root = root_layer(); |
| 2541 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2542 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2543 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2544 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2545 | |
| 2546 | root->SetDrawsContent(true); |
| 2547 | parent->SetDrawsContent(true); |
| 2548 | child->SetDrawsContent(true); |
| 2549 | grand_child->SetDrawsContent(true); |
| 2550 | leaf_node->SetDrawsContent(true); |
| 2551 | |
| 2552 | const gfx::Transform identity_matrix; |
| 2553 | |
| 2554 | // child and grand_child get render surfaces when surfaces are enabled. |
| 2555 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2556 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2557 | true); |
| 2558 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2559 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 2560 | false, false); |
| 2561 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2562 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 2563 | false, true); |
| 2564 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2565 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 2566 | true, false, true); |
| 2567 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 2568 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 2569 | true, false, false); |
| 2570 | |
| 2571 | parent->SetMasksToBounds(true); |
| 2572 | child->SetMasksToBounds(true); |
| 2573 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2574 | root->SetHasRenderSurface(true); |
| 2575 | child->SetHasRenderSurface(true); |
| 2576 | grand_child->SetHasRenderSurface(true); |
| 2577 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2578 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2579 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2580 | |
| 2581 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2582 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2583 | |
| 2584 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2585 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2586 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2587 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2588 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2589 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2590 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2591 | root->SetHasRenderSurface(true); |
| 2592 | child->SetHasRenderSurface(true); |
| 2593 | grand_child->SetHasRenderSurface(true); |
| 2594 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2595 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2596 | EXPECT_TRUE(leaf_node->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2597 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2598 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
| 2599 | EXPECT_EQ(expected_leaf_draw_transform_without_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2600 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2601 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2602 | root->SetHasRenderSurface(true); |
| 2603 | child->SetHasRenderSurface(true); |
| 2604 | grand_child->SetHasRenderSurface(true); |
| 2605 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2606 | ExecuteCalculateDrawProperties(root); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 2607 | EXPECT_FALSE(leaf_node->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2608 | EXPECT_TRUE(leaf_node->render_target()->is_clipped()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2609 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2610 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2611 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2612 | } |
| 2613 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2614 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2615 | LayerImpl* parent = root_layer(); |
| 2616 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2617 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2618 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2619 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2620 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2621 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2622 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2623 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2624 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2625 | parent->SetDrawsContent(true); |
| 2626 | render_surface1->SetDrawsContent(true); |
| 2627 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2628 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2629 | render_surface2->SetDrawsContent(true); |
| 2630 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2631 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2632 | child_of_root->SetDrawsContent(true); |
| 2633 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2634 | |
| 2635 | gfx::Transform layer_transform; |
| 2636 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2637 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2638 | SetLayerPropertiesForTesting( |
| 2639 | parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2640 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2641 | SetLayerPropertiesForTesting( |
| 2642 | render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2643 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2644 | SetLayerPropertiesForTesting( |
| 2645 | render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2646 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2647 | SetLayerPropertiesForTesting( |
| 2648 | child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2649 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2650 | SetLayerPropertiesForTesting( |
| 2651 | child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2652 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2653 | SetLayerPropertiesForTesting( |
| 2654 | child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2655 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2656 | SetLayerPropertiesForTesting( |
| 2657 | grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2658 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2659 | SetLayerPropertiesForTesting( |
| 2660 | grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2661 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2662 | SetLayerPropertiesForTesting( |
| 2663 | grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2664 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2665 | |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 2666 | parent->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2667 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2668 | // Put an animated opacity on the render surface. |
| 2669 | AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(), |
| 2670 | 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2671 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2672 | // Also put an animated opacity on a layer without descendants. |
| 2673 | AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(), |
| 2674 | timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2675 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2676 | // Put a transform animation on the render surface. |
| 2677 | AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(), |
| 2678 | 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2679 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2680 | // Also put transform animations on grand_child_of_root, and |
| 2681 | // grand_child_of_rs2 |
| 2682 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), |
| 2683 | timeline_impl(), 10.0, 30, 0); |
| 2684 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), |
| 2685 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2686 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 2687 | parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2688 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2689 | |
| 2690 | // Only layers that are associated with render surfaces should have an actual |
| 2691 | // RenderSurface() value. |
| 2692 | ASSERT_TRUE(parent->render_surface()); |
| 2693 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2694 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2695 | |
| 2696 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2697 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2698 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2699 | |
| 2700 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2701 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2702 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2703 | |
| 2704 | // Verify all render target accessors |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2705 | EXPECT_EQ(parent->render_surface(), parent->render_target()); |
| 2706 | EXPECT_EQ(parent->render_surface(), child_of_root->render_target()); |
| 2707 | EXPECT_EQ(parent->render_surface(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2709 | EXPECT_EQ(render_surface1->render_surface(), |
| 2710 | render_surface1->render_target()); |
| 2711 | EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target()); |
| 2712 | EXPECT_EQ(render_surface1->render_surface(), |
| 2713 | grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2714 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 2715 | EXPECT_EQ(render_surface2->render_surface(), |
| 2716 | render_surface2->render_target()); |
| 2717 | EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target()); |
| 2718 | EXPECT_EQ(render_surface2->render_surface(), |
| 2719 | grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2720 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2721 | // Verify screen_space_transform_is_animating values |
| 2722 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2723 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2724 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2725 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2726 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2727 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2728 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2729 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2730 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2731 | |
| 2732 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2733 | // It is expected that we correctly set up transforms so that the y-component |
| 2734 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2735 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2736 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2737 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2738 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2739 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2740 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2741 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2742 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2743 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2745 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2746 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2747 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2748 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2749 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2750 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2751 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2752 | } |
| 2753 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2754 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
| 2755 | LayerImpl* parent = root_layer(); |
| 2756 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2757 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2758 | |
| 2759 | grand_child->SetDrawsContent(true); |
| 2760 | |
| 2761 | gfx::Transform large_transform; |
| 2762 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2763 | |
| 2764 | gfx::Transform identity; |
| 2765 | |
| 2766 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2767 | gfx::Size(10, 10), true, false, true); |
| 2768 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
| 2769 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2770 | false); |
| 2771 | SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(), |
| 2772 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2773 | false); |
| 2774 | ExecuteCalculateDrawProperties(parent); |
| 2775 | |
| 2776 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2777 | } |
| 2778 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2779 | TEST_F(LayerTreeHostCommonTest, |
| 2780 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
| 2781 | LayerImpl* parent = root_layer(); |
| 2782 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2783 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2784 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2785 | |
| 2786 | parent->SetDrawsContent(true); |
| 2787 | child->SetDrawsContent(true); |
| 2788 | grand_child->SetDrawsContent(true); |
| 2789 | great_grand_child->SetDrawsContent(true); |
| 2790 | |
| 2791 | gfx::Transform identity; |
| 2792 | |
| 2793 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2794 | gfx::Size(10, 10), true, false, true); |
| 2795 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 2796 | gfx::Size(10, 10), true, false, false); |
| 2797 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 2798 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2799 | false); |
| 2800 | SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(), |
| 2801 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2802 | false); |
| 2803 | |
| 2804 | // Add a transform animation with a start delay to |grand_child|. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 2805 | std::unique_ptr<Animation> animation = Animation::Create( |
| 2806 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 2807 | TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 2808 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2809 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 2810 | AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(), |
| 2811 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2812 | ExecuteCalculateDrawProperties(parent); |
| 2813 | |
| 2814 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2815 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2816 | |
| 2817 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2818 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2819 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2820 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2821 | } |
| 2822 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2823 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) { |
| 2824 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2825 | // correctly for identity transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2826 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2827 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2828 | gfx::Transform layer_to_surface_transform; |
| 2829 | |
| 2830 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2831 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2832 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2833 | gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30); |
| 2834 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2835 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2836 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2837 | EXPECT_EQ(expected_drawable_content_rect, |
| 2838 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2839 | |
| 2840 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2841 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2842 | expected_visible_layer_rect = gfx::Rect(); |
| 2843 | expected_drawable_content_rect = gfx::Rect(); |
| 2844 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2845 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2846 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2847 | EXPECT_EQ(expected_drawable_content_rect, |
| 2848 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2849 | |
| 2850 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2851 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2852 | expected_visible_layer_rect = gfx::Rect(20, 20); |
| 2853 | expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20); |
| 2854 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2855 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2856 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2857 | EXPECT_EQ(expected_drawable_content_rect, |
| 2858 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2859 | } |
| 2860 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2861 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) { |
| 2862 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2863 | // for rotations about z-axis (i.e. 2D rotations). |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2864 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2865 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2866 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2867 | gfx::Transform layer_to_surface_transform; |
| 2868 | |
| 2869 | // Case 1: Layer is contained within the surface. |
| 2870 | layer_to_surface_transform.MakeIdentity(); |
| 2871 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2872 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2873 | gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2874 | gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43); |
| 2875 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2876 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2877 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2878 | EXPECT_EQ(expected_drawable_content_rect, |
| 2879 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2880 | |
| 2881 | // Case 2: Layer is outside the surface rect. |
| 2882 | layer_to_surface_transform.MakeIdentity(); |
| 2883 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2884 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2885 | expected_visible_layer_rect = gfx::Rect(); |
| 2886 | expected_drawable_content_rect = gfx::Rect(); |
| 2887 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2888 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2889 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2890 | EXPECT_EQ(expected_drawable_content_rect, |
| 2891 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2892 | |
| 2893 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2894 | // the layer is oriented diagonally, with the left half outside of the render |
| 2895 | // surface. In this case, the g should still be the entire layer |
| 2896 | // (remember the g is computed in layer space); both the top-left |
| 2897 | // and bottom-right corners of the layer are still visible. |
| 2898 | layer_to_surface_transform.MakeIdentity(); |
| 2899 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2900 | expected_visible_layer_rect = gfx::Rect(30, 30); |
| 2901 | expected_drawable_content_rect = gfx::Rect(22, 43); |
| 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 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2909 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2910 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2911 | // surface overlaps the right side of the layer. The g should be |
| 2912 | // the layer's right half. |
| 2913 | layer_to_surface_transform.MakeIdentity(); |
| 2914 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2915 | layer_to_surface_transform.Rotate(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2916 | // Right half of layer bounds. |
| 2917 | expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30); |
| 2918 | expected_drawable_content_rect = gfx::Rect(22, 22); |
| 2919 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2920 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2921 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2922 | EXPECT_EQ(expected_drawable_content_rect, |
| 2923 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2924 | } |
| 2925 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2926 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) { |
| 2927 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2928 | // for 3d transforms. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2929 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2930 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2931 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2932 | gfx::Transform layer_to_surface_transform; |
| 2933 | |
| 2934 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2935 | // degrees, should be fully contained in the render surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2936 | // 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] | 2937 | layer_to_surface_transform.MakeIdentity(); |
| 2938 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2939 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 2940 | gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100); |
| 2941 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2942 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2943 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2944 | EXPECT_EQ(expected_drawable_content_rect, |
| 2945 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2946 | |
| 2947 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2948 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2949 | // visible on the surface. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2950 | // 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] | 2951 | SkMScalar half_width_of_rotated_layer = |
| 2952 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2953 | layer_to_surface_transform.MakeIdentity(); |
| 2954 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2955 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2956 | // edge of the layer. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2957 | // Tight half of the layer. |
| 2958 | expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100); |
| 2959 | expected_drawable_content_rect = gfx::Rect(36, 100); |
| 2960 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2961 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2962 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2963 | EXPECT_EQ(expected_drawable_content_rect, |
| 2964 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2965 | } |
| 2966 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2967 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) { |
| 2968 | // Test visible layer rect and drawable content rect are calculated correctly |
| 2969 | // when the layer has a perspective projection onto the target surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2970 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2971 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2972 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2973 | gfx::Transform layer_to_surface_transform; |
| 2974 | |
| 2975 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2976 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2977 | // its translated more than the perspective amount. |
| 2978 | layer_to_surface_transform.MakeIdentity(); |
| 2979 | |
| 2980 | // The following sequence of transforms applies the perspective about the |
| 2981 | // center of the surface. |
| 2982 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2983 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2984 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2985 | |
| 2986 | // This translate places the layer in front of the surface's projection plane. |
| 2987 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2988 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 2989 | // Layer position is (-50, -50), visible rect in layer space is layer bounds |
| 2990 | // offset by layer position. |
| 2991 | gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150); |
| 2992 | gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38); |
| 2993 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 2994 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 2995 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 2996 | EXPECT_EQ(expected_drawable_content_rect, |
| 2997 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2998 | |
| 2999 | // Case 2: same projection as before, except that the layer is also translated |
| 3000 | // to the side, so that only the right half of the layer should be visible. |
| 3001 | // |
| 3002 | // Explanation of expected result: The perspective ratio is (z distance |
| 3003 | // between layer and camera origin) / (z distance between projection plane and |
| 3004 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3005 | // move a layer by translating -25 units in projected surface units (so that |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3006 | // 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] | 3007 | // -25 == -100 in the layer's units. |
| 3008 | layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0); |
| 3009 | // Visible layer rect is moved by 100, and drawable content rect is in target |
| 3010 | // space and is moved by 25. |
| 3011 | expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150); |
| 3012 | expected_drawable_content_rect = gfx::Rect(13, 38); |
| 3013 | drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3014 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3015 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3016 | EXPECT_EQ(expected_drawable_content_rect, |
| 3017 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3018 | } |
| 3019 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3020 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 3021 | DrawRectsFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3022 | // There is currently no explicit concept of an orthographic projection plane |
| 3023 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 3024 | // are technically behind the surface in an orthographic world should not be |
| 3025 | // clipped when they are flattened to the surface. |
| 3026 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3027 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 3028 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3029 | gfx::Transform layer_to_surface_transform; |
| 3030 | |
| 3031 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 3032 | // at the center of the layer. |
| 3033 | layer_to_surface_transform.MakeIdentity(); |
| 3034 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 3035 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 3036 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 3037 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3038 | // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface |
| 3039 | // space. |
| 3040 | gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100); |
| 3041 | gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100); |
| 3042 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3043 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3044 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3045 | EXPECT_EQ(expected_drawable_content_rect, |
| 3046 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3047 | } |
| 3048 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3049 | TEST_F(LayerTreeHostCommonDrawRectsTest, |
| 3050 | DrawRectsFor3dPerspectiveWhenClippedByW) { |
| 3051 | // Test visible layer rect and drawable content rect are calculated correctly |
| 3052 | // when projecting a surface onto a layer, but the layer is partially behind |
| 3053 | // the camera (not just behind the projection plane). In this case, the |
| 3054 | // cartesian coordinates may seem to be valid, but actually they are not. The |
| 3055 | // visible rect needs to be properly clipped by the w = 0 plane in homogeneous |
| 3056 | // coordinates before converting to cartesian coordinates. The drawable |
| 3057 | // content rect would be entire surface rect because layer is rotated at the |
| 3058 | // camera position. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3059 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3060 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200); |
| 3061 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3062 | gfx::Transform layer_to_surface_transform; |
| 3063 | |
| 3064 | // The layer is positioned so that the right half of the layer should be in |
| 3065 | // front of the camera, while the other half is behind the surface's |
| 3066 | // projection plane. The following sequence of transforms applies the |
| 3067 | // perspective and rotation about the center of the layer. |
| 3068 | layer_to_surface_transform.MakeIdentity(); |
| 3069 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3070 | layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0); |
| 3071 | layer_to_surface_transform.RotateAboutYAxis(-45.0); |
| 3072 | layer_to_surface_transform.Translate(-10, -1); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3073 | |
| 3074 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 3075 | // transform, otherwise this code is not testing the intended scenario. |
| 3076 | bool clipped; |
| 3077 | MathUtil::MapQuad(layer_to_surface_transform, |
| 3078 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 3079 | &clipped); |
| 3080 | ASSERT_TRUE(clipped); |
| 3081 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3082 | gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1); |
| 3083 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3084 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3085 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3086 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3087 | EXPECT_EQ(expected_drawable_content_rect, |
| 3088 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3089 | } |
| 3090 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3091 | TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3092 | // To determine visible rect in layer space, there needs to be an |
| 3093 | // un-projection from surface space to layer space. When the original |
| 3094 | // transform was a perspective projection that was clipped, it returns a rect |
| 3095 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 3096 | // clipping again. |
| 3097 | |
| 3098 | // This sequence of transforms causes one corner of the layer to protrude |
| 3099 | // across the w = 0 plane, and should be clipped. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3100 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150); |
| 3101 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3102 | gfx::Transform layer_to_surface_transform; |
| 3103 | layer_to_surface_transform.MakeIdentity(); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3104 | layer_to_surface_transform.Translate(10, 10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3105 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 3106 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 3107 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 3108 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3109 | layer_to_surface_transform.Translate(-10, -10); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3110 | |
| 3111 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 3112 | // code is not testing the intended scenario. |
| 3113 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3114 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 3115 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | MathUtil::ProjectQuad( |
| 3117 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 3118 | ASSERT_TRUE(clipped); |
| 3119 | |
| 3120 | // Only the corner of the layer is not visible on the surface because of being |
| 3121 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 3122 | // rect is that the entire layer should still be considered visible. |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 3123 | gfx::Rect expected_visible_layer_rect = layer_content_rect; |
| 3124 | gfx::Rect expected_drawable_content_rect = target_surface_rect; |
| 3125 | LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect( |
| 3126 | target_surface_rect, layer_to_surface_transform, layer_content_rect); |
| 3127 | EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect()); |
| 3128 | EXPECT_EQ(expected_drawable_content_rect, |
| 3129 | drawing_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3130 | } |
| 3131 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3132 | TEST_F(LayerTreeHostCommonTest, |
| 3133 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3134 | LayerImpl* root = root_layer(); |
| 3135 | root->SetDrawsContent(true); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3136 | |
| 3137 | gfx::Transform identity_matrix; |
| 3138 | // Root layer is positioned at (60, 70). The default device viewport size |
| 3139 | // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 3140 | // 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] | 3141 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3142 | gfx::PointF(60, 70), gfx::Size(100, 100), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3143 | false, true); |
| 3144 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3145 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3146 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3147 | root->render_surface()->DrawableContentRect()); |
| 3148 | // In target space, not clipped. |
| 3149 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 3150 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3151 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 3152 | } |
| 3153 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3154 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3155 | LayerImpl* root = root_layer(); |
| 3156 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
| 3157 | child1_layer->SetDrawsContent(true); |
| 3158 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
| 3159 | child2_layer->SetDrawsContent(true); |
| 3160 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
| 3161 | child3_layer->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3162 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3163 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3164 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3165 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3166 | true); |
| 3167 | SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), |
| 3168 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3169 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3170 | SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), |
| 3171 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3172 | false, false); |
| 3173 | SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), |
| 3174 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3175 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3176 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3177 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3178 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3179 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3180 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3181 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3182 | // Layers that do not draw content should have empty visible_layer_rects. |
| 3183 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3184 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3185 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3186 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 3187 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 3188 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3189 | |
| 3190 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3191 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 3192 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 3193 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3194 | } |
| 3195 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3196 | TEST_F(LayerTreeHostCommonTest, |
| 3197 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3198 | LayerImpl* root = root_layer(); |
| 3199 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3200 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 3201 | grand_child1->SetDrawsContent(true); |
| 3202 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 3203 | grand_child2->SetDrawsContent(true); |
| 3204 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 3205 | grand_child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3207 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3208 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3209 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3210 | true); |
| 3211 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 3212 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3213 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3214 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3215 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3216 | false, false); |
| 3217 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3218 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3219 | false, false); |
| 3220 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 3221 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3222 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3223 | |
| 3224 | child->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3225 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3226 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3227 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3228 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3229 | |
| 3230 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3231 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3232 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3233 | |
| 3234 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3235 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3236 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3237 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3238 | |
| 3239 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3240 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3241 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3242 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3243 | } |
| 3244 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3245 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3246 | LayerImpl* root = root_layer(); |
| 3247 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 3248 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3249 | |
| 3250 | gfx::Transform identity_matrix; |
| 3251 | gfx::Transform child_scale_matrix; |
| 3252 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3253 | gfx::Transform grand_child_scale_matrix; |
| 3254 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3255 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3256 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3257 | true); |
| 3258 | SetLayerPropertiesForTesting(child, child_scale_matrix, gfx::Point3F(), |
| 3259 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 3260 | false); |
| 3261 | SetLayerPropertiesForTesting(grand_child, grand_child_scale_matrix, |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3262 | gfx::Point3F(), gfx::PointF(), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3263 | gfx::Size(100, 100), true, false, false); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3264 | |
| 3265 | child->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 3266 | grand_child->SetDrawsContent(true); |
| 3267 | ExecuteCalculateDrawProperties(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3268 | |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame^] | 3269 | // The visible rect is expanded to integer coordinates. |
| 3270 | EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3271 | } |
| 3272 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3273 | TEST_F(LayerTreeHostCommonTest, |
| 3274 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3275 | LayerImpl* root = root_layer(); |
| 3276 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3277 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3278 | child1->SetDrawsContent(true); |
| 3279 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3280 | child2->SetDrawsContent(true); |
| 3281 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3282 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3284 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3285 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3286 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3287 | true); |
| 3288 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3289 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3290 | true); |
| 3291 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3292 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3293 | false, false); |
| 3294 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3295 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3296 | false, false); |
| 3297 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3298 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3299 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3300 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3301 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3302 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3303 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3304 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3305 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3306 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3307 | |
| 3308 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3309 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3310 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3311 | |
| 3312 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3313 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3314 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3315 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3316 | |
| 3317 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3318 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3319 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3320 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3321 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3322 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3323 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3324 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3325 | } |
| 3326 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3327 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3328 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
| 3329 | LayerImpl* root = root_layer(); |
| 3330 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3331 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3332 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3333 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3334 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3335 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3336 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3337 | |
| 3338 | root->SetDrawsContent(true); |
| 3339 | parent->SetDrawsContent(true); |
| 3340 | child1->SetDrawsContent(true); |
| 3341 | child2->SetDrawsContent(true); |
| 3342 | grand_child1->SetDrawsContent(true); |
| 3343 | grand_child2->SetDrawsContent(true); |
| 3344 | leaf_node1->SetDrawsContent(true); |
| 3345 | leaf_node2->SetDrawsContent(true); |
| 3346 | |
| 3347 | const gfx::Transform identity_matrix; |
| 3348 | |
| 3349 | // child1 and child2 get render surfaces when surfaces are enabled. |
| 3350 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3351 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3352 | true); |
| 3353 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 3354 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 3355 | false, false); |
| 3356 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3357 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 3358 | false, true); |
| 3359 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3360 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
| 3361 | false, true); |
| 3362 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3363 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 3364 | true, false, false); |
| 3365 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3366 | gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500), |
| 3367 | true, false, false); |
| 3368 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 3369 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 3370 | true, false, false); |
| 3371 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 3372 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
| 3373 | true, false, false); |
| 3374 | |
| 3375 | // Case 1: No layers clip. Visible rects are clipped by the viewport, but the |
| 3376 | // viewport clip doesn't apply to layers that draw into unclipped surfaces. |
| 3377 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3378 | // thing that changes with surfaces disabled is that target space is always |
| 3379 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3380 | root->SetHasRenderSurface(true); |
| 3381 | child1->SetHasRenderSurface(true); |
| 3382 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3383 | ExecuteCalculateDrawProperties(root); |
| 3384 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3385 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
| 3386 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3387 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3388 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect()); |
| 3389 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3390 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect()); |
| 3391 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect()); |
| 3392 | |
| 3393 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3394 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3395 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3396 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3397 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3398 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3399 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3400 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3401 | |
| 3402 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3403 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3404 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3405 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3406 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3407 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3408 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3409 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3410 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3411 | |
| 3412 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3413 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3414 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3415 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3416 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3417 | grand_child1->drawable_content_rect()); |
| 3418 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3419 | grand_child2->drawable_content_rect()); |
| 3420 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3421 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3422 | |
| 3423 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3424 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3425 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3426 | // rects are clipped only until the next render surface is reached, so |
| 3427 | // descendants of parent have their drawable content rects clipped only when |
| 3428 | // surfaces are disabled. |
| 3429 | parent->SetMasksToBounds(true); |
| 3430 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3431 | root->SetHasRenderSurface(true); |
| 3432 | child1->SetHasRenderSurface(true); |
| 3433 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3434 | ExecuteCalculateDrawProperties(root); |
| 3435 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3436 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3437 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3438 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3439 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3440 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3441 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3442 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3443 | |
| 3444 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3445 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3446 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3447 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3448 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3449 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3450 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3451 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3452 | |
| 3453 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3454 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3455 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3456 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3457 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3458 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3459 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3460 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3461 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3462 | |
| 3463 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3464 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3465 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3466 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3467 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3468 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3469 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3470 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3471 | |
| 3472 | parent->SetMasksToBounds(false); |
| 3473 | |
| 3474 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
| 3475 | // layers have their visible rects clipped by them; without surfaces, these |
| 3476 | // rects are also clipped by the viewport. Similarly, descendants of these |
| 3477 | // layers have their drawable content rects clipped by them. |
| 3478 | child1->SetMasksToBounds(true); |
| 3479 | grand_child2->SetMasksToBounds(true); |
| 3480 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3481 | root->SetHasRenderSurface(true); |
| 3482 | child1->SetHasRenderSurface(true); |
| 3483 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3484 | ExecuteCalculateDrawProperties(root); |
| 3485 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3486 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3487 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3488 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3489 | EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); |
| 3490 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3491 | EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); |
| 3492 | EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); |
| 3493 | |
| 3494 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3495 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3496 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3497 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3498 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3499 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3500 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3501 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3502 | |
| 3503 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3504 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3505 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3506 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3507 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3508 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3509 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3510 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3511 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3512 | |
| 3513 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3514 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3515 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3516 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3517 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3518 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3519 | grand_child2->drawable_content_rect()); |
| 3520 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3521 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3522 | } |
| 3523 | |
| 3524 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3525 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3526 | LayerImpl* root = root_layer(); |
| 3527 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3528 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3529 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
| 3530 | child1->SetDrawsContent(true); |
| 3531 | child2->SetDrawsContent(true); |
| 3532 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3533 | |
| 3534 | gfx::Transform identity_matrix; |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3535 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3536 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3537 | true); |
| 3538 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3539 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3540 | false, false); |
| 3541 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3542 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3543 | false, false); |
| 3544 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3545 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3546 | true, false, false); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3547 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3548 | LayerImplList render_surface_layer_list_impl; |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3549 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3550 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 3551 | root, gfx::Size(), &render_surface_layer_list_impl); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3552 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 3553 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3554 | ASSERT_TRUE(root->render_surface()); |
| 3555 | EXPECT_FALSE(root->is_clipped()); |
| 3556 | |
| 3557 | gfx::Rect empty; |
| 3558 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3559 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3560 | |
| 3561 | // Visible content rect calculation will check if the target surface is |
| 3562 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3563 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3564 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3565 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3566 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3570 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3571 | LayerImpl* root = root_layer(); |
| 3572 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3573 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3574 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3575 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3576 | gfx::Transform identity_matrix; |
| 3577 | 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] | 3578 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3579 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3580 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3581 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3582 | true); |
| 3583 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3584 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3585 | false, false); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3586 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3587 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3588 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3589 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3590 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3591 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3592 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3593 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3594 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3595 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3596 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3597 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3598 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3599 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3600 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3601 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3602 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3603 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3604 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3605 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3606 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3607 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3608 | uninvertible_matrix.MakeIdentity(); |
| 3609 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3610 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3611 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3612 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3613 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3614 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3615 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3616 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3617 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3618 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3619 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3620 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3621 | } |
| 3622 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3623 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3624 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
| 3625 | LayerImpl* root = root_layer(); |
| 3626 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3627 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 3628 | child->SetDrawsContent(true); |
| 3629 | grand_child->SetDrawsContent(true); |
| 3630 | |
| 3631 | gfx::Transform identity_matrix; |
| 3632 | |
| 3633 | gfx::Transform perspective; |
| 3634 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3635 | |
| 3636 | gfx::Transform rotation; |
| 3637 | rotation.RotateAboutYAxis(45.0); |
| 3638 | |
| 3639 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3640 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3641 | true); |
| 3642 | SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(), |
| 3643 | gfx::PointF(10.f, 10.f), gfx::Size(100, 100), |
| 3644 | false, true, false); |
| 3645 | SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(), |
| 3646 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 3647 | false); |
| 3648 | |
| 3649 | ExecuteCalculateDrawProperties(root); |
| 3650 | |
| 3651 | // Though all layers have invertible transforms, matrix multiplication using |
| 3652 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3653 | EXPECT_FALSE(root->layer_tree_impl() |
| 3654 | ->property_trees() |
| 3655 | ->transform_tree.Node(grand_child->transform_tree_index()) |
| 3656 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3657 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3658 | // CalcDrawProps skips a subtree when a layer's screen space transform is |
| 3659 | // uninvertible |
| 3660 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | TEST_F(LayerTreeHostCommonTest, |
| 3664 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3665 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3666 | TestSharedBitmapManager shared_bitmap_manager; |
| 3667 | TestTaskGraphRunner task_graph_runner; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3668 | std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3669 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3670 | &task_graph_runner); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3671 | std::unique_ptr<LayerImpl> root = |
| 3672 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 3673 | std::unique_ptr<LayerImpl> child = |
| 3674 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 3675 | std::unique_ptr<LayerImpl> grand_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3676 | LayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3677 | std::unique_ptr<LayerImpl> occluding_child = |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3678 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 3679 | child->SetDrawsContent(true); |
| 3680 | grand_child->SetDrawsContent(true); |
| 3681 | occluding_child->SetDrawsContent(true); |
| 3682 | occluding_child->SetContentsOpaque(true); |
| 3683 | |
| 3684 | gfx::Transform identity_matrix; |
| 3685 | gfx::Transform perspective; |
| 3686 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3687 | |
| 3688 | gfx::Transform rotation; |
| 3689 | rotation.RotateAboutYAxis(45.0); |
| 3690 | |
| 3691 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3692 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3693 | false, true); |
| 3694 | SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(), |
| 3695 | gfx::PointF(10.f, 10.f), gfx::Size(300, 300), |
| 3696 | false, true, false); |
| 3697 | SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(), |
| 3698 | gfx::PointF(), gfx::Size(200, 200), false, true, |
| 3699 | false); |
| 3700 | SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix, |
| 3701 | gfx::Point3F(), gfx::PointF(), |
| 3702 | gfx::Size(200, 200), false, false, false); |
| 3703 | |
| 3704 | host_impl.SetViewportSize(root->bounds()); |
| 3705 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3706 | child->AddChild(std::move(grand_child)); |
| 3707 | root->AddChild(std::move(child)); |
| 3708 | root->AddChild(std::move(occluding_child)); |
| 3709 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3710 | host_impl.SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3711 | host_impl.InitializeRenderer(output_surface.get()); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 3712 | host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3713 | bool update_lcd_text = false; |
| 3714 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3715 | |
| 3716 | LayerImpl* grand_child_ptr = |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 3717 | host_impl.active_tree()->root_layer()->children()[0]->children()[0]; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3718 | |
| 3719 | // Though all layers have invertible transforms, matrix multiplication using |
| 3720 | // floating-point math makes the draw transform uninvertible. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3721 | EXPECT_FALSE( |
| 3722 | host_impl.active_tree() |
| 3723 | ->property_trees() |
| 3724 | ->transform_tree.Node(grand_child_ptr->transform_tree_index()) |
| 3725 | ->data.ancestors_are_invertible); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3726 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 3727 | // Since |grand_child| has an uninvertible screen space transform, it is |
| 3728 | // skipped so |
| 3729 | // that we are not computing its occlusion_in_content_space. |
| 3730 | gfx::Rect layer_bounds = gfx::Rect(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3731 | EXPECT_EQ( |
| 3732 | layer_bounds, |
| 3733 | grand_child_ptr->draw_properties() |
| 3734 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3735 | } |
| 3736 | |
| 3737 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3738 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3739 | LayerImpl* root = root_layer(); |
| 3740 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3741 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3742 | child1->SetDrawsContent(true); |
| 3743 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3744 | child2->SetDrawsContent(true); |
| 3745 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3746 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3747 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3749 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3750 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3751 | true); |
| 3752 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3753 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3754 | true); |
| 3755 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3756 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3757 | false, false); |
| 3758 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3759 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3760 | false, false); |
| 3761 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3762 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3763 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3764 | |
| 3765 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3766 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3767 | ExecuteCalculateDrawProperties(root); |
| 3768 | |
| 3769 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3770 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3771 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3772 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3773 | |
| 3774 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3775 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3776 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3777 | |
| 3778 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3779 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3780 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3781 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3782 | |
| 3783 | // All layers that draw content into the surface have their visible content |
| 3784 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3785 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3786 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3787 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3788 | |
| 3789 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3790 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3791 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3792 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3793 | } |
| 3794 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3795 | TEST_F(LayerTreeHostCommonTest, |
| 3796 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3797 | // Check that clipping does not propagate down surfaces. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3798 | LayerImpl* root = root_layer(); |
| 3799 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3800 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3801 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
| 3802 | child1->SetDrawsContent(true); |
| 3803 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 3804 | child2->SetDrawsContent(true); |
| 3805 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
| 3806 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3808 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3809 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3810 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3811 | true); |
| 3812 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3813 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3814 | true); |
| 3815 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3816 | gfx::PointF(), gfx::Size(7, 13), true, false, |
| 3817 | true); |
| 3818 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3819 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3820 | false, false); |
| 3821 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3822 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3823 | false, false); |
| 3824 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3825 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3826 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3827 | |
| 3828 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3829 | |
| 3830 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3831 | |
| 3832 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3833 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3834 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3835 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3836 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3837 | |
| 3838 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3839 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3840 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3841 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3842 | |
| 3843 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3844 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3845 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3846 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3847 | |
| 3848 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3849 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3850 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3851 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3852 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3853 | |
| 3854 | // All layers that draw content into render_surface2 think they are unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3855 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3856 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3857 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3858 | |
| 3859 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3860 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3861 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3862 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3863 | } |
| 3864 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3865 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3866 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
| 3867 | LayerImpl* root = root_layer(); |
| 3868 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3869 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3870 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3871 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
| 3872 | child1->SetDrawsContent(true); |
| 3873 | child2->SetDrawsContent(true); |
| 3874 | render_surface2->SetDrawsContent(true); |
| 3875 | |
| 3876 | gfx::Transform identity_matrix; |
| 3877 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3878 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3879 | true); |
| 3880 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3881 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3882 | true); |
| 3883 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3884 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 3885 | false); |
| 3886 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3887 | gfx::PointF(), gfx::Size(700, 700), true, false, |
| 3888 | false); |
| 3889 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3890 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3891 | false, true); |
| 3892 | |
| 3893 | child1->SetMasksToBounds(true); |
| 3894 | child2->SetMasksToBounds(true); |
| 3895 | |
| 3896 | ExecuteCalculateDrawProperties(root); |
| 3897 | EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); |
| 3898 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3899 | } |
| 3900 | |
| 3901 | TEST_F(LayerTreeHostCommonTest, |
| 3902 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
| 3903 | LayerImpl* root = root_layer(); |
| 3904 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3905 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3906 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3907 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3908 | |
| 3909 | render_surface1->SetDrawsContent(true); |
| 3910 | render_surface2->SetDrawsContent(true); |
| 3911 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3912 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3913 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3914 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3915 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3916 | |
| 3917 | gfx::Transform identity_matrix; |
| 3918 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3919 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3920 | true); |
| 3921 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3922 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3923 | false); |
| 3924 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3925 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3926 | true); |
| 3927 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3928 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3929 | false); |
| 3930 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3931 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3932 | true); |
| 3933 | clip_parent->SetMasksToBounds(true); |
| 3934 | render_surface1->SetMasksToBounds(true); |
| 3935 | |
| 3936 | ExecuteCalculateDrawProperties(root); |
| 3937 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3938 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3939 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3940 | } |
| 3941 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3942 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
| 3943 | LayerImpl* root = root_layer(); |
| 3944 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3945 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3946 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3947 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3948 | |
| 3949 | render_surface1->SetDrawsContent(true); |
| 3950 | render_surface2->SetDrawsContent(true); |
| 3951 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3952 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 3953 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3954 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 3955 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3956 | |
| 3957 | gfx::Transform identity_matrix; |
| 3958 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3959 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3960 | true); |
| 3961 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3962 | gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true, |
| 3963 | false, false); |
| 3964 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3965 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3966 | true); |
| 3967 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3968 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3969 | false); |
| 3970 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3971 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3972 | true); |
| 3973 | clip_parent->SetMasksToBounds(true); |
| 3974 | render_surface1->SetMasksToBounds(true); |
| 3975 | |
| 3976 | ExecuteCalculateDrawProperties(root); |
| 3977 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3978 | } |
| 3979 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3980 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3981 | // Test that only drawn layers contribute to render surface content rect. |
| 3982 | LayerImpl* root = root_layer(); |
| 3983 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3984 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3985 | |
| 3986 | test_layer->SetDrawsContent(false); |
| 3987 | surface->SetDrawsContent(true); |
| 3988 | gfx::Transform identity_matrix; |
| 3989 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3990 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 3991 | true); |
| 3992 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 3993 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3994 | true); |
| 3995 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 3996 | gfx::PointF(), gfx::Size(150, 150), true, false, |
| 3997 | false); |
| 3998 | |
| 3999 | ExecuteCalculateDrawProperties(root); |
| 4000 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 4001 | |
| 4002 | test_layer->SetDrawsContent(true); |
| 4003 | ExecuteCalculateDrawProperties(root); |
| 4004 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 4005 | } |
| 4006 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4007 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 4008 | // Tests visible rects computation when we have unclipped_surface-> |
| 4009 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 4010 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 4011 | // clipped_surface below it. |
| 4012 | LayerImpl* root = root_layer(); |
| 4013 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 4014 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 4015 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 4016 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 4017 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 4018 | |
| 4019 | unclipped_surface->SetDrawsContent(true); |
| 4020 | unclipped_desc_surface->SetDrawsContent(true); |
| 4021 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 4022 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4023 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4024 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 4025 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4026 | |
| 4027 | gfx::Transform identity_matrix; |
| 4028 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4029 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4030 | true); |
| 4031 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 4032 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 4033 | true, false, true); |
| 4034 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 4035 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4036 | false); |
| 4037 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 4038 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 4039 | true, false, true); |
| 4040 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 4041 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 4042 | false); |
| 4043 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 4044 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 4045 | true); |
| 4046 | clip_parent->SetMasksToBounds(true); |
| 4047 | |
| 4048 | ExecuteCalculateDrawProperties(root); |
| 4049 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 4050 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 4051 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 4052 | } |
| 4053 | |
| 4054 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 4055 | // Tests visible rects computation when we have unclipped_surface-> |
| 4056 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 4057 | // of root propagate to the clipped_surface. |
| 4058 | LayerImpl* root = root_layer(); |
| 4059 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 4060 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 4061 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 4062 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 4063 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 4064 | |
| 4065 | unclipped_surface->SetDrawsContent(true); |
| 4066 | unclipped_desc_surface->SetDrawsContent(true); |
| 4067 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 4068 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4069 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4070 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 4071 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4072 | |
| 4073 | gfx::Transform identity_matrix; |
| 4074 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4075 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 4076 | true); |
| 4077 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 4078 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 4079 | true, false, true); |
| 4080 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 4081 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4082 | false); |
| 4083 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 4084 | gfx::Point3F(), gfx::PointF(), |
| 4085 | gfx::Size(100, 100), true, false, true); |
| 4086 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 4087 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4088 | false); |
| 4089 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 4090 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4091 | true); |
| 4092 | clip_parent->SetMasksToBounds(true); |
| 4093 | unclipped_desc_surface->SetMasksToBounds(true); |
| 4094 | |
| 4095 | ExecuteCalculateDrawProperties(root); |
| 4096 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 4097 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect()); |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 4098 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 4099 | } |
| 4100 | |
| 4101 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4102 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4103 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4104 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4105 | LayerImpl* root = root_layer(); |
| 4106 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4107 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4108 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4109 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4110 | gfx::Transform identity_matrix; |
| 4111 | gfx::Transform child_rotation; |
| 4112 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4113 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4114 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4115 | true); |
| 4116 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4117 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4118 | true); |
| 4119 | SetLayerPropertiesForTesting( |
| 4120 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4121 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4122 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4123 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4124 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4125 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4126 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4127 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4128 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4129 | |
| 4130 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4131 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4132 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4133 | |
| 4134 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4135 | // regions of the subtree. |
| 4136 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4137 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4138 | gfx::Rect(50 - diagonal_radius, |
| 4139 | 50 - diagonal_radius, |
| 4140 | diagonal_radius * 2, |
| 4141 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4142 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4143 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4144 | |
| 4145 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4146 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4147 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4148 | } |
| 4149 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4150 | TEST_F(LayerTreeHostCommonTest, |
| 4151 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4152 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4153 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4154 | LayerImpl* root = root_layer(); |
| 4155 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4156 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4157 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4158 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4159 | gfx::Transform identity_matrix; |
| 4160 | gfx::Transform child_rotation; |
| 4161 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4162 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4163 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4164 | true); |
| 4165 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4166 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4167 | true); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4168 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4169 | SetLayerPropertiesForTesting( |
| 4170 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4171 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4172 | |
| 4173 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4174 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4175 | ExecuteCalculateDrawProperties(root); |
| 4176 | |
| 4177 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4178 | |
| 4179 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4180 | // rotated layer. |
| 4181 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4182 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4183 | 50 - diagonal_radius, |
| 4184 | diagonal_radius * 2, |
| 4185 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4186 | gfx::RectF expected_surface_drawable_content( |
| 4187 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4188 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4189 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4190 | |
| 4191 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4192 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4193 | // up covering the full left half of child1. |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame^] | 4194 | EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4195 | |
| 4196 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4197 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4198 | } |
| 4199 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4200 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4201 | LayerImpl* root = root_layer(); |
| 4202 | FakePictureLayerImpl* render_surface1 = |
| 4203 | AddChildToRoot<FakePictureLayerImpl>(); |
| 4204 | render_surface1->SetDrawsContent(true); |
| 4205 | FakePictureLayerImpl* render_surface2 = |
| 4206 | AddChild<FakePictureLayerImpl>(render_surface1); |
| 4207 | render_surface2->SetDrawsContent(true); |
| 4208 | FakePictureLayerImpl* child1 = |
| 4209 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4210 | child1->SetDrawsContent(true); |
| 4211 | FakePictureLayerImpl* child2 = |
| 4212 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4213 | child2->SetDrawsContent(true); |
| 4214 | FakePictureLayerImpl* child3 = |
| 4215 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4216 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4217 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4218 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4219 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4220 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4221 | true); |
| 4222 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 4223 | gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true, |
| 4224 | false, true); |
| 4225 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 4226 | gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true, |
| 4227 | false, true); |
| 4228 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4229 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 4230 | false, false); |
| 4231 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4232 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 4233 | false, false); |
| 4234 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 4235 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 4236 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4237 | |
| 4238 | float device_scale_factor = 2.f; |
| 4239 | |
| 4240 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4241 | |
| 4242 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4243 | |
| 4244 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4245 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4246 | |
| 4247 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4248 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4249 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4250 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4251 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4252 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4253 | |
| 4254 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4255 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4256 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4257 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4258 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4259 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4260 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4261 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4262 | |
| 4263 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4264 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4265 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4266 | // All layer visible content rects are not expressed in content space of each |
| 4267 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4268 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4269 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4270 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 4271 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 4272 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4273 | } |
| 4274 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4275 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4276 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4277 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4278 | // "flattened" to each parent layer according to current W3C spec. |
| 4279 | |
| 4280 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4281 | LayerImpl* parent = root_layer(); |
| 4282 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4283 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4284 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4285 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4286 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4287 | AddChild<LayerImpl>(front_facing_surface); |
| 4288 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4289 | AddChild<LayerImpl>(front_facing_surface); |
| 4290 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4291 | AddChild<LayerImpl>(back_facing_surface); |
| 4292 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4293 | AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4294 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4295 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4296 | front_facing_child->test_properties()->double_sided = false; |
| 4297 | back_facing_child->test_properties()->double_sided = false; |
| 4298 | front_facing_surface->test_properties()->double_sided = false; |
| 4299 | back_facing_surface->test_properties()->double_sided = false; |
| 4300 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4301 | false; |
| 4302 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4303 | false; |
| 4304 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4305 | false; |
| 4306 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4307 | false; |
| 4308 | |
| 4309 | // Everything draws content. |
| 4310 | front_facing_child->SetDrawsContent(true); |
| 4311 | back_facing_child->SetDrawsContent(true); |
| 4312 | front_facing_surface->SetDrawsContent(true); |
| 4313 | back_facing_surface->SetDrawsContent(true); |
| 4314 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4315 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4316 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4317 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4318 | |
| 4319 | gfx::Transform backface_matrix; |
| 4320 | backface_matrix.Translate(50.0, 50.0); |
| 4321 | backface_matrix.RotateAboutYAxis(180.0); |
| 4322 | backface_matrix.Translate(-50.0, -50.0); |
| 4323 | |
| 4324 | // Having a descendant and opacity will force these to have render surfaces. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 4325 | front_facing_surface->test_properties()->opacity = 0.5f; |
| 4326 | back_facing_surface->test_properties()->opacity = 0.5f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4327 | |
| 4328 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 4329 | // these layers should blindly use their own local transforms to determine |
| 4330 | // back-face culling. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4331 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4332 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4333 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
| 4334 | gfx::Point3F(), gfx::PointF(), |
| 4335 | gfx::Size(100, 100), true, false); |
| 4336 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
| 4337 | gfx::Point3F(), gfx::PointF(), |
| 4338 | gfx::Size(100, 100), true, false); |
| 4339 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
| 4340 | gfx::Point3F(), gfx::PointF(), |
| 4341 | gfx::Size(100, 100), true, false); |
| 4342 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
| 4343 | gfx::Point3F(), gfx::PointF(), |
| 4344 | gfx::Size(100, 100), true, false); |
| 4345 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
| 4346 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4347 | gfx::Size(100, 100), true, false); |
| 4348 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
| 4349 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4350 | gfx::Size(100, 100), true, false); |
| 4351 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
| 4352 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4353 | gfx::Size(100, 100), true, false); |
| 4354 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
| 4355 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4356 | gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4358 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4359 | |
| 4360 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4361 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4362 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4363 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4364 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4365 | EXPECT_FALSE( |
| 4366 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4367 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4368 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4369 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4370 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4371 | EXPECT_EQ(4u, update_layer_list_impl()->size()); |
| 4372 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4373 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4374 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4375 | front_facing_child_of_front_facing_surface->id())); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4376 | EXPECT_TRUE(UpdateLayerListImplContains( |
| 4377 | front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4378 | } |
| 4379 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4380 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4381 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4382 | // is used. |
| 4383 | |
| 4384 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4385 | LayerImpl* parent = root_layer(); |
| 4386 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4387 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4388 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4389 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4390 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4391 | AddChild<LayerImpl>(front_facing_surface); |
| 4392 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4393 | AddChild<LayerImpl>(front_facing_surface); |
| 4394 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4395 | AddChild<LayerImpl>(back_facing_surface); |
| 4396 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4397 | AddChild<LayerImpl>(back_facing_surface); |
| 4398 | // Opacity will not force creation of render surfaces in this case because of |
| 4399 | // the preserve-3d transform style. Instead, an example of when a surface |
| 4400 | // would be created with preserve-3d is when there is a replica layer. |
| 4401 | LayerImpl* dummy_replica_layer1 = |
| 4402 | AddReplicaLayer<LayerImpl>(front_facing_surface); |
| 4403 | LayerImpl* dummy_replica_layer2 = |
| 4404 | AddReplicaLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4405 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4406 | // Nothing is double-sided |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 4407 | front_facing_child->test_properties()->double_sided = false; |
| 4408 | back_facing_child->test_properties()->double_sided = false; |
| 4409 | front_facing_surface->test_properties()->double_sided = false; |
| 4410 | back_facing_surface->test_properties()->double_sided = false; |
| 4411 | front_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4412 | false; |
| 4413 | back_facing_child_of_front_facing_surface->test_properties()->double_sided = |
| 4414 | false; |
| 4415 | front_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4416 | false; |
| 4417 | back_facing_child_of_back_facing_surface->test_properties()->double_sided = |
| 4418 | false; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4419 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4420 | // Everything draws content. |
| 4421 | front_facing_child->SetDrawsContent(true); |
| 4422 | back_facing_child->SetDrawsContent(true); |
| 4423 | front_facing_surface->SetDrawsContent(true); |
| 4424 | back_facing_surface->SetDrawsContent(true); |
| 4425 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4426 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4427 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4428 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4429 | dummy_replica_layer1->SetDrawsContent(true); |
| 4430 | dummy_replica_layer2->SetDrawsContent(true); |
| 4431 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4432 | gfx::Transform backface_matrix; |
| 4433 | backface_matrix.Translate(50.0, 50.0); |
| 4434 | backface_matrix.RotateAboutYAxis(180.0); |
| 4435 | backface_matrix.Translate(-50.0, -50.0); |
| 4436 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4437 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4438 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4439 | // rendering context should use the transform with respect to that context. |
| 4440 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4441 | // and (b) the layer's transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4442 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4443 | gfx::PointF(), gfx::Size(100, 100), true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4444 | false); // parent transform style is flat. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4445 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4446 | gfx::Point3F(), gfx::PointF(), |
| 4447 | gfx::Size(100, 100), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4448 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4449 | gfx::Point3F(), gfx::PointF(), |
| 4450 | gfx::Size(100, 100), true, false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4451 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4452 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4453 | gfx::Point3F(), gfx::PointF(), |
| 4454 | gfx::Size(100, 100), false, true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4455 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4456 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4457 | gfx::Point3F(), gfx::PointF(), |
| 4458 | gfx::Size(100, 100), false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4459 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4460 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4461 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4462 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4463 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4464 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4465 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4466 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4467 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4468 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4469 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4470 | gfx::Size(100, 100), true, true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4471 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4472 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4473 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4474 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4475 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4476 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4477 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4478 | // We expect that a has_render_surface was created but not used. |
| 4479 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4480 | EXPECT_FALSE( |
| 4481 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4482 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4483 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4484 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4486 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4487 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4488 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4489 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4490 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4491 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4492 | } |
| 4493 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4494 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | // Verify that layers are appropriately culled when their back face is showing |
| 4496 | // and they are not double sided, while animations are going on. |
| 4497 | // |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4498 | // Even layers that are animating get culled if their back face is showing and |
| 4499 | // they are not double sided. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4500 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4501 | LayerImpl* parent = root_layer(); |
| 4502 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4503 | LayerImpl* animating_surface = AddChildToRoot<LayerImpl>(); |
| 4504 | LayerImpl* child_of_animating_surface = |
| 4505 | AddChild<LayerImpl>(animating_surface); |
| 4506 | LayerImpl* animating_child = AddChildToRoot<LayerImpl>(); |
| 4507 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4508 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4509 | // Nothing is double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4510 | child->test_properties()->double_sided = false; |
| 4511 | child2->test_properties()->double_sided = false; |
| 4512 | animating_surface->test_properties()->double_sided = false; |
| 4513 | child_of_animating_surface->test_properties()->double_sided = false; |
| 4514 | animating_child->test_properties()->double_sided = false; |
| 4515 | |
| 4516 | // Everything draws content. |
| 4517 | child->SetDrawsContent(true); |
| 4518 | child2->SetDrawsContent(true); |
| 4519 | animating_surface->SetDrawsContent(true); |
| 4520 | child_of_animating_surface->SetDrawsContent(true); |
| 4521 | animating_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4522 | |
| 4523 | gfx::Transform backface_matrix; |
| 4524 | backface_matrix.Translate(50.0, 50.0); |
| 4525 | backface_matrix.RotateAboutYAxis(180.0); |
| 4526 | backface_matrix.Translate(-50.0, -50.0); |
| 4527 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4528 | // Animate the transform on the render surface. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4529 | AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), |
| 4530 | timeline_impl(), 10.0, 30, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 4531 | // This is just an animating layer, not a surface. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4532 | AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline_impl(), |
| 4533 | 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4534 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4535 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4536 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4537 | SetLayerPropertiesForTesting(child, backface_matrix, gfx::Point3F(), |
| 4538 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4539 | SetLayerPropertiesForTesting(animating_surface, backface_matrix, |
| 4540 | gfx::Point3F(), gfx::PointF(), |
| 4541 | gfx::Size(100, 100), true, false, true); |
| 4542 | SetLayerPropertiesForTesting(child_of_animating_surface, backface_matrix, |
| 4543 | gfx::Point3F(), gfx::PointF(), |
| 4544 | gfx::Size(100, 100), true, false); |
| 4545 | SetLayerPropertiesForTesting(animating_child, backface_matrix, gfx::Point3F(), |
| 4546 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4547 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4548 | gfx::PointF(), gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4549 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4550 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4551 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4552 | EXPECT_FALSE(child->has_render_surface()); |
| 4553 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4554 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4555 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4556 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4557 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4558 | EXPECT_EQ(1u, update_layer_list_impl()->size()); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4559 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4560 | // The back facing layers are culled from the layer list, and have an empty |
| 4561 | // visible rect. |
| 4562 | EXPECT_TRUE(UpdateLayerListImplContains(child2->id())); |
| 4563 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
| 4564 | EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty()); |
| 4565 | EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty()); |
| 4566 | EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4567 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4568 | EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4569 | } |
| 4570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4571 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4572 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4573 | // Verify the behavior of back-face culling for a render surface that is |
| 4574 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4575 | |
| 4576 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4577 | LayerImpl* parent = root_layer(); |
| 4578 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4579 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4580 | LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface); |
| 4581 | LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4582 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4583 | // RenderSurfaces are not double-sided |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4584 | front_facing_surface->test_properties()->double_sided = false; |
| 4585 | back_facing_surface->test_properties()->double_sided = false; |
| 4586 | |
| 4587 | // Everything draws content. |
| 4588 | front_facing_surface->SetDrawsContent(true); |
| 4589 | back_facing_surface->SetDrawsContent(true); |
| 4590 | child1->SetDrawsContent(true); |
| 4591 | child2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4592 | |
| 4593 | gfx::Transform backface_matrix; |
| 4594 | backface_matrix.Translate(50.0, 50.0); |
| 4595 | backface_matrix.RotateAboutYAxis(180.0); |
| 4596 | backface_matrix.Translate(-50.0, -50.0); |
| 4597 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4598 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4599 | gfx::PointF(), gfx::Size(100, 100), false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4600 | true); // parent transform style is preserve3d. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4601 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
| 4602 | gfx::Point3F(), gfx::PointF(), |
| 4603 | gfx::Size(100, 100), true, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4604 | true); // surface transform style is flat. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4605 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
| 4606 | gfx::Point3F(), gfx::PointF(), |
| 4607 | gfx::Size(100, 100), true, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4608 | true); // surface transform style is flat. |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4609 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4610 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 4611 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4612 | gfx::PointF(), gfx::Size(100, 100), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4613 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4614 | front_facing_surface->Set3dSortingContextId(1); |
| 4615 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4616 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4617 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4619 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4620 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4621 | |
| 4622 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4623 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4624 | EXPECT_FALSE(child1->has_render_surface()); |
| 4625 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4626 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 4627 | EXPECT_EQ(2u, update_layer_list_impl()->size()); |
| 4628 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4629 | EXPECT_TRUE(UpdateLayerListImplContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4630 | } |
| 4631 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4632 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | // Verify draw and screen space transforms of layers not in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4634 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4635 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4636 | LayerImpl* parent = root_layer(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4637 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4638 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4639 | gfx::PointF(), gfx::Size(100, 100), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4640 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4641 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4642 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4643 | child->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4644 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4645 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4646 | true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4647 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4648 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
| 4649 | child2->SetDrawsContent(true); |
| 4650 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4651 | gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false, |
| 4652 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4654 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4655 | gfx::Size viewport_size(100, 100); |
| 4656 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4657 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4658 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent); |
| 4659 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4660 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4661 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4662 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4664 | // Verify parent transforms |
| 4665 | gfx::Transform expected_parent_transform; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4666 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4668 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4669 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4670 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4671 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4672 | // Verify results of transformed parent rects |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4673 | gfx::RectF parent_bounds(gfx::SizeF(parent->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4674 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4675 | gfx::RectF parent_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4676 | MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4677 | gfx::RectF parent_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4678 | MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4679 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4680 | gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4681 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4682 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4683 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4684 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4685 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4686 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4687 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4688 | expected_child_transform.Translate(child->position().x(), |
| 4689 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4690 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4691 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4692 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4693 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4694 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4695 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4696 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4697 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4698 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4699 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4700 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4701 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4702 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4703 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4704 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4705 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4706 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4707 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4708 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4709 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4710 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4711 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4712 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4713 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4714 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4715 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4716 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4717 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4718 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4719 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4720 | } |
| 4721 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4722 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4723 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4724 | gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4725 | gfx::Transform perspective_matrix; |
| 4726 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4727 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4728 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4729 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4730 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4731 | LayerImpl* root = root_layer(); |
| 4732 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4733 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4734 | false); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4735 | |
| 4736 | LayerImpl* page_scale = AddChildToRoot<LayerImpl>(); |
| 4737 | SetLayerPropertiesForTesting(page_scale, identity_matrix, gfx::Point3F(), |
| 4738 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4739 | false); |
| 4740 | |
| 4741 | LayerImpl* parent = AddChild<LayerImpl>(page_scale); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4742 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4743 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4744 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4745 | false); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4746 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4747 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
| 4748 | SetLayerPropertiesForTesting(perspective_surface, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4749 | perspective_matrix * scale_small_matrix, |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4750 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4751 | gfx::Size(10, 10), false, true, true); |
| 4752 | perspective_surface->SetDrawsContent(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4753 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4754 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
| 4755 | SetLayerPropertiesForTesting(scale_surface, scale_small_matrix, |
| 4756 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4757 | gfx::Size(10, 10), false, true, true); |
| 4758 | scale_surface->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4759 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4760 | float device_scale_factor = 2.5f; |
| 4761 | float page_scale_factor = 3.f; |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4762 | root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4763 | Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, |
| 4764 | Layer::INVALID_ID); |
| 4765 | root->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 4766 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | c5d4fb4 | 2016-05-27 04:40:09 | [diff] [blame] | 4767 | root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4768 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4769 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4770 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4771 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4772 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4773 | perspective_surface); |
| 4774 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4775 | // the nearest render target. Here this includes the layer transform as well |
| 4776 | // as the device and page scale factors. |
| 4777 | gfx::Transform transform = scale_small_matrix; |
| 4778 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4779 | device_scale_factor * page_scale_factor); |
| 4780 | gfx::Vector2dF scales = |
| 4781 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4782 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4783 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4784 | |
| 4785 | // The ideal scale will draw 1:1 with its render target space along |
| 4786 | // the larger-scale axis. |
| 4787 | gfx::Vector2dF target_space_transform_scales = |
| 4788 | MathUtil::ComputeTransform2dScaleComponents( |
| 4789 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4790 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4791 | std::max(target_space_transform_scales.x(), |
| 4792 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4793 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4794 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4796 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4797 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4798 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4799 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4800 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4801 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4802 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4803 | // with the screen, and then scaled during drawing. |
| 4804 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4805 | expected_perspective_surface_draw_transform.Translate( |
| 4806 | device_scale_factor * page_scale_factor * |
| 4807 | perspective_surface->position().x(), |
| 4808 | device_scale_factor * page_scale_factor * |
| 4809 | perspective_surface->position().y()); |
| 4810 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4811 | perspective_matrix); |
| 4812 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4813 | scale_small_matrix); |
| 4814 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4815 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4816 | device_scale_factor * page_scale_factor, |
| 4817 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4818 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4819 | expected_perspective_surface_draw_transform, |
| 4820 | perspective_surface->render_surface()->draw_transform()); |
| 4821 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4822 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4823 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4824 | } |
| 4825 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4826 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4827 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4828 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4829 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4830 | |
| 4831 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4832 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4833 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4834 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4835 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4836 | root->SetBounds(gfx::Size(100, 100)); |
| 4837 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4838 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4839 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4840 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4841 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4842 | false); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4843 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4844 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4845 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4846 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4847 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4848 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4849 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4850 | float device_scale_factor = 2.5f; |
| 4851 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4852 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4853 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4854 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4855 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4856 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4857 | // The ideal scale is able to go below 1. |
| 4858 | float expected_ideal_scale = |
| 4859 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4860 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4861 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4862 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4863 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4864 | initial_parent_scale * initial_child_scale; |
| 4865 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4866 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4867 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4868 | } |
| 4869 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4870 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4871 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4872 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4873 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4874 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4875 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4876 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4877 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4878 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4879 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4880 | root->SetBounds(gfx::Size(100, 100)); |
| 4881 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4882 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4883 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4884 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4885 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4886 | false); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4887 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4888 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4889 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4890 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4891 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4892 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4893 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4894 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4895 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4896 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4897 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 4898 | // Animating layers compute ideal scale in the same way as when |
| 4899 | // they are static. |
| 4900 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 4901 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4902 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4903 | } |
| 4904 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4905 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4906 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4907 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4908 | LayerImpl* parent = root_layer(); |
| 4909 | parent->SetDrawsContent(true); |
| 4910 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4911 | gfx::PointF(), gfx::Size(30, 30), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4912 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4913 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4914 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4915 | child->SetDrawsContent(true); |
| 4916 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4917 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4918 | true, true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4919 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4920 | gfx::Transform replica_transform; |
| 4921 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4922 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 4923 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4924 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 4925 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 4926 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4927 | true, false); |
jaydasika | 5017a33 | 2016-03-31 01:06:22 | [diff] [blame] | 4928 | // We need to set parent on replica layer for property tree building. |
| 4929 | replica->SetParent(child); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 4930 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4931 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4932 | // This layer should end up in the same surface as child, with the same draw |
| 4933 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4934 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
| 4935 | duplicate_child_non_owner->SetDrawsContent(true); |
| 4936 | SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix, |
| 4937 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 4938 | false, true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4939 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4940 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4941 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4942 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4943 | // We should have two render surfaces. The root's render surface and child's |
| 4944 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4945 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4946 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4947 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4948 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4949 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4950 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4951 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4952 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4953 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4954 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4955 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4956 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4957 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4958 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4959 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4960 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4961 | device_scale_factor); |
| 4962 | expected_screen_space_transform.Translate(child->position().x(), |
| 4963 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4965 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4966 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4967 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4968 | child->DrawTransform(); |
| 4969 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(), |
| 4970 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4971 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4972 | child->ScreenSpaceTransform(), |
| 4973 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4974 | EXPECT_EQ(child->drawable_content_rect(), |
| 4975 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4976 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4977 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4978 | gfx::Transform expected_render_surface_draw_transform; |
| 4979 | expected_render_surface_draw_transform.Translate( |
| 4980 | device_scale_factor * child->position().x(), |
| 4981 | device_scale_factor * child->position().y()); |
| 4982 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4983 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4984 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4985 | gfx::Transform expected_surface_draw_transform; |
| 4986 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4987 | device_scale_factor * 2.f); |
| 4988 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4989 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4990 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4991 | gfx::Transform expected_surface_screen_space_transform; |
| 4992 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4993 | device_scale_factor * 2.f); |
| 4994 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4995 | expected_surface_screen_space_transform, |
| 4996 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4997 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4998 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4999 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5000 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5001 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5002 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5003 | expected_replica_draw_transform, |
| 5004 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5005 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5006 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5007 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5008 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5009 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5010 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5011 | expected_replica_screen_space_transform, |
| 5012 | child->render_surface()->replica_screen_space_transform()); |
| 5013 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5014 | expected_replica_screen_space_transform, |
| 5015 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5016 | } |
| 5017 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5018 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5019 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5020 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5021 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5022 | LayerImpl* parent = root_layer(); |
| 5023 | parent->SetDrawsContent(true); |
| 5024 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 5025 | gfx::PointF(), gfx::Size(33, 31), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5026 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5027 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5028 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 5029 | child->SetDrawsContent(true); |
| 5030 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 5031 | gfx::PointF(), gfx::Size(13, 11), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5032 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5033 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5034 | gfx::Transform replica_transform; |
| 5035 | replica_transform.Scale(1.0, -1.0); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5036 | std::unique_ptr<LayerImpl> replica = |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5037 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 5038 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 5039 | gfx::PointF(), gfx::Size(13, 11), false, true, |
| 5040 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5041 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5042 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5043 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5044 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5045 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5046 | // We should have two render surfaces. The root's render surface and child's |
| 5047 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5048 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5049 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5050 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5051 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5052 | child->render_surface()->draw_transform()); |
| 5053 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5054 | child->render_surface()->draw_transform()); |
| 5055 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5056 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5058 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5059 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5060 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5061 | expected_replica_draw_transform, |
| 5062 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5063 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5064 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5065 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5066 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5067 | expected_replica_screen_space_transform, |
| 5068 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5069 | } |
| 5070 | |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 5071 | TEST_F(LayerTreeHostCommonTest, LayerSearch) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 5072 | scoped_refptr<Layer> root = Layer::Create(); |
| 5073 | scoped_refptr<Layer> child = Layer::Create(); |
| 5074 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5075 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5076 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5077 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5078 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5079 | child->AddChild(grand_child.get()); |
| 5080 | child->SetMaskLayer(mask_layer.get()); |
| 5081 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5082 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5083 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5084 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5085 | int nonexistent_id = -1; |
jaydasika | db41a58 | 2016-03-28 20:48:21 | [diff] [blame] | 5086 | EXPECT_EQ(root.get(), host()->LayerById(root->id())); |
| 5087 | EXPECT_EQ(child.get(), host()->LayerById(child->id())); |
| 5088 | EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id())); |
| 5089 | EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id())); |
| 5090 | EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id())); |
| 5091 | EXPECT_FALSE(host()->LayerById(nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5092 | } |
| 5093 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5094 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 5095 | LayerImpl* root = root_layer(); |
| 5096 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 5097 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 5098 | grand_child->SetDrawsContent(true); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5099 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5100 | const gfx::Transform identity_matrix; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 5101 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 5102 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 5103 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 5104 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 5105 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 5106 | gfx::PointF(), gfx::Size(10, 10), true, false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5107 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5108 | child->test_properties()->opacity = 0.5f; |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5109 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 5110 | ExecuteCalculateDrawProperties(root); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5111 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 5112 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5113 | } |
| 5114 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5115 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5116 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5117 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5118 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5119 | FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, |
| 5120 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5121 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5122 | std::unique_ptr<LayerImpl> root = |
| 5123 | LayerImpl::Create(host_impl.pending_tree(), 1); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5124 | |
| 5125 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5126 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5127 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5128 | false); |
| 5129 | root->SetDrawsContent(true); |
| 5130 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5131 | std::unique_ptr<LayerImpl> child = |
| 5132 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5133 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5134 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5135 | false); |
| 5136 | child->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5137 | child->test_properties()->opacity = 0.0f; |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5138 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5139 | const int child_id = child->id(); |
| 5140 | root->AddChild(std::move(child)); |
| 5141 | root->SetHasRenderSurface(true); |
| 5142 | LayerImpl* root_layer = root.get(); |
| 5143 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 5144 | host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting(); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5145 | // Add opacity animation. |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5146 | scoped_refptr<AnimationTimeline> timeline = |
| 5147 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5148 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5149 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 5150 | AddOpacityTransitionToLayerWithPlayer(child_id, timeline, 10.0, 0.0f, 1.0f, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5151 | false); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5152 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5153 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5154 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5155 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5156 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5157 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5158 | |
| 5159 | // We should have one render surface and two layers. The child |
| 5160 | // layer should be included even though it is transparent. |
| 5161 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5162 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5163 | |
| 5164 | // If the root itself is hidden, the child should not be drawn even if it has |
| 5165 | // an animating opacity. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5166 | root_layer->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5167 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5168 | LayerImplList render_surface_layer_list2; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5169 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5170 | root_layer, root_layer->bounds(), &render_surface_layer_list2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5171 | inputs2.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5172 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5173 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5174 | LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5175 | EffectTree& tree = |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5176 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5177 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
| 5178 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5179 | |
| 5180 | // A layer should be drawn and it should contribute to drawn surface when |
| 5181 | // it has animating opacity even if it has opacity 0. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5182 | root_layer->test_properties()->opacity = 1.0f; |
| 5183 | child_ptr->test_properties()->opacity = 0.0f; |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5184 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5185 | LayerImplList render_surface_layer_list3; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5186 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5187 | root_layer, root_layer->bounds(), &render_surface_layer_list3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5188 | inputs3.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5189 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5190 | |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5191 | child_ptr = root_layer->layer_tree_impl()->LayerById(2); |
| 5192 | tree = root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5193 | node = tree.Node(child_ptr->effect_tree_index()); |
| 5194 | EXPECT_TRUE(node->data.is_drawn); |
| 5195 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5196 | |
| 5197 | // But if the opacity of the layer remains 0 after activation, it should not |
| 5198 | // be drawn. |
| 5199 | host_impl.ActivateSyncTree(); |
| 5200 | LayerImpl* active_root = host_impl.active_tree()->root_layer(); |
| 5201 | LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id()); |
| 5202 | |
| 5203 | EffectTree& active_effect_tree = |
| 5204 | host_impl.active_tree()->property_trees()->effect_tree; |
| 5205 | EXPECT_TRUE(active_effect_tree.needs_update()); |
| 5206 | |
| 5207 | ExecuteCalculateDrawProperties(active_root); |
| 5208 | |
| 5209 | node = active_effect_tree.Node(active_child->effect_tree_index()); |
| 5210 | EXPECT_FALSE(node->data.is_drawn); |
| 5211 | EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface( |
| 5212 | active_child->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5213 | } |
| 5214 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5215 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 5216 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 5217 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5218 | public: |
| 5219 | LCDTextTest() |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5220 | : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), |
| 5221 | host_impl_(LCDTextTestLayerTreeSettings(), |
| 5222 | &task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5223 | &shared_bitmap_manager_, |
| 5224 | &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5225 | root_(nullptr), |
| 5226 | child_(nullptr), |
| 5227 | grand_child_(nullptr) {} |
| 5228 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5229 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5230 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5231 | protected: |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5232 | LayerTreeSettings LCDTextTestLayerTreeSettings() { |
| 5233 | LayerTreeSettings settings = LayerTreeSettings(); |
| 5234 | |
| 5235 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
| 5236 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
| 5237 | settings.can_use_lcd_text = can_use_lcd_text_; |
| 5238 | settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_; |
| 5239 | return settings; |
| 5240 | } |
| 5241 | |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5242 | void SetUp() override { |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5243 | timeline_ = |
| 5244 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5245 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5246 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5247 | std::unique_ptr<LayerImpl> root_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5248 | LayerImpl::Create(host_impl_.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5249 | std::unique_ptr<LayerImpl> child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5250 | LayerImpl::Create(host_impl_.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5251 | std::unique_ptr<LayerImpl> grand_child_ptr = |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5252 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5253 | |
| 5254 | // Stash raw pointers to look at later. |
| 5255 | root_ = root_ptr.get(); |
| 5256 | child_ = child_ptr.get(); |
| 5257 | grand_child_ = grand_child_ptr.get(); |
| 5258 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5259 | child_->AddChild(std::move(grand_child_ptr)); |
| 5260 | root_->AddChild(std::move(child_ptr)); |
| 5261 | host_impl_.active_tree()->SetRootLayer(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5262 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5263 | root_->SetContentsOpaque(true); |
| 5264 | child_->SetContentsOpaque(true); |
| 5265 | grand_child_->SetContentsOpaque(true); |
| 5266 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5267 | root_->SetDrawsContent(true); |
| 5268 | child_->SetDrawsContent(true); |
| 5269 | grand_child_->SetDrawsContent(true); |
| 5270 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5271 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5272 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5273 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5274 | true); |
| 5275 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5276 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5277 | std::tr1::get<2>(GetParam())); |
| 5278 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5279 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5280 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5281 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5282 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5283 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5284 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5285 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5286 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5287 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5288 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5289 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5290 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5291 | |
| 5292 | LayerImpl* root_; |
| 5293 | LayerImpl* child_; |
| 5294 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5295 | }; |
| 5296 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5297 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5298 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5299 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5300 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5301 | // Case 1: Identity transform. |
| 5302 | gfx::Transform identity_matrix; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5303 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5304 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5305 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5306 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5307 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5308 | // Case 2: Integral translation. |
| 5309 | gfx::Transform integral_translation; |
| 5310 | integral_translation.Translate(1.0, 2.0); |
| 5311 | child_->SetTransform(integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5312 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5313 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5314 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5315 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5316 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5317 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5318 | // Case 3: Non-integral translation. |
| 5319 | gfx::Transform non_integral_translation; |
| 5320 | non_integral_translation.Translate(1.5, 2.5); |
| 5321 | child_->SetTransform(non_integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5322 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5323 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5324 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5325 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5326 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5327 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5328 | // Case 4: Rotation. |
| 5329 | gfx::Transform rotation; |
| 5330 | rotation.Rotate(10.0); |
| 5331 | child_->SetTransform(rotation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5332 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5333 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5334 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5335 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5336 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5337 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5338 | // Case 5: Scale. |
| 5339 | gfx::Transform scale; |
| 5340 | scale.Scale(2.0, 2.0); |
| 5341 | child_->SetTransform(scale); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5342 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5343 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5344 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5345 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5346 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5347 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5348 | // Case 6: Skew. |
| 5349 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5350 | skew.Skew(10.0, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5351 | child_->SetTransform(skew); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5352 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5353 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5354 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5355 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5356 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5357 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5358 | // Case 7: Translucent. |
| 5359 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5360 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5361 | child_->test_properties()->opacity = 0.5f; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5362 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5363 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5364 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5365 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5366 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5367 | // Case 8: Sanity check: restore transform and opacity. |
| 5368 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5369 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5370 | child_->test_properties()->opacity = 1.f; |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5371 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5372 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5373 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5374 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5375 | |
| 5376 | // Case 9: Non-opaque content. |
| 5377 | child_->SetContentsOpaque(false); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5378 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5379 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5380 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5381 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5382 | |
| 5383 | // Case 10: Sanity check: restore content opaqueness. |
| 5384 | child_->SetContentsOpaque(true); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5385 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5386 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5387 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5388 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5389 | } |
| 5390 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5391 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5392 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5393 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5394 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5395 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5396 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5397 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5398 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5399 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5400 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5401 | // Add opacity animation. |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 5402 | child_->test_properties()->opacity = 0.9f; |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5403 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5404 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5405 | 0.1f, false); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5406 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5407 | // Text LCD should be adjusted while animation is active. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5408 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5409 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5410 | EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5411 | } |
| 5412 | |
| 5413 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5414 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5415 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5416 | |
| 5417 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5418 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
| 5419 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5420 | EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); |
| 5421 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5422 | |
| 5423 | // Mark contents non-opaque within the first animation frame. |
| 5424 | child_->SetContentsOpaque(false); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 5425 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5426 | 0.1f, false); |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5427 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5428 | // LCD text should be disabled for non-opaque layers even during animations. |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 5429 | EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); |
| 5430 | EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); |
| 5431 | EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5435 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5436 | testing::Combine(testing::Bool(), |
| 5437 | testing::Bool(), |
| 5438 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5439 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5440 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5441 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5442 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5443 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5444 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5445 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5446 | host_impl.CreatePendingTree(); |
| 5447 | const gfx::Transform identity_matrix; |
| 5448 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5449 | std::unique_ptr<LayerImpl> root = |
| 5450 | LayerImpl::Create(host_impl.pending_tree(), 1); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5451 | LayerImpl* root_layer = root.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5452 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5453 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5454 | false); |
| 5455 | root->SetDrawsContent(true); |
| 5456 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5457 | std::unique_ptr<LayerImpl> child = |
| 5458 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5459 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5460 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5461 | false); |
| 5462 | child->SetDrawsContent(true); |
| 5463 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5464 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5465 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5466 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5467 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5468 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5469 | grand_child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5470 | grand_child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5471 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5472 | child->AddChild(std::move(grand_child)); |
| 5473 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5474 | root->SetHasRenderSurface(true); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5475 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5476 | |
| 5477 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5478 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5479 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5480 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5481 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5482 | |
| 5483 | // We should have one render surface and two layers. The grand child has |
| 5484 | // hidden itself. |
| 5485 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 0c2fd47 | 2016-03-24 01:26:05 | [diff] [blame] | 5486 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5487 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
| 5488 | EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5489 | } |
| 5490 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5491 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5492 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5493 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5494 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5495 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5496 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5497 | host_impl.CreatePendingTree(); |
| 5498 | const gfx::Transform identity_matrix; |
| 5499 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5500 | std::unique_ptr<LayerImpl> root = |
| 5501 | LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5502 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5503 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5504 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5505 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5506 | LayerImpl* root_layer = root.get(); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5507 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5508 | std::unique_ptr<LayerImpl> child = |
| 5509 | LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5510 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5511 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5512 | false); |
| 5513 | child->SetDrawsContent(true); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5514 | child->test_properties()->hide_layer_and_subtree = true; |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5515 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5516 | std::unique_ptr<LayerImpl> grand_child = |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5517 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5518 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5519 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5520 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5521 | grand_child->SetDrawsContent(true); |
| 5522 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5523 | child->AddChild(std::move(grand_child)); |
| 5524 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5525 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5526 | |
| 5527 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5528 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5529 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5530 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5531 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5532 | |
| 5533 | // We should have one render surface and one layers. The child has |
| 5534 | // hidden itself and the grand child. |
| 5535 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5536 | ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size()); |
| 5537 | EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5538 | } |
| 5539 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5540 | void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5541 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5542 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5543 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5544 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5545 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5546 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5547 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5548 | host_impl.CreatePendingTree(); |
| 5549 | const gfx::Transform identity_matrix; |
| 5550 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5551 | std::unique_ptr<LayerImpl> root = |
| 5552 | LayerImpl::Create(host_impl.pending_tree(), 1); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5553 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5554 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5555 | true); |
| 5556 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5557 | LayerImpl* root_layer = root.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5558 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5559 | std::unique_ptr<LayerImpl> copy_grand_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5560 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5561 | SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix, |
| 5562 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 5563 | true, false, false); |
| 5564 | copy_grand_parent->SetDrawsContent(true); |
| 5565 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5566 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5567 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5568 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5569 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5570 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5571 | true, false, true); |
| 5572 | copy_parent->SetDrawsContent(true); |
| 5573 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5574 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5575 | std::unique_ptr<LayerImpl> copy_request = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5576 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5577 | SetLayerPropertiesForTesting(copy_request.get(), identity_matrix, |
| 5578 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5579 | true, false, true); |
| 5580 | copy_request->SetDrawsContent(true); |
| 5581 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5582 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5583 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5584 | LayerImpl::Create(host_impl.pending_tree(), 5); |
| 5585 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5586 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5587 | true, false, false); |
| 5588 | copy_child->SetDrawsContent(true); |
| 5589 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5590 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5591 | std::unique_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5592 | LayerImpl::Create(host_impl.pending_tree(), 6); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5593 | SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix, |
| 5594 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5595 | true, false, false); |
| 5596 | copy_child->SetDrawsContent(true); |
| 5597 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5598 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5599 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5600 | LayerImpl::Create(host_impl.pending_tree(), 7); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5601 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5602 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5603 | gfx::Size(40, 40), true, false, false); |
| 5604 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5605 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5606 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5607 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5608 | std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5609 | LayerImpl::Create(host_impl.pending_tree(), 8); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5610 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5611 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5612 | gfx::Size(40, 40), true, false, false); |
| 5613 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5614 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5615 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5616 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5617 | copy_child->AddChild(std::move(copy_grand_child)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5618 | copy_request->AddChild(std::move(copy_child)); |
| 5619 | copy_parent->AddChild(std::move(copy_request)); |
| 5620 | copy_grand_parent->AddChild(std::move(copy_parent)); |
| 5621 | root->AddChild(std::move(copy_grand_parent_sibling_before)); |
| 5622 | root->AddChild(std::move(copy_grand_parent)); |
| 5623 | root->AddChild(std::move(copy_grand_parent_sibling_after)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5624 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5625 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5626 | // 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] | 5627 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5628 | // subtree. |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 5629 | copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true; |
| 5630 | copy_grand_parent_sibling_before_layer->test_properties() |
| 5631 | ->hide_layer_and_subtree = true; |
| 5632 | copy_grand_parent_sibling_after_layer->test_properties() |
| 5633 | ->hide_layer_and_subtree = true; |
| 5634 | copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5635 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5636 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5637 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5638 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5639 | LayerImplList render_surface_layer_list; |
| 5640 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5641 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5642 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5643 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5644 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5645 | EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5646 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5647 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5648 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5649 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5650 | // We should have four render surfaces, one for the root, one for the grand |
| 5651 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5652 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5653 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5654 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5655 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5656 | render_surface_layer_list.at(1)->id()); |
| 5657 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5658 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5659 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5660 | // The root render surface should have 2 contributing layers. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5661 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5662 | EXPECT_EQ(root_layer->id(), |
| 5663 | root_layer->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5664 | EXPECT_EQ(copy_grand_parent_layer->id(), |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5665 | root_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5666 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5667 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5668 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5669 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5670 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8185d30 | 2016-04-14 15:20:06 | [diff] [blame] | 5671 | copy_parent_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5672 | |
| 5673 | // The copy_layer's render surface should have two contributing layers. |
| 5674 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5675 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5676 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5677 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5678 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5679 | |
| 5680 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5681 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5682 | // copy grand child should not be drawn as its hidden even in the copy |
| 5683 | // request. |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 5684 | EffectTree& tree = |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 5685 | root_layer->layer_tree_impl()->property_trees()->effect_tree; |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5686 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
| 5687 | EXPECT_FALSE(node->data.is_drawn); |
| 5688 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
| 5689 | EXPECT_FALSE(node->data.is_drawn); |
| 5690 | node = tree.Node(copy_layer->effect_tree_index()); |
| 5691 | EXPECT_TRUE(node->data.is_drawn); |
| 5692 | node = tree.Node(copy_child_layer->effect_tree_index()); |
| 5693 | EXPECT_TRUE(node->data.is_drawn); |
| 5694 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
| 5695 | EXPECT_FALSE(node->data.is_drawn); |
| 5696 | |
| 5697 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5698 | // actually hidden. |
| 5699 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5700 | } |
| 5701 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5702 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5703 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5704 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5705 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5706 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5707 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5708 | host_impl.CreatePendingTree(); |
| 5709 | const gfx::Transform identity_matrix; |
| 5710 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5711 | std::unique_ptr<LayerImpl> root = |
| 5712 | LayerImpl::Create(host_impl.pending_tree(), 1); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5713 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5714 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5715 | true); |
| 5716 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5717 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5718 | std::unique_ptr<LayerImpl> copy_parent = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5719 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5720 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5721 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 5722 | false, false); |
| 5723 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5724 | copy_parent->SetMasksToBounds(true); |
| 5725 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5726 | std::unique_ptr<LayerImpl> copy_layer = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5727 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5728 | SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix, |
| 5729 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5730 | true, false, true); |
| 5731 | copy_layer->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5732 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5733 | std::unique_ptr<LayerImpl> copy_child = |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5734 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5735 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5736 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5737 | true, false, false); |
| 5738 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5739 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 5740 | copy_layer->test_properties()->copy_requests.push_back( |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5741 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5742 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5743 | copy_layer->AddChild(std::move(copy_child)); |
| 5744 | copy_parent->AddChild(std::move(copy_layer)); |
| 5745 | root->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5746 | |
| 5747 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5748 | LayerImpl* root_layer = root.get(); |
| 5749 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5750 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 5751 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5752 | inputs.can_adjust_raster_scales = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 5753 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5754 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5755 | // We should have two render surface, as the others are clipped out. |
| 5756 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5757 | EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5758 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5759 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5760 | // other layers are empty/clipped away. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 5761 | ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
| 5762 | EXPECT_EQ(root_layer->id(), |
| 5763 | root_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5764 | } |
| 5765 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5766 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5767 | LayerImpl* root = root_layer(); |
| 5768 | LayerImpl* surface = AddChild<LayerImpl>(root); |
| 5769 | LayerImpl* surface_child = AddChild<LayerImpl>(surface); |
| 5770 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5771 | const gfx::Transform identity_matrix; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5772 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 5773 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5774 | true); |
| 5775 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 5776 | gfx::PointF(-10, 20), gfx::Size(), true, false, |
| 5777 | true); |
| 5778 | SetLayerPropertiesForTesting(surface_child, identity_matrix, gfx::Point3F(), |
| 5779 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5780 | false); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5781 | root->SetDrawsContent(true); |
| 5782 | surface_child->SetDrawsContent(true); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5783 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5784 | ExecuteCalculateDrawProperties(root); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5785 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 5786 | // The visible_layer_rect for the |surface_child| should not be clipped by |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5787 | // the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5788 | EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5789 | } |
| 5790 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5791 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5792 | // Ensure that a transform between the layer and its render surface is not a |
| 5793 | // problem. Constructs the following layer tree. |
| 5794 | // |
| 5795 | // root (a render surface) |
| 5796 | // + render_surface |
| 5797 | // + clip_parent (scaled) |
| 5798 | // + intervening_clipping_layer |
| 5799 | // + clip_child |
| 5800 | // |
| 5801 | // The render surface should be resized correctly and the clip child should |
| 5802 | // inherit the right clip rect. |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5803 | LayerImpl* root = root_layer(); |
| 5804 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5805 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5806 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5807 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5808 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5809 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5810 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5811 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 5812 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5813 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5814 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5815 | |
| 5816 | intervening->SetMasksToBounds(true); |
| 5817 | clip_parent->SetMasksToBounds(true); |
| 5818 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5819 | gfx::Transform scale_transform; |
| 5820 | scale_transform.Scale(2, 2); |
| 5821 | |
| 5822 | gfx::Transform identity_transform; |
| 5823 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5824 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5825 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5826 | true); |
| 5827 | SetLayerPropertiesForTesting(render_surface, identity_transform, |
| 5828 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5829 | true, false, true); |
| 5830 | SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(), |
| 5831 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5832 | false, false); |
| 5833 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5834 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5835 | false, false); |
| 5836 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5837 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5838 | false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5839 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5840 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5841 | |
| 5842 | ASSERT_TRUE(root->render_surface()); |
| 5843 | ASSERT_TRUE(render_surface->render_surface()); |
| 5844 | |
| 5845 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5846 | // by the intervening clip layer. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5847 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect()); |
| 5848 | ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect()); |
| 5849 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5850 | |
| 5851 | // Ensure that the render surface reports a content rect that has been grown |
| 5852 | // to accomodate for the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5853 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20), |
| 5854 | render_surface->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5855 | |
| 5856 | // The above check implies the two below, but they nicely demonstrate that |
| 5857 | // we've grown, despite the intervening layer's clip. |
| 5858 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5859 | render_surface->render_surface()->content_rect())); |
| 5860 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5861 | render_surface->render_surface()->content_rect())); |
| 5862 | } |
| 5863 | |
| 5864 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5865 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5866 | // case. In the following tree, both render surfaces should be resized to |
| 5867 | // accomodate for the clip child, despite an intervening clip. |
| 5868 | // |
| 5869 | // root (a render surface) |
| 5870 | // + clip_parent (masks to bounds) |
| 5871 | // + render_surface1 (sets opacity) |
| 5872 | // + intervening (masks to bounds) |
| 5873 | // + render_surface2 (also sets opacity) |
| 5874 | // + clip_child |
| 5875 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5876 | LayerImpl* root = root_layer(); |
| 5877 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5878 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5879 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5880 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5881 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5882 | render_surface1->SetDrawsContent(true); |
| 5883 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5884 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5885 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5886 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5887 | |
| 5888 | intervening->SetMasksToBounds(true); |
| 5889 | clip_parent->SetMasksToBounds(true); |
| 5890 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5891 | gfx::Transform translation_transform; |
| 5892 | translation_transform.Translate(2, 2); |
| 5893 | |
| 5894 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5895 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5896 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5897 | true); |
| 5898 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5899 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5900 | gfx::Size(40, 40), true, false, false); |
| 5901 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5902 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5903 | true, false, true); |
| 5904 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5905 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5906 | false, false); |
| 5907 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5908 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5909 | true, false, true); |
| 5910 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5911 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 5912 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5913 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5914 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5915 | |
| 5916 | EXPECT_TRUE(root->render_surface()); |
| 5917 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5918 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5919 | |
| 5920 | // Since the render surfaces could have expanded, they should not clip (their |
| 5921 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5922 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5923 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5924 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5925 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5926 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 5927 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5928 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5929 | |
| 5930 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5931 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5932 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 5933 | |
| 5934 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5935 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5936 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 5937 | |
| 5938 | // The content rects of both render surfaces should both have expanded to |
| 5939 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5940 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 5941 | render_surface1->render_surface()->content_rect()); |
| 5942 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), |
| 5943 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5944 | |
| 5945 | // The clip child should have inherited the clip parent's clip (projected to |
| 5946 | // the right space, of course), and should have the correctly sized visible |
| 5947 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 5948 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect()); |
| 5949 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5950 | EXPECT_TRUE(clip_child->is_clipped()); |
| 5951 | } |
| 5952 | |
| 5953 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 5954 | // Ensure that intervening render surfaces are not a problem, even if there |
| 5955 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 5956 | // of transform. |
| 5957 | // |
| 5958 | // root (a render surface) |
| 5959 | // + clip_parent (masks to bounds) |
| 5960 | // + render_surface1 (sets opacity) |
| 5961 | // + intervening (masks to bounds AND scrolls) |
| 5962 | // + render_surface2 (also sets opacity) |
| 5963 | // + clip_child |
| 5964 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5965 | LayerImpl* root = root_layer(); |
| 5966 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5967 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5968 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5969 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5970 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5971 | render_surface1->SetDrawsContent(true); |
| 5972 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5973 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5974 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 5975 | clip_child->test_properties()->clip_parent = clip_parent; |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5976 | |
| 5977 | intervening->SetMasksToBounds(true); |
| 5978 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5979 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 5980 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5981 | |
| 5982 | gfx::Transform translation_transform; |
| 5983 | translation_transform.Translate(2, 2); |
| 5984 | |
| 5985 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5986 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5987 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5988 | true); |
| 5989 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5990 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5991 | gfx::Size(40, 40), true, false, false); |
| 5992 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5993 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5994 | true, false, true); |
| 5995 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5996 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5997 | false, false); |
| 5998 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5999 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 6000 | true, false, true); |
| 6001 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6002 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 6003 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6004 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6005 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6006 | |
| 6007 | EXPECT_TRUE(root->render_surface()); |
| 6008 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6009 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6010 | |
| 6011 | // Since the render surfaces could have expanded, they should not clip (their |
| 6012 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6013 | // in this case. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6014 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 6015 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6016 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6017 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 6018 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6019 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6020 | |
| 6021 | // NB: clip rects are in target space. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6022 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6023 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6024 | |
| 6025 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6026 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6027 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6028 | |
| 6029 | // The content rects of both render surfaces should both have expanded to |
| 6030 | // contain the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6031 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), |
| 6032 | render_surface1->render_surface()->content_rect()); |
| 6033 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), |
| 6034 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6035 | |
| 6036 | // The clip child should have inherited the clip parent's clip (projected to |
| 6037 | // the right space, of course), and should have the correctly sized visible |
| 6038 | // content rect. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6039 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect()); |
| 6040 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6041 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6042 | } |
| 6043 | |
| 6044 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6045 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6046 | // |
| 6047 | // root (a render surface) |
| 6048 | // + clip_parent (masks to bounds) |
| 6049 | // + intervening (masks to bounds) |
| 6050 | // + clip_child |
| 6051 | // + child |
| 6052 | // |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6053 | LayerImpl* root = root_layer(); |
| 6054 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 6055 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 6056 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 6057 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 6058 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6059 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6060 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6061 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6062 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6063 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6064 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6065 | |
| 6066 | intervening->SetMasksToBounds(true); |
| 6067 | clip_parent->SetMasksToBounds(true); |
| 6068 | |
| 6069 | gfx::Transform identity_transform; |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6070 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6071 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6072 | true); |
| 6073 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6074 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6075 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6076 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 6077 | gfx::PointF(), gfx::Size(5, 5), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6078 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6079 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6080 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6081 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6082 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6083 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6084 | false); |
| 6085 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6086 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6087 | |
| 6088 | EXPECT_TRUE(root->render_surface()); |
| 6089 | |
| 6090 | // Neither the clip child nor its descendant should have inherited the clip |
| 6091 | // from |intervening|. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6092 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6093 | EXPECT_TRUE(clip_child->is_clipped()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6094 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6095 | EXPECT_TRUE(child->is_clipped()); |
| 6096 | } |
| 6097 | |
| 6098 | TEST_F(LayerTreeHostCommonTest, |
| 6099 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6100 | // Ensures that non-descendant clip children in the tree do not affect |
| 6101 | // render surfaces. |
| 6102 | // |
| 6103 | // root (a render surface) |
| 6104 | // + clip_parent (masks to bounds) |
| 6105 | // + render_surface1 |
| 6106 | // + clip_child |
| 6107 | // + render_surface2 |
| 6108 | // + non_clip_child |
| 6109 | // |
| 6110 | // In this example render_surface2 should be unaffected by clip_child. |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6111 | LayerImpl* root = root_layer(); |
| 6112 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6113 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6114 | render_surface1->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6115 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 6116 | clip_child->SetDrawsContent(true); |
| 6117 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6118 | render_surface2->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6119 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
| 6120 | non_clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6121 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6122 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6123 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6124 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6125 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6126 | |
| 6127 | clip_parent->SetMasksToBounds(true); |
| 6128 | render_surface1->SetMasksToBounds(true); |
| 6129 | |
| 6130 | gfx::Transform identity_transform; |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6131 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6132 | gfx::PointF(), gfx::Size(15, 15), true, false, |
| 6133 | true); |
| 6134 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6135 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6136 | false); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6137 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6138 | gfx::Point3F(), gfx::PointF(5, 5), |
| 6139 | gfx::Size(5, 5), true, false, true); |
| 6140 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6141 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6142 | true, false, true); |
| 6143 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6144 | gfx::PointF(-1, 1), gfx::Size(10, 10), true, |
| 6145 | false, false); |
| 6146 | SetLayerPropertiesForTesting(non_clip_child, identity_transform, |
| 6147 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6148 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6149 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6150 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6151 | |
| 6152 | EXPECT_TRUE(root->render_surface()); |
| 6153 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6154 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6155 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6156 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6157 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6158 | |
| 6159 | // The render surface should not clip (it has unclipped descendants), instead |
| 6160 | // it should rely on layer clipping. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6161 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 6162 | render_surface1->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6163 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6164 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6165 | // That said, it should have grown to accomodate the unclipped descendant and |
| 6166 | // its own size. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6167 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5), |
| 6168 | render_surface1->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6169 | |
| 6170 | // This render surface should clip. It has no unclipped descendants. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6171 | EXPECT_EQ(gfx::Rect(0, 0, 10, 10), |
| 6172 | render_surface2->render_surface()->clip_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6173 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 6174 | EXPECT_FALSE(render_surface2->is_clipped()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6175 | |
| 6176 | // It also shouldn't have grown to accomodate the clip child. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6177 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5), |
| 6178 | render_surface2->render_surface()->content_rect()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6179 | |
| 6180 | // Sanity check our num_unclipped_descendants values. |
ajuma | 0641ded | 2016-05-05 21:28:21 | [diff] [blame] | 6181 | EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants); |
| 6182 | EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6183 | } |
| 6184 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6185 | TEST_F(LayerTreeHostCommonTest, |
| 6186 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 6187 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 6188 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6189 | LayerImpl* root = root_layer(); |
| 6190 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 6191 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 6192 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 6193 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6194 | |
| 6195 | const gfx::Transform identity_matrix; |
| 6196 | gfx::Point3F transform_origin; |
| 6197 | gfx::PointF position; |
| 6198 | gfx::Size bounds(100, 100); |
| 6199 | |
| 6200 | SetLayerPropertiesForTesting(root, identity_matrix, transform_origin, |
| 6201 | position, bounds, true, false); |
| 6202 | SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin, |
| 6203 | position, bounds, false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6204 | child1->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6205 | SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin, |
| 6206 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6207 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6208 | SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin, |
| 6209 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6210 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6211 | |
| 6212 | child2->Set3dSortingContextId(1); |
| 6213 | child3->Set3dSortingContextId(1); |
| 6214 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6215 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6216 | |
| 6217 | // Verify which render surfaces were created. |
| 6218 | EXPECT_TRUE(root->has_render_surface()); |
| 6219 | EXPECT_FALSE(child1->has_render_surface()); |
| 6220 | EXPECT_TRUE(child2->has_render_surface()); |
| 6221 | EXPECT_FALSE(child3->has_render_surface()); |
| 6222 | } |
| 6223 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6224 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6225 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6226 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6227 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6228 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6229 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6230 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6231 | std::unique_ptr<LayerImpl> root = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6232 | LayerImpl::Create(host_impl.active_tree(), 12345); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6233 | std::unique_ptr<LayerImpl> child1 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6234 | LayerImpl::Create(host_impl.active_tree(), 123456); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6235 | std::unique_ptr<LayerImpl> child2 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6236 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6237 | std::unique_ptr<LayerImpl> child3 = |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6238 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6239 | |
| 6240 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6241 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6242 | gfx::PointF position; |
| 6243 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6244 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6245 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6246 | root->SetDrawsContent(true); |
| 6247 | |
| 6248 | // This layer structure normally forces render surface due to preserves3d |
| 6249 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6250 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6251 | position, bounds, false, true, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6252 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6253 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6254 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6255 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6256 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 6257 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6258 | child3->SetDrawsContent(true); |
| 6259 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6260 | child2->Set3dSortingContextId(1); |
| 6261 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6262 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 6263 | child2->AddChild(std::move(child3)); |
| 6264 | child1->AddChild(std::move(child2)); |
| 6265 | root->AddChild(std::move(child1)); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6266 | LayerImpl* root_layer = root.get(); |
| 6267 | root_layer->layer_tree_impl()->SetRootLayer(std::move(root)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6268 | |
| 6269 | { |
| 6270 | LayerImplList render_surface_layer_list; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6271 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6272 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6273 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6274 | inputs.can_render_to_separate_surface = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6275 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6276 | |
| 6277 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6278 | |
| 6279 | int count_represents_target_render_surface = 0; |
| 6280 | int count_represents_contributing_render_surface = 0; |
| 6281 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6282 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6283 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6284 | it != end; ++it) { |
| 6285 | if (it.represents_target_render_surface()) |
| 6286 | count_represents_target_render_surface++; |
| 6287 | if (it.represents_contributing_render_surface()) |
| 6288 | count_represents_contributing_render_surface++; |
| 6289 | if (it.represents_itself()) |
| 6290 | count_represents_itself++; |
| 6291 | } |
| 6292 | |
| 6293 | // Two render surfaces. |
| 6294 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6295 | // Second render surface contributes to root render surface. |
| 6296 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6297 | // All 4 layers represent itself. |
| 6298 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | { |
| 6302 | LayerImplList render_surface_layer_list; |
| 6303 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6304 | root_layer, root_layer->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6305 | inputs.can_render_to_separate_surface = false; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6306 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6307 | |
| 6308 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6309 | |
| 6310 | int count_represents_target_render_surface = 0; |
| 6311 | int count_represents_contributing_render_surface = 0; |
| 6312 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6313 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6314 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6315 | it != end; ++it) { |
| 6316 | if (it.represents_target_render_surface()) |
| 6317 | count_represents_target_render_surface++; |
| 6318 | if (it.represents_contributing_render_surface()) |
| 6319 | count_represents_contributing_render_surface++; |
| 6320 | if (it.represents_itself()) |
| 6321 | count_represents_itself++; |
| 6322 | } |
| 6323 | |
| 6324 | // Only root layer has a render surface. |
| 6325 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6326 | // No layer contributes a render surface to root render surface. |
| 6327 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6328 | // All 4 layers represent itself. |
| 6329 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6330 | } |
| 6331 | } |
| 6332 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6333 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6334 | LayerImpl* root = root_layer(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6335 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6336 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6337 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6338 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6339 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 6340 | child1->SetDrawsContent(true); |
| 6341 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6342 | |
| 6343 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6344 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6345 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6346 | true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6347 | SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(), |
| 6348 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6349 | false); |
| 6350 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6351 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6352 | false, true, true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6353 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6354 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6355 | false, true, true); |
| 6356 | SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(), |
| 6357 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 6358 | false); |
| 6359 | SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(), |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6360 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6361 | false); |
| 6362 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6363 | root->test_properties()->should_flatten_transform = false; |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6364 | root->Set3dSortingContextId(1); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6365 | back_facing->Set3dSortingContextId(1); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6366 | back_facing->test_properties()->should_flatten_transform = false; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6367 | render_surface1->test_properties()->double_sided = false; |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6368 | render_surface2->Set3dSortingContextId(2); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6369 | render_surface2->test_properties()->double_sided = false; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6370 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6371 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6372 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6373 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6374 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6375 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6376 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6377 | ->at(0) |
| 6378 | ->render_surface() |
| 6379 | ->layer_list() |
| 6380 | .size()); |
| 6381 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6382 | ->at(1) |
| 6383 | ->render_surface() |
| 6384 | ->layer_list() |
| 6385 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6386 | |
| 6387 | gfx::Transform rotation_transform = identity_transform; |
| 6388 | rotation_transform.RotateAboutXAxis(180.0); |
| 6389 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6390 | back_facing->SetTransform(rotation_transform); |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6391 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6392 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6393 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6394 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6395 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6396 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6397 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6398 | // context. |
| 6399 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6400 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6401 | ->at(0) |
| 6402 | ->render_surface() |
| 6403 | ->layer_list() |
| 6404 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6405 | } |
| 6406 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6407 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
| 6408 | LayerImpl* root = root_layer(); |
| 6409 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6410 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 6411 | grand_child->SetDrawsContent(true); |
| 6412 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6413 | child->test_properties()->double_sided = false; |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6414 | grand_child->SetUseParentBackfaceVisibility(true); |
| 6415 | |
| 6416 | gfx::Transform identity_transform; |
| 6417 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6418 | gfx::PointF(), gfx::Size(50, 50), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6419 | true); |
| 6420 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6421 | gfx::PointF(), gfx::Size(30, 30), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6422 | false); |
| 6423 | SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6424 | gfx::PointF(), gfx::Size(20, 20), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6425 | false); |
| 6426 | |
| 6427 | ExecuteCalculateDrawProperties(root); |
| 6428 | |
| 6429 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6430 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6431 | ->at(0) |
| 6432 | ->render_surface() |
| 6433 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6434 | |
| 6435 | // As all layers have identity transform, we shouldn't check for backface |
| 6436 | // visibility. |
| 6437 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6438 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6439 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6440 | // As there are no 3d rendering contexts, all layers should use their local |
| 6441 | // transform for backface visibility. |
| 6442 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6443 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6444 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6445 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6446 | gfx::Transform rotation_transform = identity_transform; |
| 6447 | rotation_transform.RotateAboutXAxis(180.0); |
| 6448 | |
| 6449 | child->SetTransform(rotation_transform); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6450 | child->Set3dSortingContextId(1); |
| 6451 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6452 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6453 | |
| 6454 | ExecuteCalculateDrawProperties(root); |
| 6455 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6456 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6457 | ->at(0) |
| 6458 | ->render_surface() |
| 6459 | ->layer_list() |
| 6460 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6461 | |
| 6462 | // We should check for backface visibilty of child as it has a rotation |
| 6463 | // transform. We should also check for grand_child as it uses the backface |
| 6464 | // visibility of its parent. |
| 6465 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6466 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6467 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6468 | // child uses its local transform for backface visibility as it is the root of |
| 6469 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6470 | // the root, but it derives its backface visibility from its parent which uses |
| 6471 | // its local transform. |
| 6472 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6473 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6474 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6475 | |
| 6476 | grand_child->SetUseParentBackfaceVisibility(false); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6477 | grand_child->test_properties()->double_sided = false; |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6478 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6479 | |
| 6480 | ExecuteCalculateDrawProperties(root); |
| 6481 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6482 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6483 | ->at(0) |
| 6484 | ->render_surface() |
| 6485 | ->layer_list() |
| 6486 | .size()); |
| 6487 | |
| 6488 | // We should check the backface visibility of child as it has a rotation |
| 6489 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6490 | // the root of it. |
| 6491 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6492 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6493 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6494 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6495 | // local transform for backface visibility. |
| 6496 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6497 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6498 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6499 | } |
| 6500 | |
sunxd | 59dd7da | 2016-05-19 20:07:47 | [diff] [blame] | 6501 | TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) { |
| 6502 | LayerImpl* root = root_layer(); |
| 6503 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6504 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6505 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6506 | |
| 6507 | gfx::Transform identity_transform; |
| 6508 | gfx::Transform rotate_about_y; |
| 6509 | rotate_about_y.RotateAboutYAxis(180.0); |
| 6510 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6511 | gfx::PointF(), gfx::Size(50, 50), false, true, |
| 6512 | true); |
| 6513 | SetLayerPropertiesForTesting(back_facing, rotate_about_y, gfx::Point3F(), |
| 6514 | gfx::PointF(), gfx::Size(50, 50), false, true, |
| 6515 | false); |
| 6516 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6517 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6518 | false, true, true); |
| 6519 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6520 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6521 | false, true, true); |
| 6522 | |
| 6523 | render_surface1->test_properties()->double_sided = false; |
| 6524 | render_surface2->test_properties()->double_sided = false; |
| 6525 | |
| 6526 | ExecuteCalculateDrawProperties(root); |
| 6527 | |
| 6528 | const EffectTree& tree = |
| 6529 | root->layer_tree_impl()->property_trees()->effect_tree; |
| 6530 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
| 6531 | ->data.hidden_by_backface_visibility); |
| 6532 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6533 | ->data.hidden_by_backface_visibility); |
| 6534 | |
| 6535 | back_facing->OnTransformAnimated(identity_transform); |
| 6536 | render_surface2->OnTransformAnimated(rotate_about_y); |
| 6537 | ExecuteCalculateDrawProperties(root); |
| 6538 | EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index()) |
| 6539 | ->data.hidden_by_backface_visibility); |
| 6540 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6541 | ->data.hidden_by_backface_visibility); |
| 6542 | |
| 6543 | render_surface1->OnTransformAnimated(rotate_about_y); |
| 6544 | ExecuteCalculateDrawProperties(root); |
| 6545 | EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index()) |
| 6546 | ->data.hidden_by_backface_visibility); |
| 6547 | EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index()) |
| 6548 | ->data.hidden_by_backface_visibility); |
| 6549 | } |
| 6550 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6551 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6552 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6553 | // have been processed before you anyhow) results in the right clips. |
| 6554 | // |
| 6555 | // + root |
| 6556 | // + scroll_parent_border |
| 6557 | // | + scroll_parent_clip |
| 6558 | // | + scroll_parent |
| 6559 | // + scroll_child |
| 6560 | // |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6561 | LayerImpl* root = root_layer(); |
| 6562 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6563 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6564 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6565 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6566 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6567 | scroll_parent->SetDrawsContent(true); |
| 6568 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6569 | scroll_parent_clip->SetMasksToBounds(true); |
| 6570 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6571 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6572 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6573 | new std::set<LayerImpl*>); |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6574 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6575 | scroll_parent->test_properties()->scroll_children.reset( |
| 6576 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6577 | |
| 6578 | gfx::Transform identity_transform; |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6579 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6580 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6581 | true); |
| 6582 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6583 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6584 | true, false, false); |
| 6585 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6586 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6587 | true, false, false); |
| 6588 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6589 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6590 | true, false, false); |
| 6591 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6592 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6593 | false); |
| 6594 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6595 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6596 | |
| 6597 | EXPECT_TRUE(root->render_surface()); |
| 6598 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6599 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6600 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6601 | } |
| 6602 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6603 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6604 | // Tests the computation of draw transform for the scroll child when its |
| 6605 | // target is different from its scroll parent's target. |
| 6606 | LayerImpl* root = root_layer(); |
| 6607 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6608 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6609 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6610 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6611 | |
| 6612 | scroll_parent->SetDrawsContent(true); |
| 6613 | scroll_child->SetDrawsContent(true); |
| 6614 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6615 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6616 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6617 | new std::set<LayerImpl*>); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6618 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6619 | scroll_parent->test_properties()->scroll_children.reset( |
| 6620 | scroll_children.release()); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6621 | |
| 6622 | gfx::Transform identity_transform; |
| 6623 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6624 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6625 | true); |
| 6626 | SetLayerPropertiesForTesting(scroll_child_target, identity_transform, |
| 6627 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6628 | true, false, true); |
| 6629 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6630 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6631 | false); |
| 6632 | SetLayerPropertiesForTesting(scroll_parent_target, identity_transform, |
| 6633 | gfx::Point3F(), gfx::PointF(10, 10), |
| 6634 | gfx::Size(50, 50), true, false, true); |
| 6635 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6636 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6637 | true, false, false); |
| 6638 | scroll_parent_target->SetMasksToBounds(true); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6639 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6640 | float device_scale_factor = 1.5f; |
| 6641 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6642 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 6643 | root, root->bounds(), identity_transform, |
| 6644 | &render_surface_layer_list_impl); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6645 | inputs.device_scale_factor = device_scale_factor; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 6646 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6647 | |
weiliangc | 1da3fb89 | 2016-03-14 20:23:52 | [diff] [blame] | 6648 | EXPECT_EQ(scroll_child->effect_tree_index(), |
| 6649 | scroll_child_target->effect_tree_index()); |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6650 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6651 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6652 | gfx::Transform scale; |
| 6653 | scale.Scale(1.5f, 1.5f); |
| 6654 | EXPECT_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6655 | } |
| 6656 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6657 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6658 | LayerImpl* root = root_layer(); |
| 6659 | root->SetDrawsContent(true); |
| 6660 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 6661 | parent->SetDrawsContent(true); |
| 6662 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 6663 | child->SetDrawsContent(true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6664 | |
| 6665 | gfx::Transform identity_transform; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6666 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6667 | gfx::PointF(), gfx::Size(50, 50), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6668 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6669 | SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(), |
| 6670 | gfx::PointF(), gfx::Size(30, 30), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6671 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6672 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6673 | gfx::PointF(), gfx::Size(20, 20), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6674 | true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6675 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6676 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6677 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6678 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6679 | |
| 6680 | gfx::Transform singular_transform; |
| 6681 | singular_transform.Scale3d( |
| 6682 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6683 | |
| 6684 | child->SetTransform(singular_transform); |
| 6685 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6686 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6687 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6688 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6689 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6690 | |
| 6691 | // Ensure that the entire subtree under a layer with singular transform does |
| 6692 | // not get rendered. |
| 6693 | parent->SetTransform(singular_transform); |
| 6694 | child->SetTransform(identity_transform); |
| 6695 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 6696 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6697 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6698 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6699 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6700 | } |
| 6701 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6702 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6703 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6704 | // still results in correct clipping. |
| 6705 | // |
| 6706 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6707 | // + scroll_parent_border |
| 6708 | // + scroll_parent_clip |
| 6709 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6710 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6711 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6712 | LayerImpl* root = root_layer(); |
| 6713 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6714 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6715 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6716 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6717 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6718 | scroll_parent->SetDrawsContent(true); |
| 6719 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6720 | |
| 6721 | scroll_parent_clip->SetMasksToBounds(true); |
| 6722 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6723 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6724 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6725 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6726 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6727 | scroll_parent->test_properties()->scroll_children.reset( |
| 6728 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6729 | |
| 6730 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6731 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6732 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6733 | true); |
| 6734 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6735 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6736 | true, false, false); |
| 6737 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6738 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6739 | true, false, false); |
| 6740 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6741 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6742 | true, false, false); |
| 6743 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6744 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6745 | false); |
| 6746 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6747 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6748 | |
| 6749 | EXPECT_TRUE(root->render_surface()); |
| 6750 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6751 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6752 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6753 | } |
| 6754 | |
| 6755 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6756 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6757 | // you in paint order still results in correct clipping. |
| 6758 | // |
| 6759 | // + root |
| 6760 | // + scroll_child |
| 6761 | // + scroll_parent_border |
| 6762 | // | + scroll_parent_clip |
| 6763 | // | + scroll_parent |
| 6764 | // + scroll_grandparent_border |
| 6765 | // + scroll_grandparent_clip |
| 6766 | // + scroll_grandparent |
| 6767 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6768 | LayerImpl* root = root_layer(); |
| 6769 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6770 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6771 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6772 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6773 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6774 | LayerImpl* scroll_grandparent_clip = |
| 6775 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6776 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6777 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6778 | scroll_parent->SetDrawsContent(true); |
| 6779 | scroll_grandparent->SetDrawsContent(true); |
| 6780 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6781 | |
| 6782 | scroll_parent_clip->SetMasksToBounds(true); |
| 6783 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6784 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6785 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6786 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6787 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6788 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6789 | scroll_parent->test_properties()->scroll_children.reset( |
| 6790 | scroll_children.release()); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6791 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6792 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6793 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6794 | scroll_children->insert(scroll_parent_border); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6795 | scroll_grandparent->test_properties()->scroll_children.reset( |
| 6796 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6797 | |
| 6798 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6799 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6800 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6801 | true); |
| 6802 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6803 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6804 | true, false, false); |
| 6805 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6806 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6807 | true, false, false); |
| 6808 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6809 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6810 | true, false, false); |
| 6811 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6812 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6813 | true, false, false); |
| 6814 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6815 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6816 | true, false, false); |
| 6817 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6818 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6819 | true, false, false); |
| 6820 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6821 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6822 | false); |
| 6823 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6824 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6825 | |
| 6826 | EXPECT_TRUE(root->render_surface()); |
| 6827 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6828 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6829 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6830 | |
| 6831 | // Despite the fact that we visited the above layers out of order to get the |
| 6832 | // correct clip, the layer lists should be unaffected. |
| 6833 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6834 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6835 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6836 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6837 | } |
| 6838 | |
| 6839 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6840 | // 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] | 6841 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6842 | // + root |
| 6843 | // + scroll_child |
| 6844 | // + scroll_parent_border |
| 6845 | // + scroll_parent_clip |
| 6846 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6847 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6848 | // + scroll_grandparent_border |
| 6849 | // + scroll_grandparent_clip |
| 6850 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6851 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6852 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6853 | LayerImpl* root = root_layer(); |
| 6854 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6855 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6856 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6857 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6858 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6859 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6860 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6861 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6862 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6863 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6864 | LayerImpl* scroll_grandparent_clip = |
| 6865 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6866 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6867 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6868 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6869 | scroll_parent->SetDrawsContent(true); |
| 6870 | render_surface1->SetDrawsContent(true); |
| 6871 | scroll_grandparent->SetDrawsContent(true); |
| 6872 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6873 | |
| 6874 | scroll_parent_clip->SetMasksToBounds(true); |
| 6875 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6876 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6877 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 6878 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 6879 | new std::set<LayerImpl*>); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6880 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6881 | scroll_parent->test_properties()->scroll_children.reset( |
| 6882 | scroll_children.release()); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6883 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6884 | scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent; |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6885 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6886 | scroll_children->insert(scroll_parent_border); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 6887 | scroll_grandparent->test_properties()->scroll_children.reset( |
| 6888 | scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6889 | |
| 6890 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6891 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6892 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6893 | true); |
| 6894 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6895 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6896 | true, false, false); |
| 6897 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6898 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6899 | true, false, false); |
| 6900 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6901 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6902 | true, false, false); |
| 6903 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6904 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6905 | true, false, true); |
| 6906 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6907 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6908 | true, false, false); |
| 6909 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6910 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6911 | true, false, false); |
| 6912 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6913 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6914 | true, false, false); |
| 6915 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6916 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6917 | true, false, true); |
| 6918 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6919 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6920 | false); |
| 6921 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6922 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6923 | |
| 6924 | EXPECT_TRUE(root->render_surface()); |
| 6925 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 6926 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6927 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6928 | |
| 6929 | // Despite the fact that we had to process the layers out of order to get the |
| 6930 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6931 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6932 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6933 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6934 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6935 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6936 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6937 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6938 | } |
| 6939 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6940 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6941 | // Ensures that when we have a render surface between a fixed position layer |
| 6942 | // and its container, we compute the fixed position layer's draw transform |
| 6943 | // with respect to that intervening render surface, not with respect to its |
| 6944 | // container's render target. |
| 6945 | // |
| 6946 | // + root |
| 6947 | // + render_surface |
| 6948 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6949 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6950 | // |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6951 | LayerImpl* root = root_layer(); |
| 6952 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 6953 | LayerImpl* fixed = AddChild<LayerImpl>(render_surface); |
| 6954 | LayerImpl* child = AddChild<LayerImpl>(fixed); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6955 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6956 | render_surface->SetDrawsContent(true); |
| 6957 | fixed->SetDrawsContent(true); |
| 6958 | child->SetDrawsContent(true); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6959 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 6960 | render_surface->test_properties()->force_render_surface = true; |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6961 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6962 | |
| 6963 | LayerPositionConstraint constraint; |
| 6964 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 6965 | fixed->test_properties()->position_constraint = constraint; |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6966 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6967 | SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6968 | gfx::PointF(), gfx::Size(50, 50), true, false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6969 | SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(), |
| 6970 | gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true, |
| 6971 | false); |
| 6972 | SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(), |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6973 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 6974 | false); |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6975 | SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(), |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6976 | gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, |
| 6977 | false); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6978 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6979 | ExecuteCalculateDrawProperties(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6980 | |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6981 | TransformTree& tree = |
| 6982 | host_impl()->active_tree()->property_trees()->transform_tree; |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6983 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6984 | gfx::Transform expected_fixed_draw_transform; |
| 6985 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6986 | EXPECT_EQ(expected_fixed_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6987 | draw_property_utils::DrawTransform(fixed, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6988 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6989 | gfx::Transform expected_fixed_screen_space_transform; |
| 6990 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
| 6991 | EXPECT_EQ(expected_fixed_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6992 | draw_property_utils::ScreenSpaceTransform(fixed, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6993 | |
| 6994 | gfx::Transform expected_child_draw_transform; |
| 6995 | expected_child_draw_transform.Translate(11.f, 17.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 6996 | EXPECT_EQ(expected_child_draw_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 6997 | draw_property_utils::DrawTransform(child, tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6998 | |
| 6999 | gfx::Transform expected_child_screen_space_transform; |
| 7000 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
| 7001 | EXPECT_EQ(expected_child_screen_space_transform, |
sunxd | fd920f3f | 2016-04-05 16:17:51 | [diff] [blame] | 7002 | draw_property_utils::ScreenSpaceTransform(child, tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7003 | } |
| 7004 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7005 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7006 | // This test verifies that a scrolling layer that gets snapped to |
| 7007 | // integer coordinates doesn't move a fixed position child. |
| 7008 | // |
| 7009 | // + root |
| 7010 | // + container |
| 7011 | // + scroller |
| 7012 | // + fixed |
| 7013 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7014 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7015 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7016 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7017 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7018 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7019 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7020 | std::unique_ptr<LayerImpl> root_ptr = |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7021 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7022 | LayerImpl* root = root_ptr.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7023 | std::unique_ptr<LayerImpl> container = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7024 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7025 | LayerImpl* container_layer = container.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7026 | std::unique_ptr<LayerImpl> scroller = |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7027 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7028 | LayerImpl* scroll_layer = scroller.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7029 | std::unique_ptr<LayerImpl> fixed = |
| 7030 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7031 | LayerImpl* fixed_layer = fixed.get(); |
| 7032 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 7033 | container->test_properties()->is_container_for_fixed_position_layers = true; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7034 | |
| 7035 | LayerPositionConstraint constraint; |
| 7036 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 7037 | fixed->test_properties()->position_constraint = constraint; |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7038 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7039 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7040 | |
| 7041 | gfx::Transform identity_transform; |
| 7042 | gfx::Transform container_transform; |
| 7043 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7044 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7045 | |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7046 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7047 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7048 | true); |
| 7049 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7050 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7051 | true, false, false); |
| 7052 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7053 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7054 | true, false, false); |
| 7055 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7056 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7057 | false); |
| 7058 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7059 | root->SetDrawsContent(true); |
| 7060 | container->SetDrawsContent(true); |
| 7061 | scroller->SetDrawsContent(true); |
| 7062 | fixed->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7063 | scroller->AddChild(std::move(fixed)); |
| 7064 | container->AddChild(std::move(scroller)); |
| 7065 | root->AddChild(std::move(container)); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7066 | |
| 7067 | // Rounded to integers already. |
| 7068 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7069 | root->layer_tree_impl()->SetRootLayer(std::move(root_ptr)); |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 7070 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7071 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7072 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7073 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7074 | |
| 7075 | LayerImplList render_surface_layer_list; |
| 7076 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7077 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7078 | root->layer_tree_impl() |
| 7079 | ->property_trees() |
| 7080 | ->transform_tree.set_source_to_parent_updates_allowed(false); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7081 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7082 | |
| 7083 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7084 | container_layer->draw_properties().screen_space_transform, |
| 7085 | fixed_layer->draw_properties().screen_space_transform); |
| 7086 | EXPECT_VECTOR_EQ( |
| 7087 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7088 | container_offset); |
| 7089 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7090 | .screen_space_transform.To2dTranslation(), |
| 7091 | container_offset - scroll_delta); |
| 7092 | } |
| 7093 | |
| 7094 | // Scroll delta requiring rounding. |
| 7095 | { |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 7096 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7097 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7098 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7099 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7100 | |
| 7101 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7102 | |
| 7103 | LayerImplList render_surface_layer_list; |
| 7104 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7105 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7106 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7107 | |
| 7108 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7109 | container_layer->draw_properties().screen_space_transform, |
| 7110 | fixed_layer->draw_properties().screen_space_transform); |
| 7111 | EXPECT_VECTOR_EQ( |
| 7112 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7113 | container_offset); |
| 7114 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7115 | .screen_space_transform.To2dTranslation(), |
| 7116 | container_offset - rounded_scroll_delta); |
| 7117 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7118 | |
| 7119 | // Scale is applied earlier in the tree. |
| 7120 | { |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7121 | SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7122 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7123 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7124 | container_layer->SetTransform(scaled_container_transform); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7125 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 4340ea0 | 2016-06-06 19:44:26 | [diff] [blame] | 7126 | root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7127 | |
| 7128 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7129 | SetScrollOffsetDelta(scroll_layer, scroll_delta); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7130 | |
| 7131 | LayerImplList render_surface_layer_list; |
| 7132 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7133 | root, root->bounds(), &render_surface_layer_list); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7134 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7135 | |
| 7136 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7137 | container_layer->draw_properties().screen_space_transform, |
| 7138 | fixed_layer->draw_properties().screen_space_transform); |
| 7139 | EXPECT_VECTOR_EQ( |
| 7140 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7141 | container_offset); |
| 7142 | |
| 7143 | container_layer->SetTransform(container_transform); |
| 7144 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7145 | } |
| 7146 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7147 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7148 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 7149 | // This test verifies that a scrolling layer whose screen space transform is |
| 7150 | // animating doesn't get snapped to integer coordinates. |
| 7151 | // |
| 7152 | // + root |
| 7153 | // + animated layer |
| 7154 | // + surface |
| 7155 | // + container |
| 7156 | // + scroller |
| 7157 | // |
| 7158 | LayerImpl* root = root_layer(); |
| 7159 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 7160 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 7161 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 7162 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
| 7163 | scroller->SetScrollClipLayer(container->id()); |
| 7164 | scroller->SetDrawsContent(true); |
| 7165 | |
| 7166 | gfx::Transform identity_transform; |
| 7167 | gfx::Transform start_scale; |
| 7168 | start_scale.Scale(1.5f, 1.5f); |
| 7169 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 7170 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7171 | true); |
| 7172 | SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(), |
| 7173 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7174 | false); |
| 7175 | SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(), |
| 7176 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7177 | true); |
| 7178 | SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(), |
| 7179 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7180 | false); |
| 7181 | SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(), |
| 7182 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 7183 | false); |
| 7184 | |
| 7185 | gfx::Transform end_scale; |
| 7186 | end_scale.Scale(2.f, 2.f); |
| 7187 | TransformOperations start_operations; |
| 7188 | start_operations.AppendMatrix(start_scale); |
| 7189 | TransformOperations end_operations; |
| 7190 | end_operations.AppendMatrix(end_scale); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7191 | AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(), |
| 7192 | 1.0, start_operations, end_operations); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7193 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
sunxd | b7e7943 | 2016-03-09 21:13:42 | [diff] [blame] | 7194 | SetScrollOffsetDelta(scroller, scroll_delta); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7195 | |
| 7196 | ExecuteCalculateDrawProperties(root); |
| 7197 | |
| 7198 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 7199 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7200 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7201 | } |
| 7202 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7203 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7204 | public: |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7205 | static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7206 | LayerTreeImpl* tree_impl, |
| 7207 | int id) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7208 | return base::WrapUnique( |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7209 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7210 | } |
| 7211 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7212 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7213 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7214 | private: |
| 7215 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7216 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7217 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7218 | SetDrawsContent(true); |
| 7219 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7220 | }; |
| 7221 | |
| 7222 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7223 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7224 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7225 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7226 | LayerTreeSettings settings = host()->settings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7227 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7228 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7229 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7230 | gfx::Transform identity_matrix; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7231 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7232 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7233 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7234 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7235 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7236 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7237 | std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7238 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7239 | |
| 7240 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7241 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7242 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7243 | AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get(); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7244 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7245 | child->AddChild(std::move(grand_child)); |
| 7246 | parent->AddChild(std::move(child)); |
| 7247 | grand_parent->AddChild(std::move(parent)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7248 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7249 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7250 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7251 | true, false, true); |
| 7252 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7253 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7254 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7255 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7256 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7257 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7258 | |
| 7259 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7260 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7261 | false); |
| 7262 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 7263 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
| 7264 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7265 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7266 | |
| 7267 | // No layers have animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7268 | EXPECT_EQ( |
| 7269 | 0.f, |
| 7270 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7271 | EXPECT_EQ(0.f, |
| 7272 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7273 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7274 | EXPECT_EQ( |
| 7275 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7276 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7277 | EXPECT_EQ( |
| 7278 | 0.f, |
| 7279 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7280 | EXPECT_EQ(0.f, |
| 7281 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7282 | EXPECT_EQ(0.f, |
| 7283 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7284 | EXPECT_EQ( |
| 7285 | 0.f, |
| 7286 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7287 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7288 | TransformOperations translation; |
| 7289 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7290 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7291 | scoped_refptr<AnimationTimeline> timeline; |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7292 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7293 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7294 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7295 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7296 | TransformOperations(), translation); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7297 | |
| 7298 | // No layers have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7299 | EXPECT_EQ( |
| 7300 | 0.f, |
| 7301 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7302 | EXPECT_EQ(0.f, |
| 7303 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7304 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7305 | EXPECT_EQ( |
| 7306 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7307 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7308 | EXPECT_EQ( |
| 7309 | 0.f, |
| 7310 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7311 | EXPECT_EQ(0.f, |
| 7312 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7313 | EXPECT_EQ(0.f, |
| 7314 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7315 | EXPECT_EQ( |
| 7316 | 0.f, |
| 7317 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7318 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7319 | TransformOperations scale; |
| 7320 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7321 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7322 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7323 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7324 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7325 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7326 | |
| 7327 | // Only |child| has a scale-affecting animation. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7328 | EXPECT_EQ( |
| 7329 | 0.f, |
| 7330 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7331 | EXPECT_EQ(0.f, |
| 7332 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7333 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7334 | EXPECT_EQ( |
| 7335 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7336 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7337 | EXPECT_EQ( |
| 7338 | 0.f, |
| 7339 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7340 | EXPECT_EQ(0.f, |
| 7341 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7342 | EXPECT_EQ(1.f, |
| 7343 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7344 | EXPECT_EQ( |
| 7345 | 1.f, |
| 7346 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7347 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7348 | AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7349 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7350 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7351 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7352 | |
| 7353 | // |grand_parent| and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7354 | EXPECT_EQ( |
| 7355 | 5.f, |
| 7356 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7357 | EXPECT_EQ(5.f, |
| 7358 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7359 | // We don't support combining animated scales from two nodes; 0.f means |
| 7360 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7361 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7362 | EXPECT_EQ( |
| 7363 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7364 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7365 | EXPECT_EQ( |
| 7366 | 1.f, |
| 7367 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7368 | EXPECT_EQ(1.f, |
| 7369 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7370 | EXPECT_EQ(0.f, |
| 7371 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7372 | EXPECT_EQ( |
| 7373 | 0.f, |
| 7374 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7375 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7376 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7377 | TransformOperations(), scale); |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7378 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7379 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7380 | |
| 7381 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7382 | EXPECT_EQ( |
| 7383 | 5.f, |
| 7384 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7385 | EXPECT_EQ(0.f, |
| 7386 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7387 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7388 | EXPECT_EQ( |
| 7389 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7390 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7391 | EXPECT_EQ( |
| 7392 | 1.f, |
| 7393 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7394 | EXPECT_EQ(0.f, |
| 7395 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7396 | EXPECT_EQ(0.f, |
| 7397 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7398 | EXPECT_EQ( |
| 7399 | 0.f, |
| 7400 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7401 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7402 | AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline, |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7403 | TargetProperty::TRANSFORM); |
| 7404 | AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline, |
| 7405 | TargetProperty::TRANSFORM); |
| 7406 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7407 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7408 | |
| 7409 | TransformOperations perspective; |
| 7410 | perspective.AppendPerspective(10.f); |
| 7411 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7412 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7413 | TransformOperations(), perspective); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7414 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7415 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7416 | |
| 7417 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7418 | // animation is not supported. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7419 | EXPECT_EQ( |
| 7420 | 0.f, |
| 7421 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7422 | EXPECT_EQ(0.f, |
| 7423 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7424 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7425 | EXPECT_EQ( |
| 7426 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7427 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7428 | EXPECT_EQ( |
| 7429 | 0.f, |
| 7430 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7431 | EXPECT_EQ(0.f, |
| 7432 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7433 | EXPECT_EQ(0.f, |
| 7434 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7435 | EXPECT_EQ( |
| 7436 | 0.f, |
| 7437 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7438 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7439 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7440 | TargetProperty::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7441 | gfx::Transform scale_matrix; |
| 7442 | scale_matrix.Scale(1.f, 2.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7443 | grand_parent_raw->SetTransform(scale_matrix); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7444 | parent_raw->SetTransform(scale_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7445 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7446 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7447 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7448 | TransformOperations(), scale); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7449 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7450 | |
| 7451 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7452 | // animation with maximum scale 5.f. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7453 | EXPECT_EQ( |
| 7454 | 0.f, |
| 7455 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7456 | EXPECT_EQ(10.f, |
| 7457 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7458 | EXPECT_EQ(10.f, |
| 7459 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 7460 | EXPECT_EQ( |
| 7461 | 10.f, |
| 7462 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7463 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7464 | EXPECT_EQ( |
| 7465 | 0.f, |
| 7466 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7467 | EXPECT_EQ(2.f, |
| 7468 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7469 | EXPECT_EQ(2.f, |
| 7470 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7471 | EXPECT_EQ( |
| 7472 | 2.f, |
| 7473 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7474 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7475 | gfx::Transform perspective_matrix; |
| 7476 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 7477 | child_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7478 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7479 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7480 | |
| 7481 | // |child| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7482 | EXPECT_EQ( |
| 7483 | 0.f, |
| 7484 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7485 | EXPECT_EQ(10.f, |
| 7486 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7487 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7488 | EXPECT_EQ( |
| 7489 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7490 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7491 | EXPECT_EQ( |
| 7492 | 0.f, |
| 7493 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7494 | EXPECT_EQ(2.f, |
| 7495 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7496 | EXPECT_EQ(0.f, |
| 7497 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7498 | EXPECT_EQ( |
| 7499 | 0.f, |
| 7500 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7501 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7502 | parent_raw->SetTransform(perspective_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7503 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7504 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7505 | |
| 7506 | // |parent| and |child| have transforms that are neither translations nor |
| 7507 | // scales. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7508 | EXPECT_EQ( |
| 7509 | 0.f, |
| 7510 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7511 | EXPECT_EQ(0.f, |
| 7512 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7513 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7514 | EXPECT_EQ( |
| 7515 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7516 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7517 | EXPECT_EQ( |
| 7518 | 0.f, |
| 7519 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7520 | EXPECT_EQ(0.f, |
| 7521 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7522 | EXPECT_EQ(0.f, |
| 7523 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7524 | EXPECT_EQ( |
| 7525 | 0.f, |
| 7526 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7527 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7528 | parent_raw->SetTransform(identity_matrix); |
| 7529 | child_raw->SetTransform(identity_matrix); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7530 | grand_parent_raw->SetTransform(perspective_matrix); |
| 7531 | grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7532 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7533 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7534 | |
| 7535 | // |grand_parent| has a transform that's neither a translation nor a scale. |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7536 | EXPECT_EQ( |
| 7537 | 0.f, |
| 7538 | grand_parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7539 | EXPECT_EQ(0.f, |
| 7540 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7541 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7542 | EXPECT_EQ( |
| 7543 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7544 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7545 | EXPECT_EQ( |
| 7546 | 0.f, |
| 7547 | grand_parent_raw->draw_properties().starting_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7548 | EXPECT_EQ(0.f, |
| 7549 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7550 | EXPECT_EQ(0.f, |
| 7551 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7552 | EXPECT_EQ( |
| 7553 | 0.f, |
| 7554 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7555 | } |
| 7556 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7557 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 7558 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7559 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7560 | end = LayerIterator::End(rsll); |
| 7561 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7562 | LayerImpl* layer = *it; |
| 7563 | if (it.represents_itself()) |
| 7564 | drawn_layers->insert(layer); |
| 7565 | |
| 7566 | if (!it.represents_contributing_render_surface()) |
| 7567 | continue; |
| 7568 | |
| 7569 | if (layer->mask_layer()) |
| 7570 | drawn_layers->insert(layer->mask_layer()); |
| 7571 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 7572 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 7573 | } |
| 7574 | } |
| 7575 | |
| 7576 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7577 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7578 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7579 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7580 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7581 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7582 | gfx::Transform identity_matrix; |
| 7583 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7584 | std::unique_ptr<LayerImpl> grand_parent = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7585 | LayerImpl::Create(host_impl.active_tree(), 1); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7586 | std::unique_ptr<LayerImpl> parent = |
| 7587 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7588 | std::unique_ptr<LayerImpl> child = |
| 7589 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7590 | std::unique_ptr<LayerImpl> grand_child1 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7591 | LayerImpl::Create(host_impl.active_tree(), 7); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7592 | std::unique_ptr<LayerImpl> grand_child2 = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7593 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7594 | |
| 7595 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7596 | LayerImpl* parent_raw = parent.get(); |
| 7597 | LayerImpl* child_raw = child.get(); |
| 7598 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7599 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7600 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7601 | child->AddChild(std::move(grand_child1)); |
| 7602 | child->AddChild(std::move(grand_child2)); |
| 7603 | parent->AddChild(std::move(child)); |
| 7604 | grand_parent->AddChild(std::move(parent)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7605 | host_impl.active_tree()->SetRootLayer(std::move(grand_parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7606 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7607 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 7608 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7609 | true, false, true); |
| 7610 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7611 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7612 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7613 | |
| 7614 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7615 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7616 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7617 | |
| 7618 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 7619 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7620 | true, false, false); |
| 7621 | |
| 7622 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 7623 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7624 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7625 | |
| 7626 | // Start with nothing being drawn. |
| 7627 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7628 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7629 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7630 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7631 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7632 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7633 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7634 | |
| 7635 | std::set<LayerImpl*> expected; |
| 7636 | std::set<LayerImpl*> actual; |
| 7637 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7638 | EXPECT_EQ(expected, actual); |
| 7639 | |
| 7640 | // If we force render surface, but none of the layers are in the layer list, |
| 7641 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7642 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7643 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7644 | |
| 7645 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7646 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7647 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7648 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7649 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7650 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7651 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7652 | |
| 7653 | expected.clear(); |
| 7654 | actual.clear(); |
| 7655 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7656 | EXPECT_EQ(expected, actual); |
| 7657 | |
| 7658 | // However, if we say that this layer also draws content, it will appear in |
| 7659 | // RSLL. |
| 7660 | grand_child1_raw->SetDrawsContent(true); |
| 7661 | |
| 7662 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7663 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7664 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7665 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7666 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7667 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7668 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7669 | |
| 7670 | expected.clear(); |
| 7671 | expected.insert(grand_child1_raw); |
| 7672 | |
| 7673 | actual.clear(); |
| 7674 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7675 | EXPECT_EQ(expected, actual); |
| 7676 | |
| 7677 | // Now child is forced to have a render surface, and one if its children draws |
| 7678 | // content. |
| 7679 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7680 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7681 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7682 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7683 | grand_child2_raw->SetDrawsContent(true); |
| 7684 | |
| 7685 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7686 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7687 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7688 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7689 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7690 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7691 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7692 | |
| 7693 | expected.clear(); |
| 7694 | expected.insert(grand_child2_raw); |
| 7695 | |
| 7696 | actual.clear(); |
| 7697 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7698 | EXPECT_EQ(expected, actual); |
| 7699 | |
| 7700 | // Add a mask layer to child. |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7701 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7702 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7703 | |
| 7704 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7705 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7706 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7707 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7708 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7709 | EXPECT_TRUE( |
| 7710 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7711 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7712 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7713 | |
| 7714 | expected.clear(); |
| 7715 | expected.insert(grand_child2_raw); |
| 7716 | expected.insert(child_raw->mask_layer()); |
| 7717 | |
| 7718 | expected.clear(); |
| 7719 | expected.insert(grand_child2_raw); |
| 7720 | expected.insert(child_raw->mask_layer()); |
| 7721 | |
| 7722 | actual.clear(); |
| 7723 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7724 | EXPECT_EQ(expected, actual); |
| 7725 | |
| 7726 | // Add replica mask layer. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7727 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7728 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 7729 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7730 | child_raw->SetReplicaLayer(std::move(replica_layer)); |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 7731 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7732 | |
| 7733 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7734 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7735 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7736 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7737 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7738 | EXPECT_TRUE( |
| 7739 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7740 | EXPECT_TRUE(child_raw->replica_layer() |
| 7741 | ->mask_layer() |
| 7742 | ->is_drawn_render_surface_layer_list_member()); |
| 7743 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7744 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7745 | |
| 7746 | expected.clear(); |
| 7747 | expected.insert(grand_child2_raw); |
| 7748 | expected.insert(child_raw->mask_layer()); |
| 7749 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 7750 | |
| 7751 | actual.clear(); |
| 7752 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7753 | EXPECT_EQ(expected, actual); |
| 7754 | |
| 7755 | child_raw->TakeReplicaLayer(); |
| 7756 | |
| 7757 | // With nothing drawing, we should have no layers. |
| 7758 | grand_child2_raw->SetDrawsContent(false); |
| 7759 | |
| 7760 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7761 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7762 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7763 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7764 | EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7765 | EXPECT_FALSE( |
| 7766 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7767 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7768 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7769 | |
| 7770 | expected.clear(); |
| 7771 | actual.clear(); |
| 7772 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7773 | EXPECT_EQ(expected, actual); |
| 7774 | |
| 7775 | // Child itself draws means that we should have the child and the mask in the |
| 7776 | // list. |
| 7777 | child_raw->SetDrawsContent(true); |
| 7778 | |
| 7779 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7780 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7781 | EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7782 | EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7783 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7784 | EXPECT_TRUE( |
| 7785 | child_raw->mask_layer()->is_drawn_render_surface_layer_list_member()); |
| 7786 | EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7787 | EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7788 | |
| 7789 | expected.clear(); |
| 7790 | expected.insert(child_raw); |
| 7791 | expected.insert(child_raw->mask_layer()); |
| 7792 | actual.clear(); |
| 7793 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7794 | EXPECT_EQ(expected, actual); |
| 7795 | |
| 7796 | child_raw->TakeMaskLayer(); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7797 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7798 | |
| 7799 | // Now everyone's a member! |
| 7800 | grand_parent_raw->SetDrawsContent(true); |
| 7801 | parent_raw->SetDrawsContent(true); |
| 7802 | child_raw->SetDrawsContent(true); |
| 7803 | grand_child1_raw->SetDrawsContent(true); |
| 7804 | grand_child2_raw->SetDrawsContent(true); |
| 7805 | |
| 7806 | ExecuteCalculateDrawProperties(grand_parent_raw); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7807 | |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7808 | EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7809 | EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member()); |
| 7810 | EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member()); |
| 7811 | EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member()); |
| 7812 | EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member()); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7813 | |
| 7814 | expected.clear(); |
| 7815 | expected.insert(grand_parent_raw); |
| 7816 | expected.insert(parent_raw); |
| 7817 | expected.insert(child_raw); |
| 7818 | expected.insert(grand_child1_raw); |
| 7819 | expected.insert(grand_child2_raw); |
| 7820 | |
| 7821 | actual.clear(); |
| 7822 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7823 | EXPECT_EQ(expected, actual); |
| 7824 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7825 | |
| 7826 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7827 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7828 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7829 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7830 | LayerTreeSettings settings = host()->settings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7831 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7832 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7833 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7834 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7835 | std::unique_ptr<LayerImpl> root = |
| 7836 | LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7837 | LayerImpl* root_layer = root.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7838 | std::unique_ptr<LayerImpl> child1 = |
| 7839 | LayerImpl::Create(host_impl.active_tree(), 2); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7840 | LayerImpl* child1_layer = child1.get(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7841 | std::unique_ptr<LayerImpl> child2 = |
| 7842 | LayerImpl::Create(host_impl.active_tree(), 3); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7843 | LayerImpl* child2_layer = child2.get(); |
| 7844 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7845 | root->AddChild(std::move(child1)); |
| 7846 | root->AddChild(std::move(child2)); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 7847 | root->test_properties()->force_render_surface = true; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7848 | root->SetDrawsContent(true); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7849 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7850 | |
| 7851 | gfx::Transform identity_matrix, scale_transform_child1, |
| 7852 | scale_transform_child2; |
| 7853 | scale_transform_child1.Scale(2, 3); |
| 7854 | scale_transform_child2.Scale(4, 5); |
| 7855 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7856 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 7857 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 7858 | true); |
| 7859 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7860 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7861 | true, false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7862 | |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7863 | child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7864 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7865 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 7866 | std::unique_ptr<LayerImpl> replica_layer = |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7867 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7868 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7869 | child1_layer->SetReplicaLayer(std::move(replica_layer)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7870 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7871 | |
| 7872 | ExecuteCalculateDrawProperties(root_layer); |
| 7873 | |
| 7874 | TransformOperations scale; |
| 7875 | scale.AppendScale(5.f, 8.f, 3.f); |
| 7876 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7877 | scoped_refptr<AnimationTimeline> timeline = |
| 7878 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7879 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7880 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 7881 | AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0, |
| 7882 | TransformOperations(), scale); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7883 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7884 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7885 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7886 | true, false, false); |
| 7887 | child2_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7888 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7889 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7890 | ExecuteCalculateDrawProperties(root_layer); |
| 7891 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7892 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 7893 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
| 7894 | EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
| 7895 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7896 | |
| 7897 | EXPECT_FLOAT_EQ( |
| 7898 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7899 | EXPECT_FLOAT_EQ( |
| 7900 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7901 | EXPECT_FLOAT_EQ(0.f, |
| 7902 | child1_layer->mask_layer() |
| 7903 | ->draw_properties() |
| 7904 | .maximum_animation_contents_scale); |
| 7905 | EXPECT_FLOAT_EQ(0.f, |
| 7906 | child1_layer->replica_layer() |
| 7907 | ->mask_layer() |
| 7908 | ->draw_properties() |
| 7909 | .maximum_animation_contents_scale); |
| 7910 | EXPECT_FLOAT_EQ( |
| 7911 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7912 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7913 | // Changing page-scale would affect ideal_contents_scale and |
| 7914 | // maximum_animation_contents_scale. |
| 7915 | |
| 7916 | float page_scale_factor = 3.f; |
| 7917 | float device_scale_factor = 1.0f; |
| 7918 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7919 | gfx::Size device_viewport_size = |
| 7920 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 7921 | root_layer->bounds().height() * device_scale_factor); |
| 7922 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 7923 | root_layer, device_viewport_size, &render_surface_layer_list); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7924 | |
| 7925 | inputs.page_scale_factor = page_scale_factor; |
| 7926 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 7927 | inputs.page_scale_layer = root_layer; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7928 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7929 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7930 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 7931 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
| 7932 | EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7933 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7934 | 9.f, |
| 7935 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 7936 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7937 | |
| 7938 | EXPECT_FLOAT_EQ( |
| 7939 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7940 | EXPECT_FLOAT_EQ( |
| 7941 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7942 | EXPECT_FLOAT_EQ(0.f, |
| 7943 | child1_layer->mask_layer() |
| 7944 | ->draw_properties() |
| 7945 | .maximum_animation_contents_scale); |
| 7946 | EXPECT_FLOAT_EQ(0.f, |
| 7947 | child1_layer->replica_layer() |
| 7948 | ->mask_layer() |
| 7949 | ->draw_properties() |
| 7950 | .maximum_animation_contents_scale); |
| 7951 | EXPECT_FLOAT_EQ( |
| 7952 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 7953 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7954 | // Changing device-scale would affect ideal_contents_scale and |
| 7955 | // maximum_animation_contents_scale. |
| 7956 | |
| 7957 | device_scale_factor = 4.0f; |
| 7958 | inputs.device_scale_factor = device_scale_factor; |
| 7959 | inputs.can_adjust_raster_scales = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 7960 | root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 7961 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7962 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7963 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 7964 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
| 7965 | EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7966 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7967 | 36.f, |
| 7968 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 7969 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7970 | |
| 7971 | EXPECT_FLOAT_EQ( |
| 7972 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 7973 | EXPECT_FLOAT_EQ( |
| 7974 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 7975 | EXPECT_FLOAT_EQ(0.f, |
| 7976 | child1_layer->mask_layer() |
| 7977 | ->draw_properties() |
| 7978 | .maximum_animation_contents_scale); |
| 7979 | EXPECT_FLOAT_EQ(0.f, |
| 7980 | child1_layer->replica_layer() |
| 7981 | ->mask_layer() |
| 7982 | ->draw_properties() |
| 7983 | .maximum_animation_contents_scale); |
| 7984 | EXPECT_FLOAT_EQ( |
| 7985 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7986 | } |
| 7987 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7988 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7989 | LayerImpl* root = root_layer(); |
| 7990 | LayerImpl* clip = AddChild<LayerImpl>(root); |
| 7991 | LayerImpl* content = AddChild<LayerImpl>(clip); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 7992 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 7993 | const gfx::Transform identity_matrix; |
| 7994 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 7995 | gfx::PointF(), gfx::Size(768 / 2, 3000), true, |
| 7996 | false, true); |
| 7997 | SetLayerPropertiesForTesting(clip, identity_matrix, gfx::Point3F(), |
| 7998 | gfx::PointF(), gfx::Size(768 / 2, 10000), true, |
| 7999 | false, false); |
| 8000 | SetLayerPropertiesForTesting(content, identity_matrix, gfx::Point3F(), |
| 8001 | gfx::PointF(), gfx::Size(768 / 2, 10000), true, |
| 8002 | false, true); |
| 8003 | root->SetDrawsContent(true); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8004 | clip->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8005 | content->SetDrawsContent(true); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8006 | |
| 8007 | gfx::Size device_viewport_size(768, 582); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8008 | LayerImplList render_surface_layer_list_impl; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8009 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8010 | root, device_viewport_size, identity_matrix, |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8011 | &render_surface_layer_list_impl); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8012 | inputs.device_scale_factor = 2.f; |
| 8013 | inputs.page_scale_factor = 1.f; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8014 | inputs.page_scale_layer = NULL; |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8015 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8016 | |
| 8017 | // Layers in the root render surface have their visible content rect clipped |
| 8018 | // by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8019 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8020 | |
| 8021 | // Layers drawing to a child render surface should still have their visible |
| 8022 | // content rect clipped by the viewport. |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8023 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8024 | } |
| 8025 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8026 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8027 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8028 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8029 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8030 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8031 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8032 | |
| 8033 | // Set two layers: the root layer clips it's child, |
| 8034 | // the child draws its content. |
| 8035 | |
| 8036 | gfx::Size root_size = gfx::Size(300, 500); |
| 8037 | |
| 8038 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8039 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8040 | |
| 8041 | // Device viewport accomidated the root and the top controls. |
| 8042 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8043 | gfx::Transform identity_matrix; |
| 8044 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8045 | host_impl.SetViewportSize(device_viewport_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8046 | host_impl.active_tree()->SetRootLayer( |
| 8047 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8048 | |
| 8049 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8050 | SetLayerPropertiesForTesting(root, |
| 8051 | identity_matrix, |
| 8052 | gfx::Point3F(), |
| 8053 | gfx::PointF(), |
| 8054 | root_size, |
| 8055 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8056 | false, |
| 8057 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8058 | root->SetMasksToBounds(true); |
| 8059 | |
| 8060 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8061 | |
| 8062 | LayerImpl* sublayer = root->child_at(0); |
| 8063 | SetLayerPropertiesForTesting(sublayer, |
| 8064 | identity_matrix, |
| 8065 | gfx::Point3F(), |
| 8066 | gfx::PointF(), |
| 8067 | sublayer_size, |
| 8068 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8069 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8070 | false); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8071 | sublayer->SetDrawsContent(true); |
| 8072 | |
| 8073 | LayerImplList layer_impl_list; |
| 8074 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | 0adb590 | 2016-04-28 16:32:38 | [diff] [blame] | 8075 | root, device_viewport_size, &layer_impl_list); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8076 | |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8077 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8078 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8079 | |
| 8080 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
sunxd | b365de0 | 2016-04-28 20:32:57 | [diff] [blame] | 8081 | LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8082 | |
| 8083 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8084 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8085 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8086 | } |
| 8087 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8088 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8089 | scoped_refptr<Layer> root = Layer::Create(); |
| 8090 | scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
| 8091 | scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
| 8092 | scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
| 8093 | scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8094 | |
| 8095 | root->AddChild(inner_viewport_container_layer); |
| 8096 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8097 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8098 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8099 | |
| 8100 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8101 | inner_viewport_container_layer->id()); |
| 8102 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8103 | outer_viewport_container_layer->id()); |
| 8104 | |
| 8105 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8106 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8107 | |
| 8108 | host()->SetRootLayer(root); |
| 8109 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 8110 | outer_viewport_scroll_layer); |
| 8111 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8112 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8113 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8114 | |
| 8115 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8116 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8117 | |
| 8118 | LayerPositionConstraint fixed_to_right; |
| 8119 | fixed_to_right.set_is_fixed_position(true); |
| 8120 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8121 | |
| 8122 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8123 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8124 | |
| 8125 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8126 | |
| 8127 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8128 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8129 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8130 | |
| 8131 | LayerPositionConstraint fixed_to_left; |
| 8132 | fixed_to_left.set_is_fixed_position(true); |
| 8133 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8134 | |
| 8135 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8136 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8137 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8138 | |
| 8139 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8140 | |
| 8141 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8142 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8143 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8144 | } |
| 8145 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8146 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8147 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8148 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8149 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8150 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8151 | |
| 8152 | root->AddChild(animated); |
| 8153 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8154 | host()->SetRootLayer(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8155 | |
| 8156 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8157 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8158 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8159 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8160 | |
| 8161 | root->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8162 | root->SetForceRenderSurfaceForTesting(true); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8163 | animated->SetOpacity(0.f); |
| 8164 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8165 | AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f, |
| 8166 | 1.f, false); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8167 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8168 | |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8169 | EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8170 | } |
| 8171 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8172 | TEST_F(LayerTreeHostCommonTest, |
| 8173 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
| 8174 | const gfx::Transform identity_matrix; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8175 | scoped_refptr<Layer> root = Layer::Create(); |
| 8176 | scoped_refptr<Layer> clip = Layer::Create(); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8177 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8178 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8179 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8180 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8181 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8182 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8183 | |
| 8184 | root->AddChild(clip); |
| 8185 | clip->AddChild(animated); |
| 8186 | animated->AddChild(surface); |
| 8187 | surface->AddChild(descendant_of_animation); |
| 8188 | |
| 8189 | clip->SetMasksToBounds(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8190 | surface->SetForceRenderSurfaceForTesting(true); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8191 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8192 | host()->SetRootLayer(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8193 | |
| 8194 | gfx::Transform uninvertible_matrix; |
| 8195 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8196 | |
| 8197 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8198 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8199 | SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 8200 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8201 | SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix, |
| 8202 | gfx::Point3F(), gfx::PointF(), |
| 8203 | gfx::Size(120, 120), true, false); |
| 8204 | SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 8205 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8206 | SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix, |
| 8207 | gfx::Point3F(), gfx::PointF(), |
| 8208 | gfx::Size(200, 200), true, false); |
| 8209 | |
| 8210 | TransformOperations start_transform_operations; |
| 8211 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8212 | TransformOperations end_transform_operations; |
| 8213 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8214 | AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0, |
| 8215 | start_transform_operations, |
| 8216 | end_transform_operations); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8217 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8218 | |
| 8219 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8220 | // clipped target space, so is treated as fully visible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8221 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8222 | |
| 8223 | // The singular transform on |animated| is flattened when inherited by |
| 8224 | // |surface|, and this happens to make it invertible. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8225 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing()); |
| 8226 | EXPECT_EQ(gfx::Rect(2, 2), |
| 8227 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8228 | |
| 8229 | gfx::Transform zero_matrix; |
| 8230 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8231 | SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(), |
| 8232 | gfx::PointF(), gfx::Size(120, 120), true, false); |
| 8233 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8234 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8235 | |
| 8236 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8237 | // treated as having an empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8238 | EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8239 | |
| 8240 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8241 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8242 | // |surface| and layers that draw into it as having empty visible rect. |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8243 | EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing()); |
| 8244 | EXPECT_EQ(gfx::Rect(), |
| 8245 | descendant_of_animation->visible_layer_rect_for_testing()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8246 | } |
| 8247 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8248 | // Verify that having an animated filter (but no current filter, as these |
| 8249 | // are mutually exclusive) correctly creates a render surface. |
| 8250 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8251 | LayerImpl* root = root_layer(); |
| 8252 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8253 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8254 | |
| 8255 | gfx::Transform identity_transform; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8256 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8257 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8258 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8259 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8260 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8261 | gfx::PointF(), gfx::Size(50, 50), true, false); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8262 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8263 | AddAnimatedFilterToLayerWithPlayer(child->id(), timeline_impl(), 10.0, 0.1f, |
| 8264 | 0.2f); |
| 8265 | ExecuteCalculateDrawProperties(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8266 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8267 | EXPECT_TRUE(root->has_render_surface()); |
| 8268 | EXPECT_TRUE(child->has_render_surface()); |
| 8269 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8270 | |
| 8271 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8272 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8273 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8274 | |
| 8275 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8276 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8277 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8278 | } |
| 8279 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8280 | // Verify that having a filter animation with a delayed start time creates a |
| 8281 | // render surface. |
| 8282 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8283 | LayerImpl* root = root_layer(); |
| 8284 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8285 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8286 | |
| 8287 | gfx::Transform identity_transform; |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8288 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8289 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8290 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8291 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8292 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8293 | gfx::PointF(), gfx::Size(50, 50), true, false); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8294 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8295 | std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8296 | KeyframedFilterAnimationCurve::Create()); |
| 8297 | FilterOperations start_filters; |
| 8298 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8299 | FilterOperations end_filters; |
| 8300 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8301 | curve->AddKeyframe( |
| 8302 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8303 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8304 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8305 | std::unique_ptr<Animation> animation = |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8306 | Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8307 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8308 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8309 | |
ajuma | 4711f4b1 | 2016-05-16 18:48:32 | [diff] [blame] | 8310 | AddAnimationToLayerWithPlayer(child->id(), timeline_impl(), |
| 8311 | std::move(animation)); |
| 8312 | ExecuteCalculateDrawProperties(root); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8313 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8314 | EXPECT_TRUE(root->has_render_surface()); |
| 8315 | EXPECT_TRUE(child->has_render_surface()); |
| 8316 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8317 | |
| 8318 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8319 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8320 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8321 | |
| 8322 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8323 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8324 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8325 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8326 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8327 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8328 | } |
| 8329 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8330 | // Ensures that the property tree code accounts for offsets between fixed |
| 8331 | // position layers and their respective containers. |
| 8332 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8333 | LayerImpl* root = root_layer(); |
| 8334 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8335 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8336 | |
| 8337 | gfx::Transform identity_transform; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8338 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8339 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8340 | true); |
| 8341 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8342 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8343 | false, false); |
| 8344 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8345 | gfx::PointF(-1000, -1000), gfx::Size(50, 50), |
| 8346 | true, false, false); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8347 | |
| 8348 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8349 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8350 | LayerPositionConstraint constraint; |
| 8351 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8352 | grandchild->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8353 | grandchild->SetDrawsContent(true); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8354 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8355 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8356 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8357 | ExecuteCalculateDrawProperties(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8358 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8359 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8360 | } |
| 8361 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8362 | // Ensures that the property tree code accounts for offsets between fixed |
| 8363 | // position containers and their transform tree parents, when a fixed position |
| 8364 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8365 | // own transform tree node. |
| 8366 | TEST_F(LayerTreeHostCommonTest, |
| 8367 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8368 | LayerImpl* root = root_layer(); |
| 8369 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8370 | LayerImpl* grandchild = AddChild<LayerImpl>(child); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8371 | |
| 8372 | gfx::Transform identity_transform; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8373 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8374 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8375 | true); |
| 8376 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8377 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8378 | false, false); |
| 8379 | SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(), |
| 8380 | gfx::PointF(-1000, -1000), gfx::Size(50, 50), |
| 8381 | true, false, false); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8382 | |
| 8383 | root->SetMasksToBounds(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8384 | child->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8385 | LayerPositionConstraint constraint; |
| 8386 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8387 | grandchild->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8388 | grandchild->SetDrawsContent(true); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8389 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8390 | root->test_properties()->is_container_for_fixed_position_layers = true; |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8391 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8392 | ExecuteCalculateDrawProperties(root); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8393 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8394 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect()); |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8395 | } |
| 8396 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8397 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8398 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8399 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8400 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8401 | // test ensures that happens. |
| 8402 | |
| 8403 | gfx::Transform rotate; |
| 8404 | rotate.Rotate(5); |
| 8405 | gfx::Transform identity; |
| 8406 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8407 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8408 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8409 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8410 | false); |
| 8411 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8412 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8413 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8414 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8415 | false); |
| 8416 | frame_clip->SetMasksToBounds(true); |
| 8417 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8418 | scoped_refptr<Layer> rotated = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8419 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8420 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8421 | gfx::Size(2500, 500), true, false); |
| 8422 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8423 | scoped_refptr<Layer> surface = Layer::Create(); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8424 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8425 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8426 | false); |
| 8427 | surface->SetOpacity(0.5); |
| 8428 | |
| 8429 | scoped_refptr<LayerWithForcedDrawsContent> container = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8430 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8431 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8432 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8433 | |
| 8434 | scoped_refptr<LayerWithForcedDrawsContent> box = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8435 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8436 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8437 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8438 | |
| 8439 | root->AddChild(frame_clip); |
| 8440 | frame_clip->AddChild(rotated); |
| 8441 | rotated->AddChild(surface); |
| 8442 | surface->AddChild(container); |
| 8443 | surface->AddChild(box); |
| 8444 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8445 | host()->SetRootLayer(root); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8446 | |
| 8447 | ExecuteCalculateDrawProperties(root.get()); |
| 8448 | } |
| 8449 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8450 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8451 | LayerImpl* root = root_layer(); |
| 8452 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8453 | LayerImpl* fixed = AddChild<LayerImpl>(frame_clip); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8454 | gfx::Transform identity; |
| 8455 | gfx::Transform translate_z; |
| 8456 | translate_z.Translate3d(0, 0, 10); |
| 8457 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8458 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8459 | gfx::Size(800, 800), true, false, true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8460 | root->test_properties()->is_container_for_fixed_position_layers = true; |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8461 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8462 | SetLayerPropertiesForTesting(frame_clip, translate_z, gfx::Point3F(), |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8463 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8464 | false, false); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8465 | frame_clip->SetMasksToBounds(true); |
| 8466 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8467 | SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), gfx::PointF(), |
| 8468 | gfx::Size(1000, 1000), true, false, false); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8469 | |
| 8470 | LayerPositionConstraint constraint; |
| 8471 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8472 | fixed->test_properties()->position_constraint = constraint; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8473 | fixed->SetDrawsContent(true); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8474 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8475 | ExecuteCalculateDrawProperties(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8476 | |
| 8477 | gfx::Rect expected(0, 0, 100, 100); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8478 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8479 | } |
| 8480 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8481 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8482 | LayerImpl* root = root_layer(); |
| 8483 | LayerImpl* frame_clip = AddChild<LayerImpl>(root); |
| 8484 | LayerImpl* scroller = AddChild<LayerImpl>(frame_clip); |
| 8485 | LayerImpl* fixed = AddChild<LayerImpl>(scroller); |
| 8486 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8487 | gfx::Transform identity; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8488 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8489 | gfx::Size(800, 800), true, false, true); |
| 8490 | SetLayerPropertiesForTesting(frame_clip, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8491 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8492 | false, false); |
| 8493 | SetLayerPropertiesForTesting(scroller, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8494 | gfx::PointF(), gfx::Size(1000, 1000), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8495 | false, false); |
| 8496 | SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8497 | gfx::PointF(100, 100), gfx::Size(50, 50), true, |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8498 | false, true); |
| 8499 | |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8500 | root->test_properties()->is_container_for_fixed_position_layers = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8501 | root->SetDrawsContent(true); |
| 8502 | |
| 8503 | frame_clip->SetMasksToBounds(true); |
| 8504 | frame_clip->SetDrawsContent(true); |
| 8505 | |
| 8506 | scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8507 | scroller->SetScrollClipLayer(frame_clip->id()); |
| 8508 | scroller->SetDrawsContent(true); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8509 | |
| 8510 | LayerPositionConstraint constraint; |
| 8511 | constraint.set_is_fixed_position(true); |
jaydasika | ca2605e | 2016-04-23 02:52:52 | [diff] [blame] | 8512 | fixed->test_properties()->position_constraint = constraint; |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8513 | fixed->SetMasksToBounds(true); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8514 | fixed->SetDrawsContent(true); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8515 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8516 | ExecuteCalculateDrawProperties(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8517 | |
| 8518 | gfx::Rect expected(0, 0, 50, 50); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8519 | EXPECT_EQ(expected, fixed->visible_layer_rect()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8520 | } |
| 8521 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8522 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
| 8523 | gfx::Transform identity; |
| 8524 | gfx::Transform translate; |
| 8525 | gfx::Transform rotate; |
| 8526 | |
| 8527 | translate.Translate(10, 10); |
| 8528 | rotate.Rotate(45); |
| 8529 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8530 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8531 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8532 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8533 | root->SetIsContainerForFixedPositionLayers(true); |
| 8534 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8535 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8536 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8537 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8538 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8539 | |
| 8540 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8541 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8542 | |
| 8543 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8544 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8545 | } |
| 8546 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8547 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8548 | LayerImpl* root = root_layer(); |
| 8549 | LayerImpl* child = AddChild<LayerImpl>(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8550 | |
| 8551 | gfx::Transform identity_matrix; |
| 8552 | gfx::Transform scale_matrix; |
| 8553 | scale_matrix.Scale(2.f, 2.f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8554 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 8555 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8556 | true); |
| 8557 | SetLayerPropertiesForTesting(child, scale_matrix, gfx::Point3F(), |
| 8558 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8559 | false); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8560 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8561 | root->SetDrawsContent(true); |
| 8562 | child->SetDrawsContent(true); |
| 8563 | |
| 8564 | ExecuteCalculateDrawProperties(root); |
| 8565 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8566 | |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 8567 | child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8568 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8569 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8570 | ExecuteCalculateDrawProperties(root); |
| 8571 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8572 | } |
| 8573 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8574 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8575 | LayerImpl* root = root_layer(); |
| 8576 | LayerImpl* scroll_parent = AddChild<LayerImpl>(root); |
| 8577 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8578 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8579 | scroll_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8580 | scroll_child->test_properties()->scroll_parent = scroll_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8581 | std::unique_ptr<std::set<LayerImpl*>> scroll_children( |
| 8582 | new std::set<LayerImpl*>); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8583 | scroll_children->insert(scroll_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 8584 | scroll_parent->test_properties()->scroll_children.reset( |
| 8585 | scroll_children.release()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8586 | scroll_parent->SetDrawsContent(true); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8587 | |
| 8588 | gfx::Transform identity_transform; |
| 8589 | gfx::Transform scale; |
| 8590 | scale.Scale(2.f, 2.f); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8591 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 8592 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8593 | true); |
| 8594 | SetLayerPropertiesForTesting(scroll_child, scale, gfx::Point3F(), |
| 8595 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 8596 | false); |
| 8597 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8598 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8599 | true, false, false); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8600 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8601 | ExecuteCalculateDrawProperties(root); |
| 8602 | EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8603 | |
| 8604 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 8605 | scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
| 8606 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8607 | ExecuteCalculateDrawProperties(root); |
| 8608 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8609 | } |
| 8610 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8611 | static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8612 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8613 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8614 | // If the layer has a node in effect_tree, the return value of |
| 8615 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8616 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8617 | // to be the value of its nearest ancestor that owns an effect node and |
| 8618 | // greater than or equal to the actual number of copy requests in the |
| 8619 | // sub-layer_tree. |
| 8620 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8621 | scoped_refptr<Layer> root = Layer::Create(); |
| 8622 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 8623 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 8624 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8625 | scoped_refptr<Layer> greatgrandchild = Layer::Create(); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8626 | |
| 8627 | root->AddChild(child1); |
| 8628 | root->AddChild(child2); |
| 8629 | child1->AddChild(grandchild); |
| 8630 | grandchild->AddChild(greatgrandchild); |
| 8631 | host()->SetRootLayer(root); |
| 8632 | |
| 8633 | child1->RequestCopyOfOutput( |
| 8634 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8635 | greatgrandchild->RequestCopyOfOutput( |
| 8636 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8637 | child2->SetOpacity(0.f); |
| 8638 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8639 | |
| 8640 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8641 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8642 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8643 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8644 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8645 | } |
| 8646 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8647 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
| 8648 | gfx::Transform identity; |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8649 | scoped_refptr<Layer> root = Layer::Create(); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8650 | FakeContentLayerClient client; |
| 8651 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8652 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8653 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8654 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8655 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8656 | scoped_refptr<FakePictureLayer> greatgrandchild( |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 8657 | FakePictureLayer::Create(&client)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8658 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8659 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8660 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8661 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8662 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8663 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8664 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 8665 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8666 | |
| 8667 | root->AddChild(child); |
| 8668 | child->AddChild(grandchild); |
| 8669 | grandchild->AddChild(greatgrandchild); |
| 8670 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8671 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8672 | |
| 8673 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8674 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8675 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8676 | |
| 8677 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8678 | // and we will configure |child| in several ways that should force the subtree |
| 8679 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8680 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8681 | grandchild->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8682 | gfx::Transform singular; |
| 8683 | singular.matrix().set(0, 0, 0); |
| 8684 | |
| 8685 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8686 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8687 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8688 | child->SetTransform(identity); |
| 8689 | |
| 8690 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8691 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8692 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8693 | child->SetHideLayerAndSubtree(false); |
| 8694 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8695 | gfx::Transform zero_z_scale; |
| 8696 | zero_z_scale.Scale3d(1, 1, 0); |
| 8697 | child->SetTransform(zero_z_scale); |
| 8698 | |
| 8699 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8700 | // a singular transform, the subtree should still get processed. |
| 8701 | int animation_id = 0; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8702 | std::unique_ptr<Animation> animation = Animation::Create( |
| 8703 | std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8704 | animation_id, 1, TargetProperty::TRANSFORM); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8705 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8706 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8707 | AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8708 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8709 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8710 | grandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8711 | |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8712 | RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(), |
| 8713 | animation_id); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8714 | child->SetTransform(identity); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8715 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8716 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8717 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8718 | |
| 8719 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8720 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8721 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 8722 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8723 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8724 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8725 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8726 | greatgrandchild->set_visible_layer_rect(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8727 | |
| 8728 | // Add an opacity animation with a start delay. |
| 8729 | animation_id = 1; |
| 8730 | animation = Animation::Create( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8731 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
loyso | 0c8e440 | 2016-02-25 04:12:30 | [diff] [blame] | 8732 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 8733 | animation->set_fill_mode(Animation::FillMode::NONE); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8734 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 8735 | AddAnimationToLayerWithExistingPlayer(child->id(), timeline(), |
| 8736 | std::move(animation)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8737 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
jaydasika | 74bf516f | 2016-04-01 19:48:15 | [diff] [blame] | 8738 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8739 | } |
| 8740 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8741 | TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8742 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8743 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8744 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8745 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8746 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8747 | |
| 8748 | gfx::Transform identity; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8749 | std::unique_ptr<LayerImpl> root = |
| 8750 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8751 | std::unique_ptr<LayerImpl> child = |
| 8752 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8753 | std::unique_ptr<LayerImpl> grandchild = |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8754 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8755 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8756 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8757 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8758 | |
| 8759 | child->SetDrawsContent(true); |
| 8760 | grandchild->SetDrawsContent(true); |
| 8761 | greatgrandchild->SetDrawsContent(true); |
| 8762 | |
| 8763 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8764 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8765 | true); |
| 8766 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8767 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8768 | false); |
| 8769 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8770 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8771 | false); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8772 | |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8773 | LayerImpl* root_ptr = root.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8774 | LayerImpl* child_ptr = child.get(); |
| 8775 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8776 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8777 | child->AddChild(std::move(grandchild)); |
| 8778 | root->AddChild(std::move(child)); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8779 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8780 | |
| 8781 | // Check the non-skipped case. |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8782 | // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8783 | // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8784 | |
| 8785 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8786 | // and we will configure |child| in several ways that should force the subtree |
| 8787 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8788 | // remain empty. |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8789 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8790 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8791 | gfx::Transform singular; |
| 8792 | singular.matrix().set(0, 0, 0); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8793 | // This line is used to make the results of skipping and not skipping layers |
| 8794 | // different. |
| 8795 | singular.matrix().set(0, 1, 1); |
| 8796 | |
| 8797 | gfx::Transform rotate; |
| 8798 | rotate.Rotate(90); |
| 8799 | |
| 8800 | gfx::Transform rotate_back_and_translate; |
| 8801 | rotate_back_and_translate.RotateAboutYAxis(180); |
| 8802 | rotate_back_and_translate.Translate(-10, 0); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8803 | |
| 8804 | child_ptr->SetTransform(singular); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8805 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8806 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8807 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8808 | child_ptr->SetTransform(identity); |
| 8809 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8810 | child_ptr->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8811 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8812 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 8813 | child_ptr->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8814 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8815 | child_ptr->OnOpacityAnimated(0.f); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8816 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8817 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8818 | child_ptr->test_properties()->opacity = 1.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8819 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8820 | root_ptr->SetTransform(singular); |
| 8821 | // Force transform tree to have a node for child, so that ancestor's |
| 8822 | // invertible transform can be tested. |
| 8823 | child_ptr->SetTransform(rotate); |
| 8824 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8825 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8826 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
| 8827 | root_ptr->SetTransform(identity); |
| 8828 | child_ptr->SetTransform(identity); |
| 8829 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8830 | root_ptr->test_properties()->opacity = 0.f; |
| 8831 | child_ptr->test_properties()->opacity = 0.7f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8832 | host_impl.active_tree()->property_trees()->needs_rebuild = true; |
| 8833 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8834 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8835 | root_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8836 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8837 | child_ptr->test_properties()->opacity = 0.f; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8838 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8839 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8840 | // processed anyhow. |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8841 | grandchild_ptr->test_properties()->copy_requests.push_back( |
| 8842 | CopyOutputRequest::CreateEmptyRequest()); |
jaydasika | 2411692c | 2016-03-23 01:56:09 | [diff] [blame] | 8843 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8844 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 8845 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 8846 | |
| 8847 | host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests(); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 8848 | child_ptr->test_properties()->opacity = 1.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8849 | |
| 8850 | // A double sided render surface with backface visible should not be skipped |
| 8851 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8852 | child_ptr->SetHasRenderSurface(true); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 8853 | child_ptr->test_properties()->double_sided = true; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8854 | child_ptr->SetTransform(rotate_back_and_translate); |
| 8855 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8856 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8857 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8858 | child_ptr->SetTransform(identity); |
| 8859 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8860 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8861 | KeyframedTransformAnimationCurve::Create()); |
| 8862 | TransformOperations start; |
| 8863 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8864 | gfx::Transform transform; |
| 8865 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8866 | TransformOperations operation; |
| 8867 | operation.AppendMatrix(transform); |
| 8868 | curve->AddKeyframe( |
| 8869 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8870 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8871 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8872 | std::unique_ptr<Animation> transform_animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8873 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8874 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8875 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8876 | root_ptr->id(), player.get()); |
| 8877 | host_impl.active_tree() |
| 8878 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8879 | ->GetElementAnimationsForElementId(root_ptr->id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8880 | ->AddAnimation(std::move(transform_animation)); |
| 8881 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 8882 | child_ptr->SetScrollClipLayer(root_ptr->id()); |
| 8883 | root_ptr->SetTransform(singular); |
| 8884 | child_ptr->SetTransform(singular); |
| 8885 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 8886 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8887 | EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8888 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8889 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8890 | root_ptr->id(), player.get()); |
| 8891 | } |
| 8892 | |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8893 | TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { |
| 8894 | LayerImpl* root = root_layer(); |
| 8895 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 8896 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 8897 | |
| 8898 | gfx::Transform identity; |
| 8899 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 8900 | gfx::Size(10, 10), true, false, true); |
| 8901 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 8902 | gfx::Size(10, 10), true, false, false); |
| 8903 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 8904 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8905 | false); |
| 8906 | |
| 8907 | gfx::Transform singular; |
| 8908 | singular.matrix().set(0, 0, 0); |
| 8909 | singular.matrix().set(0, 1, 1); |
| 8910 | |
| 8911 | child->SetTransform(singular); |
| 8912 | child->SetDrawsContent(true); |
| 8913 | grand_child->SetDrawsContent(true); |
| 8914 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8915 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8916 | KeyframedTransformAnimationCurve::Create()); |
| 8917 | TransformOperations start; |
| 8918 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 8919 | gfx::Transform transform; |
| 8920 | transform.Scale3d(1.0, 2.0, 3.0); |
| 8921 | TransformOperations operation; |
| 8922 | operation.AppendMatrix(transform); |
| 8923 | curve->AddKeyframe( |
| 8924 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 8925 | curve->AddKeyframe(TransformKeyframe::Create( |
| 8926 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8927 | std::unique_ptr<Animation> transform_animation( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8928 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 8929 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8930 | host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8931 | grand_child->id(), player.get()); |
| 8932 | host_impl() |
| 8933 | ->active_tree() |
| 8934 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8935 | ->GetElementAnimationsForElementId(grand_child->id()) |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8936 | ->AddAnimation(std::move(transform_animation)); |
| 8937 | |
| 8938 | ExecuteCalculateDrawProperties(root); |
| 8939 | EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); |
| 8940 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
| 8941 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 8942 | host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( |
jaydasika | f187b06b | 2016-04-11 23:30:27 | [diff] [blame] | 8943 | grand_child->id(), player.get()); |
| 8944 | } |
| 8945 | |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8946 | TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { |
| 8947 | FakeImplTaskRunnerProvider task_runner_provider; |
| 8948 | TestSharedBitmapManager shared_bitmap_manager; |
| 8949 | TestTaskGraphRunner task_graph_runner; |
| 8950 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
| 8951 | &task_graph_runner); |
| 8952 | |
| 8953 | gfx::Transform identity; |
| 8954 | host_impl.CreatePendingTree(); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8955 | std::unique_ptr<LayerImpl> root = |
| 8956 | LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8957 | std::unique_ptr<LayerImpl> child = |
| 8958 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8959 | std::unique_ptr<LayerImpl> grandchild = |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8960 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8961 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8962 | std::unique_ptr<FakePictureLayerImpl> greatgrandchild( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8963 | FakePictureLayerImpl::Create(host_impl.pending_tree(), 4)); |
| 8964 | |
| 8965 | child->SetDrawsContent(true); |
| 8966 | grandchild->SetDrawsContent(true); |
| 8967 | greatgrandchild->SetDrawsContent(true); |
| 8968 | |
| 8969 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8970 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 8971 | true); |
| 8972 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8973 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8974 | false); |
| 8975 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8976 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 8977 | false); |
| 8978 | |
| 8979 | LayerImpl* root_ptr = root.get(); |
| 8980 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 8981 | |
| 8982 | child->AddChild(std::move(grandchild)); |
| 8983 | root->AddChild(std::move(child)); |
| 8984 | |
| 8985 | host_impl.pending_tree()->SetRootLayer(std::move(root)); |
| 8986 | |
| 8987 | // Check the non-skipped case. |
| 8988 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 8989 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 8990 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8991 | std::unique_ptr<KeyframedFloatAnimationCurve> curve( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8992 | KeyframedFloatAnimationCurve::Create()); |
loyso | 1e4e7ee | 2016-06-03 03:04:49 | [diff] [blame] | 8993 | std::unique_ptr<TimingFunction> func = |
| 8994 | CubicBezierTimingFunction::CreatePreset( |
| 8995 | CubicBezierTimingFunction::EaseType::EASE); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 8996 | curve->AddKeyframe( |
| 8997 | FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func))); |
| 8998 | curve->AddKeyframe( |
| 8999 | FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr)); |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9000 | std::unique_ptr<Animation> animation( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9001 | Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); |
| 9002 | scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9003 | host_impl.active_tree()->animation_host()->RegisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9004 | root_ptr->id(), player.get()); |
| 9005 | host_impl.active_tree() |
| 9006 | ->animation_host() |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9007 | ->GetElementAnimationsForElementId(root_ptr->id()) |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9008 | ->AddAnimation(std::move(animation)); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9009 | root_ptr->test_properties()->opacity = 0.f; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9010 | grandchild_ptr->set_visible_layer_rect(gfx::Rect()); |
| 9011 | root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9012 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr); |
| 9013 | EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); |
| 9014 | |
loyso | fb69174e | 2016-04-27 00:58:58 | [diff] [blame] | 9015 | host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9016 | root_ptr->id(), player.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9017 | } |
| 9018 | |
| 9019 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
| 9020 | gfx::Transform identity; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9021 | LayerImpl* root = root_layer(); |
| 9022 | LayerImpl* child = AddChild<LayerImpl>(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9023 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9024 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 9025 | gfx::Size(100, 100), true, false, true); |
| 9026 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 9027 | gfx::Size(10, 10), true, false, false); |
| 9028 | child->SetDrawsContent(true); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9029 | |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9030 | ExecuteCalculateDrawProperties(root); |
| 9031 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9032 | child->set_visible_layer_rect(gfx::Rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9033 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9034 | child->test_properties()->hide_layer_and_subtree = true; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9035 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9036 | ExecuteCalculateDrawProperties(root); |
| 9037 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9038 | child->test_properties()->hide_layer_and_subtree = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9039 | |
| 9040 | child->SetBounds(gfx::Size()); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9041 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9042 | ExecuteCalculateDrawProperties(root); |
| 9043 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9044 | child->SetBounds(gfx::Size(10, 10)); |
| 9045 | |
| 9046 | gfx::Transform rotate; |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9047 | child->test_properties()->double_sided = false; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9048 | rotate.RotateAboutXAxis(180.f); |
| 9049 | child->SetTransform(rotate); |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9050 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9051 | ExecuteCalculateDrawProperties(root); |
| 9052 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9053 | child->test_properties()->double_sided = true; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9054 | child->SetTransform(identity); |
| 9055 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9056 | child->test_properties()->opacity = 0.f; |
jaydasika | 6f972de | 2016-04-07 16:16:14 | [diff] [blame] | 9057 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9058 | ExecuteCalculateDrawProperties(root); |
| 9059 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9060 | } |
| 9061 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9062 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9063 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9064 | // PreCalculateMetaInformation happens when its required. |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9065 | scoped_refptr<Layer> root = Layer::Create(); |
| 9066 | scoped_refptr<Layer> parent = Layer::Create(); |
| 9067 | scoped_refptr<Layer> child = Layer::Create(); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9068 | |
| 9069 | root->AddChild(parent); |
| 9070 | parent->AddChild(child); |
| 9071 | |
| 9072 | child->SetClipParent(root.get()); |
| 9073 | |
| 9074 | gfx::Transform identity; |
| 9075 | |
| 9076 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9077 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9078 | SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(), |
| 9079 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9080 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9081 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9082 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9083 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9084 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9085 | child->RequestCopyOfOutput( |
| 9086 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9087 | |
| 9088 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9089 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9090 | |
| 9091 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 9092 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9093 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9094 | } |
| 9095 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9096 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
| 9097 | gfx::Transform identity; |
| 9098 | gfx::Transform translate_z; |
| 9099 | translate_z.Translate3d(0, 0, 10); |
| 9100 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9101 | scoped_refptr<Layer> root = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9102 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9103 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9104 | |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 9105 | scoped_refptr<Layer> child = Layer::Create(); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9106 | SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(), |
| 9107 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9108 | |
| 9109 | root->AddChild(child); |
| 9110 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9111 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9112 | |
| 9113 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9114 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9115 | |
| 9116 | child->RemoveFromParent(); |
| 9117 | |
| 9118 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9119 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9120 | } |
| 9121 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9122 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9123 | // Ensure that a Clip Node is added when a render surface applies clip. |
| 9124 | LayerImpl* root = root_layer(); |
| 9125 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9126 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9127 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9128 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9129 | |
| 9130 | const gfx::Transform identity_matrix; |
| 9131 | // This transform should be a significant one so that a transform node is |
| 9132 | // formed for it. |
| 9133 | gfx::Transform transform1; |
| 9134 | transform1.RotateAboutYAxis(45); |
| 9135 | transform1.RotateAboutXAxis(30); |
| 9136 | // This transform should be a 3d transform as we want the render surface |
| 9137 | // to flatten the transform |
| 9138 | gfx::Transform transform2; |
| 9139 | transform2.Translate3d(10, 10, 10); |
| 9140 | |
| 9141 | layer_clips_subtree->SetMasksToBounds(true); |
| 9142 | test_layer->SetDrawsContent(true); |
| 9143 | |
| 9144 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9145 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9146 | SetLayerPropertiesForTesting(significant_transform, transform1, |
| 9147 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9148 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9149 | SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix, |
| 9150 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9151 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9152 | SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9153 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9154 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9155 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9156 | |
jaydasika | 6b5a32bf | 2016-04-22 21:56:36 | [diff] [blame] | 9157 | root->test_properties()->force_render_surface = true; |
| 9158 | significant_transform->test_properties()->force_render_surface = false; |
| 9159 | layer_clips_subtree->test_properties()->force_render_surface = true; |
| 9160 | render_surface->test_properties()->force_render_surface = true; |
| 9161 | test_layer->test_properties()->force_render_surface = false; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9162 | ExecuteCalculateDrawProperties(root); |
| 9163 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9164 | TransformTree& transform_tree = |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9165 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9166 | TransformNode* transform_node = |
| 9167 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9168 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9169 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9170 | EXPECT_TRUE(root->has_render_surface()); |
| 9171 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9172 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9173 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9174 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9175 | |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 9176 | ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9177 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9178 | EXPECT_FALSE(clip_node->data.applies_local_clip); |
weiliangc | d1578443 | 2016-06-07 17:57:33 | [diff] [blame^] | 9179 | EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9180 | } |
| 9181 | |
| 9182 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9183 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9184 | // clip node's target, clip is 'projected' from parent space to current |
| 9185 | // target space and visible rects are calculated correctly. |
| 9186 | LayerImpl* root = root_layer(); |
| 9187 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9188 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9189 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9190 | |
| 9191 | const gfx::Transform identity_matrix; |
| 9192 | gfx::Transform transform; |
| 9193 | transform.RotateAboutYAxis(45); |
| 9194 | clip_layer->SetMasksToBounds(true); |
| 9195 | target_layer->SetMasksToBounds(true); |
| 9196 | test_layer->SetDrawsContent(true); |
| 9197 | |
| 9198 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9199 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9200 | true); |
| 9201 | SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(), |
| 9202 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9203 | false); |
| 9204 | SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), |
| 9205 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9206 | true); |
| 9207 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9208 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9209 | false); |
| 9210 | ExecuteCalculateDrawProperties(root); |
| 9211 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 9212 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9213 | } |
| 9214 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9215 | TEST_F(LayerTreeHostCommonTest, |
| 9216 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9217 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9218 | // descendants. |
| 9219 | LayerImpl* root = root_layer(); |
| 9220 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9221 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9222 | LayerImpl* render_surface = |
| 9223 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9224 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9225 | |
| 9226 | const gfx::Transform identity_matrix; |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9227 | gfx::Transform translate; |
| 9228 | translate.Translate(2.0, 2.0); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9229 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9230 | clip_parent->SetMasksToBounds(true); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9231 | test_layer->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9232 | render_surface->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9233 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | e9d0970 | 2015-09-15 01:26:41 | [diff] [blame] | 9234 | clip_children->insert(render_surface); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9235 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9236 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9237 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9238 | true); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9239 | SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(), |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9240 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9241 | false); |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9242 | SetLayerPropertiesForTesting(between_clip_parent_and_child, translate, |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9243 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 9244 | true, false, false); |
| 9245 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9246 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9247 | true); |
| 9248 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9249 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9250 | false); |
| 9251 | |
| 9252 | ExecuteCalculateDrawProperties(root); |
| 9253 | |
weiliangc | bb2e864 | 2016-03-04 00:24:42 | [diff] [blame] | 9254 | EXPECT_TRUE(test_layer->is_clipped()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 9255 | EXPECT_FALSE(test_layer->render_target()->is_clipped()); |
weiliangc | 0b41eaf | 2016-03-14 21:35:56 | [diff] [blame] | 9256 | EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect()); |
| 9257 | EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9258 | } |
| 9259 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9260 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9261 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9262 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9263 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9264 | // a clip. |
| 9265 | LayerImpl* root = root_layer(); |
| 9266 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9267 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9268 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9269 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9270 | |
| 9271 | const gfx::Transform identity_matrix; |
| 9272 | |
| 9273 | clip_child->SetDrawsContent(true); |
| 9274 | child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9275 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9276 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9277 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9278 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9279 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9280 | gfx::PointF(), gfx::Size(30, 10), true, false, |
| 9281 | true); |
| 9282 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9283 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9284 | false); |
| 9285 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9286 | gfx::PointF(), gfx::Size(10, 15), true, false, |
| 9287 | true); |
| 9288 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9289 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9290 | false); |
| 9291 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 9292 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 9293 | false); |
| 9294 | |
| 9295 | ExecuteCalculateDrawProperties(root); |
| 9296 | EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect()); |
| 9297 | } |
| 9298 | |
| 9299 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9300 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
| 9301 | LayerImpl* root = root_layer(); |
| 9302 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9303 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9304 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9305 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9306 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9307 | |
| 9308 | const gfx::Transform identity_matrix; |
| 9309 | root->SetMasksToBounds(true); |
| 9310 | render_surface->SetMasksToBounds(true); |
| 9311 | render_surface->SetDrawsContent(true); |
| 9312 | clip_child->SetDrawsContent(true); |
| 9313 | test_layer1->SetDrawsContent(true); |
| 9314 | test_layer2->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9315 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9316 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9317 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9318 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9319 | |
| 9320 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9321 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9322 | true); |
| 9323 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9324 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9325 | false); |
| 9326 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9327 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9328 | true); |
| 9329 | SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(), |
| 9330 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9331 | false); |
| 9332 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9333 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9334 | false); |
| 9335 | SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(), |
| 9336 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9337 | false); |
| 9338 | |
| 9339 | ExecuteCalculateDrawProperties(root); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9340 | EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect()); |
| 9341 | EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect()); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9342 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9343 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9344 | } |
| 9345 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9346 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
| 9347 | LayerImpl* root = root_layer(); |
| 9348 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9349 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9350 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9351 | |
| 9352 | const gfx::Transform identity_matrix; |
| 9353 | clip_parent->SetDrawsContent(true); |
| 9354 | render_surface->SetMasksToBounds(true); |
| 9355 | render_surface->SetDrawsContent(true); |
| 9356 | clip_child->SetDrawsContent(true); |
| 9357 | |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9358 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9359 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9360 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9361 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9362 | |
| 9363 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9364 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9365 | true); |
| 9366 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9367 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9368 | false); |
| 9369 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9370 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9371 | true); |
| 9372 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9373 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9374 | false); |
| 9375 | |
| 9376 | ExecuteCalculateDrawProperties(root); |
| 9377 | |
| 9378 | // The clip child should inherit its clip parent's clipping state, not its |
| 9379 | // tree parent's clipping state. |
| 9380 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9381 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9382 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9383 | } |
| 9384 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9385 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9386 | // Tests the value of render surface content rect when we have multiple types |
| 9387 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9388 | // clipped surfaces. |
| 9389 | LayerImpl* root = root_layer(); |
| 9390 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9391 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9392 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9393 | LayerImpl* unclipped_desc_surface2 = |
| 9394 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9395 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9396 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9397 | |
| 9398 | unclipped_surface->SetDrawsContent(true); |
| 9399 | unclipped_desc_surface->SetDrawsContent(true); |
| 9400 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9401 | clipped_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9402 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9403 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9404 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9405 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9406 | |
| 9407 | gfx::Transform identity_matrix; |
| 9408 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9409 | gfx::PointF(), gfx::Size(80, 80), true, false, |
| 9410 | true); |
| 9411 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 9412 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 9413 | true, false, true); |
| 9414 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9415 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9416 | false); |
| 9417 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9418 | gfx::Point3F(), gfx::PointF(), |
| 9419 | gfx::Size(100, 100), true, false, true); |
| 9420 | SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix, |
| 9421 | gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60), |
| 9422 | true, false, true); |
| 9423 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9424 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9425 | false); |
| 9426 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 9427 | gfx::PointF(), gfx::Size(70, 70), true, false, |
| 9428 | true); |
| 9429 | clip_parent->SetMasksToBounds(true); |
| 9430 | unclipped_surface->SetMasksToBounds(true); |
| 9431 | unclipped_desc_surface->SetMasksToBounds(true); |
| 9432 | |
| 9433 | ExecuteCalculateDrawProperties(root); |
| 9434 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9435 | unclipped_surface->render_surface()->content_rect()); |
weiliangc | 0e13ba60 | 2016-03-12 04:53:56 | [diff] [blame] | 9436 | EXPECT_EQ(gfx::Rect(50, 50), |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9437 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9438 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9439 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9440 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9441 | clipped_surface->render_surface()->content_rect()); |
| 9442 | } |
| 9443 | |
| 9444 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9445 | // Tests the value of render surface content rect when we have a layer that |
| 9446 | // clips between the clip parent's target and clip child's target. |
| 9447 | LayerImpl* root = root_layer(); |
| 9448 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9449 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9450 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9451 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9452 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9453 | |
| 9454 | clip_child->SetDrawsContent(true); |
| 9455 | unclipped_desc_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9456 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9457 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9458 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9459 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9460 | |
| 9461 | gfx::Transform identity_matrix; |
| 9462 | gfx::Transform translate; |
| 9463 | translate.Translate(10, 10); |
| 9464 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9465 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9466 | true); |
| 9467 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 9468 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9469 | true); |
| 9470 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9471 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9472 | false); |
| 9473 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9474 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9475 | false); |
| 9476 | SetLayerPropertiesForTesting(unclipped_desc_surface, translate, |
| 9477 | gfx::Point3F(), gfx::PointF(), |
| 9478 | gfx::Size(100, 100), true, false, true); |
| 9479 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9480 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9481 | false); |
| 9482 | surface->SetMasksToBounds(true); |
| 9483 | clip_layer->SetMasksToBounds(true); |
| 9484 | |
| 9485 | ExecuteCalculateDrawProperties(root); |
| 9486 | |
| 9487 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9488 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9489 | } |
| 9490 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9491 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
| 9492 | LayerImpl* root = root_layer(); |
| 9493 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9494 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9495 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9496 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9497 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9498 | |
| 9499 | clip_child->SetDrawsContent(true); |
| 9500 | unclipped_desc_surface->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9501 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9502 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9503 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9504 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9505 | |
| 9506 | gfx::Transform identity_matrix; |
| 9507 | gfx::Transform scale; |
| 9508 | scale.Scale(2, 2); |
| 9509 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9510 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9511 | true); |
| 9512 | SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(), |
| 9513 | gfx::Size(100, 100), true, false, true); |
| 9514 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9515 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9516 | false); |
| 9517 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9518 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9519 | false); |
| 9520 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9521 | gfx::Point3F(), gfx::PointF(), |
| 9522 | gfx::Size(100, 100), true, false, true); |
| 9523 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9524 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9525 | false); |
| 9526 | surface->SetMasksToBounds(true); |
| 9527 | clip_layer->SetMasksToBounds(true); |
| 9528 | |
| 9529 | ExecuteCalculateDrawProperties(root); |
| 9530 | |
| 9531 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9532 | } |
| 9533 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9534 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
| 9535 | LayerImpl* root = root_layer(); |
| 9536 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9537 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9538 | |
| 9539 | const gfx::Transform identity_matrix; |
| 9540 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9541 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9542 | true); |
| 9543 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9544 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9545 | true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9546 | gfx::Transform translation; |
| 9547 | translation.Translate(10, 10); |
| 9548 | SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(), |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9549 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9550 | false); |
| 9551 | |
| 9552 | render_surface->SetMasksToBounds(true); |
| 9553 | test_layer->SetDrawsContent(true); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 9554 | test_layer->test_properties()->opacity = 0.f; |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9555 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9556 | |
| 9557 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9558 | EXPECT_EQ(translation, test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9559 | } |
| 9560 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9561 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
| 9562 | LayerImpl* root = root_layer(); |
| 9563 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9564 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9565 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9566 | |
| 9567 | const gfx::Transform identity_matrix; |
| 9568 | clip_parent->SetMasksToBounds(true); |
| 9569 | render_surface->SetMasksToBounds(true); |
| 9570 | render_surface->SetDrawsContent(true); |
| 9571 | clip_child->SetDrawsContent(true); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9572 | clip_child->test_properties()->clip_parent = clip_parent; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9573 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9574 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9575 | clip_parent->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9576 | |
| 9577 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9578 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9579 | true); |
| 9580 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9581 | gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true, |
| 9582 | false, false); |
| 9583 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9584 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9585 | true); |
| 9586 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9587 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9588 | false); |
| 9589 | |
| 9590 | ExecuteCalculateDrawProperties(root); |
| 9591 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect()); |
| 9592 | } |
| 9593 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9594 | TEST_F(LayerTreeHostCommonTest, |
| 9595 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
| 9596 | LayerImpl* root = root_layer(); |
| 9597 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9598 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9599 | const gfx::Transform identity_matrix; |
| 9600 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9601 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9602 | true); |
| 9603 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9604 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9605 | true); |
| 9606 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9607 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9608 | false); |
| 9609 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9610 | root->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9611 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9612 | render_surface->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9613 | test_layer->SetMasksToBounds(true); |
| 9614 | test_layer->SetDrawsContent(true); |
| 9615 | ExecuteCalculateDrawProperties(root); |
| 9616 | |
| 9617 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9618 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9619 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9620 | } |
| 9621 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9622 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9623 | // Tests that subtree is hidden is updated. |
| 9624 | LayerImpl* root = root_layer(); |
| 9625 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9626 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9627 | |
| 9628 | const gfx::Transform identity_matrix; |
| 9629 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9630 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9631 | true); |
| 9632 | SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(), |
| 9633 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9634 | false, true); |
| 9635 | SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(), |
| 9636 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9637 | true); |
| 9638 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9639 | hidden->test_properties()->hide_layer_and_subtree = true; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9640 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9641 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9642 | |
jaydasika | 5121caa8 | 2016-05-05 15:43:35 | [diff] [blame] | 9643 | hidden->test_properties()->hide_layer_and_subtree = false; |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9644 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9645 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9646 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9647 | } |
| 9648 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9649 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
| 9650 | LayerImpl* root = root_layer(); |
| 9651 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9652 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9653 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9654 | |
| 9655 | const gfx::Transform identity_matrix; |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9656 | clip_child->test_properties()->clip_parent = root; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 9657 | std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9658 | clip_children->insert(clip_child); |
jaydasika | 1c0a27d4 | 2016-04-28 01:54:56 | [diff] [blame] | 9659 | root->test_properties()->clip_children.reset(clip_children.release()); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9660 | root->SetMasksToBounds(true); |
| 9661 | render_surface1->SetDrawsContent(true); |
| 9662 | render_surface2->SetDrawsContent(true); |
| 9663 | |
| 9664 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9665 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9666 | true); |
| 9667 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 9668 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9669 | false, true); |
| 9670 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9671 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9672 | true); |
| 9673 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9674 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9675 | false); |
| 9676 | ExecuteCalculateDrawProperties(root); |
| 9677 | |
| 9678 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9679 | // A clip node is created for every render surface and for layers that have |
| 9680 | // local clip. So, here it should be craeted for every layer. |
| 9681 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9682 | } |
| 9683 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9684 | TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) { |
| 9685 | // Tests that the mask layer gets its owning layer's screen space transform. |
| 9686 | LayerImpl* root = root_layer(); |
| 9687 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9688 | |
| 9689 | const gfx::Transform identity_matrix; |
| 9690 | gfx::Transform transform; |
| 9691 | transform.Translate(10, 10); |
| 9692 | |
| 9693 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9694 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9695 | true); |
| 9696 | SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(), |
| 9697 | gfx::Size(30, 30), true, false, false); |
| 9698 | root->SetDrawsContent(true); |
| 9699 | child->SetDrawsContent(false); |
| 9700 | child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9701 | ExecuteCalculateDrawProperties(root); |
| 9702 | |
| 9703 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9704 | child->mask_layer()->ScreenSpaceTransform()); |
| 9705 | transform.Translate(10, 10); |
| 9706 | child->SetTransform(transform); |
| 9707 | child->SetDrawsContent(true); |
| 9708 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9709 | ExecuteCalculateDrawProperties(root); |
| 9710 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9711 | child->mask_layer()->ScreenSpaceTransform()); |
| 9712 | } |
| 9713 | |
jaydasika | f62311f | 2016-04-20 14:38:45 | [diff] [blame] | 9714 | TEST_F(LayerTreeHostCommonTest, |
| 9715 | SublayerScaleWithTransformNodeBetweenTwoTargets) { |
| 9716 | LayerImpl* root = root_layer(); |
| 9717 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9718 | LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1); |
| 9719 | LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets); |
| 9720 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2); |
| 9721 | const gfx::Transform identity_matrix; |
| 9722 | test_layer->SetDrawsContent(true); |
| 9723 | |
| 9724 | gfx::Transform scale; |
| 9725 | scale.Scale(2.f, 2.f); |
| 9726 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9727 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9728 | true); |
| 9729 | SetLayerPropertiesForTesting(render_surface1, scale, gfx::Point3F(), |
| 9730 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9731 | true); |
| 9732 | SetLayerPropertiesForTesting(between_targets, identity_matrix, gfx::Point3F(), |
| 9733 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9734 | false); |
| 9735 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9736 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9737 | true); |
| 9738 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9739 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9740 | false); |
| 9741 | // We want layer between the two targets to create a clip node and transform |
| 9742 | // node but it shouldn't create a render surface. |
| 9743 | between_targets->SetMasksToBounds(true); |
| 9744 | between_targets->Set3dSortingContextId(2); |
| 9745 | |
| 9746 | ExecuteCalculateDrawProperties(root); |
| 9747 | |
| 9748 | TransformTree& tree = |
| 9749 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9750 | TransformNode* node = tree.Node(render_surface1->transform_tree_index()); |
| 9751 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f)); |
| 9752 | |
| 9753 | node = tree.Node(between_targets->transform_tree_index()); |
| 9754 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); |
| 9755 | |
| 9756 | node = tree.Node(render_surface2->transform_tree_index()); |
| 9757 | EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f)); |
| 9758 | |
| 9759 | EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); |
| 9760 | } |
| 9761 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9762 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
| 9763 | LayerImpl* root = root_layer(); |
| 9764 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9765 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9766 | |
| 9767 | const gfx::Transform identity_matrix; |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9768 | child->SetDrawsContent(true); |
| 9769 | child->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9770 | |
| 9771 | gfx::Transform large_transform; |
| 9772 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9773 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9774 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9775 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9776 | |
| 9777 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9778 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9779 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9780 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9781 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9782 | true); |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9783 | // TODO(sunxd): we make child have no render surface, because if the |
| 9784 | // child has one, the large transform applied to child will result in NaNs in |
| 9785 | // the draw_transform of the render_surface, thus make draw property updates |
| 9786 | // skip the child layer. We need further investigation into this to know |
| 9787 | // what exactly happens here. |
| 9788 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9789 | gfx::PointF(), gfx::Size(30, 30), true, false, |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9790 | false); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9791 | |
| 9792 | ExecuteCalculateDrawProperties(root); |
| 9793 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9794 | EXPECT_EQ(gfx::RectF(), |
sunxd | 71aea3e | 2016-04-01 23:48:05 | [diff] [blame] | 9795 | render_surface1->render_surface()->DrawableContentRect()); |
| 9796 | |
| 9797 | bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) || |
| 9798 | std::isnan(child->DrawTransform().matrix().get(0, 0)); |
| 9799 | EXPECT_TRUE(is_inf_or_nan); |
| 9800 | |
| 9801 | is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
| 9802 | std::isnan(child->DrawTransform().matrix().get(1, 1)); |
| 9803 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9804 | |
| 9805 | std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); |
| 9806 | bool root_in_rsll = |
| 9807 | std::find(rsll->begin(), rsll->end(), root) != rsll->end(); |
| 9808 | EXPECT_TRUE(root_in_rsll); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9809 | } |
| 9810 | |
jaydasika | 8d6efe2e | 2016-05-17 15:37:21 | [diff] [blame] | 9811 | TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) { |
| 9812 | const gfx::Transform identity_matrix; |
| 9813 | scoped_refptr<Layer> root = Layer::Create(); |
| 9814 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9815 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9816 | root->AddChild(child); |
| 9817 | |
| 9818 | host()->SetRootLayer(root); |
| 9819 | |
| 9820 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9821 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9822 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 9823 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9824 | |
| 9825 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9826 | |
| 9827 | // Changing the opacity from 1 to non-1 value should trigger rebuild of |
| 9828 | // property trees as a new effect node will be created. |
| 9829 | child->SetOpacity(0.5f); |
| 9830 | PropertyTrees* property_trees = host()->property_trees(); |
| 9831 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9832 | |
| 9833 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9834 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9835 | property_trees->effect_id_to_index_map.end()); |
| 9836 | |
| 9837 | // child already has an effect node. Changing its opacity shouldn't trigger |
| 9838 | // a property trees rebuild. |
| 9839 | child->SetOpacity(0.8f); |
| 9840 | property_trees = host()->property_trees(); |
| 9841 | EXPECT_FALSE(property_trees->needs_rebuild); |
| 9842 | |
| 9843 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9844 | EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()), |
| 9845 | property_trees->effect_id_to_index_map.end()); |
| 9846 | |
| 9847 | // Changing the opacity from non-1 value to 1 should trigger a rebuild of |
| 9848 | // property trees as the effect node may no longer be needed. |
| 9849 | child->SetOpacity(1.f); |
| 9850 | property_trees = host()->property_trees(); |
| 9851 | EXPECT_TRUE(property_trees->needs_rebuild); |
| 9852 | |
| 9853 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9854 | EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()), |
| 9855 | property_trees->effect_id_to_index_map.end()); |
| 9856 | } |
| 9857 | |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9858 | TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
| 9859 | const gfx::Transform identity_matrix; |
| 9860 | scoped_refptr<Layer> root = Layer::Create(); |
| 9861 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9862 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9863 | root->AddChild(animated); |
| 9864 | |
| 9865 | host()->SetRootLayer(root); |
| 9866 | |
| 9867 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9868 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9869 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 9870 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9871 | |
| 9872 | root->SetForceRenderSurfaceForTesting(true); |
| 9873 | animated->SetOpacity(0.f); |
| 9874 | |
| 9875 | scoped_refptr<AnimationPlayer> player = |
| 9876 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9877 | timeline()->AttachPlayer(player); |
| 9878 | player->AttachElement(animated->id()); |
| 9879 | |
| 9880 | int animation_id = 0; |
| 9881 | std::unique_ptr<Animation> animation = Animation::Create( |
| 9882 | std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9883 | animation_id, 1, TargetProperty::OPACITY); |
loyso | c255f27 | 2016-05-18 02:53:55 | [diff] [blame] | 9884 | animation->set_fill_mode(Animation::FillMode::NONE); |
jaydasika | 9cb21c77 | 2016-05-10 22:37:08 | [diff] [blame] | 9885 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9886 | Animation* animation_ptr = animation.get(); |
| 9887 | AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(), |
| 9888 | std::move(animation)); |
| 9889 | |
| 9890 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9891 | |
| 9892 | EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
| 9893 | EffectNode* node = tree.Node(animated->effect_tree_index()); |
| 9894 | EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9895 | EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9896 | |
| 9897 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9898 | root->layer_tree_host()->AnimateLayers( |
| 9899 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9900 | node = tree.Node(animated->effect_tree_index()); |
| 9901 | EXPECT_TRUE(node->data.is_currently_animating_opacity); |
| 9902 | EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9903 | |
| 9904 | player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9905 | node = tree.Node(animated->effect_tree_index()); |
| 9906 | EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9907 | EXPECT_FALSE(node->data.has_potential_opacity_animation); |
| 9908 | } |
| 9909 | |
jaydasika | 6c3404e9 | 2016-05-19 02:40:36 | [diff] [blame] | 9910 | TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { |
| 9911 | const gfx::Transform identity_matrix; |
| 9912 | scoped_refptr<Layer> root = Layer::Create(); |
| 9913 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9914 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9915 | root->AddChild(animated); |
| 9916 | |
| 9917 | host()->SetRootLayer(root); |
| 9918 | |
| 9919 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9920 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9921 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 9922 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9923 | |
| 9924 | root->SetForceRenderSurfaceForTesting(true); |
| 9925 | |
| 9926 | scoped_refptr<AnimationPlayer> player = |
| 9927 | AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9928 | timeline()->AttachPlayer(player); |
| 9929 | player->AttachElement(animated->id()); |
| 9930 | |
| 9931 | std::unique_ptr<KeyframedTransformAnimationCurve> curve( |
| 9932 | KeyframedTransformAnimationCurve::Create()); |
| 9933 | TransformOperations start; |
| 9934 | start.AppendTranslate(1.f, 2.f, 3.f); |
| 9935 | gfx::Transform transform; |
| 9936 | transform.Scale3d(1.0, 2.0, 3.0); |
| 9937 | TransformOperations operation; |
| 9938 | operation.AppendMatrix(transform); |
| 9939 | curve->AddKeyframe( |
| 9940 | TransformKeyframe::Create(base::TimeDelta(), start, nullptr)); |
| 9941 | curve->AddKeyframe(TransformKeyframe::Create( |
| 9942 | base::TimeDelta::FromSecondsD(1.0), operation, nullptr)); |
| 9943 | std::unique_ptr<Animation> animation( |
| 9944 | Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); |
| 9945 | animation->set_fill_mode(Animation::FillMode::NONE); |
| 9946 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9947 | Animation* animation_ptr = animation.get(); |
| 9948 | AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(), |
| 9949 | std::move(animation)); |
| 9950 | |
| 9951 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9952 | |
| 9953 | TransformTree& tree = |
| 9954 | root->layer_tree_host()->property_trees()->transform_tree; |
| 9955 | TransformNode* node = tree.Node(animated->transform_tree_index()); |
| 9956 | EXPECT_FALSE(node->data.is_currently_animating); |
| 9957 | EXPECT_TRUE(node->data.has_potential_animation); |
| 9958 | |
| 9959 | animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9960 | root->layer_tree_host()->AnimateLayers( |
| 9961 | base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9962 | node = tree.Node(animated->transform_tree_index()); |
| 9963 | EXPECT_TRUE(node->data.is_currently_animating); |
| 9964 | EXPECT_TRUE(node->data.has_potential_animation); |
| 9965 | |
| 9966 | player->AbortAnimations(TargetProperty::TRANSFORM, |
| 9967 | false /*needs_completion*/); |
| 9968 | node = tree.Node(animated->transform_tree_index()); |
| 9969 | EXPECT_FALSE(node->data.is_currently_animating); |
| 9970 | EXPECT_FALSE(node->data.has_potential_animation); |
| 9971 | } |
| 9972 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9973 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9974 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9975 | scroll.layer_id = 2; |
| 9976 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9977 | |
| 9978 | proto::ScrollUpdateInfo proto; |
| 9979 | scroll.ToProtobuf(&proto); |
| 9980 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9981 | new_scroll.FromProtobuf(proto); |
| 9982 | |
| 9983 | EXPECT_EQ(scroll, new_scroll); |
| 9984 | } |
| 9985 | |
| 9986 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9987 | ScrollAndScaleSet scroll_and_scale_set; |
| 9988 | |
| 9989 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9990 | scroll1.layer_id = 1; |
| 9991 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9992 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9993 | scroll2.layer_id = 2; |
| 9994 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9995 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9996 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9997 | |
| 9998 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9999 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 10000 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 10001 | |
| 10002 | proto::ScrollAndScaleSet proto; |
| 10003 | scroll_and_scale_set.ToProtobuf(&proto); |
| 10004 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 10005 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 10006 | |
| 10007 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 10008 | } |
| 10009 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10010 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 10011 | // Test the behavior of scroll tree builder |
| 10012 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10013 | // +root1(1)[inner_viewport_container_layer] |
| 10014 | // +-page_scale_layer |
| 10015 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 10016 | // scrollable, inner_viewport_scroll_layer] |
| 10017 | // +------child6(6)[kScrollbarScrolling] |
| 10018 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 10019 | // +----parent3(3) |
| 10020 | // +------child7(7)[scrollable] |
| 10021 | // +------child8(8)[scroll_parent=7] |
| 10022 | // +--------grand_child11(11)[scrollable] |
| 10023 | // +----parent4(4) |
| 10024 | // +------child9(9) |
| 10025 | // +--------grand_child12(12) |
| 10026 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10027 | // |
| 10028 | // Expected scroll tree topology: |
| 10029 | // +property_tree_root---owner:-1 |
| 10030 | // +--root---owner:1, id:1 |
| 10031 | // +----node---owner:2, id:2 |
| 10032 | // +------node---owner:6, id:3 |
| 10033 | // +----node---owner:7, id:4 |
| 10034 | // +------node---owner:11, id:5 |
| 10035 | // +----node---owner:5, id:6 |
| 10036 | // |
| 10037 | // Extra check: |
| 10038 | // scroll_tree_index() of: |
| 10039 | // grand_child10:3 |
| 10040 | // parent3:1 |
| 10041 | // child8:4 |
| 10042 | // parent4:1 |
| 10043 | // child9:1 |
| 10044 | // grand_child12:1 |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 10045 | scoped_refptr<Layer> root1 = Layer::Create(); |
| 10046 | scoped_refptr<Layer> page_scale_layer = Layer::Create(); |
| 10047 | scoped_refptr<Layer> parent2 = Layer::Create(); |
| 10048 | scoped_refptr<Layer> parent3 = Layer::Create(); |
| 10049 | scoped_refptr<Layer> parent4 = Layer::Create(); |
| 10050 | scoped_refptr<Layer> parent5 = Layer::Create(); |
| 10051 | scoped_refptr<Layer> child6 = Layer::Create(); |
| 10052 | scoped_refptr<Layer> child7 = Layer::Create(); |
| 10053 | scoped_refptr<Layer> child8 = Layer::Create(); |
| 10054 | scoped_refptr<Layer> child9 = Layer::Create(); |
| 10055 | scoped_refptr<Layer> grand_child10 = Layer::Create(); |
| 10056 | scoped_refptr<Layer> grand_child11 = Layer::Create(); |
| 10057 | scoped_refptr<Layer> grand_child12 = Layer::Create(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10058 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10059 | root1->AddChild(page_scale_layer); |
| 10060 | page_scale_layer->AddChild(parent2); |
| 10061 | page_scale_layer->AddChild(parent3); |
| 10062 | page_scale_layer->AddChild(parent4); |
| 10063 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10064 | parent2->AddChild(child6); |
| 10065 | parent3->AddChild(child7); |
| 10066 | parent3->AddChild(child8); |
| 10067 | parent4->AddChild(child9); |
| 10068 | child6->AddChild(grand_child10); |
| 10069 | child8->AddChild(grand_child11); |
| 10070 | child9->AddChild(grand_child12); |
| 10071 | host()->SetRootLayer(root1); |
| 10072 | |
| 10073 | parent2->AddMainThreadScrollingReasons( |
| 10074 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10075 | parent2->AddMainThreadScrollingReasons( |
| 10076 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10077 | parent2->SetScrollClipLayerId(root1->id()); |
| 10078 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10079 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10080 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10081 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10082 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10083 | child7->SetScrollClipLayerId(parent3->id()); |
| 10084 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10085 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10086 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10087 | |
| 10088 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10089 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10090 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10091 | host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10092 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 10093 | |
| 10094 | const int kInvalidPropertyTreeNodeId = -1; |
| 10095 | const int kRootPropertyTreeNodeId = 0; |
| 10096 | |
| 10097 | // Property tree root |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10098 | ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 10099 | PropertyTrees property_trees; |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10100 | property_trees.is_main_thread = true; |
| 10101 | property_trees.is_active = false; |
ajuma | e4af4706 | 2016-05-24 23:59:04 | [diff] [blame] | 10102 | ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10103 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10104 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 10105 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 10106 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
| 10107 | property_tree_root->data.scrollable = false; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10108 | property_tree_root->data.main_thread_scrolling_reasons = |
| 10109 | MainThreadScrollingReason::kNotScrollingOnMain; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10110 | property_tree_root->data.contains_non_fast_scrollable_region = false; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10111 | property_tree_root->data.transform_id = kRootPropertyTreeNodeId; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10112 | |
| 10113 | // The node owned by root1 |
| 10114 | ScrollNode scroll_root1; |
| 10115 | scroll_root1.id = 1; |
| 10116 | scroll_root1.owner_id = root1->id(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10117 | scroll_root1.data.user_scrollable_horizontal = true; |
| 10118 | scroll_root1.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10119 | scroll_root1.data.transform_id = root1->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10120 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10121 | |
| 10122 | // The node owned by parent2 |
| 10123 | ScrollNode scroll_parent2; |
| 10124 | scroll_parent2.id = 2; |
| 10125 | scroll_parent2.owner_id = parent2->id(); |
| 10126 | scroll_parent2.data.scrollable = true; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10127 | scroll_parent2.data.main_thread_scrolling_reasons = |
| 10128 | parent2->main_thread_scrolling_reasons(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10129 | scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds(); |
| 10130 | scroll_parent2.data.bounds = parent2->bounds(); |
| 10131 | scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true; |
| 10132 | scroll_parent2.data.is_inner_viewport_scroll_layer = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10133 | scroll_parent2.data.user_scrollable_horizontal = true; |
| 10134 | scroll_parent2.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10135 | scroll_parent2.data.transform_id = parent2->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10136 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10137 | |
| 10138 | // The node owned by child6 |
| 10139 | ScrollNode scroll_child6; |
| 10140 | scroll_child6.id = 3; |
| 10141 | scroll_child6.owner_id = child6->id(); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10142 | scroll_child6.data.main_thread_scrolling_reasons = |
| 10143 | child6->main_thread_scrolling_reasons(); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10144 | scroll_child6.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10145 | scroll_child6.data.user_scrollable_horizontal = true; |
| 10146 | scroll_child6.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10147 | scroll_child6.data.transform_id = child6->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10148 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10149 | |
| 10150 | // The node owned by child7, child7 also owns a transform node |
| 10151 | ScrollNode scroll_child7; |
| 10152 | scroll_child7.id = 4; |
| 10153 | scroll_child7.owner_id = child7->id(); |
| 10154 | scroll_child7.data.scrollable = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10155 | scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds(); |
| 10156 | scroll_child7.data.bounds = child7->bounds(); |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10157 | scroll_child7.data.user_scrollable_horizontal = true; |
| 10158 | scroll_child7.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10159 | scroll_child7.data.transform_id = child7->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10160 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10161 | |
| 10162 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10163 | ScrollNode scroll_grand_child11; |
| 10164 | scroll_grand_child11.id = 5; |
| 10165 | scroll_grand_child11.owner_id = grand_child11->id(); |
| 10166 | scroll_grand_child11.data.scrollable = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10167 | scroll_grand_child11.data.user_scrollable_horizontal = true; |
| 10168 | scroll_grand_child11.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10169 | scroll_grand_child11.data.transform_id = |
| 10170 | grand_child11->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10171 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10172 | |
| 10173 | // The node owned by parent5 |
| 10174 | ScrollNode scroll_parent5; |
| 10175 | scroll_parent5.id = 8; |
| 10176 | scroll_parent5.owner_id = parent5->id(); |
| 10177 | scroll_parent5.data.contains_non_fast_scrollable_region = true; |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10178 | scroll_parent5.data.bounds = gfx::Size(10, 10); |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10179 | scroll_parent5.data.should_flatten = true; |
sunxd | 54e08e9d | 2016-02-22 23:01:28 | [diff] [blame] | 10180 | scroll_parent5.data.user_scrollable_horizontal = true; |
| 10181 | scroll_parent5.data.user_scrollable_vertical = true; |
sunxd | d1abacf | 2016-02-16 22:08:30 | [diff] [blame] | 10182 | scroll_parent5.data.transform_id = parent5->transform_tree_index(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10183 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10184 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 10185 | expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0)); |
| 10186 | expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0)); |
| 10187 | expected_scroll_tree.SetScrollOffset(grand_child11->id(), |
| 10188 | gfx::ScrollOffset(0, 0)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10189 | expected_scroll_tree.set_needs_update(false); |
| 10190 | |
| 10191 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10192 | |
| 10193 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 10194 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10195 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10196 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10197 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10198 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10199 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10200 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10201 | } |
| 10202 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10203 | } // namespace |
| 10204 | } // namespace cc |