ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 10 | #include <set> |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 11 | #include <vector> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 12 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 13 | #include "cc/animation/animation_host.h" |
| 14 | #include "cc/animation/animation_id_provider.h" |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 15 | #include "cc/animation/keyframed_animation_curve.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 16 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 17 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 18 | #include "cc/base/math_util.h" |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 19 | #include "cc/input/main_thread_scrolling_reason.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 20 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 21 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 22 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 24 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 25 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 26 | #include "cc/output/copy_output_request.h" |
| 27 | #include "cc/output/copy_output_result.h" |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 28 | #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 29 | #include "cc/proto/gfx_conversions.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 30 | #include "cc/test/animation_test_common.h" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 31 | #include "cc/test/fake_content_layer_client.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 32 | #include "cc/test/fake_impl_task_runner_provider.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 33 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 34 | #include "cc/test/fake_layer_tree_host_impl.h" |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 35 | #include "cc/test/fake_output_surface.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 36 | #include "cc/test/fake_picture_layer.h" |
| 37 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 38 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 39 | #include "cc/test/layer_tree_host_common_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 40 | #include "cc/test/test_task_graph_runner.h" |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 41 | #include "cc/trees/draw_property_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 42 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 43 | #include "cc/trees/single_thread_proxy.h" |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 44 | #include "cc/trees/task_runner_provider.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 45 | #include "testing/gmock/include/gmock/gmock.h" |
| 46 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 47 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 48 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 49 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 51 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | namespace { |
| 53 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 54 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 55 | public: |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 56 | explicit LayerWithForcedDrawsContent(const LayerSettings& settings) |
| 57 | : Layer(settings) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 59 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 60 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 61 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 62 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 63 | }; |
| 64 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 65 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 66 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 67 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 68 | public: |
| 69 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 70 | ~MockContentLayerClient() override {} |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 71 | gfx::Rect PaintableRegion() override { return gfx::Rect(); } |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 72 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 73 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 74 | NOTIMPLEMENTED(); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 75 | return nullptr; |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 76 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 77 | bool FillsBoundsCompletely() const override { return false; } |
jbroman | 9f60f1a | 2015-07-16 21:40:32 | [diff] [blame] | 78 | size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 79 | }; |
| 80 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 81 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 82 | do { \ |
| 83 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 84 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 85 | } while (false) |
| 86 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 87 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 88 | do { \ |
| 89 | EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \ |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 90 | } while (false) |
| 91 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 92 | class LayerTreeSettingsScaleContent : public LayerTreeSettings { |
| 93 | public: |
| 94 | LayerTreeSettingsScaleContent() { |
| 95 | layer_transforms_should_scale_layer_contents = true; |
loyso | 8ce123b6 | 2016-01-06 23:10:31 | [diff] [blame] | 96 | use_compositor_animation_timelines = true; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 97 | } |
| 98 | }; |
| 99 | |
| 100 | class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest { |
| 101 | public: |
| 102 | LayerTreeHostCommonScalingTest() |
| 103 | : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {} |
| 104 | }; |
| 105 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 106 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 107 | // Sanity check: For layers positioned at zero, with zero size, |
| 108 | // and with identity transforms, then the draw transform, |
| 109 | // screen space transform, and the hierarchy passed on to children |
| 110 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 111 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 112 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 113 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 114 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 115 | parent->AddChild(child); |
| 116 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 117 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 118 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 119 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 120 | gfx::Transform identity_matrix; |
| 121 | SetLayerPropertiesForTesting(parent.get(), |
| 122 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 123 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 124 | gfx::PointF(), |
| 125 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 127 | false); |
| 128 | SetLayerPropertiesForTesting(child.get(), |
| 129 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 130 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 131 | gfx::PointF(), |
| 132 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 134 | false); |
| 135 | SetLayerPropertiesForTesting(grand_child.get(), |
| 136 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 137 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 138 | gfx::PointF(), |
| 139 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 140 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 141 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 142 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 143 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 145 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 146 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 147 | child->screen_space_transform()); |
| 148 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 149 | grand_child->draw_transform()); |
| 150 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 151 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 152 | } |
| 153 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 154 | TEST_F(LayerTreeHostCommonTest, |
| 155 | ScreenSpaceTransformOfSkippedLayersWithHandlers) { |
| 156 | // Even for layers that are skipped, we need to compute the correct screen |
| 157 | // space transform because it is used during hit testing. |
enne | 36715232 | 2015-08-18 18:06:09 | [diff] [blame] | 158 | LayerImpl* parent = root_layer(); |
| 159 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 160 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 161 | child->SetDrawsContent(true); |
| 162 | grand_child->SetDrawsContent(true); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 163 | |
| 164 | gfx::Transform identity_matrix; |
enne | 36715232 | 2015-08-18 18:06:09 | [diff] [blame] | 165 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 166 | gfx::PointF(), gfx::Size(100, 100), true, false); |
enne | 36715232 | 2015-08-18 18:06:09 | [diff] [blame] | 167 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 168 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 169 | false); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 170 | // This will cause the subtree to be skipped. |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 171 | child->SetOpacity(0.f); |
enne | 36715232 | 2015-08-18 18:06:09 | [diff] [blame] | 172 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 173 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 174 | false); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 175 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 176 | |
enne | 36715232 | 2015-08-18 18:06:09 | [diff] [blame] | 177 | ExecuteCalculateDrawProperties(parent); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 178 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 179 | EXPECT_TRUE(child->has_render_surface()); |
| 180 | EXPECT_FALSE(grand_child->has_render_surface()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 181 | // Check that we've computed draw properties for the subtree rooted at |
| 182 | // |child|. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 183 | EXPECT_FALSE(child->render_surface()->screen_space_transform().IsIdentity()); |
| 184 | EXPECT_FALSE(grand_child->ScreenSpaceTransform().IsIdentity()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 185 | } |
| 186 | |
jaydasika | 32243637 | 2015-12-16 23:42:38 | [diff] [blame] | 187 | TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) { |
| 188 | // Tests that effect tree node gets a valid transform id when a layer |
| 189 | // has opacity but doesn't create a render surface. |
| 190 | LayerImpl* parent = root_layer(); |
| 191 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 192 | child->SetDrawsContent(true); |
| 193 | |
| 194 | gfx::Transform identity_matrix; |
| 195 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 196 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 197 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 198 | gfx::PointF(10, 10), gfx::Size(100, 100), true, |
| 199 | false); |
| 200 | child->SetOpacity(0.f); |
| 201 | ExecuteCalculateDrawProperties(parent); |
| 202 | EffectTree effect_tree = |
| 203 | parent->layer_tree_impl()->property_trees()->effect_tree; |
| 204 | EffectNode* node = effect_tree.Node(child->effect_tree_index()); |
| 205 | const int transform_tree_size = parent->layer_tree_impl() |
| 206 | ->property_trees() |
| 207 | ->transform_tree.next_available_id(); |
| 208 | EXPECT_LT(node->data.transform_id, transform_tree_size); |
| 209 | } |
| 210 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 211 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 212 | gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 213 | scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 214 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 215 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 216 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 217 | gfx::PointF(), gfx::Size(1, 2), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 218 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 219 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 220 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 221 | |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 222 | TransformTree& tree = host()->property_trees()->transform_tree; |
| 223 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 224 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 225 | // transform or the screenspace transform. |
| 226 | gfx::Transform translation_to_center; |
| 227 | translation_to_center.Translate(5.0, 6.0); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 228 | SetLayerPropertiesForTesting(layer.get(), identity_matrix, gfx::Point3F(), |
| 229 | gfx::PointF(), gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 230 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 231 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 232 | identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 233 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 234 | identity_matrix, |
| 235 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 237 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 238 | // no effect on the transforms. |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 239 | SetLayerPropertiesForTesting(layer.get(), identity_matrix, |
| 240 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 241 | gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 242 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 243 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 244 | identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 245 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 246 | identity_matrix, |
| 247 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 248 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 249 | // Case 4: A change in actual position affects both the draw transform and |
| 250 | // screen space transform. |
| 251 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 252 | position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 253 | SetLayerPropertiesForTesting( |
| 254 | layer.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
| 255 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 256 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 257 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 258 | position_transform, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 259 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 260 | position_transform, |
| 261 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 263 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 264 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 265 | // scale transform, because scale and translation are not commutative. |
| 266 | gfx::Transform layer_transform; |
| 267 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 268 | SetLayerPropertiesForTesting(layer.get(), layer_transform, gfx::Point3F(), |
| 269 | gfx::PointF(), gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 270 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 271 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 272 | layer_transform, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 273 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 274 | layer_transform, |
| 275 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 276 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 277 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 278 | gfx::Transform translation_to_anchor; |
| 279 | translation_to_anchor.Translate(5.0, 0.0); |
| 280 | gfx::Transform expected_result = |
| 281 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 282 | SetLayerPropertiesForTesting(layer.get(), layer_transform, |
| 283 | gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(), |
| 284 | gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 285 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 286 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 287 | expected_result, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 288 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 289 | expected_result, |
| 290 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 291 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 292 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 293 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 294 | // it is still worth testing to detect accidental regressions. |
| 295 | expected_result = position_transform * translation_to_anchor * |
| 296 | layer_transform * Inverse(translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 297 | SetLayerPropertiesForTesting( |
| 298 | layer.get(), layer_transform, gfx::Point3F(5.0f, 0.f, 0.f), |
| 299 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 300 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 301 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 302 | expected_result, DrawTransformFromPropertyTrees(layer.get(), tree)); |
| 303 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 304 | expected_result, |
| 305 | ScreenSpaceTransformFromPropertyTrees(layer.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 308 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 309 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 311 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 312 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 313 | -kScrollOffset.y()); |
| 314 | const float kPageScale = 0.888f; |
| 315 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 316 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 317 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 318 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 319 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 320 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 321 | &task_graph_runner); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 323 | gfx::Transform identity_matrix; |
| 324 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 325 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 326 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 327 | sublayer->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 328 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 329 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 330 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 331 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 332 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 333 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 334 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 335 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 336 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 337 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 338 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 339 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 340 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 341 | |
| 342 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 343 | clip_layer->SetBounds( |
| 344 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 345 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 346 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 347 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 348 | gfx::Transform impl_transform; |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 349 | scroll_layer->AddChild(std::move(sublayer_scoped_ptr)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 350 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 351 | clip_layer->AddChild(std::move(scroll_layer_scoped_ptr)); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 352 | scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 353 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 354 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 355 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 356 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 357 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 358 | root->AddChild(std::move(clip_layer_scoped_ptr)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 359 | root->SetHasRenderSurface(true); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 360 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 361 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 362 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 363 | gfx::Transform expected_transform = identity_matrix; |
| 364 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 365 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * |
| 366 | kPageScale * kDeviceScale), |
| 367 | MathUtil::Round(sub_layer_screen_position.y() * |
| 368 | kPageScale * kDeviceScale)); |
| 369 | expected_transform.Scale(kPageScale * kDeviceScale, |
| 370 | kPageScale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 371 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 372 | sublayer->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 373 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 374 | sublayer->ScreenSpaceTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 375 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 376 | gfx::Transform arbitrary_translate; |
| 377 | const float kTranslateX = 10.6f; |
| 378 | const float kTranslateY = 20.6f; |
| 379 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 380 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 381 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 382 | true, false, false); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 383 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 384 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 385 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 386 | expected_transform.MakeIdentity(); |
| 387 | expected_transform.Translate( |
| 388 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 389 | sub_layer_screen_position.x() * kPageScale * |
| 390 | kDeviceScale), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 391 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 392 | sub_layer_screen_position.y() * kPageScale * |
| 393 | kDeviceScale)); |
| 394 | expected_transform.Scale(kPageScale * kDeviceScale, |
| 395 | kPageScale * kDeviceScale); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 396 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 397 | sublayer->DrawTransform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 398 | } |
| 399 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 400 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 401 | gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 402 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 403 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 404 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 405 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 406 | root->AddChild(parent); |
| 407 | parent->AddChild(child); |
| 408 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 409 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 410 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 412 | // One-time setup of root layer |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 413 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 414 | gfx::PointF(), gfx::Size(1, 2), true, false); |
| 415 | |
| 416 | TransformTree& tree = host()->property_trees()->transform_tree; |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 417 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 418 | // Case 1: parent's anchor point should not affect child or grand_child. |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 419 | SetLayerPropertiesForTesting(parent.get(), identity_matrix, |
| 420 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 421 | gfx::Size(10, 12), true, false); |
| 422 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 423 | gfx::PointF(), gfx::Size(16, 18), true, false); |
| 424 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 425 | gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), |
| 426 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 427 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 428 | |
| 429 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 430 | identity_matrix, DrawTransformFromPropertyTrees(child.get(), tree)); |
| 431 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 432 | identity_matrix, |
| 433 | ScreenSpaceTransformFromPropertyTrees(child.get(), tree)); |
| 434 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 435 | identity_matrix, DrawTransformFromPropertyTrees(grand_child.get(), tree)); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 437 | identity_matrix, |
| 438 | ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 439 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 440 | // Case 2: parent's position affects child and grand_child. |
| 441 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 442 | parent_position_transform.Translate(0.f, 1.2f); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 443 | SetLayerPropertiesForTesting( |
| 444 | parent.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f), |
| 445 | gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false); |
| 446 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 447 | gfx::PointF(), gfx::Size(16, 18), true, false); |
| 448 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 449 | gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), |
| 450 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 451 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 452 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 453 | parent_position_transform, |
| 454 | DrawTransformFromPropertyTrees(child.get(), tree)); |
| 455 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 456 | parent_position_transform, |
| 457 | ScreenSpaceTransformFromPropertyTrees(child.get(), tree)); |
| 458 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 459 | parent_position_transform, |
| 460 | DrawTransformFromPropertyTrees(grand_child.get(), tree)); |
| 461 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 462 | parent_position_transform, |
| 463 | ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 464 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 465 | // Case 3: parent's local transform affects child and grandchild |
| 466 | gfx::Transform parent_layer_transform; |
| 467 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 468 | gfx::Transform parent_translation_to_anchor; |
| 469 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 470 | gfx::Transform parent_composite_transform = |
| 471 | parent_translation_to_anchor * parent_layer_transform * |
| 472 | Inverse(parent_translation_to_anchor); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 473 | SetLayerPropertiesForTesting(parent.get(), parent_layer_transform, |
| 474 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 475 | gfx::Size(10, 12), true, false); |
| 476 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 477 | gfx::PointF(), gfx::Size(16, 18), true, false); |
| 478 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 479 | gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78), |
| 480 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 481 | ExecuteCalculateDrawProperties(root.get()); |
enne | 82645272 | 2015-08-18 22:22:31 | [diff] [blame] | 482 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 483 | parent_composite_transform, |
| 484 | DrawTransformFromPropertyTrees(child.get(), tree)); |
| 485 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 486 | parent_composite_transform, |
| 487 | ScreenSpaceTransformFromPropertyTrees(child.get(), tree)); |
| 488 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 489 | parent_composite_transform, |
| 490 | DrawTransformFromPropertyTrees(grand_child.get(), tree)); |
| 491 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 492 | parent_composite_transform, |
| 493 | ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 496 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 497 | LayerImpl* root = root_layer(); |
| 498 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 499 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 500 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 501 | grand_child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 502 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 503 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 504 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 505 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 506 | true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 508 | // Child is set up so that a new render surface should be created. |
| 509 | child->SetOpacity(0.5f); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 510 | child->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 511 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 512 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 513 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 514 | gfx::Transform parent_translation_to_anchor; |
| 515 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 516 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 517 | gfx::Transform parent_composite_transform = |
| 518 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 519 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 520 | gfx::Vector2dF parent_composite_scale = |
| 521 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 522 | 1.f); |
| 523 | gfx::Transform surface_sublayer_transform; |
| 524 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 525 | parent_composite_scale.y()); |
| 526 | gfx::Transform surface_sublayer_composite_transform = |
| 527 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 528 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 529 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 530 | gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(), |
| 531 | gfx::Size(100, 120), true, false, false); |
| 532 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 533 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 534 | true); |
| 535 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 536 | gfx::PointF(), gfx::Size(8, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 537 | false); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 538 | ExecuteCalculateDrawProperties(root); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 540 | // Render surface should have been created now. |
| 541 | ASSERT_TRUE(child->render_surface()); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 542 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 544 | // The child layer's draw transform should refer to its new render surface. |
| 545 | // The screen-space transform, however, should still refer to the root. |
| 546 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 547 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 548 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 549 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 551 | // Because the grand_child is the only drawable content, the child's render |
| 552 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 553 | // surface's subtree is drawn must be removed from the composite transform. |
| 554 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 555 | surface_sublayer_composite_transform, |
| 556 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 558 | // The screen space is the same as the target since the child surface draws |
| 559 | // into the root. |
| 560 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 561 | surface_sublayer_composite_transform, |
| 562 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 563 | } |
| 564 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 565 | TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) { |
| 566 | LayerImpl* root = root_layer(); |
| 567 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 568 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 569 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 570 | grand_child->SetDrawsContent(true); |
| 571 | |
| 572 | gfx::Transform identity_matrix; |
| 573 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 574 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 575 | true); |
| 576 | |
| 577 | gfx::Transform parent_transform; |
| 578 | parent_transform.Translate(10.0, 10.0); |
| 579 | |
| 580 | gfx::Transform child_transform; |
| 581 | child_transform.Rotate(45.0); |
| 582 | |
| 583 | // child gets a render surface when surfaces are enabled. |
| 584 | SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(), |
| 585 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 586 | false); |
| 587 | SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(), |
| 588 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 589 | true); |
| 590 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 591 | gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true, |
| 592 | false, false); |
| 593 | |
| 594 | gfx::Transform expected_grand_child_screen_space_transform; |
| 595 | expected_grand_child_screen_space_transform.Translate(10.0, 10.0); |
| 596 | expected_grand_child_screen_space_transform.Rotate(45.0); |
| 597 | expected_grand_child_screen_space_transform.Translate(2.0, 2.0); |
| 598 | |
| 599 | // First compute draw properties with separate surfaces enabled. |
| 600 | ExecuteCalculateDrawProperties(root); |
| 601 | |
| 602 | // The grand child's draw transform should be its offset wrt the child. |
| 603 | gfx::Transform expected_grand_child_draw_transform; |
| 604 | expected_grand_child_draw_transform.Translate(2.0, 2.0); |
| 605 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 606 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 607 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 608 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 609 | |
| 610 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 611 | |
| 612 | // With separate surfaces disabled, the grand child's draw transform should be |
| 613 | // the same as its screen space transform. |
| 614 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 615 | grand_child->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 616 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 617 | grand_child->ScreenSpaceTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 620 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 621 | LayerImpl* root = root_layer(); |
| 622 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 623 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 624 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 625 | grand_child->SetDrawsContent(true); |
| 626 | scoped_ptr<LayerImpl> child_replica = |
| 627 | LayerImpl::Create(host_impl()->active_tree(), 100); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 628 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 629 | // One-time setup of root layer |
| 630 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 631 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 632 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 633 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 634 | |
| 635 | // Child is set up so that a new render surface should be created. |
| 636 | child->SetOpacity(0.5f); |
| 637 | |
| 638 | gfx::Transform parent_layer_transform; |
| 639 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 640 | gfx::Transform parent_translation_to_anchor; |
| 641 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 642 | gfx::Transform parent_composite_transform = |
| 643 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 644 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 645 | gfx::Transform replica_layer_transform; |
| 646 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 647 | gfx::Vector2dF parent_composite_scale = |
| 648 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 649 | 1.f); |
| 650 | gfx::Transform surface_sublayer_transform; |
| 651 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 652 | parent_composite_scale.y()); |
| 653 | gfx::Transform replica_composite_transform = |
| 654 | parent_composite_transform * replica_layer_transform * |
| 655 | Inverse(surface_sublayer_transform); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 656 | child_replica->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 657 | // Child's render surface should not exist yet. |
| 658 | ASSERT_FALSE(child->render_surface()); |
| 659 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 660 | SetLayerPropertiesForTesting(parent, parent_layer_transform, |
| 661 | gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(), |
| 662 | gfx::Size(10, 12), true, false, false); |
| 663 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 664 | gfx::PointF(), gfx::Size(16, 18), true, false, |
| 665 | true); |
| 666 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 667 | gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true, |
| 668 | false, false); |
| 669 | SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform, |
| 670 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 671 | false, false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 672 | child->SetReplicaLayer(std::move(child_replica)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 673 | |
| 674 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 675 | |
| 676 | // Render surface should have been created now. |
| 677 | ASSERT_TRUE(child->render_surface()); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 678 | ASSERT_EQ(child, child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 679 | |
| 680 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 681 | replica_composite_transform, |
| 682 | child->render_target()->render_surface()->replica_draw_transform()); |
| 683 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 684 | child->render_target() |
| 685 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | ->replica_screen_space_transform()); |
| 687 | } |
| 688 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 689 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | // This test creates a more complex tree and verifies it all at once. This |
| 691 | // covers the following cases: |
| 692 | // - layers that are described w.r.t. a render surface: should have draw |
| 693 | // transforms described w.r.t. that surface |
| 694 | // - A render surface described w.r.t. an ancestor render surface: should |
| 695 | // have a draw transform described w.r.t. that ancestor surface |
| 696 | // - Replicas of a render surface are described w.r.t. the replica's |
| 697 | // transform around its anchor, along with the surface itself. |
| 698 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 699 | // a render surface that is described w.r.t. an ancestor render surface. |
| 700 | // - verifying that each layer has a reference to the correct render surface |
| 701 | // and render target values. |
| 702 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 703 | LayerImpl* root = root_layer(); |
| 704 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 705 | parent->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 706 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 707 | render_surface1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 708 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 709 | render_surface2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 710 | LayerImpl* child_of_root = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 711 | child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 712 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 713 | child_of_rs1->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 714 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 715 | child_of_rs2->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 716 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 717 | grand_child_of_root->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 718 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 719 | grand_child_of_rs1->SetDrawsContent(true); |
| 720 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 721 | grand_child_of_rs2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 722 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 723 | scoped_ptr<LayerImpl> replica_of_rs1 = |
| 724 | LayerImpl::Create(host_impl()->active_tree(), 101); |
| 725 | scoped_ptr<LayerImpl> replica_of_rs2 = |
| 726 | LayerImpl::Create(host_impl()->active_tree(), 102); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 727 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 728 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 729 | // to have a new render surface. |
| 730 | render_surface1->SetOpacity(0.5f); |
| 731 | render_surface2->SetOpacity(0.33f); |
| 732 | |
| 733 | // One-time setup of root layer |
| 734 | gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 735 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 736 | gfx::PointF(), gfx::Size(1, 2), true, false, |
| 737 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 738 | |
| 739 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 740 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 741 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 742 | gfx::Transform translation_to_anchor; |
| 743 | translation_to_anchor.Translate(2.5, 0.0); |
| 744 | gfx::Transform layer_transform; |
| 745 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 746 | gfx::Transform replica_layer_transform; |
| 747 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 748 | |
| 749 | gfx::Transform A = |
| 750 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 751 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 752 | Inverse(translation_to_anchor); |
| 753 | |
| 754 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 755 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 756 | gfx::Transform surface1_sublayer_transform; |
| 757 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 758 | surface1_parent_transform_scale.y()); |
| 759 | |
| 760 | // SS1 = transform given to the subtree of render_surface1 |
| 761 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 762 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 763 | // the owning layer |
| 764 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 765 | |
| 766 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 767 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 768 | gfx::Transform surface2_sublayer_transform; |
| 769 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 770 | surface2_parent_transform_scale.y()); |
| 771 | |
| 772 | // SS2 = transform given to the subtree of render_surface2 |
| 773 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 774 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 775 | // the owning layer |
| 776 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 777 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 778 | SetLayerPropertiesForTesting(parent, layer_transform, |
| 779 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 780 | gfx::Size(10, 10), true, false, false); |
| 781 | SetLayerPropertiesForTesting(render_surface1, layer_transform, |
| 782 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 783 | gfx::Size(10, 10), true, false, true); |
| 784 | SetLayerPropertiesForTesting(render_surface2, layer_transform, |
| 785 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 786 | gfx::Size(10, 10), true, false, true); |
| 787 | SetLayerPropertiesForTesting(child_of_root, layer_transform, |
| 788 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 789 | gfx::Size(10, 10), true, false, false); |
| 790 | SetLayerPropertiesForTesting(child_of_rs1, 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_rs2, layer_transform, |
| 794 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 795 | gfx::Size(10, 10), true, false, false); |
| 796 | SetLayerPropertiesForTesting(grand_child_of_root, 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_rs1, 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_rs2, layer_transform, |
| 803 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 804 | gfx::Size(10, 10), true, false, false); |
| 805 | SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform, |
| 806 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 807 | gfx::Size(), true, false, false); |
| 808 | SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform, |
| 809 | gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(), |
| 810 | gfx::Size(), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 811 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 812 | render_surface1->SetReplicaLayer(std::move(replica_of_rs1)); |
| 813 | render_surface2->SetReplicaLayer(std::move(replica_of_rs2)); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 814 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 815 | |
| 816 | // Only layers that are associated with render surfaces should have an actual |
| 817 | // RenderSurface() value. |
| 818 | ASSERT_TRUE(root->render_surface()); |
| 819 | ASSERT_FALSE(child_of_root->render_surface()); |
| 820 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 821 | |
| 822 | ASSERT_TRUE(render_surface1->render_surface()); |
| 823 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 824 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 825 | |
| 826 | ASSERT_TRUE(render_surface2->render_surface()); |
| 827 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 828 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 829 | |
| 830 | // Verify all render target accessors |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 831 | EXPECT_EQ(root, parent->render_target()); |
| 832 | EXPECT_EQ(root, child_of_root->render_target()); |
| 833 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 834 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 835 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 836 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 837 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 838 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 839 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 840 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 841 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 842 | |
| 843 | // Verify layer draw transforms note that draw transforms are described with |
| 844 | // respect to the nearest ancestor render surface but screen space transforms |
| 845 | // are described with respect to the root. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 846 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform()); |
| 847 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 848 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 849 | grand_child_of_root->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 850 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 851 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform()); |
| 852 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 853 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 854 | grand_child_of_rs1->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 855 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 856 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform()); |
| 857 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 858 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 859 | grand_child_of_rs2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 860 | |
| 861 | // Verify layer screen-space transforms |
| 862 | // |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 863 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform()); |
| 864 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform()); |
| 865 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
| 866 | grand_child_of_root->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 867 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 868 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 869 | render_surface1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 870 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 871 | child_of_rs1->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 872 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 873 | grand_child_of_rs1->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 874 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 875 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 876 | render_surface2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 877 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 878 | child_of_rs2->ScreenSpaceTransform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 879 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 880 | grand_child_of_rs2->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 881 | |
| 882 | // Verify render surface transforms. |
| 883 | // |
| 884 | // Draw transform of render surface 1 is described with respect to root. |
| 885 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 886 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 887 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 888 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 889 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 890 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 891 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 892 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 893 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 894 | // Draw transform of render surface 2 is described with respect to render |
| 895 | // surface 1. |
| 896 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 897 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 898 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 899 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 900 | render_surface2->render_surface()->replica_draw_transform()); |
| 901 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 902 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 903 | render_surface2->render_surface()->screen_space_transform()); |
| 904 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 905 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 906 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 907 | |
| 908 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 909 | // is expected that we correctly set up transforms so that the y-component of |
| 910 | // the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 911 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 912 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 913 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 914 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 915 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 917 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 918 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 919 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 920 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 921 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 922 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 923 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 924 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 925 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 926 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 927 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 928 | } |
| 929 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 930 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 931 | // For layers that flatten their subtree, there should be an orthographic |
| 932 | // projection (for x and y values) in the middle of the transform sequence. |
| 933 | // Note that the way the code is currently implemented, it is not expected to |
| 934 | // use a canonical orthographic projection. |
| 935 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 936 | LayerImpl* root = root_layer(); |
| 937 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 938 | child->SetDrawsContent(true); |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 939 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 940 | grand_child->SetDrawsContent(true); |
| 941 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 942 | great_grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 943 | |
| 944 | gfx::Transform rotation_about_y_axis; |
| 945 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 946 | |
| 947 | const gfx::Transform identity_matrix; |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 948 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 949 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 950 | true); |
| 951 | SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(), |
| 952 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 953 | true); |
| 954 | SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis, |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 955 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 956 | true, false, false); |
| 957 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 958 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 959 | true, false, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 960 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 961 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 962 | ASSERT_TRUE(root->should_flatten_transform()); |
| 963 | ASSERT_TRUE(child->should_flatten_transform()); |
| 964 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 965 | ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | |
| 967 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 968 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 969 | gfx::Transform expected_grand_child_draw_transform = |
| 970 | rotation_about_y_axis; // draws onto child's render surface |
| 971 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 972 | flattened_rotation_about_y.FlattenTo2d(); |
| 973 | gfx::Transform expected_grand_child_screen_space_transform = |
| 974 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 975 | gfx::Transform expected_great_grand_child_draw_transform = |
| 976 | flattened_rotation_about_y; |
| 977 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 978 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 979 | |
enne | 25dea3f | 2015-07-27 16:44:28 | [diff] [blame] | 980 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 981 | |
| 982 | // The child's draw transform should have been taken by its surface. |
| 983 | ASSERT_TRUE(child->render_surface()); |
| 984 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 985 | child->render_surface()->draw_transform()); |
| 986 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 987 | expected_child_screen_space_transform, |
| 988 | child->render_surface()->screen_space_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 989 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 990 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 991 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 992 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 993 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 994 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 995 | grand_child->ScreenSpaceTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 996 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 997 | great_grand_child->DrawTransform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 998 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 999 | expected_great_grand_child_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1000 | great_grand_child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | } |
| 1002 | |
ajuma | dbd92cb | 2015-07-16 13:47:06 | [diff] [blame] | 1003 | TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { |
| 1004 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 1005 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 1006 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1007 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
| 1008 | |
| 1009 | gfx::Transform child_transform; |
| 1010 | child_transform.Translate(50.0, 50.0); |
| 1011 | child_transform.RotateAboutZAxis(30.0); |
| 1012 | |
| 1013 | gfx::Transform grand_child_transform; |
| 1014 | grand_child_transform.RotateAboutYAxis(90.0); |
| 1015 | |
| 1016 | const gfx::Transform identity_matrix; |
| 1017 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 1018 | gfx::PointF(), gfx::Size(200, 200), true, false); |
| 1019 | SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(), |
| 1020 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1021 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform, |
| 1022 | gfx::Point3F(), gfx::PointF(), |
| 1023 | gfx::Size(100, 100), true, false); |
| 1024 | |
| 1025 | root->AddChild(child); |
| 1026 | child->AddChild(grand_child); |
| 1027 | grand_child->SetShouldFlattenTransform(false); |
| 1028 | |
| 1029 | host()->SetRootLayer(root); |
| 1030 | |
| 1031 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 1032 | |
| 1033 | // Mapping grand_child's bounds to target space produces a non-empty rect |
| 1034 | // that is fully contained within the target's bounds, so grand_child should |
| 1035 | // be considered fully visible. |
| 1036 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
| 1037 | grand_child->visible_rect_from_property_trees()); |
| 1038 | } |
| 1039 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1040 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1041 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1042 | // skipping a necessary translation. Without that translation, the coordinate |
| 1043 | // space of the layer's draw transform is incorrect. |
| 1044 | // |
| 1045 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1046 | // but if that layer becomes a render surface, then its draw transform is |
| 1047 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1048 | // incorrectly as a result. |
| 1049 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1050 | LayerImpl* root = root_layer(); |
| 1051 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1052 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1053 | grand_child->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1054 | |
| 1055 | // The child height is zero, but has non-zero width that should be accounted |
| 1056 | // for while computing draw transforms. |
| 1057 | const gfx::Transform identity_matrix; |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1058 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1059 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1060 | true); |
| 1061 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1062 | gfx::PointF(), gfx::Size(10, 0), true, false, |
| 1063 | true); |
| 1064 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1065 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1066 | false); |
| 1067 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1068 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1069 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1070 | ASSERT_TRUE(child->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1071 | // This is the real test, the rest are sanity checks. |
| 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1073 | child->render_surface()->draw_transform()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1074 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1075 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1076 | grand_child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1077 | } |
| 1078 | |
jaydasika | 9bbee9b | 2016-01-13 00:36:48 | [diff] [blame] | 1079 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { |
| 1080 | const gfx::Transform identity_matrix; |
| 1081 | LayerImpl* root = root_layer(); |
| 1082 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 1083 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 1084 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1085 | |
| 1086 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1087 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1088 | true); |
| 1089 | gfx::Transform translate; |
| 1090 | translate.Translate3d(5, 5, 5); |
| 1091 | SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(), |
| 1092 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1093 | true); |
| 1094 | SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(), |
| 1095 | gfx::Size(100, 100), true, false, false); |
| 1096 | SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(), |
| 1097 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1098 | false); |
| 1099 | grand_child->SetDrawsContent(true); |
| 1100 | |
| 1101 | // render_surface will have a sublayer scale because of device scale factor. |
| 1102 | float device_scale_factor = 2.0f; |
| 1103 | LayerImplList render_surface_layer_list_impl; |
| 1104 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1105 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1106 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1107 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 1108 | inputs.device_scale_factor = device_scale_factor; |
| 1109 | inputs.property_trees->needs_rebuild = true; |
| 1110 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1111 | |
| 1112 | // Between grand_child and render_surface, we translate by (10, 10) and scale |
| 1113 | // by a factor of 2. |
| 1114 | gfx::Vector2dF expected_translation(20.0f, 20.0f); |
| 1115 | EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(), |
| 1116 | expected_translation); |
| 1117 | } |
| 1118 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1119 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1120 | // Transformations applied at the root of the tree should be forwarded |
| 1121 | // to child layers instead of applied to the root RenderSurface. |
| 1122 | const gfx::Transform identity_matrix; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1123 | LayerImpl* root = root_layer(); |
| 1124 | root->SetDrawsContent(true); |
| 1125 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 1126 | child->SetDrawsContent(true); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1127 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1128 | child->SetScrollClipLayer(root->id()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1129 | |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1130 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1131 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1132 | true); |
| 1133 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1134 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1135 | false); |
| 1136 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1137 | gfx::Transform translate; |
| 1138 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1139 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1140 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1141 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1142 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1143 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1144 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1145 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1146 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1147 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1148 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1149 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1150 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1151 | |
| 1152 | gfx::Transform scale; |
| 1153 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1154 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1155 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1156 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1157 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1158 | root, root->bounds(), scale, &render_surface_layer_list_impl, |
| 1159 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1160 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1161 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1162 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1163 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1164 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1165 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1166 | |
| 1167 | gfx::Transform rotate; |
| 1168 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1169 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1170 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1171 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1172 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1173 | root, root->bounds(), rotate, &render_surface_layer_list_impl, |
| 1174 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1175 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1176 | LayerTreeHostCommon::CalculateDrawProperties(&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; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1188 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1189 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1190 | root, root->bounds(), composite, &render_surface_layer_list_impl, |
| 1191 | root->layer_tree_impl()->current_render_surface_list_id()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1192 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1193 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1194 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1195 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1196 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1197 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1198 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1199 | // Verify it composes correctly with device scale. |
| 1200 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1201 | |
| 1202 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1203 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1204 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1205 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1206 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1207 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1208 | inputs.device_scale_factor = device_scale_factor; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1209 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1210 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1211 | gfx::Transform device_scaled_translate = translate; |
| 1212 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1213 | EXPECT_EQ(device_scaled_translate, |
| 1214 | root->draw_properties().target_space_transform); |
| 1215 | EXPECT_EQ(device_scaled_translate, |
| 1216 | child->draw_properties().target_space_transform); |
| 1217 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1218 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1219 | |
| 1220 | // Verify it composes correctly with page scale. |
| 1221 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1222 | |
| 1223 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1224 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1225 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1226 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1227 | root, root->bounds(), translate, &render_surface_layer_list_impl, |
| 1228 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1229 | inputs.page_scale_factor = page_scale_factor; |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1230 | inputs.page_scale_layer = root; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1231 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1232 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1233 | gfx::Transform page_scaled_translate = translate; |
| 1234 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1235 | EXPECT_EQ(page_scaled_translate, |
| 1236 | root->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1237 | EXPECT_EQ(page_scaled_translate, |
| 1238 | child->draw_properties().target_space_transform); |
| 1239 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1240 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1241 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1242 | // Verify that it composes correctly with transforms directly on root layer. |
| 1243 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1244 | |
| 1245 | { |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1246 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1247 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1248 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1249 | root, root->bounds(), composite, &render_surface_layer_list_impl, |
| 1250 | root->layer_tree_impl()->current_render_surface_list_id()); |
enne | d3f61fb0 | 2015-08-18 22:54:39 | [diff] [blame] | 1251 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1252 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1253 | gfx::Transform compositeSquared = composite; |
| 1254 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1255 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1256 | compositeSquared, root->draw_properties().target_space_transform); |
| 1257 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1258 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1259 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1260 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1261 | } |
| 1262 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1263 | TEST_F(LayerTreeHostCommonTest, |
| 1264 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1265 | LayerImpl* parent = root_layer(); |
| 1266 | parent->SetMasksToBounds(true); |
| 1267 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1268 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1269 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1270 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1271 | const gfx::Transform identity_matrix; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1272 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1273 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1274 | true); |
| 1275 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1276 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1277 | true); |
| 1278 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1279 | gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true, |
| 1280 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1281 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1282 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1283 | |
| 1284 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1285 | // the intermediate render surface should not be listed here, even if it was |
| 1286 | // forced to be created. Render surfaces without children or visible content |
| 1287 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1288 | // of size 0). |
| 1289 | ASSERT_TRUE(parent->render_surface()); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 1290 | EXPECT_EQ(1U, render_surface_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1291 | } |
| 1292 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1293 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1294 | LayerImpl* parent = root_layer(); |
| 1295 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1296 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1297 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1298 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1299 | const gfx::Transform identity_matrix; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1300 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1301 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1302 | true); |
| 1303 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1304 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1305 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1306 | render_surface1->SetOpacity(0.f); |
| 1307 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1308 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1309 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 1310 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1311 | parent, parent->bounds(), &render_surface_layer_list, |
| 1312 | parent->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1313 | inputs.can_adjust_raster_scales = true; |
| 1314 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1315 | |
| 1316 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1317 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1318 | // have been extended by the children. |
| 1319 | ASSERT_TRUE(parent->render_surface()); |
| 1320 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1321 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1322 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1323 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1324 | } |
| 1325 | |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1326 | TEST_F(LayerTreeHostCommonTest, |
| 1327 | RenderSurfaceListForTransparentChildWithBackgroundFilter) { |
| 1328 | LayerImpl* parent = root_layer(); |
| 1329 | LayerImpl* render_surface1 = AddChild<LayerImpl>(parent); |
| 1330 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
| 1331 | child->SetDrawsContent(true); |
| 1332 | |
| 1333 | const gfx::Transform identity_matrix; |
| 1334 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1335 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1336 | true); |
| 1337 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1338 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1339 | true); |
| 1340 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1341 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1342 | false); |
| 1343 | render_surface1->SetOpacity(0.f); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 1344 | render_surface1->SetDrawsContent(true); |
| 1345 | child->SetDrawsContent(true); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1346 | FilterOperations filters; |
| 1347 | filters.Append(FilterOperation::CreateBlurFilter(1.5f)); |
| 1348 | render_surface1->SetBackgroundFilters(filters); |
| 1349 | |
| 1350 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1351 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1352 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1353 | parent, parent->bounds(), &render_surface_layer_list, |
| 1354 | parent->layer_tree_impl()->current_render_surface_list_id()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1355 | inputs.can_adjust_raster_scales = true; |
| 1356 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1357 | |
| 1358 | // The layer is fully transparent, but has a background filter, so it |
| 1359 | // shouldn't be skipped. |
| 1360 | ASSERT_TRUE(parent->render_surface()); |
| 1361 | EXPECT_EQ(1U, parent->render_surface()->layer_list().size()); |
| 1362 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1363 | EXPECT_EQ(gfx::RectF(0, 0, 10, 10), |
| 1364 | parent->render_surface()->DrawableContentRect()); |
hendrikw | c266f7b | 2015-08-21 23:41:34 | [diff] [blame] | 1365 | } |
| 1366 | |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 1367 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) { |
| 1368 | LayerImpl* root = root_layer(); |
| 1369 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1370 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1371 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1372 | child1->SetDrawsContent(true); |
| 1373 | child2->SetDrawsContent(true); |
| 1374 | |
| 1375 | const gfx::Transform identity_matrix; |
| 1376 | gfx::Transform scale_matrix; |
| 1377 | scale_matrix.Scale(2.0f, 2.0f); |
| 1378 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1379 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1380 | true); |
| 1381 | SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(), |
| 1382 | gfx::PointF(), gfx::Size(), true, false, true); |
| 1383 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1384 | gfx::PointF(0, 0), gfx::Size(25, 25), true, |
| 1385 | false, true); |
| 1386 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1387 | gfx::PointF(25, 25), gfx::Size(25, 25), true, |
| 1388 | false, true); |
| 1389 | FilterOperations filters; |
| 1390 | filters.Append(FilterOperation::CreateBlurFilter(10.0f)); |
| 1391 | parent->SetFilters(filters); |
| 1392 | |
| 1393 | LayerImplList render_surface_layer_list; |
| 1394 | parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 1395 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 1396 | root, root->bounds(), &render_surface_layer_list, |
| 1397 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 1398 | inputs.can_adjust_raster_scales = true; |
| 1399 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1400 | |
| 1401 | ASSERT_TRUE(parent->render_surface()); |
| 1402 | EXPECT_EQ(2U, parent->render_surface()->layer_list().size()); |
| 1403 | EXPECT_EQ(4U, render_surface_layer_list.size()); |
| 1404 | EXPECT_EQ(gfx::RectF(-29, -29, 158, 158), |
| 1405 | parent->render_surface()->DrawableContentRect()); |
| 1406 | } |
| 1407 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1408 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1409 | LayerImpl* parent = root_layer(); |
| 1410 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1411 | child->SetDrawsContent(true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1412 | |
| 1413 | const gfx::Transform identity_matrix; |
| 1414 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1415 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1416 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1417 | true); |
| 1418 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1419 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1420 | true); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1421 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1422 | child->SetBlendMode(blend_mode); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1423 | child->SetOpacity(0.5f); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1424 | |
enne | d5f4ddd | 2015-08-18 16:50:06 | [diff] [blame] | 1425 | ExecuteCalculateDrawProperties(parent); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1426 | |
| 1427 | // Since the child layer has a blend mode other than normal, it should get |
| 1428 | // its own render surface. Also, layer's draw_properties should contain the |
| 1429 | // default blend mode, since the render surface becomes responsible for |
| 1430 | // applying the blend mode. |
| 1431 | ASSERT_TRUE(child->render_surface()); |
weiliangc | 451b818f | 2015-07-24 17:52:29 | [diff] [blame] | 1432 | EXPECT_EQ(1.0f, child->draw_opacity()); |
| 1433 | EXPECT_EQ(0.5f, child->render_surface()->draw_opacity()); |
jaydasika | 92239dc | 2015-08-15 02:59:26 | [diff] [blame] | 1434 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1435 | } |
| 1436 | |
jaydasika | fbdb86e | 2016-01-21 18:57:51 | [diff] [blame] | 1437 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) { |
| 1438 | LayerImpl* root = root_layer(); |
| 1439 | LayerImpl* surface1 = AddChildToRoot<LayerImpl>(); |
| 1440 | LayerImpl* not_surface = AddChild<LayerImpl>(surface1); |
| 1441 | LayerImpl* surface2 = AddChild<LayerImpl>(not_surface); |
| 1442 | |
| 1443 | const gfx::Transform identity_matrix; |
| 1444 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1445 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1446 | true); |
| 1447 | SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(), |
| 1448 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1449 | true); |
| 1450 | SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(), |
| 1451 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1452 | false); |
| 1453 | SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(), |
| 1454 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1455 | true); |
| 1456 | surface1->SetDrawsContent(true); |
| 1457 | surface2->SetDrawsContent(true); |
| 1458 | |
| 1459 | surface1->SetOpacity(0.5f); |
| 1460 | not_surface->SetOpacity(0.5f); |
| 1461 | surface2->SetOpacity(0.5f); |
| 1462 | |
| 1463 | ExecuteCalculateDrawProperties(root); |
| 1464 | |
| 1465 | ASSERT_TRUE(surface1->render_surface()); |
| 1466 | ASSERT_FALSE(not_surface->render_surface()); |
| 1467 | ASSERT_TRUE(surface2->render_surface()); |
| 1468 | EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity()); |
| 1469 | // surface2's draw opacity should include the opacity of not-surface and |
| 1470 | // itself, but not the opacity of surface1. |
| 1471 | EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity()); |
| 1472 | } |
| 1473 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1474 | TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) { |
| 1475 | // Tests that when separate surfaces are disabled, a layer's draw opacity is |
| 1476 | // the product of all ancestor layer opacties and the layer's own opacity. |
| 1477 | // (Rendering will still be incorrect in situations where we really do need |
| 1478 | // surfaces to apply opacity, such as when we have overlapping layers with an |
| 1479 | // ancestor whose opacity is <1.) |
| 1480 | LayerImpl* root = root_layer(); |
| 1481 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1482 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1483 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1484 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1485 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1486 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1487 | |
| 1488 | root->SetDrawsContent(true); |
| 1489 | parent->SetDrawsContent(true); |
| 1490 | child1->SetDrawsContent(true); |
| 1491 | child2->SetDrawsContent(true); |
| 1492 | grand_child->SetDrawsContent(true); |
| 1493 | leaf_node1->SetDrawsContent(true); |
| 1494 | leaf_node2->SetDrawsContent(true); |
| 1495 | |
| 1496 | const gfx::Transform identity_matrix; |
| 1497 | |
| 1498 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1499 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1500 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1501 | true); |
| 1502 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1503 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1504 | false); |
| 1505 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1506 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1507 | true); |
| 1508 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1509 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1510 | false); |
| 1511 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1512 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1513 | true); |
| 1514 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1515 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1516 | false); |
| 1517 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1518 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1519 | false); |
| 1520 | |
| 1521 | child1->SetOpacity(0.5f); |
| 1522 | grand_child->SetOpacity(0.5f); |
| 1523 | leaf_node1->SetOpacity(0.5f); |
| 1524 | leaf_node2->SetOpacity(0.5f); |
| 1525 | |
| 1526 | // With surfaces enabled, each layer's draw opacity is the product of layer |
| 1527 | // opacities on the path from the layer to its render target, not including |
| 1528 | // the opacity of the layer that owns the target surface (since that opacity |
| 1529 | // is applied by the surface). |
| 1530 | ExecuteCalculateDrawProperties(root); |
| 1531 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1532 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1533 | EXPECT_EQ(1.f, child1->draw_opacity()); |
| 1534 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1535 | EXPECT_EQ(1.f, grand_child->draw_opacity()); |
| 1536 | EXPECT_EQ(0.5f, leaf_node1->draw_opacity()); |
| 1537 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1538 | |
| 1539 | // With surfaces disabled, each layer's draw opacity is the product of layer |
| 1540 | // opacities on the path from the layer to the root. |
| 1541 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1542 | EXPECT_EQ(1.f, root->draw_opacity()); |
| 1543 | EXPECT_EQ(1.f, parent->draw_opacity()); |
| 1544 | EXPECT_EQ(0.5f, child1->draw_opacity()); |
| 1545 | EXPECT_EQ(1.f, child2->draw_opacity()); |
| 1546 | EXPECT_EQ(0.25f, grand_child->draw_opacity()); |
| 1547 | EXPECT_EQ(0.125f, leaf_node1->draw_opacity()); |
| 1548 | EXPECT_EQ(0.5f, leaf_node2->draw_opacity()); |
| 1549 | } |
| 1550 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1551 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1552 | LayerImpl* parent = root_layer(); |
| 1553 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 1554 | LayerImpl* child = AddChild<LayerImpl>(render_surface1); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1555 | |
| 1556 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1557 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1558 | gfx::PointF(), gfx::Size(10, 10), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1559 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 1560 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1561 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1562 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1563 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1564 | child->SetDrawsContent(true); |
| 1565 | render_surface1->SetForceRenderSurface(true); |
weiliangc | effae046 | 2015-12-08 23:17:26 | [diff] [blame] | 1566 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1567 | { |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1568 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1569 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1570 | // The root layer always creates a render surface |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1571 | EXPECT_TRUE(parent->has_render_surface()); |
| 1572 | EXPECT_TRUE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1573 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1574 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1575 | { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1576 | render_surface1->SetForceRenderSurface(false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1577 | render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1578 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 1579 | EXPECT_TRUE(parent->has_render_surface()); |
| 1580 | EXPECT_FALSE(render_surface1->has_render_surface()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1581 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1582 | } |
| 1583 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1584 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1585 | // Render surfaces act as a flattening point for their subtree, so should |
| 1586 | // always flatten the target-to-screen space transform seen by descendants. |
| 1587 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1588 | LayerImpl* root = root_layer(); |
| 1589 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1590 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 1591 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1592 | |
| 1593 | child->SetDrawsContent(true); |
| 1594 | grand_child->SetDrawsContent(true); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1595 | |
| 1596 | gfx::Transform rotation_about_y_axis; |
| 1597 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1598 | // Make |parent| have a render surface. |
| 1599 | parent->SetOpacity(0.9f); |
| 1600 | |
| 1601 | const gfx::Transform identity_matrix; |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1602 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1603 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1604 | true); |
| 1605 | SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(), |
| 1606 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1607 | true); |
| 1608 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1609 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1610 | false); |
| 1611 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1612 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 1613 | false); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1614 | |
| 1615 | grand_child->SetShouldFlattenTransform(false); |
| 1616 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1617 | // Only grand_child should preserve 3d. |
| 1618 | EXPECT_TRUE(root->should_flatten_transform()); |
| 1619 | EXPECT_TRUE(parent->should_flatten_transform()); |
| 1620 | EXPECT_TRUE(child->should_flatten_transform()); |
| 1621 | EXPECT_FALSE(grand_child->should_flatten_transform()); |
| 1622 | |
| 1623 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1624 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1625 | |
| 1626 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1627 | flattened_rotation_about_y.FlattenTo2d(); |
| 1628 | |
enne | 1a79c554 | 2015-08-18 19:43:57 | [diff] [blame] | 1629 | ExecuteCalculateDrawProperties(root); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1630 | |
| 1631 | EXPECT_TRUE(parent->render_surface()); |
| 1632 | EXPECT_FALSE(child->render_surface()); |
| 1633 | EXPECT_FALSE(grand_child->render_surface()); |
| 1634 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1635 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1636 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 1637 | grand_child->DrawTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1638 | |
| 1639 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1640 | // have been flattened at their render target. In particular, the fact that |
| 1641 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1642 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1643 | child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1644 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 1645 | grand_child->ScreenSpaceTransform()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1646 | } |
| 1647 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1648 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1649 | // The entire subtree of layers that are outside the clip rect should be |
| 1650 | // culled away, and should not affect the render_surface_layer_list. |
| 1651 | // |
| 1652 | // The test tree is set up as follows: |
| 1653 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1654 | // that have something to draw. |
| 1655 | // - parent is a large container layer. |
| 1656 | // - child has masksToBounds=true to cause clipping. |
| 1657 | // - grand_child is positioned outside of the child's bounds |
| 1658 | // - great_grand_child is also kept outside child's bounds. |
| 1659 | // |
| 1660 | // In this configuration, grand_child and great_grand_child are completely |
| 1661 | // outside the clip rect, and they should never get scheduled on the list of |
| 1662 | // render surfaces. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1663 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1664 | LayerImpl* parent = root_layer(); |
| 1665 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1666 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1667 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1668 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1669 | // leaf_node1 ensures that parent and child are kept on the |
| 1670 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1671 | // should be clipped. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1672 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(child); |
| 1673 | leaf_node1->SetDrawsContent(true); |
| 1674 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child); |
| 1675 | leaf_node2->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1676 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1677 | const gfx::Transform identity_matrix; |
| 1678 | |
| 1679 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1680 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 1681 | true); |
| 1682 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1683 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1684 | true); |
| 1685 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1686 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 1687 | false, false); |
| 1688 | SetLayerPropertiesForTesting(great_grand_child, identity_matrix, |
| 1689 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1690 | true, false, false); |
| 1691 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1692 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1693 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1694 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1695 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1696 | false); |
| 1697 | |
| 1698 | child->SetMasksToBounds(true); |
| 1699 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1700 | grand_child->SetOpacity(0.5f); |
| 1701 | great_grand_child->SetOpacity(0.4f); |
| 1702 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1703 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1704 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1705 | ASSERT_EQ(2U, render_surface_layer_list_impl()->size()); |
| 1706 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
| 1707 | EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1708 | } |
| 1709 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1710 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | // 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] | 1712 | // of the surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1713 | |
| 1714 | // The test tree is set up as follows: |
| 1715 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1716 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1717 | // the parent. |
| 1718 | // - grand_child is a render surface, and the only visible content in child. |
| 1719 | // It is positioned outside of the clip rect from parent. |
| 1720 | |
| 1721 | // In this configuration, grand_child should be outside the clipped |
| 1722 | // content rect of the child, making grand_child not appear in the |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1723 | // render_surface_layer_list. |
| 1724 | |
| 1725 | LayerImpl* parent = root_layer(); |
| 1726 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 1727 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 1728 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 1729 | leaf_node->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1730 | |
| 1731 | const gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1732 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1733 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1734 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1735 | true); |
| 1736 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 1737 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 1738 | true); |
| 1739 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1740 | gfx::PointF(200.f, 200.f), gfx::Size(10, 10), |
| 1741 | true, false, true); |
| 1742 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 1743 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | false); |
| 1745 | |
| 1746 | parent->SetMasksToBounds(true); |
| 1747 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1748 | grand_child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1749 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1750 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1751 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 1752 | // We should cull child and grand_child from the |
| 1753 | // render_surface_layer_list. |
| 1754 | ASSERT_EQ(1U, render_surface_layer_list_impl()->size()); |
| 1755 | EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1756 | } |
| 1757 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1758 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) { |
| 1759 | // Tests that LayerImpl's IsClipped() property is set to true when: |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1760 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1761 | // - the layer is clipped by an ancestor that contributes to the same |
| 1762 | // render target, |
| 1763 | // - a surface is clipped by an ancestor that contributes to the same |
| 1764 | // render target. |
| 1765 | // |
| 1766 | // In particular, for a layer that owns a render surface: |
| 1767 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1768 | // pass that clipped status to the layer itself. |
| 1769 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1770 | // and propagates the clip to the subtree. |
| 1771 | |
| 1772 | const gfx::Transform identity_matrix; |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1773 | LayerImpl* root = root_layer(); |
| 1774 | LayerImpl* parent = AddChild<LayerImpl>(root); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1775 | parent->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1776 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1777 | child1->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1778 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1779 | child2->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1780 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 1781 | grand_child->SetDrawsContent(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1782 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1783 | leaf_node1->SetDrawsContent(true); |
| 1784 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1785 | leaf_node2->SetDrawsContent(true); |
| 1786 | |
| 1787 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1788 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1789 | true); |
| 1790 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1791 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1792 | false); |
| 1793 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1794 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1795 | false); |
| 1796 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1797 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1798 | true); |
| 1799 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1800 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1801 | false); |
| 1802 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1803 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1804 | false); |
| 1805 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1806 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1807 | false); |
| 1808 | |
| 1809 | // Case 1: nothing is clipped except the root render surface. |
| 1810 | { |
| 1811 | ExecuteCalculateDrawProperties(root); |
| 1812 | |
| 1813 | ASSERT_TRUE(root->render_surface()); |
| 1814 | ASSERT_TRUE(child2->render_surface()); |
| 1815 | |
| 1816 | EXPECT_FALSE(root->is_clipped()); |
| 1817 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1818 | EXPECT_FALSE(parent->is_clipped()); |
| 1819 | EXPECT_FALSE(child1->is_clipped()); |
| 1820 | EXPECT_FALSE(child2->is_clipped()); |
| 1821 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1822 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1823 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1824 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1825 | } |
| 1826 | |
| 1827 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1828 | // surface are clipped. But layers that contribute to child2's surface are |
| 1829 | // not clipped explicitly because child2's surface already accounts for |
| 1830 | // that clip. |
| 1831 | { |
| 1832 | parent->SetMasksToBounds(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1833 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1834 | |
| 1835 | ExecuteCalculateDrawProperties(root); |
| 1836 | |
| 1837 | ASSERT_TRUE(root->render_surface()); |
| 1838 | ASSERT_TRUE(child2->render_surface()); |
| 1839 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1840 | EXPECT_FALSE(root->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1841 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1842 | EXPECT_TRUE(parent->is_clipped()); |
| 1843 | EXPECT_TRUE(child1->is_clipped()); |
| 1844 | EXPECT_FALSE(child2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1845 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 1846 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1847 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1848 | EXPECT_FALSE(leaf_node2->is_clipped()); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1849 | |
| 1850 | parent->SetMasksToBounds(false); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1854 | // child2's render surface is not clipped. |
| 1855 | { |
| 1856 | child2->SetMasksToBounds(true); |
enne | 76bf898 | 2015-08-18 17:55:33 | [diff] [blame] | 1857 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
| 1858 | |
| 1859 | ExecuteCalculateDrawProperties(root); |
| 1860 | |
| 1861 | ASSERT_TRUE(root->render_surface()); |
| 1862 | ASSERT_TRUE(child2->render_surface()); |
| 1863 | |
| 1864 | EXPECT_FALSE(root->is_clipped()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1865 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1866 | EXPECT_FALSE(parent->is_clipped()); |
| 1867 | EXPECT_FALSE(child1->is_clipped()); |
| 1868 | EXPECT_TRUE(child2->is_clipped()); |
| 1869 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1870 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1871 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1872 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1873 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1874 | } |
| 1875 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1876 | TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) { |
| 1877 | // Tests that when separate surfaces are disabled, is_clipped is true exactly |
| 1878 | // when a layer or its ancestor has a clip; in particular, if a layer |
| 1879 | // is_clipped, so is its entire subtree (since there are no render surfaces |
| 1880 | // that can reset is_clipped). |
| 1881 | LayerImpl* root = root_layer(); |
| 1882 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 1883 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 1884 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 1885 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 1886 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 1887 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 1888 | |
| 1889 | root->SetDrawsContent(true); |
| 1890 | parent->SetDrawsContent(true); |
| 1891 | child1->SetDrawsContent(true); |
| 1892 | child2->SetDrawsContent(true); |
| 1893 | grand_child->SetDrawsContent(true); |
| 1894 | leaf_node1->SetDrawsContent(true); |
| 1895 | leaf_node2->SetDrawsContent(true); |
| 1896 | |
| 1897 | const gfx::Transform identity_matrix; |
| 1898 | |
| 1899 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 1900 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 1901 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1902 | true); |
| 1903 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 1904 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1905 | false); |
| 1906 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 1907 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1908 | true); |
| 1909 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 1910 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1911 | false); |
| 1912 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 1913 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1914 | true); |
| 1915 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 1916 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1917 | false); |
| 1918 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 1919 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 1920 | false); |
| 1921 | |
| 1922 | // Case 1: Nothing is clipped. In this case, is_clipped is always false, with |
| 1923 | // or without surfaces. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1924 | root->SetHasRenderSurface(true); |
| 1925 | child1->SetHasRenderSurface(true); |
| 1926 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1927 | ExecuteCalculateDrawProperties(root); |
| 1928 | EXPECT_FALSE(root->is_clipped()); |
| 1929 | EXPECT_FALSE(parent->is_clipped()); |
| 1930 | EXPECT_FALSE(child1->is_clipped()); |
| 1931 | EXPECT_FALSE(child2->is_clipped()); |
| 1932 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1933 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1934 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1935 | |
| 1936 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1937 | EXPECT_FALSE(root->is_clipped()); |
| 1938 | EXPECT_FALSE(parent->is_clipped()); |
| 1939 | EXPECT_FALSE(child1->is_clipped()); |
| 1940 | EXPECT_FALSE(child2->is_clipped()); |
| 1941 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1942 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1943 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1944 | |
| 1945 | // Case 2: The root is clipped. With surfaces, this only persists until the |
| 1946 | // next render surface. Without surfaces, the entire tree is clipped. |
| 1947 | root->SetMasksToBounds(true); |
| 1948 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1949 | root->SetHasRenderSurface(true); |
| 1950 | child1->SetHasRenderSurface(true); |
| 1951 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1952 | ExecuteCalculateDrawProperties(root); |
| 1953 | EXPECT_TRUE(root->is_clipped()); |
| 1954 | EXPECT_TRUE(parent->is_clipped()); |
| 1955 | EXPECT_FALSE(child1->is_clipped()); |
| 1956 | EXPECT_TRUE(child2->is_clipped()); |
| 1957 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1958 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1959 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1960 | |
| 1961 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1962 | EXPECT_TRUE(root->is_clipped()); |
| 1963 | EXPECT_TRUE(parent->is_clipped()); |
| 1964 | EXPECT_TRUE(child1->is_clipped()); |
| 1965 | EXPECT_TRUE(child2->is_clipped()); |
| 1966 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1967 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1968 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1969 | |
| 1970 | root->SetMasksToBounds(false); |
| 1971 | |
| 1972 | // Case 3: The parent is clipped. Again, with surfaces, this only persists |
| 1973 | // until the next render surface. Without surfaces, parent's entire subtree is |
| 1974 | // clipped. |
| 1975 | parent->SetMasksToBounds(true); |
| 1976 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 1977 | root->SetHasRenderSurface(true); |
| 1978 | child1->SetHasRenderSurface(true); |
| 1979 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 1980 | ExecuteCalculateDrawProperties(root); |
| 1981 | EXPECT_FALSE(root->is_clipped()); |
| 1982 | EXPECT_TRUE(parent->is_clipped()); |
| 1983 | EXPECT_FALSE(child1->is_clipped()); |
| 1984 | EXPECT_TRUE(child2->is_clipped()); |
| 1985 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1986 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1987 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1988 | |
| 1989 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 1990 | EXPECT_FALSE(root->is_clipped()); |
| 1991 | EXPECT_TRUE(parent->is_clipped()); |
| 1992 | EXPECT_TRUE(child1->is_clipped()); |
| 1993 | EXPECT_TRUE(child2->is_clipped()); |
| 1994 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1995 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1996 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1997 | |
| 1998 | parent->SetMasksToBounds(false); |
| 1999 | |
| 2000 | // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it |
| 2001 | // has no non-surface children. Without surfaces, child1's entire subtree is |
| 2002 | // clipped. |
| 2003 | child1->SetMasksToBounds(true); |
| 2004 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2005 | root->SetHasRenderSurface(true); |
| 2006 | child1->SetHasRenderSurface(true); |
| 2007 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2008 | ExecuteCalculateDrawProperties(root); |
| 2009 | EXPECT_FALSE(root->is_clipped()); |
| 2010 | EXPECT_FALSE(parent->is_clipped()); |
| 2011 | EXPECT_TRUE(child1->is_clipped()); |
| 2012 | EXPECT_FALSE(child2->is_clipped()); |
| 2013 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2014 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2015 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2016 | |
| 2017 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2018 | EXPECT_FALSE(root->is_clipped()); |
| 2019 | EXPECT_FALSE(parent->is_clipped()); |
| 2020 | EXPECT_TRUE(child1->is_clipped()); |
| 2021 | EXPECT_FALSE(child2->is_clipped()); |
| 2022 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2023 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2024 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2025 | |
| 2026 | child1->SetMasksToBounds(false); |
| 2027 | |
| 2028 | // Case 5: Only the leaf nodes are clipped. The behavior with and without |
| 2029 | // surfaces is the same. |
| 2030 | leaf_node1->SetMasksToBounds(true); |
| 2031 | leaf_node2->SetMasksToBounds(true); |
| 2032 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2033 | root->SetHasRenderSurface(true); |
| 2034 | child1->SetHasRenderSurface(true); |
| 2035 | grand_child->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2036 | ExecuteCalculateDrawProperties(root); |
| 2037 | EXPECT_FALSE(root->is_clipped()); |
| 2038 | EXPECT_FALSE(parent->is_clipped()); |
| 2039 | EXPECT_FALSE(child1->is_clipped()); |
| 2040 | EXPECT_FALSE(child2->is_clipped()); |
| 2041 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2042 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2043 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2044 | |
| 2045 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2046 | EXPECT_FALSE(root->is_clipped()); |
| 2047 | EXPECT_FALSE(parent->is_clipped()); |
| 2048 | EXPECT_FALSE(child1->is_clipped()); |
| 2049 | EXPECT_FALSE(child2->is_clipped()); |
| 2050 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2051 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2052 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2053 | } |
| 2054 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 2055 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2056 | // Verify that layers get the appropriate DrawableContentRect when their |
| 2057 | // parent masksToBounds is true. |
| 2058 | // |
| 2059 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2060 | // be the layer rect expressed in target space. |
| 2061 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 2062 | // will be the intersection of layer bounds and the mask region. |
| 2063 | // grand_child3 - partially clipped and masksToBounds; the |
| 2064 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2065 | // the mask region. |
| 2066 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2067 | // be empty. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2068 | |
| 2069 | const gfx::Transform identity_matrix; |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2070 | LayerImpl* parent = root_layer(); |
| 2071 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2072 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2073 | grand_child1->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2074 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2075 | grand_child2->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2076 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2077 | grand_child3->SetDrawsContent(true); |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2078 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2079 | grand_child4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2080 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2081 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2082 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2083 | true); |
| 2084 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2085 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2086 | true); |
| 2087 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2088 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2089 | false, false); |
| 2090 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2091 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2092 | false, false); |
| 2093 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2094 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2095 | false, false); |
| 2096 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2097 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2098 | false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2099 | |
| 2100 | child->SetMasksToBounds(true); |
| 2101 | grand_child3->SetMasksToBounds(true); |
| 2102 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2103 | // Force child to be a render surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2104 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2105 | |
enne | 07405c77 | 2015-08-18 17:56:45 | [diff] [blame] | 2106 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2108 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2109 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2110 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2111 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2112 | } |
| 2113 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2114 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2115 | // Verify that render surfaces (and their layers) get the appropriate |
| 2116 | // clip rects when their parent masksToBounds is true. |
| 2117 | // |
| 2118 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2119 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2120 | // They may still have a clip rect of their own layer bounds, however, if |
| 2121 | // masksToBounds was true. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2122 | LayerImpl* parent = root_layer(); |
| 2123 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2124 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 2125 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 2126 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 2127 | LayerImpl* grand_child4 = AddChild<LayerImpl>(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2129 | // this test. |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2130 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 2131 | leaf_node1->SetDrawsContent(true); |
| 2132 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 2133 | leaf_node2->SetDrawsContent(true); |
| 2134 | LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3); |
| 2135 | leaf_node3->SetDrawsContent(true); |
| 2136 | LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4); |
| 2137 | leaf_node4->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2139 | const gfx::Transform identity_matrix; |
| 2140 | |
| 2141 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2142 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 2143 | true); |
| 2144 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2145 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 2146 | true); |
| 2147 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 2148 | gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true, |
| 2149 | false, true); |
| 2150 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 2151 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2152 | false, true); |
| 2153 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 2154 | gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true, |
| 2155 | false, true); |
| 2156 | SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(), |
| 2157 | gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true, |
| 2158 | false, true); |
| 2159 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2160 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2161 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2162 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2163 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2164 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2165 | SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(), |
| 2166 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2167 | false); |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2168 | SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(), |
| 2169 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2170 | false); |
| 2171 | |
| 2172 | child->SetMasksToBounds(true); |
| 2173 | grand_child3->SetMasksToBounds(true); |
| 2174 | grand_child4->SetMasksToBounds(true); |
| 2175 | |
| 2176 | // Force everyone to be a render surface. |
| 2177 | child->SetOpacity(0.4f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2178 | grand_child1->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2179 | grand_child2->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2180 | grand_child3->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2181 | grand_child4->SetOpacity(0.5f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2182 | |
weiliangc | fb3d5eaa | 2015-07-28 23:54:57 | [diff] [blame] | 2183 | ExecuteCalculateDrawProperties(parent); |
| 2184 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2185 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2186 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2187 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2188 | |
| 2189 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2190 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2191 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2192 | grand_child1->render_surface()->clip_rect()); |
| 2193 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2194 | grand_child2->render_surface()->clip_rect()); |
| 2195 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2196 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2197 | } |
| 2198 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2199 | TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) { |
| 2200 | // Tests that when separate surfaces are disabled, a layer's clip_rect is the |
| 2201 | // intersection of all ancestor clips in screen space; in particular, if a |
| 2202 | // layer masks to bounds, it contributes to the clip_rect of all layers in its |
| 2203 | // subtree (since there are no render surfaces that can reset the clip_rect). |
| 2204 | LayerImpl* root = root_layer(); |
| 2205 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2206 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 2207 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 2208 | LayerImpl* grand_child = AddChild<LayerImpl>(child1); |
| 2209 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child); |
| 2210 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2); |
| 2211 | |
| 2212 | root->SetDrawsContent(true); |
| 2213 | parent->SetDrawsContent(true); |
| 2214 | child1->SetDrawsContent(true); |
| 2215 | child2->SetDrawsContent(true); |
| 2216 | grand_child->SetDrawsContent(true); |
| 2217 | leaf_node1->SetDrawsContent(true); |
| 2218 | leaf_node2->SetDrawsContent(true); |
| 2219 | |
| 2220 | const gfx::Transform identity_matrix; |
| 2221 | |
| 2222 | // child1 and grand_child get render surfaces when surfaces are enabled. |
| 2223 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2224 | gfx::PointF(), gfx::Size(100, 100), true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2225 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2226 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2227 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2228 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 2229 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2230 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2231 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 2232 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2233 | false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2234 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2235 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2236 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2237 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 2238 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2239 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2240 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 2241 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2242 | true, false); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2243 | |
| 2244 | // Case 1: Nothing is clipped. In this case, each layer's clip rect is its |
| 2245 | // bounds in target space. The only thing that changes when surfaces are |
| 2246 | // disabled is that target space is always screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2247 | root->SetForceRenderSurface(true); |
| 2248 | child1->SetForceRenderSurface(true); |
| 2249 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2250 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2251 | EXPECT_TRUE(root->has_render_surface()); |
| 2252 | EXPECT_FALSE(parent->has_render_surface()); |
| 2253 | EXPECT_TRUE(child1->has_render_surface()); |
| 2254 | EXPECT_FALSE(child2->has_render_surface()); |
| 2255 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2256 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2257 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2258 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2259 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2260 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2261 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect()); |
| 2262 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect()); |
| 2263 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect()); |
| 2264 | EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect()); |
| 2265 | |
| 2266 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2267 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2268 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2269 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->clip_rect()); |
| 2270 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect()); |
| 2271 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), grand_child->clip_rect()); |
| 2272 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->clip_rect()); |
| 2273 | EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect()); |
| 2274 | |
| 2275 | // Case 2: The root is clipped. In this case, layers that draw into the root |
| 2276 | // render surface are clipped by the root's bounds. |
| 2277 | root->SetMasksToBounds(true); |
| 2278 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2279 | root->SetForceRenderSurface(true); |
| 2280 | child1->SetForceRenderSurface(true); |
| 2281 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2282 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2283 | EXPECT_TRUE(root->has_render_surface()); |
| 2284 | EXPECT_FALSE(parent->has_render_surface()); |
| 2285 | EXPECT_TRUE(child1->has_render_surface()); |
| 2286 | EXPECT_FALSE(child2->has_render_surface()); |
| 2287 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2288 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2289 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2290 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2291 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2292 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2293 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2294 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect()); |
| 2295 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect()); |
| 2296 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2297 | |
| 2298 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2299 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2300 | EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect()); |
| 2301 | EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect()); |
| 2302 | EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect()); |
| 2303 | EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect()); |
| 2304 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect()); |
| 2305 | EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect()); |
| 2306 | |
| 2307 | root->SetMasksToBounds(false); |
| 2308 | |
| 2309 | // Case 3: The parent and child1 are clipped. When surfaces are enabled, the |
| 2310 | // parent clip rect only contributes to the subtree rooted at child2, since |
| 2311 | // the subtree rooted at child1 renders into a separate surface. Similarly, |
| 2312 | // child1's clip rect doesn't contribute to its descendants, since its only |
| 2313 | // child is a render surface. However, without surfaces, these clip rects |
| 2314 | // contribute to all descendants. |
| 2315 | parent->SetMasksToBounds(true); |
| 2316 | child1->SetMasksToBounds(true); |
| 2317 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2318 | root->SetForceRenderSurface(true); |
| 2319 | child1->SetForceRenderSurface(true); |
| 2320 | grand_child->SetForceRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2321 | ExecuteCalculateDrawProperties(root); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2322 | EXPECT_TRUE(root->has_render_surface()); |
| 2323 | EXPECT_FALSE(parent->has_render_surface()); |
| 2324 | EXPECT_TRUE(child1->has_render_surface()); |
| 2325 | EXPECT_FALSE(child2->has_render_surface()); |
| 2326 | EXPECT_TRUE(grand_child->has_render_surface()); |
| 2327 | EXPECT_FALSE(leaf_node1->has_render_surface()); |
| 2328 | EXPECT_FALSE(leaf_node2->has_render_surface()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2329 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2330 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2331 | EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect()); |
| 2332 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2333 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect()); |
| 2334 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect()); |
| 2335 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2336 | |
| 2337 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2338 | EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect()); |
| 2339 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect()); |
| 2340 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect()); |
| 2341 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect()); |
| 2342 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect()); |
| 2343 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect()); |
| 2344 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect()); |
| 2345 | } |
| 2346 | |
| 2347 | TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) { |
| 2348 | // Tests that draw properties are computed correctly when we disable and then |
| 2349 | // re-enable separate surfaces. |
| 2350 | LayerImpl* root = root_layer(); |
| 2351 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 2352 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2353 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2354 | LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child); |
| 2355 | |
| 2356 | root->SetDrawsContent(true); |
| 2357 | parent->SetDrawsContent(true); |
| 2358 | child->SetDrawsContent(true); |
| 2359 | grand_child->SetDrawsContent(true); |
| 2360 | leaf_node->SetDrawsContent(true); |
| 2361 | |
| 2362 | const gfx::Transform identity_matrix; |
| 2363 | |
| 2364 | // child and grand_child get render surfaces when surfaces are enabled. |
| 2365 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2366 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2367 | true); |
| 2368 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 2369 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 2370 | false, false); |
| 2371 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 2372 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 2373 | false, true); |
| 2374 | SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(), |
| 2375 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 2376 | true, false, true); |
| 2377 | SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(), |
| 2378 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 2379 | true, false, false); |
| 2380 | |
| 2381 | parent->SetMasksToBounds(true); |
| 2382 | child->SetMasksToBounds(true); |
| 2383 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2384 | root->SetHasRenderSurface(true); |
| 2385 | child->SetHasRenderSurface(true); |
| 2386 | grand_child->SetHasRenderSurface(true); |
| 2387 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2388 | gfx::Transform expected_leaf_draw_transform_with_surfaces; |
| 2389 | expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0); |
| 2390 | |
| 2391 | gfx::Transform expected_leaf_draw_transform_without_surfaces; |
| 2392 | expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0); |
| 2393 | |
| 2394 | ExecuteCalculateDrawProperties(root); |
| 2395 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect()); |
| 2396 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2397 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2398 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2399 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2400 | root->SetHasRenderSurface(true); |
| 2401 | child->SetHasRenderSurface(true); |
| 2402 | grand_child->SetHasRenderSurface(true); |
| 2403 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2404 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 2405 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect()); |
| 2406 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect()); |
| 2407 | EXPECT_EQ(expected_leaf_draw_transform_without_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2408 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2409 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 2410 | root->SetHasRenderSurface(true); |
| 2411 | child->SetHasRenderSurface(true); |
| 2412 | grand_child->SetHasRenderSurface(true); |
| 2413 | |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2414 | ExecuteCalculateDrawProperties(root); |
| 2415 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect()); |
| 2416 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect()); |
| 2417 | EXPECT_EQ(expected_leaf_draw_transform_with_surfaces, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 2418 | leaf_node->DrawTransform()); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 2419 | } |
| 2420 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2421 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2422 | LayerImpl* parent = root_layer(); |
| 2423 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 2424 | LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1); |
| 2425 | LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1); |
| 2426 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 2427 | LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2); |
| 2428 | LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2); |
| 2429 | LayerImpl* child_of_root = AddChildToRoot<LayerImpl>(); |
| 2430 | LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2431 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2432 | parent->SetDrawsContent(true); |
| 2433 | render_surface1->SetDrawsContent(true); |
| 2434 | child_of_rs1->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2435 | grand_child_of_rs1->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2436 | render_surface2->SetDrawsContent(true); |
| 2437 | child_of_rs2->SetDrawsContent(true); |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2438 | grand_child_of_rs2->SetDrawsContent(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 2439 | child_of_root->SetDrawsContent(true); |
| 2440 | grand_child_of_root->SetDrawsContent(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2441 | |
| 2442 | gfx::Transform layer_transform; |
| 2443 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2445 | SetLayerPropertiesForTesting( |
| 2446 | parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2447 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2448 | SetLayerPropertiesForTesting( |
| 2449 | render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2450 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2451 | SetLayerPropertiesForTesting( |
| 2452 | render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2453 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true); |
| 2454 | SetLayerPropertiesForTesting( |
| 2455 | child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2456 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2457 | SetLayerPropertiesForTesting( |
| 2458 | child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2459 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2460 | SetLayerPropertiesForTesting( |
| 2461 | child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2462 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2463 | SetLayerPropertiesForTesting( |
| 2464 | grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2465 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2466 | SetLayerPropertiesForTesting( |
| 2467 | grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2468 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
| 2469 | SetLayerPropertiesForTesting( |
| 2470 | grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
| 2471 | gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2472 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 2473 | if (layer_settings().use_compositor_animation_timelines) { |
| 2474 | // Put an animated opacity on the render surface. |
| 2475 | AddOpacityTransitionToLayerWithPlayer( |
| 2476 | render_surface1->id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2477 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 2478 | // Also put an animated opacity on a layer without descendants. |
| 2479 | AddOpacityTransitionToLayerWithPlayer( |
| 2480 | grand_child_of_root->id(), timeline_impl(), 10.0, 1.f, 0.f, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2481 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 2482 | // Put a transform animation on the render surface. |
| 2483 | AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), |
| 2484 | timeline_impl(), 10.0, 30, 0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 2486 | // Also put transform animations on grand_child_of_root, and |
| 2487 | // grand_child_of_rs2 |
| 2488 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), |
| 2489 | timeline_impl(), 10.0, 30, 0); |
| 2490 | AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), |
| 2491 | timeline_impl(), 10.0, 30, 0); |
| 2492 | } else { |
| 2493 | // Put an animated opacity on the render surface. |
| 2494 | AddOpacityTransitionToController( |
| 2495 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2496 | |
| 2497 | // Also put an animated opacity on a layer without descendants. |
| 2498 | AddOpacityTransitionToController( |
| 2499 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, |
| 2500 | false); |
| 2501 | |
| 2502 | // Put a transform animation on the render surface. |
| 2503 | AddAnimatedTransformToController( |
| 2504 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2505 | |
| 2506 | // Also put transform animations on grand_child_of_root, and |
| 2507 | // grand_child_of_rs2 |
| 2508 | AddAnimatedTransformToController( |
| 2509 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2510 | AddAnimatedTransformToController( |
| 2511 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2512 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2513 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2514 | ExecuteCalculateDrawProperties(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2515 | |
| 2516 | // Only layers that are associated with render surfaces should have an actual |
| 2517 | // RenderSurface() value. |
| 2518 | ASSERT_TRUE(parent->render_surface()); |
| 2519 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2520 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2521 | |
| 2522 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2523 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2524 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2525 | |
| 2526 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2527 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2528 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2529 | |
| 2530 | // Verify all render target accessors |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2531 | EXPECT_EQ(parent, parent->render_target()); |
| 2532 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2533 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2534 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2535 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2536 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2537 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2538 | |
enne | ab0fee4 | 2015-07-07 17:36:42 | [diff] [blame] | 2539 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2540 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2541 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2542 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2543 | // Verify screen_space_transform_is_animating values |
| 2544 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2545 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2546 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2547 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2548 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2549 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2550 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2551 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2552 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2553 | |
| 2554 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2555 | // It is expected that we correctly set up transforms so that the y-component |
| 2556 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2557 | EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2558 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2559 | child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2560 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2561 | 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2562 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2563 | EXPECT_FLOAT_EQ(2.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2564 | render_surface1->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2565 | EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2566 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2567 | 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2568 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2569 | EXPECT_FLOAT_EQ(3.0, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2570 | render_surface2->ScreenSpaceTransform().matrix().get(1, 3)); |
| 2571 | EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2572 | EXPECT_FLOAT_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 2573 | 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2574 | } |
| 2575 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 2576 | TEST_F(LayerTreeHostCommonTest, LargeTransforms) { |
| 2577 | LayerImpl* parent = root_layer(); |
| 2578 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 2579 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2580 | |
| 2581 | grand_child->SetDrawsContent(true); |
| 2582 | |
| 2583 | gfx::Transform large_transform; |
| 2584 | large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); |
| 2585 | |
| 2586 | gfx::Transform identity; |
| 2587 | |
| 2588 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2589 | gfx::Size(10, 10), true, false, true); |
| 2590 | SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(), |
| 2591 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2592 | false); |
| 2593 | SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(), |
| 2594 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2595 | false); |
| 2596 | ExecuteCalculateDrawProperties(parent); |
| 2597 | |
| 2598 | EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect()); |
| 2599 | } |
| 2600 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2601 | TEST_F(LayerTreeHostCommonTest, |
| 2602 | ScreenSpaceTransformIsAnimatingWithDelayedAnimation) { |
| 2603 | LayerImpl* parent = root_layer(); |
| 2604 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 2605 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 2606 | LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child); |
| 2607 | |
| 2608 | parent->SetDrawsContent(true); |
| 2609 | child->SetDrawsContent(true); |
| 2610 | grand_child->SetDrawsContent(true); |
| 2611 | great_grand_child->SetDrawsContent(true); |
| 2612 | |
| 2613 | gfx::Transform identity; |
| 2614 | |
| 2615 | SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(), |
| 2616 | gfx::Size(10, 10), true, false, true); |
| 2617 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 2618 | gfx::Size(10, 10), true, false, false); |
| 2619 | SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(), |
| 2620 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2621 | false); |
| 2622 | SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(), |
| 2623 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 2624 | false); |
| 2625 | |
| 2626 | // Add a transform animation with a start delay to |grand_child|. |
| 2627 | scoped_ptr<Animation> animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 2628 | scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1, |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2629 | Animation::TRANSFORM); |
| 2630 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 2631 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 2632 | if (layer_settings().use_compositor_animation_timelines) { |
| 2633 | AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(), |
| 2634 | std::move(animation)); |
| 2635 | } else { |
| 2636 | grand_child->layer_animation_controller()->AddAnimation( |
| 2637 | std::move(animation)); |
| 2638 | } |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 2639 | ExecuteCalculateDrawProperties(parent); |
| 2640 | |
| 2641 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2642 | EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| 2643 | |
| 2644 | EXPECT_FALSE(grand_child->TransformIsAnimating()); |
| 2645 | EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation()); |
| 2646 | EXPECT_TRUE(grand_child->screen_space_transform_is_animating()); |
| 2647 | EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating()); |
| 2648 | } |
| 2649 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2650 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2651 | // Test the calculateVisibleRect() function works correctly for identity |
| 2652 | // transforms. |
| 2653 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2654 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2655 | gfx::Transform layer_to_surface_transform; |
| 2656 | |
| 2657 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2658 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2659 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2660 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2661 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2662 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2663 | |
| 2664 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2665 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2666 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2667 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2668 | EXPECT_TRUE(actual.IsEmpty()); |
| 2669 | |
| 2670 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2671 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2672 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2673 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2674 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2675 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2676 | } |
| 2677 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2678 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2679 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2680 | // transforms. |
| 2681 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2682 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2683 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2684 | gfx::Transform layer_to_surface_transform; |
| 2685 | |
| 2686 | // Case 1: Layer is contained within the surface. |
| 2687 | layer_to_surface_transform.MakeIdentity(); |
| 2688 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2689 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2690 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2691 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2692 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2693 | |
| 2694 | // Case 2: Layer is outside the surface rect. |
| 2695 | layer_to_surface_transform.MakeIdentity(); |
| 2696 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2697 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2698 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2699 | EXPECT_TRUE(actual.IsEmpty()); |
| 2700 | |
| 2701 | // Case 3: Layer is partially overlapping the surface rect. |
| 2702 | layer_to_surface_transform.MakeIdentity(); |
| 2703 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2704 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2706 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2707 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | } |
| 2709 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2710 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2711 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2712 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2713 | // should return the g in the layer's space. |
| 2714 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2715 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2716 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | gfx::Transform layer_to_surface_transform; |
| 2718 | |
| 2719 | // Case 1: Layer is contained within the surface. |
| 2720 | layer_to_surface_transform.MakeIdentity(); |
| 2721 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2722 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2723 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2724 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2725 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2726 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2727 | |
| 2728 | // Case 2: Layer is outside the surface rect. |
| 2729 | layer_to_surface_transform.MakeIdentity(); |
| 2730 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2731 | layer_to_surface_transform.Rotate(45.0); |
| 2732 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2733 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2734 | EXPECT_TRUE(actual.IsEmpty()); |
| 2735 | |
| 2736 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2737 | // the layer is oriented diagonally, with the left half outside of the render |
| 2738 | // surface. In this case, the g should still be the entire layer |
| 2739 | // (remember the g is computed in layer space); both the top-left |
| 2740 | // and bottom-right corners of the layer are still visible. |
| 2741 | layer_to_surface_transform.MakeIdentity(); |
| 2742 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2743 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2745 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2746 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2747 | |
| 2748 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2749 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2750 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2751 | // surface overlaps the right side of the layer. The g should be |
| 2752 | // the layer's right half. |
| 2753 | layer_to_surface_transform.MakeIdentity(); |
| 2754 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2755 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2756 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2757 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2758 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2759 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2760 | } |
| 2761 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2762 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2763 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2764 | // transforms. |
| 2765 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2766 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2767 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2768 | gfx::Transform layer_to_surface_transform; |
| 2769 | |
| 2770 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2771 | // degrees, should be fully contained in the render surface. |
| 2772 | layer_to_surface_transform.MakeIdentity(); |
| 2773 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2774 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2775 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2776 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2777 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2778 | |
| 2779 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2780 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2781 | // visible on the surface. |
| 2782 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2783 | SkMScalar half_width_of_rotated_layer = |
| 2784 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2785 | layer_to_surface_transform.MakeIdentity(); |
| 2786 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2787 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2788 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2789 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2790 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2791 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2792 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2793 | } |
| 2794 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2795 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2797 | // a perspective projection onto the target surface. |
| 2798 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2799 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2800 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2801 | gfx::Transform layer_to_surface_transform; |
| 2802 | |
| 2803 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2804 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2805 | // its translated more than the perspective amount. |
| 2806 | layer_to_surface_transform.MakeIdentity(); |
| 2807 | |
| 2808 | // The following sequence of transforms applies the perspective about the |
| 2809 | // center of the surface. |
| 2810 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2811 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2812 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2813 | |
| 2814 | // This translate places the layer in front of the surface's projection plane. |
| 2815 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2816 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2817 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2818 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2819 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2820 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2821 | |
| 2822 | // Case 2: same projection as before, except that the layer is also translated |
| 2823 | // to the side, so that only the right half of the layer should be visible. |
| 2824 | // |
| 2825 | // Explanation of expected result: The perspective ratio is (z distance |
| 2826 | // between layer and camera origin) / (z distance between projection plane and |
| 2827 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2828 | // move a layer by translating -50 units in projected surface units (so that |
| 2829 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2830 | // -50 == -200 in the layer's units. |
| 2831 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2832 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2833 | gfx::Size(100, 200)); // The right half of the layer's |
| 2834 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2835 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2836 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2837 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2838 | } |
| 2839 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2840 | TEST_F(LayerTreeHostCommonTest, |
| 2841 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2842 | // There is currently no explicit concept of an orthographic projection plane |
| 2843 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2844 | // are technically behind the surface in an orthographic world should not be |
| 2845 | // clipped when they are flattened to the surface. |
| 2846 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2847 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2848 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2849 | gfx::Transform layer_to_surface_transform; |
| 2850 | |
| 2851 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2852 | // at the center of the layer. |
| 2853 | layer_to_surface_transform.MakeIdentity(); |
| 2854 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2855 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2856 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2857 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2858 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2859 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2860 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2861 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2862 | } |
| 2863 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2864 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2865 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2866 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2867 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2868 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2869 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2870 | // converting to cartesian coordinates. |
| 2871 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2872 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2873 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2874 | gfx::Transform layer_to_surface_transform; |
| 2875 | |
| 2876 | // The layer is positioned so that the right half of the layer should be in |
| 2877 | // front of the camera, while the other half is behind the surface's |
| 2878 | // projection plane. The following sequence of transforms applies the |
| 2879 | // perspective and rotation about the center of the layer. |
| 2880 | layer_to_surface_transform.MakeIdentity(); |
| 2881 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2882 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2883 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2884 | |
| 2885 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2886 | // transform, otherwise this code is not testing the intended scenario. |
| 2887 | bool clipped; |
| 2888 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2889 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2890 | &clipped); |
| 2891 | ASSERT_TRUE(clipped); |
| 2892 | |
| 2893 | int expected_x_position = 0; |
| 2894 | int expected_width = 10; |
| 2895 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2896 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2897 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2898 | EXPECT_EQ(expected_width, actual.width()); |
| 2899 | } |
| 2900 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2901 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2902 | // To determine visible rect in layer space, there needs to be an |
| 2903 | // un-projection from surface space to layer space. When the original |
| 2904 | // transform was a perspective projection that was clipped, it returns a rect |
| 2905 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2906 | // clipping again. |
| 2907 | |
| 2908 | // This sequence of transforms causes one corner of the layer to protrude |
| 2909 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2910 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2911 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2912 | gfx::Transform layer_to_surface_transform; |
| 2913 | layer_to_surface_transform.MakeIdentity(); |
| 2914 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2915 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2916 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2917 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2918 | |
| 2919 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2920 | // code is not testing the intended scenario. |
| 2921 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2922 | gfx::RectF clipped_rect = MathUtil::MapClippedRect( |
| 2923 | layer_to_surface_transform, gfx::RectF(layer_content_rect)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2924 | MathUtil::ProjectQuad( |
| 2925 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2926 | ASSERT_TRUE(clipped); |
| 2927 | |
| 2928 | // Only the corner of the layer is not visible on the surface because of being |
| 2929 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2930 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2931 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2932 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2933 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2934 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2935 | } |
| 2936 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2937 | TEST_F(LayerTreeHostCommonTest, |
| 2938 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2939 | LayerImpl* root = root_layer(); |
| 2940 | root->SetDrawsContent(true); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2941 | |
| 2942 | gfx::Transform identity_matrix; |
| 2943 | // Root layer is positioned at (60, 70). The default device viewport size |
| 2944 | // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 2945 | // 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] | 2946 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2947 | gfx::PointF(60, 70), gfx::Size(100, 100), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 2948 | false, true); |
| 2949 | ExecuteCalculateDrawProperties(root); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2950 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2951 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2952 | root->render_surface()->DrawableContentRect()); |
| 2953 | // In target space, not clipped. |
| 2954 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2955 | // In layer space, clipped. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2956 | EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect()); |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame] | 2957 | } |
| 2958 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2959 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2960 | LayerImpl* root = root_layer(); |
| 2961 | LayerImpl* child1_layer = AddChildToRoot<LayerImpl>(); |
| 2962 | child1_layer->SetDrawsContent(true); |
| 2963 | LayerImpl* child2_layer = AddChildToRoot<LayerImpl>(); |
| 2964 | child2_layer->SetDrawsContent(true); |
| 2965 | LayerImpl* child3_layer = AddChildToRoot<LayerImpl>(); |
| 2966 | child3_layer->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2967 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2968 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2969 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 2970 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 2971 | true); |
| 2972 | SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(), |
| 2973 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2974 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2975 | SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(), |
| 2976 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2977 | false, false); |
| 2978 | SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(), |
| 2979 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2980 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2981 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2982 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2983 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 2984 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2985 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2986 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2987 | // Layers that do not draw content should have empty visible_layer_rects. |
| 2988 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2989 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 2990 | // layer visible_layer_rects are clipped by their target surface. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2991 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect()); |
| 2992 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect()); |
| 2993 | EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2994 | |
| 2995 | // layer drawable_content_rects are not clipped. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 2996 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect()); |
| 2997 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect()); |
| 2998 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2999 | } |
| 3000 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3001 | TEST_F(LayerTreeHostCommonTest, |
| 3002 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3003 | LayerImpl* root = root_layer(); |
| 3004 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3005 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child); |
| 3006 | grand_child1->SetDrawsContent(true); |
| 3007 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child); |
| 3008 | grand_child2->SetDrawsContent(true); |
| 3009 | LayerImpl* grand_child3 = AddChild<LayerImpl>(child); |
| 3010 | grand_child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3011 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3012 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3013 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3014 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3015 | true); |
| 3016 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 3017 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3018 | false); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3019 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3020 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3021 | false, false); |
| 3022 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3023 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3024 | false, false); |
| 3025 | SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(), |
| 3026 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3027 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3028 | |
| 3029 | child->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3030 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3031 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3032 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3033 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3034 | |
| 3035 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3036 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3037 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3038 | |
| 3039 | // All grandchild visible content rects should be clipped by child. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3040 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect()); |
| 3041 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect()); |
| 3042 | EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3043 | |
| 3044 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3045 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 3046 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3047 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3048 | } |
| 3049 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3050 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3051 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 3052 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3053 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3054 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3055 | root->AddChild(child); |
| 3056 | child->AddChild(grand_child); |
| 3057 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 3058 | host()->SetRootLayer(root); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3059 | |
| 3060 | gfx::Transform identity_matrix; |
| 3061 | gfx::Transform child_scale_matrix; |
| 3062 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 3063 | gfx::Transform grand_child_scale_matrix; |
| 3064 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
| 3065 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3066 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 3067 | SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(), |
| 3068 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 3069 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix, |
| 3070 | gfx::Point3F(), gfx::PointF(), |
| 3071 | gfx::Size(100, 100), true, false); |
| 3072 | |
| 3073 | child->SetMasksToBounds(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 3074 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 3075 | |
| 3076 | // The visible rect is expanded to integer coordinates in target space before |
| 3077 | // being projected back to layer space, where it is once again expanded to |
| 3078 | // integer coordinates. |
| 3079 | EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees()); |
| 3080 | } |
| 3081 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3082 | TEST_F(LayerTreeHostCommonTest, |
| 3083 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3084 | LayerImpl* root = root_layer(); |
| 3085 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3086 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3087 | child1->SetDrawsContent(true); |
| 3088 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3089 | child2->SetDrawsContent(true); |
| 3090 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3091 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3092 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3093 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3094 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3095 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3096 | true); |
| 3097 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3098 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3099 | true); |
| 3100 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3101 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3102 | false, false); |
| 3103 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3104 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3105 | false, false); |
| 3106 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3107 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3108 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3109 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3110 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3111 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3112 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3113 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3114 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3115 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | |
| 3117 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3118 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3119 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3120 | |
| 3121 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3122 | // regions of the subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3123 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3124 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3125 | |
| 3126 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3127 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3128 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3129 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3130 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3131 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3132 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3133 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3134 | } |
| 3135 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3136 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3137 | DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) { |
| 3138 | LayerImpl* root = root_layer(); |
| 3139 | LayerImpl* parent = AddChild<LayerImpl>(root); |
| 3140 | LayerImpl* child1 = AddChild<LayerImpl>(parent); |
| 3141 | LayerImpl* child2 = AddChild<LayerImpl>(parent); |
| 3142 | LayerImpl* grand_child1 = AddChild<LayerImpl>(child1); |
| 3143 | LayerImpl* grand_child2 = AddChild<LayerImpl>(child2); |
| 3144 | LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1); |
| 3145 | LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2); |
| 3146 | |
| 3147 | root->SetDrawsContent(true); |
| 3148 | parent->SetDrawsContent(true); |
| 3149 | child1->SetDrawsContent(true); |
| 3150 | child2->SetDrawsContent(true); |
| 3151 | grand_child1->SetDrawsContent(true); |
| 3152 | grand_child2->SetDrawsContent(true); |
| 3153 | leaf_node1->SetDrawsContent(true); |
| 3154 | leaf_node2->SetDrawsContent(true); |
| 3155 | |
| 3156 | const gfx::Transform identity_matrix; |
| 3157 | |
| 3158 | // child1 and child2 get render surfaces when surfaces are enabled. |
| 3159 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3160 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3161 | true); |
| 3162 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 3163 | gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true, |
| 3164 | false, false); |
| 3165 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3166 | gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true, |
| 3167 | false, true); |
| 3168 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3169 | gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true, |
| 3170 | false, true); |
| 3171 | SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(), |
| 3172 | gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500), |
| 3173 | true, false, false); |
| 3174 | SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(), |
| 3175 | gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500), |
| 3176 | true, false, false); |
| 3177 | SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(), |
| 3178 | gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000), |
| 3179 | true, false, false); |
| 3180 | SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(), |
| 3181 | gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000), |
| 3182 | true, false, false); |
| 3183 | |
| 3184 | // Case 1: No layers clip. Visible rects are clipped by the viewport, but the |
| 3185 | // viewport clip doesn't apply to layers that draw into unclipped surfaces. |
| 3186 | // Each layer's drawable content rect is its bounds in target space; the only |
| 3187 | // thing that changes with surfaces disabled is that target space is always |
| 3188 | // screen space. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3189 | root->SetHasRenderSurface(true); |
| 3190 | child1->SetHasRenderSurface(true); |
| 3191 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3192 | ExecuteCalculateDrawProperties(root); |
| 3193 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3194 | EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect()); |
| 3195 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3196 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3197 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect()); |
| 3198 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3199 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect()); |
| 3200 | EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect()); |
| 3201 | |
| 3202 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3203 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3204 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3205 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3206 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3207 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3208 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3209 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3210 | |
| 3211 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3212 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3213 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3214 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3215 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3216 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3217 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3218 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3219 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3220 | |
| 3221 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3222 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3223 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3224 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3225 | EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), |
| 3226 | grand_child1->drawable_content_rect()); |
| 3227 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3228 | grand_child2->drawable_content_rect()); |
| 3229 | EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3230 | EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3231 | |
| 3232 | // Case 2: The parent clips. In this case, neither surface is unclipped, so |
| 3233 | // all visible layer rects are clipped by the intersection of all ancestor |
| 3234 | // clips, whether or not surfaces are disabled. However, drawable content |
| 3235 | // rects are clipped only until the next render surface is reached, so |
| 3236 | // descendants of parent have their drawable content rects clipped only when |
| 3237 | // surfaces are disabled. |
| 3238 | parent->SetMasksToBounds(true); |
| 3239 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3240 | root->SetHasRenderSurface(true); |
| 3241 | child1->SetHasRenderSurface(true); |
| 3242 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3243 | ExecuteCalculateDrawProperties(root); |
| 3244 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3245 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3246 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3247 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3248 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3249 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3250 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3251 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3252 | |
| 3253 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3254 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3255 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3256 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3257 | EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect()); |
| 3258 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3259 | EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect()); |
| 3260 | EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect()); |
| 3261 | |
| 3262 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3263 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3266 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3267 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3268 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3269 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3270 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3271 | |
| 3272 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3273 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3274 | EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect()); |
| 3275 | EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect()); |
| 3277 | EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect()); |
| 3278 | EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect()); |
| 3279 | EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect()); |
| 3280 | |
| 3281 | parent->SetMasksToBounds(false); |
| 3282 | |
| 3283 | // Case 3: child1 and grand_child2 clip. In this case, descendants of these |
| 3284 | // layers have their visible rects clipped by them; without surfaces, these |
| 3285 | // rects are also clipped by the viewport. Similarly, descendants of these |
| 3286 | // layers have their drawable content rects clipped by them. |
| 3287 | child1->SetMasksToBounds(true); |
| 3288 | grand_child2->SetMasksToBounds(true); |
| 3289 | host_impl()->active_tree()->property_trees()->needs_rebuild = true; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 3290 | root->SetHasRenderSurface(true); |
| 3291 | child1->SetHasRenderSurface(true); |
| 3292 | child2->SetHasRenderSurface(true); |
ajuma | 51d73f7 | 2015-10-19 19:43:58 | [diff] [blame] | 3293 | ExecuteCalculateDrawProperties(root); |
| 3294 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3295 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3296 | EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect()); |
| 3297 | EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect()); |
| 3298 | EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect()); |
| 3299 | EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect()); |
| 3300 | EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect()); |
| 3301 | EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect()); |
| 3302 | |
| 3303 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3304 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3305 | EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect()); |
| 3307 | EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect()); |
| 3308 | EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect()); |
| 3309 | EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect()); |
| 3310 | EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3311 | |
| 3312 | ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root); |
| 3313 | EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect()); |
| 3314 | EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect()); |
| 3315 | EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect()); |
| 3316 | EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect()); |
| 3317 | EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect()); |
| 3318 | EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect()); |
| 3319 | EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect()); |
| 3320 | EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect()); |
| 3321 | |
| 3322 | EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect()); |
| 3323 | EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect()); |
| 3324 | EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect()); |
| 3325 | EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect()); |
| 3326 | EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500), |
| 3328 | grand_child2->drawable_content_rect()); |
| 3329 | EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect()); |
| 3330 | EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect()); |
| 3331 | } |
| 3332 | |
| 3333 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3334 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3335 | LayerImpl* root = root_layer(); |
| 3336 | LayerImpl* child1 = AddChild<LayerImpl>(root); |
| 3337 | LayerImpl* child2 = AddChild<LayerImpl>(root); |
| 3338 | LayerImpl* child3 = AddChild<LayerImpl>(root); |
| 3339 | child1->SetDrawsContent(true); |
| 3340 | child2->SetDrawsContent(true); |
| 3341 | child3->SetDrawsContent(true); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3342 | |
| 3343 | gfx::Transform identity_matrix; |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3344 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3345 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3346 | true); |
| 3347 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3348 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3349 | false, false); |
| 3350 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3351 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3352 | false, false); |
| 3353 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3354 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3355 | true, false, false); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3356 | |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3357 | LayerImplList render_surface_layer_list_impl; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3358 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3359 | // Now set the root render surface an empty clip. |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 3360 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3361 | root, gfx::Size(), &render_surface_layer_list_impl, |
| 3362 | root->layer_tree_impl()->current_render_surface_list_id()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3363 | |
| 3364 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 3365 | ASSERT_TRUE(root->render_surface()); |
| 3366 | EXPECT_FALSE(root->is_clipped()); |
| 3367 | |
| 3368 | gfx::Rect empty; |
| 3369 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3370 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3371 | |
| 3372 | // Visible content rect calculation will check if the target surface is |
| 3373 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3374 | // is unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3375 | EXPECT_EQ(empty, child1->visible_layer_rect()); |
| 3376 | EXPECT_EQ(empty, child2->visible_layer_rect()); |
| 3377 | EXPECT_EQ(empty, child3->visible_layer_rect()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3381 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3382 | LayerImpl* root = root_layer(); |
| 3383 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3384 | child->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3385 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3386 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3387 | gfx::Transform identity_matrix; |
| 3388 | 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] | 3389 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3390 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3391 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3392 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3393 | true); |
| 3394 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3395 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3396 | false, false); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3397 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3398 | ExecuteCalculateDrawProperties(root); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3399 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3400 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3401 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3402 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3403 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3404 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3405 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3406 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3407 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3408 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3409 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3410 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3411 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3412 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3413 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3414 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3415 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3416 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3417 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3418 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3419 | uninvertible_matrix.MakeIdentity(); |
| 3420 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3421 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3422 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3423 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3424 | SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(), |
| 3425 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3426 | false, false); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3427 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3428 | ExecuteCalculateDrawProperties(root); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3429 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3430 | EXPECT_TRUE(child->visible_layer_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3431 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3432 | } |
| 3433 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3434 | TEST_F(LayerTreeHostCommonTest, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3435 | VisibleContentRectForLayerWithUninvertibleDrawTransform) { |
| 3436 | LayerImpl* root = root_layer(); |
| 3437 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 3438 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 3439 | child->SetDrawsContent(true); |
| 3440 | grand_child->SetDrawsContent(true); |
| 3441 | |
| 3442 | gfx::Transform identity_matrix; |
| 3443 | |
| 3444 | gfx::Transform perspective; |
| 3445 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3446 | |
| 3447 | gfx::Transform rotation; |
| 3448 | rotation.RotateAboutYAxis(45.0); |
| 3449 | |
| 3450 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3451 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3452 | true); |
| 3453 | SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(), |
| 3454 | gfx::PointF(10.f, 10.f), gfx::Size(100, 100), |
| 3455 | false, true, false); |
| 3456 | SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(), |
| 3457 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 3458 | false); |
| 3459 | |
| 3460 | ExecuteCalculateDrawProperties(root); |
| 3461 | |
| 3462 | // Though all layers have invertible transforms, matrix multiplication using |
| 3463 | // floating-point math makes the draw transform uninvertible. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3464 | EXPECT_FALSE(grand_child->DrawTransform().IsInvertible()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3465 | |
| 3466 | // CalcDrawProps only skips a subtree when a layer's own transform is |
| 3467 | // uninvertible, not when its draw transform is invertible, since CDP makes |
| 3468 | // skipping decisions before computing a layer's draw transform. Property |
| 3469 | // trees make skipping decisions after computing draw transforms, so could be |
| 3470 | // made to skip layers with an uninvertible draw transform (once CDP is |
| 3471 | // deleted). |
| 3472 | EXPECT_EQ(gfx::Rect(grand_child->bounds()), |
| 3473 | grand_child->visible_layer_rect()); |
| 3474 | } |
| 3475 | |
| 3476 | TEST_F(LayerTreeHostCommonTest, |
| 3477 | OcclusionForLayerWithUninvertibleDrawTransform) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3478 | FakeImplTaskRunnerProvider task_runner_provider; |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3479 | TestSharedBitmapManager shared_bitmap_manager; |
| 3480 | TestTaskGraphRunner task_graph_runner; |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3481 | scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d(); |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 3482 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3483 | &task_graph_runner); |
| 3484 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 3485 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); |
| 3486 | scoped_ptr<LayerImpl> grand_child = |
| 3487 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 3488 | scoped_ptr<LayerImpl> occluding_child = |
| 3489 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 3490 | child->SetDrawsContent(true); |
| 3491 | grand_child->SetDrawsContent(true); |
| 3492 | occluding_child->SetDrawsContent(true); |
| 3493 | occluding_child->SetContentsOpaque(true); |
| 3494 | |
| 3495 | gfx::Transform identity_matrix; |
| 3496 | gfx::Transform perspective; |
| 3497 | perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12)); |
| 3498 | |
| 3499 | gfx::Transform rotation; |
| 3500 | rotation.RotateAboutYAxis(45.0); |
| 3501 | |
| 3502 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 3503 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3504 | false, true); |
| 3505 | SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(), |
| 3506 | gfx::PointF(10.f, 10.f), gfx::Size(300, 300), |
| 3507 | false, true, false); |
| 3508 | SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(), |
| 3509 | gfx::PointF(), gfx::Size(200, 200), false, true, |
| 3510 | false); |
| 3511 | SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix, |
| 3512 | gfx::Point3F(), gfx::PointF(), |
| 3513 | gfx::Size(200, 200), false, false, false); |
| 3514 | |
| 3515 | host_impl.SetViewportSize(root->bounds()); |
| 3516 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 3517 | child->AddChild(std::move(grand_child)); |
| 3518 | root->AddChild(std::move(child)); |
| 3519 | root->AddChild(std::move(occluding_child)); |
| 3520 | host_impl.active_tree()->SetRootLayer(std::move(root)); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 3521 | host_impl.SetVisible(true); |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 3522 | host_impl.InitializeRenderer(output_surface.get()); |
jaydasika | d7dea63 | 2015-11-06 04:40:12 | [diff] [blame] | 3523 | host_impl.active_tree()->BuildPropertyTreesForTesting(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3524 | bool update_lcd_text = false; |
| 3525 | host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); |
| 3526 | |
| 3527 | LayerImpl* grand_child_ptr = |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 3528 | host_impl.active_tree()->root_layer()->children()[0]->children()[0].get(); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3529 | |
| 3530 | // Though all layers have invertible transforms, matrix multiplication using |
| 3531 | // floating-point math makes the draw transform uninvertible. |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 3532 | EXPECT_FALSE(grand_child_ptr->DrawTransform().IsInvertible()); |
ajuma | ae0dc2d | 2015-08-05 21:55:56 | [diff] [blame] | 3533 | |
| 3534 | // Since |grand_child| has an uninvertible draw transform, it is treated as |
| 3535 | // unoccluded (even though |occluding_child| comes later in draw order, and |
| 3536 | // hence potentially occludes it). |
| 3537 | gfx::Rect layer_bounds = gfx::Rect(grand_child_ptr->bounds()); |
| 3538 | EXPECT_EQ( |
| 3539 | layer_bounds, |
| 3540 | grand_child_ptr->draw_properties() |
| 3541 | .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds)); |
| 3542 | } |
| 3543 | |
| 3544 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3545 | SingularTransformDoesNotPreventClearingDrawProperties) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3546 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3547 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3548 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3549 | root->AddChild(child); |
| 3550 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 3551 | host()->SetRootLayer(root); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3552 | |
| 3553 | gfx::Transform identity_matrix; |
| 3554 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3555 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3556 | |
| 3557 | SetLayerPropertiesForTesting(root.get(), |
| 3558 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3559 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3560 | gfx::PointF(), |
| 3561 | gfx::Size(100, 100), |
| 3562 | true, |
| 3563 | false); |
| 3564 | SetLayerPropertiesForTesting(child.get(), |
| 3565 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3566 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3567 | gfx::PointF(5.f, 5.f), |
| 3568 | gfx::Size(50, 50), |
| 3569 | true, |
| 3570 | false); |
| 3571 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3572 | child->set_sorted_for_recursion(true); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3573 | |
| 3574 | TransformOperations start_transform_operations; |
| 3575 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3576 | |
| 3577 | TransformOperations end_transform_operations; |
| 3578 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3579 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 3580 | if (layer_settings().use_compositor_animation_timelines) { |
| 3581 | AddAnimatedTransformToLayerWithPlayer(root->id(), timeline(), 10.0, |
| 3582 | start_transform_operations, |
| 3583 | end_transform_operations); |
| 3584 | } else { |
| 3585 | AddAnimatedTransformToLayer(root.get(), 10.0, start_transform_operations, |
| 3586 | end_transform_operations); |
| 3587 | } |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3588 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3589 | |
| 3590 | ExecuteCalculateDrawProperties(root.get()); |
| 3591 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3592 | EXPECT_FALSE(child->sorted_for_recursion()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3596 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3597 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3598 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 3599 | host()->SetRootLayer(root); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3600 | |
| 3601 | gfx::Transform identity_matrix; |
| 3602 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3603 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3604 | |
| 3605 | SetLayerPropertiesForTesting(root.get(), |
| 3606 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3607 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3608 | gfx::PointF(), |
| 3609 | gfx::Size(100, 100), |
| 3610 | true, |
| 3611 | false); |
| 3612 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3613 | root->set_sorted_for_recursion(true); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3614 | |
| 3615 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3616 | |
| 3617 | ExecuteCalculateDrawProperties(root.get()); |
| 3618 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3619 | EXPECT_FALSE(root->sorted_for_recursion()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3623 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3624 | LayerImpl* root = root_layer(); |
| 3625 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3626 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3627 | child1->SetDrawsContent(true); |
| 3628 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface); |
| 3629 | child2->SetDrawsContent(true); |
| 3630 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface); |
| 3631 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3633 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3634 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3635 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3636 | true); |
| 3637 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 3638 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3639 | true); |
| 3640 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3641 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3642 | false, false); |
| 3643 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3644 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3645 | false, false); |
| 3646 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3647 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3648 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3649 | |
| 3650 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3651 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3652 | ExecuteCalculateDrawProperties(root); |
| 3653 | |
| 3654 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3655 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3656 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3657 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3658 | |
| 3659 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3660 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3661 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3662 | |
| 3663 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3664 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3665 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3666 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3667 | |
| 3668 | // All layers that draw content into the surface have their visible content |
| 3669 | // rect clipped by the surface clip rect. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3670 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3671 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect()); |
| 3672 | EXPECT_TRUE(child3->visible_layer_rect().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3673 | |
| 3674 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3675 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3676 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3677 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3678 | } |
| 3679 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3680 | TEST_F(LayerTreeHostCommonTest, |
| 3681 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3682 | // Check that clipping does not propagate down surfaces. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3683 | LayerImpl* root = root_layer(); |
| 3684 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3685 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 3686 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface2); |
| 3687 | child1->SetDrawsContent(true); |
| 3688 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 3689 | child2->SetDrawsContent(true); |
| 3690 | LayerImpl* child3 = AddChild<LayerImpl>(render_surface2); |
| 3691 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3692 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3693 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3694 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3695 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3696 | true); |
| 3697 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3698 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 3699 | true); |
| 3700 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3701 | gfx::PointF(), gfx::Size(7, 13), true, false, |
| 3702 | true); |
| 3703 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3704 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 3705 | false, false); |
| 3706 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3707 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 3708 | false, false); |
| 3709 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 3710 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 3711 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3712 | |
| 3713 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3714 | |
| 3715 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3716 | |
| 3717 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3718 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3719 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3720 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3721 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3722 | |
| 3723 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3724 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
| 3725 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect()); |
| 3726 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3727 | |
| 3728 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3729 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3730 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3731 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3732 | |
| 3733 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3734 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3735 | // render_surface2 grows to enclose all drawable content of its subtree. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 3736 | EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3737 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3738 | |
| 3739 | // All layers that draw content into render_surface2 think they are unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 3740 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 3741 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 3742 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | |
| 3744 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3745 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3746 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3747 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | } |
| 3749 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3750 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3751 | VisibleRectsForClippedDescendantsOfUnclippedSurfaces) { |
| 3752 | LayerImpl* root = root_layer(); |
| 3753 | LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>(); |
| 3754 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 3755 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 3756 | LayerImpl* render_surface2 = AddChild<LayerImpl>(child2); |
| 3757 | child1->SetDrawsContent(true); |
| 3758 | child2->SetDrawsContent(true); |
| 3759 | render_surface2->SetDrawsContent(true); |
| 3760 | |
| 3761 | gfx::Transform identity_matrix; |
| 3762 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3763 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3764 | true); |
| 3765 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3766 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3767 | true); |
| 3768 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 3769 | gfx::PointF(), gfx::Size(500, 500), true, false, |
| 3770 | false); |
| 3771 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 3772 | gfx::PointF(), gfx::Size(700, 700), true, false, |
| 3773 | false); |
| 3774 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3775 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 3776 | false, true); |
| 3777 | |
| 3778 | child1->SetMasksToBounds(true); |
| 3779 | child2->SetMasksToBounds(true); |
| 3780 | |
| 3781 | ExecuteCalculateDrawProperties(root); |
| 3782 | EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect()); |
| 3783 | EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect()); |
| 3784 | } |
| 3785 | |
| 3786 | TEST_F(LayerTreeHostCommonTest, |
| 3787 | VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) { |
| 3788 | LayerImpl* root = root_layer(); |
| 3789 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3790 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3791 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3792 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3793 | |
| 3794 | render_surface1->SetDrawsContent(true); |
| 3795 | render_surface2->SetDrawsContent(true); |
| 3796 | clip_child->SetDrawsContent(true); |
| 3797 | clip_child->SetClipParent(clip_parent); |
| 3798 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3799 | clip_children->insert(clip_child); |
| 3800 | clip_parent->SetClipChildren(clip_children.release()); |
| 3801 | |
| 3802 | gfx::Transform identity_matrix; |
| 3803 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3804 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3805 | true); |
| 3806 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3807 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3808 | false); |
| 3809 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3810 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3811 | true); |
| 3812 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3813 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3814 | false); |
| 3815 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3816 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3817 | true); |
| 3818 | clip_parent->SetMasksToBounds(true); |
| 3819 | render_surface1->SetMasksToBounds(true); |
| 3820 | |
| 3821 | ExecuteCalculateDrawProperties(root); |
| 3822 | EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect()); |
| 3823 | EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect()); |
| 3824 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect()); |
| 3825 | } |
| 3826 | |
jaydasika | 1f5312d | 2015-10-21 21:34:32 | [diff] [blame] | 3827 | TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) { |
| 3828 | LayerImpl* root = root_layer(); |
| 3829 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 3830 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 3831 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 3832 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child); |
| 3833 | |
| 3834 | render_surface1->SetDrawsContent(true); |
| 3835 | render_surface2->SetDrawsContent(true); |
| 3836 | clip_child->SetDrawsContent(true); |
| 3837 | clip_child->SetClipParent(clip_parent); |
| 3838 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3839 | clip_children->insert(clip_child); |
| 3840 | clip_parent->SetClipChildren(clip_children.release()); |
| 3841 | |
| 3842 | gfx::Transform identity_matrix; |
| 3843 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3844 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3845 | true); |
| 3846 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3847 | gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true, |
| 3848 | false, false); |
| 3849 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 3850 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 3851 | true); |
| 3852 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3853 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3854 | false); |
| 3855 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 3856 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3857 | true); |
| 3858 | clip_parent->SetMasksToBounds(true); |
| 3859 | render_surface1->SetMasksToBounds(true); |
| 3860 | |
| 3861 | ExecuteCalculateDrawProperties(root); |
| 3862 | EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect()); |
| 3863 | } |
| 3864 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 3865 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) { |
| 3866 | // Test that only drawn layers contribute to render surface content rect. |
| 3867 | LayerImpl* root = root_layer(); |
| 3868 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 3869 | LayerImpl* test_layer = AddChild<LayerImpl>(surface); |
| 3870 | |
| 3871 | test_layer->SetDrawsContent(false); |
| 3872 | surface->SetDrawsContent(true); |
| 3873 | gfx::Transform identity_matrix; |
| 3874 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3875 | gfx::PointF(), gfx::Size(200, 200), true, false, |
| 3876 | true); |
| 3877 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 3878 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3879 | true); |
| 3880 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 3881 | gfx::PointF(), gfx::Size(150, 150), true, false, |
| 3882 | false); |
| 3883 | |
| 3884 | ExecuteCalculateDrawProperties(root); |
| 3885 | EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect()); |
| 3886 | |
| 3887 | test_layer->SetDrawsContent(true); |
| 3888 | ExecuteCalculateDrawProperties(root); |
| 3889 | EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect()); |
| 3890 | } |
| 3891 | |
jaydasika | 27d0f2e | 2015-10-16 23:52:46 | [diff] [blame] | 3892 | TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) { |
| 3893 | // Tests visible rects computation when we have unclipped_surface-> |
| 3894 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3895 | // of surface_with_unclipped_descendants doesn't propagate to the |
| 3896 | // clipped_surface below it. |
| 3897 | LayerImpl* root = root_layer(); |
| 3898 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3899 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3900 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3901 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3902 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3903 | |
| 3904 | unclipped_surface->SetDrawsContent(true); |
| 3905 | unclipped_desc_surface->SetDrawsContent(true); |
| 3906 | clipped_surface->SetDrawsContent(true); |
| 3907 | clip_child->SetClipParent(clip_parent); |
| 3908 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3909 | clip_children->insert(clip_child); |
| 3910 | clip_parent->SetClipChildren(clip_children.release()); |
| 3911 | |
| 3912 | gfx::Transform identity_matrix; |
| 3913 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3914 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3915 | true); |
| 3916 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3917 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 3918 | true, false, true); |
| 3919 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3920 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3921 | false); |
| 3922 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3923 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 3924 | true, false, true); |
| 3925 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3926 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3927 | false); |
| 3928 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 3929 | gfx::PointF(), gfx::Size(60, 60), true, false, |
| 3930 | true); |
| 3931 | clip_parent->SetMasksToBounds(true); |
| 3932 | |
| 3933 | ExecuteCalculateDrawProperties(root); |
| 3934 | EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect()); |
| 3935 | EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect()); |
| 3936 | EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect()); |
| 3937 | } |
| 3938 | |
| 3939 | TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) { |
| 3940 | // Tests visible rects computation when we have unclipped_surface-> |
| 3941 | // surface_with_unclipped_descendants->clipped_surface, checks that the bounds |
| 3942 | // of root propagate to the clipped_surface. |
| 3943 | LayerImpl* root = root_layer(); |
| 3944 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 3945 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 3946 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 3947 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 3948 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 3949 | |
| 3950 | unclipped_surface->SetDrawsContent(true); |
| 3951 | unclipped_desc_surface->SetDrawsContent(true); |
| 3952 | clipped_surface->SetDrawsContent(true); |
| 3953 | clip_child->SetClipParent(clip_parent); |
| 3954 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 3955 | clip_children->insert(clip_child); |
| 3956 | clip_parent->SetClipChildren(clip_children.release()); |
| 3957 | |
| 3958 | gfx::Transform identity_matrix; |
| 3959 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3960 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 3961 | true); |
| 3962 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 3963 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 3964 | true, false, true); |
| 3965 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 3966 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3967 | false); |
| 3968 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 3969 | gfx::Point3F(), gfx::PointF(), |
| 3970 | gfx::Size(100, 100), true, false, true); |
| 3971 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 3972 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 3973 | false); |
| 3974 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 3975 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 3976 | true); |
| 3977 | clip_parent->SetMasksToBounds(true); |
| 3978 | unclipped_desc_surface->SetMasksToBounds(true); |
| 3979 | |
| 3980 | ExecuteCalculateDrawProperties(root); |
| 3981 | EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect()); |
| 3982 | EXPECT_EQ(gfx::Rect(100, 100), unclipped_desc_surface->visible_layer_rect()); |
| 3983 | EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect()); |
| 3984 | } |
| 3985 | |
| 3986 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3987 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3988 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3989 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3990 | LayerImpl* root = root_layer(); |
| 3991 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 3992 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 3993 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3994 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | gfx::Transform identity_matrix; |
| 3996 | gfx::Transform child_rotation; |
| 3997 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 3998 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3999 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4000 | true); |
| 4001 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4002 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4003 | true); |
| 4004 | SetLayerPropertiesForTesting( |
| 4005 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4006 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4007 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4008 | ExecuteCalculateDrawProperties(root); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4009 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4010 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4011 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4012 | EXPECT_EQ(gfx::RectF(100.f, 100.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4013 | root->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4014 | |
| 4015 | // Layers that do not draw content should have empty visible content rects. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4016 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4017 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4018 | |
| 4019 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 4020 | // regions of the subtree. |
| 4021 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 4022 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4023 | gfx::Rect(50 - diagonal_radius, |
| 4024 | 50 - diagonal_radius, |
| 4025 | diagonal_radius * 2, |
| 4026 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4027 | EXPECT_EQ(gfx::RectF(expected_surface_drawable_content), |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4028 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4029 | |
| 4030 | // All layers that draw content into the unclipped surface are also unclipped. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4031 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4032 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4033 | } |
| 4034 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4035 | TEST_F(LayerTreeHostCommonTest, |
| 4036 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4037 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 4038 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4039 | LayerImpl* root = root_layer(); |
| 4040 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 4041 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface); |
| 4042 | child1->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4044 | gfx::Transform identity_matrix; |
| 4045 | gfx::Transform child_rotation; |
| 4046 | child_rotation.Rotate(45.0); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4047 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4048 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 4049 | true); |
| 4050 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 4051 | gfx::PointF(), gfx::Size(3, 4), true, false, |
| 4052 | true); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4053 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4054 | SetLayerPropertiesForTesting( |
| 4055 | child1, child_rotation, gfx::Point3F(25, 25, 0.f), |
| 4056 | gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4057 | |
| 4058 | root->SetMasksToBounds(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4060 | ExecuteCalculateDrawProperties(root); |
| 4061 | |
| 4062 | ASSERT_TRUE(render_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | |
| 4064 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 4065 | // rotated layer. |
| 4066 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4067 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 4068 | 50 - diagonal_radius, |
| 4069 | diagonal_radius * 2, |
| 4070 | diagonal_radius * 2); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4071 | gfx::RectF expected_surface_drawable_content( |
| 4072 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50))); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4073 | EXPECT_EQ(expected_surface_drawable_content, |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4074 | render_surface->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4075 | |
| 4076 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 4077 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 4078 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4079 | // |
| 4080 | // Given the floating point math, this number is a little bit fuzzy. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4081 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4082 | |
| 4083 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4084 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4085 | } |
| 4086 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4087 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4088 | LayerImpl* root = root_layer(); |
| 4089 | FakePictureLayerImpl* render_surface1 = |
| 4090 | AddChildToRoot<FakePictureLayerImpl>(); |
| 4091 | render_surface1->SetDrawsContent(true); |
| 4092 | FakePictureLayerImpl* render_surface2 = |
| 4093 | AddChild<FakePictureLayerImpl>(render_surface1); |
| 4094 | render_surface2->SetDrawsContent(true); |
| 4095 | FakePictureLayerImpl* child1 = |
| 4096 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4097 | child1->SetDrawsContent(true); |
| 4098 | FakePictureLayerImpl* child2 = |
| 4099 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4100 | child2->SetDrawsContent(true); |
| 4101 | FakePictureLayerImpl* child3 = |
| 4102 | AddChild<FakePictureLayerImpl>(render_surface2); |
| 4103 | child3->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4104 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4105 | gfx::Transform identity_matrix; |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4106 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4107 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 4108 | true); |
| 4109 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 4110 | gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true, |
| 4111 | false, true); |
| 4112 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 4113 | gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true, |
| 4114 | false, true); |
| 4115 | SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(), |
| 4116 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 4117 | false, false); |
| 4118 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4119 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 4120 | false, false); |
| 4121 | SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(), |
| 4122 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 4123 | true, false, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4124 | |
| 4125 | float device_scale_factor = 2.f; |
| 4126 | |
| 4127 | root->SetMasksToBounds(true); |
weiliangc | 0dece73 | 2015-07-27 19:06:17 | [diff] [blame] | 4128 | |
| 4129 | ExecuteCalculateDrawProperties(root, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4130 | |
| 4131 | ASSERT_TRUE(render_surface1->render_surface()); |
| 4132 | ASSERT_TRUE(render_surface2->render_surface()); |
| 4133 | |
| 4134 | // drawable_content_rects for all layers and surfaces are scaled by |
| 4135 | // device_scale_factor. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4136 | EXPECT_EQ(gfx::RectF(200.f, 200.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4137 | root->render_surface()->DrawableContentRect()); |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4138 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4139 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4140 | |
| 4141 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 4142 | // is only implicitly clipped by render_surface1. |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 4143 | EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f), |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4144 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4145 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4146 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 4147 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 4148 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4149 | |
| 4150 | // The root layer does not actually draw content of its own. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4151 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4152 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4153 | // All layer visible content rects are not expressed in content space of each |
| 4154 | // layer, so they are not scaled by the device_scale_factor. |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 4155 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect()); |
| 4156 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect()); |
| 4157 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect()); |
| 4158 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect()); |
| 4159 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4160 | } |
| 4161 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4162 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4163 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 4164 | // layers. Note that 3d transforms still apply in this case, but they are |
| 4165 | // "flattened" to each parent layer according to current W3C spec. |
| 4166 | |
| 4167 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4168 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4169 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4170 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4171 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4172 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4173 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4174 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4175 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4176 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4178 | front_facing_child_of_front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4179 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4180 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4181 | back_facing_child_of_front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4182 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4183 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4184 | front_facing_child_of_back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4185 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4186 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4187 | back_facing_child_of_back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4188 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | |
| 4190 | parent->AddChild(front_facing_child); |
| 4191 | parent->AddChild(back_facing_child); |
| 4192 | parent->AddChild(front_facing_surface); |
| 4193 | parent->AddChild(back_facing_surface); |
| 4194 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 4195 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 4196 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 4197 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 4198 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4199 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4200 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4201 | // Nothing is double-sided |
| 4202 | front_facing_child->SetDoubleSided(false); |
| 4203 | back_facing_child->SetDoubleSided(false); |
| 4204 | front_facing_surface->SetDoubleSided(false); |
| 4205 | back_facing_surface->SetDoubleSided(false); |
| 4206 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4207 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4208 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4209 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4210 | |
| 4211 | gfx::Transform backface_matrix; |
| 4212 | backface_matrix.Translate(50.0, 50.0); |
| 4213 | backface_matrix.RotateAboutYAxis(180.0); |
| 4214 | backface_matrix.Translate(-50.0, -50.0); |
| 4215 | |
| 4216 | // Having a descendant and opacity will force these to have render surfaces. |
| 4217 | front_facing_surface->SetOpacity(0.5f); |
| 4218 | back_facing_surface->SetOpacity(0.5f); |
| 4219 | |
| 4220 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 4221 | // these layers should blindly use their own local transforms to determine |
| 4222 | // back-face culling. |
| 4223 | SetLayerPropertiesForTesting(parent.get(), |
| 4224 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4225 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4226 | gfx::PointF(), |
| 4227 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4228 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4229 | false); |
| 4230 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 4231 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4232 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4233 | gfx::PointF(), |
| 4234 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4235 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4236 | false); |
| 4237 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 4238 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4239 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4240 | gfx::PointF(), |
| 4241 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4242 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4243 | false); |
| 4244 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4245 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4246 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4247 | gfx::PointF(), |
| 4248 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4249 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4250 | false); |
| 4251 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4252 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4253 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4254 | gfx::PointF(), |
| 4255 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4256 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4257 | false); |
| 4258 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 4259 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4260 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4261 | gfx::PointF(), |
| 4262 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4263 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4264 | false); |
| 4265 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 4266 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4267 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4268 | gfx::PointF(), |
| 4269 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4270 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4271 | false); |
| 4272 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 4273 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4274 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4275 | gfx::PointF(), |
| 4276 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4277 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4278 | false); |
| 4279 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 4280 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4281 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | gfx::PointF(), |
| 4283 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4284 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4285 | false); |
| 4286 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4287 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | |
| 4289 | // Verify which render surfaces were created. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4290 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4291 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4292 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
| 4293 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4294 | EXPECT_FALSE( |
| 4295 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4296 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4297 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4298 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4299 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4300 | EXPECT_EQ(4u, update_layer_list().size()); |
| 4301 | EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id())); |
| 4302 | EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id())); |
| 4303 | EXPECT_TRUE(UpdateLayerListContains( |
| 4304 | front_facing_child_of_front_facing_surface->id())); |
| 4305 | EXPECT_TRUE( |
| 4306 | UpdateLayerListContains(front_facing_child_of_back_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4307 | } |
| 4308 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4309 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4310 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 4311 | // is used. |
| 4312 | |
| 4313 | const gfx::Transform identity_matrix; |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4314 | LayerImpl* parent = root_layer(); |
| 4315 | LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>(); |
| 4316 | LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>(); |
| 4317 | LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4318 | LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>(); |
| 4319 | LayerImpl* front_facing_child_of_front_facing_surface = |
| 4320 | AddChild<LayerImpl>(front_facing_surface); |
| 4321 | LayerImpl* back_facing_child_of_front_facing_surface = |
| 4322 | AddChild<LayerImpl>(front_facing_surface); |
| 4323 | LayerImpl* front_facing_child_of_back_facing_surface = |
| 4324 | AddChild<LayerImpl>(back_facing_surface); |
| 4325 | LayerImpl* back_facing_child_of_back_facing_surface = |
| 4326 | AddChild<LayerImpl>(back_facing_surface); |
| 4327 | // Opacity will not force creation of render surfaces in this case because of |
| 4328 | // the preserve-3d transform style. Instead, an example of when a surface |
| 4329 | // would be created with preserve-3d is when there is a replica layer. |
| 4330 | LayerImpl* dummy_replica_layer1 = |
| 4331 | AddReplicaLayer<LayerImpl>(front_facing_surface); |
| 4332 | LayerImpl* dummy_replica_layer2 = |
| 4333 | AddReplicaLayer<LayerImpl>(back_facing_surface); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4334 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4335 | // Nothing is double-sided |
| 4336 | front_facing_child->SetDoubleSided(false); |
| 4337 | back_facing_child->SetDoubleSided(false); |
| 4338 | front_facing_surface->SetDoubleSided(false); |
| 4339 | back_facing_surface->SetDoubleSided(false); |
| 4340 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4341 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 4342 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4343 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 4344 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4345 | // Everything draws content. |
| 4346 | front_facing_child->SetDrawsContent(true); |
| 4347 | back_facing_child->SetDrawsContent(true); |
| 4348 | front_facing_surface->SetDrawsContent(true); |
| 4349 | back_facing_surface->SetDrawsContent(true); |
| 4350 | front_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4351 | back_facing_child_of_front_facing_surface->SetDrawsContent(true); |
| 4352 | front_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4353 | back_facing_child_of_back_facing_surface->SetDrawsContent(true); |
| 4354 | dummy_replica_layer1->SetDrawsContent(true); |
| 4355 | dummy_replica_layer2->SetDrawsContent(true); |
| 4356 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | gfx::Transform backface_matrix; |
| 4358 | backface_matrix.Translate(50.0, 50.0); |
| 4359 | backface_matrix.RotateAboutYAxis(180.0); |
| 4360 | backface_matrix.Translate(-50.0, -50.0); |
| 4361 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4362 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 4363 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 4364 | // rendering context should use the transform with respect to that context. |
| 4365 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 4366 | // and (b) the layer's transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4367 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4368 | gfx::PointF(), gfx::Size(100, 100), true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4369 | false); // parent transform style is flat. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4370 | SetLayerPropertiesForTesting(front_facing_child, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4371 | gfx::Point3F(), gfx::PointF(), |
| 4372 | gfx::Size(100, 100), true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4373 | SetLayerPropertiesForTesting(back_facing_child, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4374 | gfx::Point3F(), gfx::PointF(), |
| 4375 | gfx::Size(100, 100), true, false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4376 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4377 | SetLayerPropertiesForTesting(front_facing_surface, identity_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4378 | gfx::Point3F(), gfx::PointF(), |
| 4379 | gfx::Size(100, 100), false, true); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4380 | // surface transform style is preserve-3d. |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4381 | SetLayerPropertiesForTesting(back_facing_surface, backface_matrix, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4382 | gfx::Point3F(), gfx::PointF(), |
| 4383 | gfx::Size(100, 100), false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4384 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4385 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4386 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4387 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4388 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4389 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4390 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4391 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 4392 | gfx::Size(100, 100), true, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4393 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface, |
weiliangc | 4374c2cc | 2015-12-07 19:26:01 | [diff] [blame] | 4394 | backface_matrix, gfx::Point3F(), gfx::PointF(), |
| 4395 | gfx::Size(100, 100), true, true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4397 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4398 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4399 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4400 | EXPECT_FALSE(front_facing_child->has_render_surface()); |
| 4401 | EXPECT_FALSE(back_facing_child->has_render_surface()); |
| 4402 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4403 | // We expect that a has_render_surface was created but not used. |
| 4404 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
| 4405 | EXPECT_FALSE( |
| 4406 | front_facing_child_of_front_facing_surface->has_render_surface()); |
| 4407 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface()); |
| 4408 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); |
| 4409 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4410 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4411 | EXPECT_EQ(3u, update_layer_list_impl()->size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4412 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 4413 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); |
| 4414 | EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); |
| 4415 | EXPECT_TRUE(UpdateLayerListImplContains( |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4416 | front_facing_child_of_front_facing_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4417 | } |
| 4418 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4419 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4420 | // Verify that layers are appropriately culled when their back face is showing |
| 4421 | // and they are not double sided, while animations are going on. |
| 4422 | // |
| 4423 | // Layers that are animating do not get culled on the main thread, as their |
| 4424 | // transforms should be treated as "unknown" so we can not be sure that their |
| 4425 | // back face is really showing. |
| 4426 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4427 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4429 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4430 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4431 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4432 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4433 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4434 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4435 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4436 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4437 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4438 | |
| 4439 | parent->AddChild(child); |
| 4440 | parent->AddChild(animating_surface); |
| 4441 | animating_surface->AddChild(child_of_animating_surface); |
| 4442 | parent->AddChild(animating_child); |
| 4443 | parent->AddChild(child2); |
| 4444 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4445 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4446 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4447 | // Nothing is double-sided |
| 4448 | child->SetDoubleSided(false); |
| 4449 | child2->SetDoubleSided(false); |
| 4450 | animating_surface->SetDoubleSided(false); |
| 4451 | child_of_animating_surface->SetDoubleSided(false); |
| 4452 | animating_child->SetDoubleSided(false); |
| 4453 | |
| 4454 | gfx::Transform backface_matrix; |
| 4455 | backface_matrix.Translate(50.0, 50.0); |
| 4456 | backface_matrix.RotateAboutYAxis(180.0); |
| 4457 | backface_matrix.Translate(-50.0, -50.0); |
| 4458 | |
| 4459 | // Make our render surface. |
| 4460 | animating_surface->SetForceRenderSurface(true); |
| 4461 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 4462 | if (layer_settings().use_compositor_animation_timelines) { |
| 4463 | // Animate the transform on the render surface. |
| 4464 | AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), timeline(), |
| 4465 | 10.0, 30, 0); |
| 4466 | // This is just an animating layer, not a surface. |
| 4467 | AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline(), |
| 4468 | 10.0, 30, 0); |
| 4469 | } else { |
| 4470 | // Animate the transform on the render surface. |
| 4471 | AddAnimatedTransformToController( |
| 4472 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 4473 | // This is just an animating layer, not a surface. |
| 4474 | AddAnimatedTransformToController( |
| 4475 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 4476 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4477 | |
| 4478 | SetLayerPropertiesForTesting(parent.get(), |
| 4479 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4480 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4481 | gfx::PointF(), |
| 4482 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4483 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4484 | false); |
| 4485 | SetLayerPropertiesForTesting(child.get(), |
| 4486 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4487 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4488 | gfx::PointF(), |
| 4489 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4490 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4491 | false); |
| 4492 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 4493 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4494 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | gfx::PointF(), |
| 4496 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4497 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4498 | false); |
| 4499 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 4500 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4501 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4502 | gfx::PointF(), |
| 4503 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4504 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4505 | false); |
| 4506 | SetLayerPropertiesForTesting(animating_child.get(), |
| 4507 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4508 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4509 | gfx::PointF(), |
| 4510 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4511 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4512 | false); |
| 4513 | SetLayerPropertiesForTesting(child2.get(), |
| 4514 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4515 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4516 | gfx::PointF(), |
| 4517 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4518 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4519 | false); |
| 4520 | |
enne | 1e1008c | 2015-08-21 00:45:46 | [diff] [blame] | 4521 | LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(), |
| 4522 | parent->bounds()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4523 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4524 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4525 | EXPECT_FALSE(child->has_render_surface()); |
| 4526 | EXPECT_TRUE(animating_surface->has_render_surface()); |
| 4527 | EXPECT_FALSE(child_of_animating_surface->has_render_surface()); |
| 4528 | EXPECT_FALSE(animating_child->has_render_surface()); |
| 4529 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4530 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4531 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
| 4532 | |
| 4533 | EXPECT_EQ(4u, update_layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4534 | |
| 4535 | // The non-animating child be culled from the layer list for the parent render |
| 4536 | // surface. |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4537 | EXPECT_TRUE(UpdateLayerListContains(animating_surface->id())); |
| 4538 | EXPECT_TRUE(UpdateLayerListContains(animating_child->id())); |
| 4539 | EXPECT_TRUE(UpdateLayerListContains(child2->id())); |
| 4540 | EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4541 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4542 | EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4543 | |
| 4544 | // The animating layers should have a visible content rect that represents the |
| 4545 | // area of the front face that is within the viewport. |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4546 | EXPECT_EQ(animating_child->visible_rect_from_property_trees(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4547 | gfx::Rect(animating_child->bounds())); |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4548 | EXPECT_EQ(animating_surface->visible_rect_from_property_trees(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4549 | gfx::Rect(animating_surface->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4550 | // And layers in the subtree of the animating layer should have valid visible |
| 4551 | // content rects also. |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4552 | EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4553 | gfx::Rect(child_of_animating_surface->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4554 | } |
| 4555 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4556 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4557 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4558 | // Verify the behavior of back-face culling for a render surface that is |
| 4559 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4560 | |
| 4561 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4562 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4563 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4564 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4565 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4566 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4567 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4568 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4569 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4570 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4571 | |
| 4572 | parent->AddChild(front_facing_surface); |
| 4573 | parent->AddChild(back_facing_surface); |
| 4574 | front_facing_surface->AddChild(child1); |
| 4575 | back_facing_surface->AddChild(child2); |
| 4576 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 4577 | host()->SetRootLayer(parent); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4578 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4579 | // RenderSurfaces are not double-sided |
| 4580 | front_facing_surface->SetDoubleSided(false); |
| 4581 | back_facing_surface->SetDoubleSided(false); |
| 4582 | |
| 4583 | gfx::Transform backface_matrix; |
| 4584 | backface_matrix.Translate(50.0, 50.0); |
| 4585 | backface_matrix.RotateAboutYAxis(180.0); |
| 4586 | backface_matrix.Translate(-50.0, -50.0); |
| 4587 | |
| 4588 | SetLayerPropertiesForTesting(parent.get(), |
| 4589 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4590 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4591 | gfx::PointF(), |
| 4592 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4593 | false, |
| 4594 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4596 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4597 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4598 | gfx::PointF(), |
| 4599 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4600 | true, |
| 4601 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4603 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4604 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4605 | gfx::PointF(), |
| 4606 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4607 | true, |
| 4608 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4609 | SetLayerPropertiesForTesting(child1.get(), |
| 4610 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4611 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4612 | gfx::PointF(), |
| 4613 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4614 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4615 | false); |
| 4616 | SetLayerPropertiesForTesting(child2.get(), |
| 4617 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4618 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4619 | gfx::PointF(), |
| 4620 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4621 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | false); |
| 4623 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4624 | front_facing_surface->Set3dSortingContextId(1); |
| 4625 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4626 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4627 | ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4628 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4629 | // Verify which render surfaces were created and used. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4630 | EXPECT_TRUE(front_facing_surface->has_render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4631 | |
| 4632 | // We expect the render surface to have been created, but remain unused. |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4633 | EXPECT_TRUE(back_facing_surface->has_render_surface()); |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 4634 | EXPECT_FALSE(child1->has_render_surface()); |
| 4635 | EXPECT_FALSE(child2->has_render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | |
enne | 7b2a217 | 2015-07-14 00:04:53 | [diff] [blame] | 4637 | EXPECT_EQ(2u, update_layer_list().size()); |
| 4638 | EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id())); |
| 4639 | EXPECT_TRUE(UpdateLayerListContains(child1->id())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4640 | } |
| 4641 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4642 | TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4643 | // Verify draw and screen space transforms of layers not in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4644 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4645 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4646 | LayerImpl* parent = root_layer(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4647 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4648 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4649 | gfx::PointF(), gfx::Size(100, 100), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4650 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4651 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4652 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4653 | child->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4654 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4655 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4656 | true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4657 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4658 | LayerImpl* child2 = AddChildToRoot<LayerImpl>(); |
| 4659 | child2->SetDrawsContent(true); |
| 4660 | SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(), |
| 4661 | gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false, |
| 4662 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4664 | float device_scale_factor = 2.5f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4665 | gfx::Size viewport_size(100, 100); |
| 4666 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4667 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4668 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent); |
| 4669 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4670 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4671 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4672 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4673 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4674 | // Verify parent transforms |
| 4675 | gfx::Transform expected_parent_transform; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4676 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4677 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4678 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4679 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4680 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4681 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4682 | // Verify results of transformed parent rects |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4683 | gfx::RectF parent_bounds(gfx::SizeF(parent->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4685 | gfx::RectF parent_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4686 | MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4687 | gfx::RectF parent_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4688 | MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4689 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4690 | gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4691 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4692 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4693 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4694 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4695 | // Verify child and child2 transforms. They should match. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4696 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4697 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4698 | expected_child_transform.Translate(child->position().x(), |
| 4699 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4700 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4701 | child->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4702 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4703 | child->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4704 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4705 | child2->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4706 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4707 | child2->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4708 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4709 | // Verify results of transformed child and child2 rects. They should |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4710 | // match. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4711 | gfx::RectF child_bounds(gfx::SizeF(child->bounds())); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4712 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4713 | gfx::RectF child_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4714 | MathUtil::MapClippedRect(child->DrawTransform(), child_bounds); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4715 | gfx::RectF child_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4716 | MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4717 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4718 | gfx::RectF child2_draw_rect = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4719 | MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4720 | gfx::RectF child2_screen_space_rect = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4721 | MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4722 | |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 4723 | gfx::RectF expected_child_draw_rect(child->position(), |
| 4724 | gfx::SizeF(child->bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4725 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4726 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4727 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4728 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect); |
| 4729 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4730 | } |
| 4731 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4732 | TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4733 | // Verify draw and screen space transforms of layers in a surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4734 | gfx::Transform identity_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4735 | gfx::Transform perspective_matrix; |
| 4736 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4737 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4738 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4739 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4740 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4741 | LayerImpl* root = root_layer(); |
| 4742 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 4743 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4744 | false); |
| 4745 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4746 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4747 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4748 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4749 | false); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4750 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4751 | LayerImpl* perspective_surface = AddChild<LayerImpl>(parent); |
| 4752 | SetLayerPropertiesForTesting(perspective_surface, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4753 | perspective_matrix * scale_small_matrix, |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4754 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4755 | gfx::Size(10, 10), false, true, true); |
| 4756 | perspective_surface->SetDrawsContent(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4757 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4758 | LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
| 4759 | SetLayerPropertiesForTesting(scale_surface, scale_small_matrix, |
| 4760 | gfx::Point3F(), gfx::PointF(2.f, 2.f), |
| 4761 | gfx::Size(10, 10), false, true, true); |
| 4762 | scale_surface->SetDrawsContent(true); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4763 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4764 | float device_scale_factor = 2.5f; |
| 4765 | float page_scale_factor = 3.f; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4766 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4767 | root); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4768 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4769 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4770 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4771 | perspective_surface); |
| 4772 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4773 | // the nearest render target. Here this includes the layer transform as well |
| 4774 | // as the device and page scale factors. |
| 4775 | gfx::Transform transform = scale_small_matrix; |
| 4776 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4777 | device_scale_factor * page_scale_factor); |
| 4778 | gfx::Vector2dF scales = |
| 4779 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4780 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4781 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4782 | |
| 4783 | // The ideal scale will draw 1:1 with its render target space along |
| 4784 | // the larger-scale axis. |
| 4785 | gfx::Vector2dF target_space_transform_scales = |
| 4786 | MathUtil::ComputeTransform2dScaleComponents( |
| 4787 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4788 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4789 | std::max(target_space_transform_scales.x(), |
| 4790 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4791 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4792 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4793 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4794 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4795 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4796 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4797 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4798 | parent->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4799 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4800 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4801 | // with the screen, and then scaled during drawing. |
| 4802 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4803 | expected_perspective_surface_draw_transform.Translate( |
| 4804 | device_scale_factor * page_scale_factor * |
| 4805 | perspective_surface->position().x(), |
| 4806 | device_scale_factor * page_scale_factor * |
| 4807 | perspective_surface->position().y()); |
| 4808 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4809 | perspective_matrix); |
| 4810 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4811 | scale_small_matrix); |
| 4812 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4813 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4814 | device_scale_factor * page_scale_factor, |
| 4815 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4816 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4817 | expected_perspective_surface_draw_transform, |
| 4818 | perspective_surface->render_surface()->draw_transform()); |
| 4819 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4820 | expected_perspective_surface_layer_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4821 | perspective_surface->DrawTransform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4822 | } |
| 4823 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4824 | TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4825 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4826 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4827 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4828 | |
| 4829 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4830 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4831 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4832 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4833 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4834 | root->SetBounds(gfx::Size(100, 100)); |
| 4835 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4836 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4837 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4838 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4839 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4840 | false); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4841 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4842 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4843 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4844 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4845 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4846 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4847 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4848 | float device_scale_factor = 2.5f; |
| 4849 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4850 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4851 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4852 | ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4853 | root); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4854 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4855 | // The ideal scale is able to go below 1. |
| 4856 | float expected_ideal_scale = |
| 4857 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4858 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4859 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4860 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4861 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4862 | initial_parent_scale * initial_child_scale; |
| 4863 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4864 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4865 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4866 | } |
| 4867 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4868 | TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4869 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4870 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4871 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4872 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4873 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4874 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4875 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4876 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4877 | LayerImpl* root = root_layer(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4878 | root->SetBounds(gfx::Size(100, 100)); |
| 4879 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4880 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4881 | parent->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4882 | SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(), |
| 4883 | gfx::PointF(), gfx::Size(100, 100), false, true, |
| 4884 | false); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4885 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4886 | LayerImpl* child_scale = AddChild<LayerImpl>(parent); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 4887 | child_scale->SetDrawsContent(true); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4888 | SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(), |
| 4889 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4890 | true, false); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4891 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4892 | { |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 4893 | ExecuteCalculateDrawProperties(root); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4894 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4895 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 4896 | // Animating layers compute ideal scale in the same way as when |
| 4897 | // they are static. |
| 4898 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 4899 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4900 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4901 | } |
| 4902 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4903 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4904 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 4905 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4906 | LayerImpl* parent = root_layer(); |
| 4907 | parent->SetDrawsContent(true); |
| 4908 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 4909 | gfx::PointF(), gfx::Size(30, 30), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4910 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4911 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4912 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 4913 | child->SetDrawsContent(true); |
| 4914 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 4915 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4916 | true, true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4917 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4918 | gfx::Transform replica_transform; |
| 4919 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4920 | |
| 4921 | scoped_ptr<LayerImpl> replica = |
| 4922 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 4923 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 4924 | gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false, |
| 4925 | true, false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 4926 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4927 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4928 | // This layer should end up in the same surface as child, with the same draw |
| 4929 | // and screen space transforms. |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4930 | LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child); |
| 4931 | duplicate_child_non_owner->SetDrawsContent(true); |
| 4932 | SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix, |
| 4933 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 4934 | false, true, false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4935 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4936 | float device_scale_factor = 1.5f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4937 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4938 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4939 | // We should have two render surfaces. The root's render surface and child's |
| 4940 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 4941 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4942 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4943 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4944 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4945 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4946 | parent->ScreenSpaceTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4947 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4948 | parent->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4949 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4950 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4951 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4952 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4953 | child->DrawTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4954 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4955 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4956 | expected_screen_space_transform.Scale(device_scale_factor, |
| 4957 | device_scale_factor); |
| 4958 | expected_screen_space_transform.Translate(child->position().x(), |
| 4959 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4960 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4961 | child->ScreenSpaceTransform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4962 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4963 | gfx::Transform expected_duplicate_child_draw_transform = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 4964 | child->DrawTransform(); |
| 4965 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(), |
| 4966 | duplicate_child_non_owner->DrawTransform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4967 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 4968 | child->ScreenSpaceTransform(), |
| 4969 | duplicate_child_non_owner->ScreenSpaceTransform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 4970 | EXPECT_EQ(child->drawable_content_rect(), |
| 4971 | duplicate_child_non_owner->drawable_content_rect()); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 4972 | EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4973 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | gfx::Transform expected_render_surface_draw_transform; |
| 4975 | expected_render_surface_draw_transform.Translate( |
| 4976 | device_scale_factor * child->position().x(), |
| 4977 | device_scale_factor * child->position().y()); |
| 4978 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 4979 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4980 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4981 | gfx::Transform expected_surface_draw_transform; |
| 4982 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 4983 | device_scale_factor * 2.f); |
| 4984 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 4985 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4986 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4987 | gfx::Transform expected_surface_screen_space_transform; |
| 4988 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 4989 | device_scale_factor * 2.f); |
| 4990 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4991 | expected_surface_screen_space_transform, |
| 4992 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4993 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4994 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4995 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 4996 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 4997 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4998 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4999 | expected_replica_draw_transform, |
| 5000 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5001 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5002 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5003 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5004 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5005 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5006 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5007 | expected_replica_screen_space_transform, |
| 5008 | child->render_surface()->replica_screen_space_transform()); |
| 5009 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5010 | expected_replica_screen_space_transform, |
| 5011 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5012 | } |
| 5013 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5014 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5015 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5016 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5017 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5018 | LayerImpl* parent = root_layer(); |
| 5019 | parent->SetDrawsContent(true); |
| 5020 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 5021 | gfx::PointF(), gfx::Size(33, 31), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5022 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5023 | |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5024 | LayerImpl* child = AddChildToRoot<LayerImpl>(); |
| 5025 | child->SetDrawsContent(true); |
| 5026 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 5027 | gfx::PointF(), gfx::Size(13, 11), false, true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5029 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5030 | gfx::Transform replica_transform; |
| 5031 | replica_transform.Scale(1.0, -1.0); |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5032 | scoped_ptr<LayerImpl> replica = |
| 5033 | LayerImpl::Create(host_impl()->active_tree(), 7); |
| 5034 | SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(), |
| 5035 | gfx::PointF(), gfx::Size(13, 11), false, true, |
| 5036 | false); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5037 | child->SetReplicaLayer(std::move(replica)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5038 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5039 | float device_scale_factor = 1.7f; |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5040 | ExecuteCalculateDrawProperties(parent, device_scale_factor); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5041 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5042 | // We should have two render surfaces. The root's render surface and child's |
| 5043 | // render surface (it needs one because it has a replica layer). |
enne | ea85023 | 2015-07-27 16:43:12 | [diff] [blame] | 5044 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5045 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5046 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5047 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5048 | child->render_surface()->draw_transform()); |
| 5049 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5050 | child->render_surface()->draw_transform()); |
| 5051 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5052 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5053 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5054 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5055 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5056 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5057 | expected_replica_draw_transform, |
| 5058 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5059 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5060 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5061 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5062 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5063 | expected_replica_screen_space_transform, |
| 5064 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5065 | } |
| 5066 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5067 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5068 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 5069 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 5070 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
| 5071 | scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings()); |
| 5072 | scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5073 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5074 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5075 | child->AddChild(grand_child.get()); |
| 5076 | child->SetMaskLayer(mask_layer.get()); |
| 5077 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5078 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5079 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5080 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5081 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5082 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5083 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5084 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5085 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5086 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5087 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5088 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5089 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5090 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5091 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5092 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5093 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5094 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5095 | EXPECT_EQ( |
| 5096 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5097 | } |
| 5098 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5099 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5100 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 5101 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5102 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5103 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5104 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5105 | const gfx::Transform identity_matrix; |
| 5106 | SetLayerPropertiesForTesting(root.get(), |
| 5107 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5108 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5109 | gfx::PointF(), |
| 5110 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5111 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5112 | false); |
| 5113 | SetLayerPropertiesForTesting(child.get(), |
| 5114 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5115 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5116 | gfx::PointF(), |
| 5117 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5118 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5119 | false); |
| 5120 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5121 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5122 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5123 | gfx::PointF(), |
| 5124 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5125 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5126 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5127 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5128 | root->AddChild(child); |
| 5129 | child->AddChild(grand_child); |
| 5130 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5131 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5132 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5133 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5134 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5135 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 5136 | EXPECT_FALSE(child->has_render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5137 | } |
| 5138 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5139 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5140 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5141 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5142 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5143 | FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider, |
| 5144 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5145 | host_impl.CreatePendingTree(); |
| 5146 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5147 | |
| 5148 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5149 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5150 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5151 | false); |
| 5152 | root->SetDrawsContent(true); |
| 5153 | |
| 5154 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5155 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5156 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5157 | false); |
| 5158 | child->SetDrawsContent(true); |
| 5159 | child->SetOpacity(0.0f); |
| 5160 | |
| 5161 | // Add opacity animation. |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5162 | if (layer_settings().use_compositor_animation_timelines) { |
| 5163 | scoped_refptr<AnimationTimeline> timeline = |
| 5164 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5165 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 5166 | |
| 5167 | AddOpacityTransitionToLayerWithPlayer(child->id(), timeline, 10.0, 0.0f, |
| 5168 | 1.0f, false); |
| 5169 | } else { |
| 5170 | AddOpacityTransitionToController(child->layer_animation_controller(), 10.0, |
| 5171 | 0.0f, 1.0f, false); |
| 5172 | } |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5173 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5174 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5175 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5176 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5177 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5178 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5179 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5180 | root.get(), root->bounds(), &render_surface_layer_list, |
| 5181 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5182 | inputs.can_adjust_raster_scales = true; |
| 5183 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5184 | |
| 5185 | // We should have one render surface and two layers. The child |
| 5186 | // layer should be included even though it is transparent. |
| 5187 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5188 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5189 | |
| 5190 | // If the root itself is hidden, the child should not be drawn even if it has |
| 5191 | // an animating opacity. |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5192 | root->SetOpacity(0.0f); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5193 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5194 | LayerImplList render_surface_layer_list2; |
| 5195 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 5196 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2( |
| 5197 | root.get(), root->bounds(), &render_surface_layer_list2, |
| 5198 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 5199 | inputs2.can_adjust_raster_scales = true; |
| 5200 | LayerTreeHostCommon::CalculateDrawProperties(&inputs2); |
| 5201 | |
| 5202 | LayerImpl* child_ptr = root->layer_tree_impl()->LayerById(2); |
| 5203 | EffectTree tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 5204 | EffectNode* node = tree.Node(child_ptr->effect_tree_index()); |
| 5205 | EXPECT_FALSE(node->data.is_drawn); |
jaydasika | e99e83e | 2016-01-29 19:35:40 | [diff] [blame] | 5206 | |
| 5207 | // A layer should be drawn and it should contribute to drawn surface when |
| 5208 | // it has animating opacity even if it has opacity 0. |
| 5209 | root->SetOpacity(1.0f); |
| 5210 | child_ptr->SetOpacity(0.0f); |
| 5211 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 5212 | LayerImplList render_surface_layer_list3; |
| 5213 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 5214 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3( |
| 5215 | root.get(), root->bounds(), &render_surface_layer_list3, |
| 5216 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 5217 | inputs3.can_adjust_raster_scales = true; |
| 5218 | LayerTreeHostCommon::CalculateDrawProperties(&inputs3); |
| 5219 | |
| 5220 | child_ptr = root->layer_tree_impl()->LayerById(2); |
| 5221 | tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 5222 | node = tree.Node(child_ptr->effect_tree_index()); |
| 5223 | EXPECT_TRUE(node->data.is_drawn); |
| 5224 | EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index())); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5225 | } |
| 5226 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5227 | class LayerTreeSettingsForLCDTextTest : public LayerTreeSettings { |
| 5228 | public: |
| 5229 | LayerTreeSettingsForLCDTextTest() { |
| 5230 | use_compositor_animation_timelines = true; |
| 5231 | } |
| 5232 | }; |
| 5233 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5234 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 5235 | class LCDTextTest : public LayerTreeHostCommonTestBase, |
| 5236 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5237 | public: |
| 5238 | LCDTextTest() |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5239 | : LayerTreeHostCommonTestBase(LayerTreeSettingsForLCDTextTest()), |
| 5240 | host_impl_(LayerTreeSettingsForLCDTextTest(), |
| 5241 | &task_runner_provider_, |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5242 | &shared_bitmap_manager_, |
| 5243 | &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5244 | root_(nullptr), |
| 5245 | child_(nullptr), |
| 5246 | grand_child_(nullptr) {} |
| 5247 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5248 | scoped_refptr<AnimationTimeline> timeline() { return timeline_; } |
| 5249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5250 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5251 | void SetUp() override { |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5252 | if (layer_settings().use_compositor_animation_timelines) { |
| 5253 | timeline_ = |
| 5254 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 5255 | host_impl_.animation_host()->AddAnimationTimeline(timeline_); |
| 5256 | } |
| 5257 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5258 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5259 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5260 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5261 | scoped_ptr<LayerImpl> root_ptr = |
| 5262 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5263 | scoped_ptr<LayerImpl> child_ptr = |
| 5264 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5265 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5266 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5267 | |
| 5268 | // Stash raw pointers to look at later. |
| 5269 | root_ = root_ptr.get(); |
| 5270 | child_ = child_ptr.get(); |
| 5271 | grand_child_ = grand_child_ptr.get(); |
| 5272 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5273 | child_->AddChild(std::move(grand_child_ptr)); |
| 5274 | root_->AddChild(std::move(child_ptr)); |
| 5275 | host_impl_.active_tree()->SetRootLayer(std::move(root_ptr)); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5276 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5277 | root_->SetContentsOpaque(true); |
| 5278 | child_->SetContentsOpaque(true); |
| 5279 | grand_child_->SetContentsOpaque(true); |
| 5280 | |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5281 | root_->SetDrawsContent(true); |
| 5282 | child_->SetDrawsContent(true); |
| 5283 | grand_child_->SetDrawsContent(true); |
| 5284 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5285 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5286 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5287 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5288 | true); |
| 5289 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5290 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5291 | std::tr1::get<2>(GetParam())); |
| 5292 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5293 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5294 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5295 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5296 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5297 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5298 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5299 | |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5300 | FakeImplTaskRunnerProvider task_runner_provider_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5301 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5302 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5303 | FakeLayerTreeHostImpl host_impl_; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5304 | scoped_refptr<AnimationTimeline> timeline_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5305 | |
| 5306 | LayerImpl* root_; |
| 5307 | LayerImpl* child_; |
| 5308 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5309 | }; |
| 5310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5311 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5312 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5313 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5314 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5315 | // Case 1: Identity transform. |
| 5316 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5317 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5318 | layers_always_allowed_lcd_text_); |
| 5319 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5320 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5321 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5323 | // Case 2: Integral translation. |
| 5324 | gfx::Transform integral_translation; |
| 5325 | integral_translation.Translate(1.0, 2.0); |
| 5326 | child_->SetTransform(integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5327 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5328 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5329 | layers_always_allowed_lcd_text_); |
| 5330 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5331 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5332 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5333 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5334 | // Case 3: Non-integral translation. |
| 5335 | gfx::Transform non_integral_translation; |
| 5336 | non_integral_translation.Translate(1.5, 2.5); |
| 5337 | child_->SetTransform(non_integral_translation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5338 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5339 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5340 | layers_always_allowed_lcd_text_); |
| 5341 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5342 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5343 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5344 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5345 | // Case 4: Rotation. |
| 5346 | gfx::Transform rotation; |
| 5347 | rotation.Rotate(10.0); |
| 5348 | child_->SetTransform(rotation); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5349 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5350 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5351 | layers_always_allowed_lcd_text_); |
| 5352 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5353 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5354 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5355 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5356 | // Case 5: Scale. |
| 5357 | gfx::Transform scale; |
| 5358 | scale.Scale(2.0, 2.0); |
| 5359 | child_->SetTransform(scale); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5360 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5361 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5362 | layers_always_allowed_lcd_text_); |
| 5363 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5364 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5365 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[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 6: Skew. |
| 5368 | gfx::Transform skew; |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 5369 | skew.Skew(10.0, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5370 | child_->SetTransform(skew); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5371 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5372 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5373 | layers_always_allowed_lcd_text_); |
| 5374 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5375 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5376 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5377 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5378 | // Case 7: Translucent. |
| 5379 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5380 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5381 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5382 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5383 | layers_always_allowed_lcd_text_); |
| 5384 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5385 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5386 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5387 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5388 | // Case 8: Sanity check: restore transform and opacity. |
| 5389 | child_->SetTransform(identity_matrix); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5390 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5391 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5392 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5393 | layers_always_allowed_lcd_text_); |
| 5394 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5395 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5396 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5397 | |
| 5398 | // Case 9: Non-opaque content. |
| 5399 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5400 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5401 | layers_always_allowed_lcd_text_); |
| 5402 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5403 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5404 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5405 | |
| 5406 | // Case 10: Sanity check: restore content opaqueness. |
| 5407 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5408 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5409 | layers_always_allowed_lcd_text_); |
| 5410 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5411 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5412 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5413 | } |
| 5414 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5415 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5416 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5417 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5419 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5420 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5421 | layers_always_allowed_lcd_text_); |
| 5422 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5423 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5424 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5425 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5426 | // Add opacity animation. |
| 5427 | child_->SetOpacity(0.9f); |
jaydasika | 3f930c1 | 2015-06-30 15:18:25 | [diff] [blame] | 5428 | child_->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5429 | if (layer_settings().use_compositor_animation_timelines) { |
| 5430 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5431 | 0.1f, false); |
| 5432 | } else { |
| 5433 | AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0, |
| 5434 | 0.9f, 0.1f, false); |
| 5435 | } |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5436 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5437 | layers_always_allowed_lcd_text_); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5438 | // Text LCD should be adjusted while animation is active. |
| 5439 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5440 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5441 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
| 5442 | } |
| 5443 | |
| 5444 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 5445 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5446 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5447 | |
| 5448 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5449 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5450 | layers_always_allowed_lcd_text_); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5451 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5452 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5453 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5454 | |
| 5455 | // Mark contents non-opaque within the first animation frame. |
| 5456 | child_->SetContentsOpaque(false); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 5457 | if (layer_settings().use_compositor_animation_timelines) { |
| 5458 | AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f, |
| 5459 | 0.1f, false); |
| 5460 | } else { |
| 5461 | AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0, |
| 5462 | 0.9f, 0.1f, false); |
| 5463 | } |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 5464 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5465 | layers_always_allowed_lcd_text_); |
| 5466 | // LCD text should be disabled for non-opaque layers even during animations. |
| 5467 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5468 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5469 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5473 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5474 | testing::Combine(testing::Bool(), |
| 5475 | testing::Bool(), |
| 5476 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5477 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5478 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5479 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5480 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5481 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5482 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5483 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5484 | host_impl.CreatePendingTree(); |
| 5485 | const gfx::Transform identity_matrix; |
| 5486 | |
| 5487 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5488 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5489 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5490 | false); |
| 5491 | root->SetDrawsContent(true); |
| 5492 | |
| 5493 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5494 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5495 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5496 | false); |
| 5497 | child->SetDrawsContent(true); |
| 5498 | |
| 5499 | scoped_ptr<LayerImpl> grand_child = |
| 5500 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5501 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5502 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5503 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5504 | grand_child->SetDrawsContent(true); |
| 5505 | grand_child->SetHideLayerAndSubtree(true); |
| 5506 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5507 | child->AddChild(std::move(grand_child)); |
| 5508 | root->AddChild(std::move(child)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5509 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5510 | |
| 5511 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5512 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5513 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5514 | root.get(), root->bounds(), &render_surface_layer_list, |
| 5515 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5516 | inputs.can_adjust_raster_scales = true; |
| 5517 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5518 | |
| 5519 | // We should have one render surface and two layers. The grand child has |
| 5520 | // hidden itself. |
| 5521 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5522 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5523 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 5524 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5525 | } |
| 5526 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5527 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5528 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5529 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5530 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5531 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5532 | &task_graph_runner); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5533 | host_impl.CreatePendingTree(); |
| 5534 | const gfx::Transform identity_matrix; |
| 5535 | |
| 5536 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5537 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5538 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5539 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5540 | root->SetDrawsContent(true); |
| 5541 | |
| 5542 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5543 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5544 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5545 | false); |
| 5546 | child->SetDrawsContent(true); |
| 5547 | child->SetHideLayerAndSubtree(true); |
| 5548 | |
| 5549 | scoped_ptr<LayerImpl> grand_child = |
| 5550 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5551 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5552 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5553 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5554 | grand_child->SetDrawsContent(true); |
| 5555 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5556 | child->AddChild(std::move(grand_child)); |
| 5557 | root->AddChild(std::move(child)); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5558 | |
| 5559 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5560 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5561 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5562 | root.get(), root->bounds(), &render_surface_layer_list, |
| 5563 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5564 | inputs.can_adjust_raster_scales = true; |
| 5565 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5566 | |
| 5567 | // We should have one render surface and one layers. The child has |
| 5568 | // hidden itself and the grand child. |
| 5569 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5570 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5571 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5572 | } |
| 5573 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5574 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 5575 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5576 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5577 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5578 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5579 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5580 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5581 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5582 | host_impl.CreatePendingTree(); |
| 5583 | const gfx::Transform identity_matrix; |
| 5584 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5585 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5586 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5587 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5588 | true); |
| 5589 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5590 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5591 | scoped_ptr<LayerImpl> copy_grand_parent = |
| 5592 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5593 | SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix, |
| 5594 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 5595 | true, false, false); |
| 5596 | copy_grand_parent->SetDrawsContent(true); |
| 5597 | LayerImpl* copy_grand_parent_layer = copy_grand_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5598 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5599 | scoped_ptr<LayerImpl> copy_parent = |
| 5600 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5601 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5602 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5603 | true, false, true); |
| 5604 | copy_parent->SetDrawsContent(true); |
| 5605 | LayerImpl* copy_parent_layer = copy_parent.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5606 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5607 | scoped_ptr<LayerImpl> copy_request = |
| 5608 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5609 | SetLayerPropertiesForTesting(copy_request.get(), identity_matrix, |
| 5610 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5611 | true, false, true); |
| 5612 | copy_request->SetDrawsContent(true); |
| 5613 | LayerImpl* copy_layer = copy_request.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5614 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5615 | scoped_ptr<LayerImpl> copy_child = |
| 5616 | LayerImpl::Create(host_impl.pending_tree(), 5); |
| 5617 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5618 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5619 | true, false, false); |
| 5620 | copy_child->SetDrawsContent(true); |
| 5621 | LayerImpl* copy_child_layer = copy_child.get(); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5622 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5623 | scoped_ptr<LayerImpl> copy_grand_child = |
thakis | e53c527 | 2016-01-24 01:20:40 | [diff] [blame] | 5624 | LayerImpl::Create(host_impl.pending_tree(), 6); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5625 | SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix, |
| 5626 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5627 | true, false, false); |
| 5628 | copy_child->SetDrawsContent(true); |
| 5629 | LayerImpl* copy_grand_child_layer = copy_grand_child.get(); |
| 5630 | |
| 5631 | scoped_ptr<LayerImpl> copy_grand_parent_sibling_before = |
| 5632 | LayerImpl::Create(host_impl.pending_tree(), 7); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5633 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5634 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5635 | gfx::Size(40, 40), true, false, false); |
| 5636 | copy_grand_parent_sibling_before->SetDrawsContent(true); |
| 5637 | LayerImpl* copy_grand_parent_sibling_before_layer = |
| 5638 | copy_grand_parent_sibling_before.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5639 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5640 | scoped_ptr<LayerImpl> copy_grand_parent_sibling_after = |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5641 | LayerImpl::Create(host_impl.pending_tree(), 8); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5642 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5643 | identity_matrix, gfx::Point3F(), gfx::PointF(), |
| 5644 | gfx::Size(40, 40), true, false, false); |
| 5645 | copy_grand_parent_sibling_after->SetDrawsContent(true); |
| 5646 | LayerImpl* copy_grand_parent_sibling_after_layer = |
| 5647 | copy_grand_parent_sibling_after.get(); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5648 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5649 | copy_child->AddChild(std::move(copy_grand_child)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5650 | copy_request->AddChild(std::move(copy_child)); |
| 5651 | copy_parent->AddChild(std::move(copy_request)); |
| 5652 | copy_grand_parent->AddChild(std::move(copy_parent)); |
| 5653 | root->AddChild(std::move(copy_grand_parent_sibling_before)); |
| 5654 | root->AddChild(std::move(copy_grand_parent)); |
| 5655 | root->AddChild(std::move(copy_grand_parent_sibling_after)); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5656 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5657 | // 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] | 5658 | // hidden subtree on copy_layer. Also hide the copy grand child and its |
| 5659 | // subtree. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5660 | copy_grand_parent_layer->SetHideLayerAndSubtree(true); |
| 5661 | copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true); |
| 5662 | copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5663 | copy_grand_child_layer->SetHideLayerAndSubtree(true); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5664 | |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 5665 | std::vector<scoped_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5666 | copy_requests.push_back( |
| 5667 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5668 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5669 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5670 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5671 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5672 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5673 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5674 | root.get(), root->bounds(), &render_surface_layer_list, |
| 5675 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5676 | inputs.can_adjust_raster_scales = true; |
| 5677 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5678 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 5679 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 5680 | EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5681 | EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0); |
| 5682 | EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 5683 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5684 | // We should have four render surfaces, one for the root, one for the grand |
| 5685 | // parent since it has opacity and two drawing descendants, one for the parent |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5686 | // since it owns a surface, and one for the copy_layer. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5687 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5688 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5689 | EXPECT_EQ(copy_grand_parent_layer->id(), |
| 5690 | render_surface_layer_list.at(1)->id()); |
| 5691 | EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id()); |
| 5692 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5693 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5694 | // The root render surface should have 2 contributing layers. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5695 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5696 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5697 | EXPECT_EQ(copy_grand_parent_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5698 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5699 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 5700 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5701 | // appear in its list, since it needs to be drawn for the copy request. |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5702 | ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5703 | EXPECT_EQ(copy_layer->id(), |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5704 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5705 | |
| 5706 | // The copy_layer's render surface should have two contributing layers. |
| 5707 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 5708 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5709 | copy_layer->render_surface()->layer_list().at(0)->id()); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5710 | EXPECT_EQ(copy_child_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5711 | copy_layer->render_surface()->layer_list().at(1)->id()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 5712 | |
| 5713 | // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden, |
| 5714 | // but the copy_layer and copy_child should be drawn for the copy request. |
| 5715 | // copy grand child should not be drawn as its hidden even in the copy |
| 5716 | // request. |
| 5717 | EffectTree tree = root->layer_tree_impl()->property_trees()->effect_tree; |
| 5718 | EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index()); |
| 5719 | EXPECT_FALSE(node->data.is_drawn); |
| 5720 | node = tree.Node(copy_parent_layer->effect_tree_index()); |
| 5721 | EXPECT_FALSE(node->data.is_drawn); |
| 5722 | node = tree.Node(copy_layer->effect_tree_index()); |
| 5723 | EXPECT_TRUE(node->data.is_drawn); |
| 5724 | node = tree.Node(copy_child_layer->effect_tree_index()); |
| 5725 | EXPECT_TRUE(node->data.is_drawn); |
| 5726 | node = tree.Node(copy_grand_child_layer->effect_tree_index()); |
| 5727 | EXPECT_FALSE(node->data.is_drawn); |
| 5728 | |
| 5729 | // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its |
| 5730 | // actually hidden. |
| 5731 | EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5732 | } |
| 5733 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5734 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5735 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5736 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5737 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5738 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5739 | &task_graph_runner); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5740 | host_impl.CreatePendingTree(); |
| 5741 | const gfx::Transform identity_matrix; |
| 5742 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5743 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5744 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5745 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5746 | true); |
| 5747 | root->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5748 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5749 | scoped_ptr<LayerImpl> copy_parent = |
| 5750 | LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5751 | SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix, |
| 5752 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 5753 | false, false); |
| 5754 | copy_parent->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5755 | copy_parent->SetMasksToBounds(true); |
| 5756 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5757 | scoped_ptr<LayerImpl> copy_layer = |
| 5758 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5759 | SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix, |
| 5760 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5761 | true, false, true); |
| 5762 | copy_layer->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5763 | |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5764 | scoped_ptr<LayerImpl> copy_child = |
| 5765 | LayerImpl::Create(host_impl.pending_tree(), 4); |
| 5766 | SetLayerPropertiesForTesting(copy_child.get(), identity_matrix, |
| 5767 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 5768 | true, false, false); |
| 5769 | copy_child->SetDrawsContent(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5770 | |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 5771 | std::vector<scoped_ptr<CopyOutputRequest>> copy_requests; |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5772 | copy_requests.push_back( |
| 5773 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 5774 | copy_layer->PassCopyRequests(©_requests); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5775 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 5776 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 5777 | copy_layer->AddChild(std::move(copy_child)); |
| 5778 | copy_parent->AddChild(std::move(copy_layer)); |
| 5779 | root->AddChild(std::move(copy_parent)); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5780 | |
| 5781 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5782 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
weiliangc | 51fb255d | 2015-07-24 15:32:30 | [diff] [blame] | 5783 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 5784 | root.get(), root->bounds(), &render_surface_layer_list, |
| 5785 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5786 | inputs.can_adjust_raster_scales = true; |
| 5787 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5788 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5789 | // We should have two render surface, as the others are clipped out. |
| 5790 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5791 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5792 | |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5793 | // The root render surface should only have 2 contributing layer, since the |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5794 | // other layers are empty/clipped away. |
xjz | e19f7640 | 2015-11-06 21:48:44 | [diff] [blame] | 5795 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5796 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 5797 | } |
| 5798 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5799 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5800 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5801 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5802 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 5803 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 5804 | &task_graph_runner); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5805 | host_impl.CreatePendingTree(); |
| 5806 | const gfx::Transform identity_matrix; |
| 5807 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5808 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5809 | SetLayerPropertiesForTesting(root.get(), |
| 5810 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5811 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5812 | gfx::PointF(), |
| 5813 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5814 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5815 | false); |
| 5816 | root->SetIsDrawable(true); |
| 5817 | |
| 5818 | // The surface is moved slightly outside of the viewport. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5819 | scoped_refptr<Layer> surface = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5820 | SetLayerPropertiesForTesting(surface.get(), |
| 5821 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5822 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5823 | gfx::PointF(-10, -20), |
| 5824 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5825 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5826 | false); |
| 5827 | surface->SetForceRenderSurface(true); |
| 5828 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5829 | scoped_refptr<Layer> surface_child = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5830 | SetLayerPropertiesForTesting(surface_child.get(), |
| 5831 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5832 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5833 | gfx::PointF(), |
| 5834 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5835 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5836 | false); |
| 5837 | surface_child->SetIsDrawable(true); |
| 5838 | |
| 5839 | surface->AddChild(surface_child); |
| 5840 | root->AddChild(surface); |
| 5841 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 5842 | host()->SetRootLayer(root); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5843 | |
enne | 1e1008c | 2015-08-21 00:45:46 | [diff] [blame] | 5844 | LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(), |
| 5845 | root->bounds()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5846 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5847 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 5848 | // The visible_layer_rect for the |surface_child| should not be clipped by |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5849 | // the viewport. |
| 5850 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
enne | 6c281f6e | 2015-08-18 23:23:00 | [diff] [blame] | 5851 | surface_child->visible_rect_from_property_trees().ToString()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 5852 | } |
| 5853 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5854 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 5855 | // Ensure that a transform between the layer and its render surface is not a |
| 5856 | // problem. Constructs the following layer tree. |
| 5857 | // |
| 5858 | // root (a render surface) |
| 5859 | // + render_surface |
| 5860 | // + clip_parent (scaled) |
| 5861 | // + intervening_clipping_layer |
| 5862 | // + clip_child |
| 5863 | // |
| 5864 | // The render surface should be resized correctly and the clip child should |
| 5865 | // inherit the right clip rect. |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5866 | LayerImpl* root = root_layer(); |
| 5867 | LayerImpl* render_surface = AddChildToRoot<LayerImpl>(); |
| 5868 | LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5869 | clip_parent->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5870 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5871 | intervening->SetDrawsContent(true); |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5872 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 5873 | clip_child->SetDrawsContent(true); |
| 5874 | clip_child->SetClipParent(clip_parent); |
| 5875 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 5876 | clip_children->insert(clip_child); |
| 5877 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5878 | |
| 5879 | intervening->SetMasksToBounds(true); |
| 5880 | clip_parent->SetMasksToBounds(true); |
| 5881 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5882 | gfx::Transform scale_transform; |
| 5883 | scale_transform.Scale(2, 2); |
| 5884 | |
| 5885 | gfx::Transform identity_transform; |
| 5886 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5887 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5888 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5889 | true); |
| 5890 | SetLayerPropertiesForTesting(render_surface, identity_transform, |
| 5891 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5892 | true, false, true); |
| 5893 | SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(), |
| 5894 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5895 | false, false); |
| 5896 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5897 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5898 | false, false); |
| 5899 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5900 | gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true, |
| 5901 | false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5902 | |
enne | 70aa712d | 2015-07-28 22:46:31 | [diff] [blame] | 5903 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5904 | |
| 5905 | ASSERT_TRUE(root->render_surface()); |
| 5906 | ASSERT_TRUE(render_surface->render_surface()); |
| 5907 | |
| 5908 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 5909 | // by the intervening clip layer. |
| 5910 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 5911 | clip_parent->clip_rect().ToString()); |
| 5912 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 5913 | clip_child->clip_rect().ToString()); |
| 5914 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 5915 | intervening->clip_rect().ToString()); |
| 5916 | |
| 5917 | // Ensure that the render surface reports a content rect that has been grown |
| 5918 | // to accomodate for the clip child. |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 5919 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5920 | render_surface->render_surface()->content_rect().ToString()); |
| 5921 | |
| 5922 | // The above check implies the two below, but they nicely demonstrate that |
| 5923 | // we've grown, despite the intervening layer's clip. |
| 5924 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 5925 | render_surface->render_surface()->content_rect())); |
| 5926 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 5927 | render_surface->render_surface()->content_rect())); |
| 5928 | } |
| 5929 | |
| 5930 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 5931 | // Ensure that intervening render surfaces are not a problem in the basic |
| 5932 | // case. In the following tree, both render surfaces should be resized to |
| 5933 | // accomodate for the clip child, despite an intervening clip. |
| 5934 | // |
| 5935 | // root (a render surface) |
| 5936 | // + clip_parent (masks to bounds) |
| 5937 | // + render_surface1 (sets opacity) |
| 5938 | // + intervening (masks to bounds) |
| 5939 | // + render_surface2 (also sets opacity) |
| 5940 | // + clip_child |
| 5941 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5942 | LayerImpl* root = root_layer(); |
| 5943 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 5944 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 5945 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 5946 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 5947 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 5948 | render_surface1->SetDrawsContent(true); |
| 5949 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5950 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5951 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5952 | clip_child->SetClipParent(clip_parent); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5953 | |
| 5954 | intervening->SetMasksToBounds(true); |
| 5955 | clip_parent->SetMasksToBounds(true); |
| 5956 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5957 | gfx::Transform translation_transform; |
| 5958 | translation_transform.Translate(2, 2); |
| 5959 | |
| 5960 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5961 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 5962 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 5963 | true); |
| 5964 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 5965 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 5966 | gfx::Size(40, 40), true, false, false); |
| 5967 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 5968 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5969 | true, false, true); |
| 5970 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 5971 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 5972 | false, false); |
| 5973 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 5974 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 5975 | true, false, true); |
| 5976 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 5977 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 5978 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5979 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 5980 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 5981 | |
| 5982 | EXPECT_TRUE(root->render_surface()); |
| 5983 | EXPECT_TRUE(render_surface1->render_surface()); |
| 5984 | EXPECT_TRUE(render_surface2->render_surface()); |
| 5985 | |
| 5986 | // Since the render surfaces could have expanded, they should not clip (their |
| 5987 | // bounds would no longer be reliable). We should resort to layer clipping |
| 5988 | // in this case. |
| 5989 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 5990 | render_surface1->render_surface()->clip_rect().ToString()); |
| 5991 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 5992 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 5993 | render_surface2->render_surface()->clip_rect().ToString()); |
| 5994 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 5995 | |
| 5996 | // NB: clip rects are in target space. |
| 5997 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 5998 | render_surface1->clip_rect().ToString()); |
| 5999 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6000 | |
| 6001 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6002 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6003 | render_surface2->clip_rect().ToString()); |
| 6004 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6005 | |
| 6006 | // The content rects of both render surfaces should both have expanded to |
| 6007 | // contain the clip child. |
| 6008 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6009 | render_surface1->render_surface()->content_rect().ToString()); |
| 6010 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6011 | render_surface2->render_surface()->content_rect().ToString()); |
| 6012 | |
| 6013 | // The clip child should have inherited the clip parent's clip (projected to |
| 6014 | // the right space, of course), and should have the correctly sized visible |
| 6015 | // content rect. |
| 6016 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6017 | clip_child->clip_rect().ToString()); |
| 6018 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6019 | clip_child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6020 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6021 | } |
| 6022 | |
| 6023 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6024 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6025 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6026 | // of transform. |
| 6027 | // |
| 6028 | // root (a render surface) |
| 6029 | // + clip_parent (masks to bounds) |
| 6030 | // + render_surface1 (sets opacity) |
| 6031 | // + intervening (masks to bounds AND scrolls) |
| 6032 | // + render_surface2 (also sets opacity) |
| 6033 | // + clip_child |
| 6034 | // |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6035 | LayerImpl* root = root_layer(); |
| 6036 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6037 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
| 6038 | LayerImpl* intervening = AddChild<LayerImpl>(render_surface1); |
| 6039 | LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening); |
| 6040 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 6041 | render_surface1->SetDrawsContent(true); |
| 6042 | render_surface2->SetDrawsContent(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6043 | clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6044 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6045 | clip_child->SetClipParent(clip_parent); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6046 | |
| 6047 | intervening->SetMasksToBounds(true); |
| 6048 | clip_parent->SetMasksToBounds(true); |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6049 | intervening->SetScrollClipLayer(clip_parent->id()); |
| 6050 | intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6051 | |
| 6052 | gfx::Transform translation_transform; |
| 6053 | translation_transform.Translate(2, 2); |
| 6054 | |
| 6055 | gfx::Transform identity_transform; |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6056 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6057 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6058 | true); |
| 6059 | SetLayerPropertiesForTesting(clip_parent, translation_transform, |
| 6060 | gfx::Point3F(), gfx::PointF(1.f, 1.f), |
| 6061 | gfx::Size(40, 40), true, false, false); |
| 6062 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6063 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 6064 | true, false, true); |
| 6065 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 6066 | gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true, |
| 6067 | false, false); |
| 6068 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6069 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 6070 | true, false, true); |
| 6071 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6072 | gfx::PointF(-10.f, -10.f), gfx::Size(60, 60), |
| 6073 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6074 | |
weiliangc | d6a836d | 2015-07-28 21:20:23 | [diff] [blame] | 6075 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6076 | |
| 6077 | EXPECT_TRUE(root->render_surface()); |
| 6078 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6079 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6080 | |
| 6081 | // Since the render surfaces could have expanded, they should not clip (their |
| 6082 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6083 | // in this case. |
| 6084 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6085 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6086 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6087 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6088 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6089 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6090 | |
| 6091 | // NB: clip rects are in target space. |
| 6092 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6093 | render_surface1->clip_rect().ToString()); |
| 6094 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6095 | |
| 6096 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6097 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6098 | render_surface2->clip_rect().ToString()); |
| 6099 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6100 | |
| 6101 | // The content rects of both render surfaces should both have expanded to |
| 6102 | // contain the clip child. |
| 6103 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6104 | render_surface1->render_surface()->content_rect().ToString()); |
| 6105 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6106 | render_surface2->render_surface()->content_rect().ToString()); |
| 6107 | |
| 6108 | // The clip child should have inherited the clip parent's clip (projected to |
| 6109 | // the right space, of course), and should have the correctly sized visible |
| 6110 | // content rect. |
| 6111 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6112 | clip_child->clip_rect().ToString()); |
| 6113 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6114 | clip_child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6115 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6116 | } |
| 6117 | |
| 6118 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6119 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6120 | // |
| 6121 | // root (a render surface) |
| 6122 | // + clip_parent (masks to bounds) |
| 6123 | // + intervening (masks to bounds) |
| 6124 | // + clip_child |
| 6125 | // + child |
| 6126 | // |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6127 | LayerImpl* root = root_layer(); |
| 6128 | LayerImpl* clip_parent = AddChild<LayerImpl>(root); |
| 6129 | LayerImpl* intervening = AddChild<LayerImpl>(clip_parent); |
| 6130 | LayerImpl* clip_child = AddChild<LayerImpl>(intervening); |
| 6131 | LayerImpl* child = AddChild<LayerImpl>(clip_child); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 6132 | clip_child->SetDrawsContent(true); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6133 | child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6134 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6135 | clip_child->SetClipParent(clip_parent); |
| 6136 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 6137 | clip_children->insert(clip_child); |
| 6138 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6139 | |
| 6140 | intervening->SetMasksToBounds(true); |
| 6141 | clip_parent->SetMasksToBounds(true); |
| 6142 | |
| 6143 | gfx::Transform identity_transform; |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6144 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6145 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6146 | true); |
| 6147 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6148 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6149 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6150 | SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(), |
| 6151 | gfx::PointF(), gfx::Size(5, 5), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6152 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6153 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6154 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6155 | false); |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6156 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6157 | gfx::PointF(), gfx::Size(60, 60), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6158 | false); |
| 6159 | |
enne | 2d0d8e6 | 2015-08-18 18:29:17 | [diff] [blame] | 6160 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6161 | |
| 6162 | EXPECT_TRUE(root->render_surface()); |
| 6163 | |
| 6164 | // Neither the clip child nor its descendant should have inherited the clip |
| 6165 | // from |intervening|. |
| 6166 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6167 | clip_child->clip_rect().ToString()); |
| 6168 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6169 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 6170 | child->visible_layer_rect().ToString()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6171 | EXPECT_TRUE(child->is_clipped()); |
| 6172 | } |
| 6173 | |
| 6174 | TEST_F(LayerTreeHostCommonTest, |
| 6175 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6176 | // Ensures that non-descendant clip children in the tree do not affect |
| 6177 | // render surfaces. |
| 6178 | // |
| 6179 | // root (a render surface) |
| 6180 | // + clip_parent (masks to bounds) |
| 6181 | // + render_surface1 |
| 6182 | // + clip_child |
| 6183 | // + render_surface2 |
| 6184 | // + non_clip_child |
| 6185 | // |
| 6186 | // In this example render_surface2 should be unaffected by clip_child. |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6187 | LayerImpl* root = root_layer(); |
| 6188 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 6189 | LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6190 | render_surface1->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6191 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1); |
| 6192 | clip_child->SetDrawsContent(true); |
| 6193 | LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6194 | render_surface2->SetDrawsContent(true); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6195 | LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2); |
| 6196 | non_clip_child->SetDrawsContent(true); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6197 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6198 | clip_child->SetClipParent(clip_parent); |
| 6199 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 6200 | clip_children->insert(clip_child); |
| 6201 | clip_parent->SetClipChildren(clip_children.release()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6202 | |
| 6203 | clip_parent->SetMasksToBounds(true); |
| 6204 | render_surface1->SetMasksToBounds(true); |
| 6205 | |
| 6206 | gfx::Transform identity_transform; |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6207 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6208 | gfx::PointF(), gfx::Size(15, 15), true, false, |
| 6209 | true); |
| 6210 | SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(), |
| 6211 | gfx::PointF(), gfx::Size(10, 10), true, false, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6212 | false); |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6213 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6214 | gfx::Point3F(), gfx::PointF(5, 5), |
| 6215 | gfx::Size(5, 5), true, false, true); |
| 6216 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6217 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6218 | true, false, true); |
| 6219 | SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(), |
| 6220 | gfx::PointF(-1, 1), gfx::Size(10, 10), true, |
| 6221 | false, false); |
| 6222 | SetLayerPropertiesForTesting(non_clip_child, identity_transform, |
| 6223 | gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5), |
| 6224 | true, false, false); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6225 | |
enne | b441cdd | 2015-07-28 22:47:50 | [diff] [blame] | 6226 | ExecuteCalculateDrawProperties(root); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6227 | |
| 6228 | EXPECT_TRUE(root->render_surface()); |
| 6229 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6230 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6231 | |
| 6232 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6233 | render_surface1->clip_rect().ToString()); |
| 6234 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6235 | |
| 6236 | // The render surface should not clip (it has unclipped descendants), instead |
| 6237 | // it should rely on layer clipping. |
| 6238 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6239 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6240 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6241 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 6242 | // That said, it should have grown to accomodate the unclipped descendant and |
| 6243 | // its own size. |
| 6244 | EXPECT_EQ(gfx::Rect(-1, 0, 6, 5).ToString(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6245 | render_surface1->render_surface()->content_rect().ToString()); |
| 6246 | |
| 6247 | // This render surface should clip. It has no unclipped descendants. |
| 6248 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6249 | render_surface2->clip_rect().ToString()); |
| 6250 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 6251 | |
| 6252 | // It also shouldn't have grown to accomodate the clip child. |
| 6253 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6254 | render_surface2->render_surface()->content_rect().ToString()); |
| 6255 | |
| 6256 | // Sanity check our num_unclipped_descendants values. |
vmpstr | 762e70d | 2015-06-10 02:12:57 | [diff] [blame] | 6257 | EXPECT_EQ(1u, render_surface1->num_unclipped_descendants()); |
| 6258 | EXPECT_EQ(0u, render_surface2->num_unclipped_descendants()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6259 | } |
| 6260 | |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6261 | TEST_F(LayerTreeHostCommonTest, |
| 6262 | CreateRenderSurfaceWhenFlattenInsideRenderingContext) { |
| 6263 | // Verifies that Render Surfaces are created at the edge of rendering context. |
| 6264 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6265 | LayerImpl* root = root_layer(); |
| 6266 | LayerImpl* child1 = AddChildToRoot<LayerImpl>(); |
| 6267 | LayerImpl* child2 = AddChild<LayerImpl>(child1); |
| 6268 | LayerImpl* child3 = AddChild<LayerImpl>(child2); |
| 6269 | root->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6270 | |
| 6271 | const gfx::Transform identity_matrix; |
| 6272 | gfx::Point3F transform_origin; |
| 6273 | gfx::PointF position; |
| 6274 | gfx::Size bounds(100, 100); |
| 6275 | |
| 6276 | SetLayerPropertiesForTesting(root, identity_matrix, transform_origin, |
| 6277 | position, bounds, true, false); |
| 6278 | SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin, |
| 6279 | position, bounds, false, true); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6280 | child1->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6281 | SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin, |
| 6282 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6283 | child2->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6284 | SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin, |
| 6285 | position, bounds, true, false); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6286 | child3->SetDrawsContent(true); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6287 | |
| 6288 | child2->Set3dSortingContextId(1); |
| 6289 | child3->Set3dSortingContextId(1); |
| 6290 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6291 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root); |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6292 | |
| 6293 | // Verify which render surfaces were created. |
| 6294 | EXPECT_TRUE(root->has_render_surface()); |
| 6295 | EXPECT_FALSE(child1->has_render_surface()); |
| 6296 | EXPECT_TRUE(child2->has_render_surface()); |
| 6297 | EXPECT_FALSE(child3->has_render_surface()); |
| 6298 | } |
| 6299 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6300 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6301 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6302 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6303 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 6304 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 6305 | &task_graph_runner); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 6306 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6307 | scoped_ptr<LayerImpl> root = |
| 6308 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6309 | scoped_ptr<LayerImpl> child1 = |
| 6310 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6311 | scoped_ptr<LayerImpl> child2 = |
| 6312 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6313 | scoped_ptr<LayerImpl> child3 = |
| 6314 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6315 | |
| 6316 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6317 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6318 | gfx::PointF position; |
| 6319 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6320 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6321 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6322 | root->SetDrawsContent(true); |
| 6323 | |
| 6324 | // This layer structure normally forces render surface due to preserves3d |
| 6325 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6326 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6327 | position, bounds, false, true, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6328 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6329 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
weiliangc | 9ced159 | 2015-11-17 19:04:37 | [diff] [blame] | 6330 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6331 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6332 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 6333 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6334 | child3->SetDrawsContent(true); |
| 6335 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6336 | child2->Set3dSortingContextId(1); |
| 6337 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6338 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 6339 | child2->AddChild(std::move(child3)); |
| 6340 | child1->AddChild(std::move(child2)); |
| 6341 | root->AddChild(std::move(child1)); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6342 | |
| 6343 | { |
| 6344 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 6345 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6346 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6347 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6348 | root.get(), root->bounds(), &render_surface_layer_list, |
| 6349 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6350 | inputs.can_render_to_separate_surface = true; |
| 6351 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6352 | |
| 6353 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6354 | |
| 6355 | int count_represents_target_render_surface = 0; |
| 6356 | int count_represents_contributing_render_surface = 0; |
| 6357 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6358 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6359 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6360 | it != end; ++it) { |
| 6361 | if (it.represents_target_render_surface()) |
| 6362 | count_represents_target_render_surface++; |
| 6363 | if (it.represents_contributing_render_surface()) |
| 6364 | count_represents_contributing_render_surface++; |
| 6365 | if (it.represents_itself()) |
| 6366 | count_represents_itself++; |
| 6367 | } |
| 6368 | |
| 6369 | // Two render surfaces. |
| 6370 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 6371 | // Second render surface contributes to root render surface. |
| 6372 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 6373 | // All 4 layers represent itself. |
| 6374 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | { |
| 6378 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6379 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6380 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 6381 | root.get(), root->bounds(), &render_surface_layer_list, |
| 6382 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6383 | inputs.can_render_to_separate_surface = false; |
| 6384 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6385 | |
| 6386 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6387 | |
| 6388 | int count_represents_target_render_surface = 0; |
| 6389 | int count_represents_contributing_render_surface = 0; |
| 6390 | int count_represents_itself = 0; |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 6391 | LayerIterator end = LayerIterator::End(&render_surface_layer_list); |
| 6392 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 6393 | it != end; ++it) { |
| 6394 | if (it.represents_target_render_surface()) |
| 6395 | count_represents_target_render_surface++; |
| 6396 | if (it.represents_contributing_render_surface()) |
| 6397 | count_represents_contributing_render_surface++; |
| 6398 | if (it.represents_itself()) |
| 6399 | count_represents_itself++; |
| 6400 | } |
| 6401 | |
| 6402 | // Only root layer has a render surface. |
| 6403 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 6404 | // No layer contributes a render surface to root render surface. |
| 6405 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 6406 | // All 4 layers represent itself. |
| 6407 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6408 | } |
| 6409 | } |
| 6410 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6411 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6412 | LayerImpl* root = root_layer(); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6413 | LayerImpl* back_facing = AddChild<LayerImpl>(root); |
| 6414 | LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); |
| 6415 | LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); |
| 6416 | LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); |
| 6417 | LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); |
| 6418 | child1->SetDrawsContent(true); |
| 6419 | child2->SetDrawsContent(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6420 | |
| 6421 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6422 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6423 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6424 | true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6425 | SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(), |
| 6426 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6427 | false); |
| 6428 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6429 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6430 | false, true, true); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6431 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6432 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6433 | false, true, true); |
| 6434 | SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(), |
| 6435 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 6436 | false); |
| 6437 | SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(), |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6438 | gfx::PointF(), gfx::Size(20, 20), true, false, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6439 | false); |
| 6440 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6441 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6442 | root->Set3dSortingContextId(1); |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6443 | back_facing->Set3dSortingContextId(1); |
| 6444 | back_facing->SetShouldFlattenTransform(false); |
| 6445 | render_surface1->SetDoubleSided(false); |
| 6446 | render_surface2->Set3dSortingContextId(2); |
| 6447 | render_surface2->SetDoubleSided(false); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6448 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6449 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6450 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6451 | EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); |
| 6452 | EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); |
| 6453 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6454 | EXPECT_EQ(2u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6455 | ->at(0) |
| 6456 | ->render_surface() |
| 6457 | ->layer_list() |
| 6458 | .size()); |
| 6459 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
| 6460 | ->at(1) |
| 6461 | ->render_surface() |
| 6462 | ->layer_list() |
| 6463 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6464 | |
| 6465 | gfx::Transform rotation_transform = identity_transform; |
| 6466 | rotation_transform.RotateAboutXAxis(180.0); |
| 6467 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6468 | back_facing->SetTransform(rotation_transform); |
jaydasika | 5aa88b8 | 2015-11-10 01:48:03 | [diff] [blame] | 6469 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6470 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6471 | ExecuteCalculateDrawProperties(root); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6472 | |
jaydasika | e00c8a4 | 2016-01-28 20:18:33 | [diff] [blame] | 6473 | // render_surface1 is in the same 3d rendering context as back_facing and is |
| 6474 | // not double sided, so it should not be in RSLL. render_surface2 is also not |
| 6475 | // double-sided, but will still be in RSLL as it's in a different 3d rendering |
| 6476 | // context. |
| 6477 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
| 6478 | EXPECT_EQ(1u, render_surface_layer_list_impl() |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6479 | ->at(0) |
| 6480 | ->render_surface() |
| 6481 | ->layer_list() |
| 6482 | .size()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6483 | } |
| 6484 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6485 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) { |
| 6486 | LayerImpl* root = root_layer(); |
| 6487 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 6488 | LayerImpl* grand_child = AddChild<LayerImpl>(child); |
| 6489 | grand_child->SetDrawsContent(true); |
| 6490 | |
| 6491 | child->SetDoubleSided(false); |
| 6492 | grand_child->SetUseParentBackfaceVisibility(true); |
| 6493 | |
| 6494 | gfx::Transform identity_transform; |
| 6495 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6496 | gfx::PointF(), gfx::Size(50, 50), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6497 | true); |
| 6498 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6499 | gfx::PointF(), gfx::Size(30, 30), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6500 | false); |
| 6501 | SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6502 | gfx::PointF(), gfx::Size(20, 20), false, false, |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6503 | false); |
| 6504 | |
| 6505 | ExecuteCalculateDrawProperties(root); |
| 6506 | |
| 6507 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6508 | EXPECT_EQ(grand_child, render_surface_layer_list_impl() |
| 6509 | ->at(0) |
| 6510 | ->render_surface() |
| 6511 | ->layer_list()[0]); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6512 | |
| 6513 | // As all layers have identity transform, we shouldn't check for backface |
| 6514 | // visibility. |
| 6515 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6516 | EXPECT_FALSE(child->should_check_backface_visibility()); |
| 6517 | EXPECT_FALSE(grand_child->should_check_backface_visibility()); |
| 6518 | // As there are no 3d rendering contexts, all layers should use their local |
| 6519 | // transform for backface visibility. |
| 6520 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6521 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6522 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6523 | |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6524 | gfx::Transform rotation_transform = identity_transform; |
| 6525 | rotation_transform.RotateAboutXAxis(180.0); |
| 6526 | |
| 6527 | child->SetTransform(rotation_transform); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6528 | child->Set3dSortingContextId(1); |
| 6529 | grand_child->Set3dSortingContextId(1); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6530 | child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6531 | |
| 6532 | ExecuteCalculateDrawProperties(root); |
| 6533 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6534 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6535 | ->at(0) |
| 6536 | ->render_surface() |
| 6537 | ->layer_list() |
| 6538 | .size()); |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 6539 | |
| 6540 | // We should check for backface visibilty of child as it has a rotation |
| 6541 | // transform. We should also check for grand_child as it uses the backface |
| 6542 | // visibility of its parent. |
| 6543 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6544 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6545 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6546 | // child uses its local transform for backface visibility as it is the root of |
| 6547 | // a 3d rendering context. grand_child is in a 3d rendering context and is not |
| 6548 | // the root, but it derives its backface visibility from its parent which uses |
| 6549 | // its local transform. |
| 6550 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6551 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6552 | EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility()); |
| 6553 | |
| 6554 | grand_child->SetUseParentBackfaceVisibility(false); |
| 6555 | grand_child->SetDoubleSided(false); |
| 6556 | grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 6557 | |
| 6558 | ExecuteCalculateDrawProperties(root); |
| 6559 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
| 6560 | EXPECT_EQ(0u, render_surface_layer_list_impl() |
| 6561 | ->at(0) |
| 6562 | ->render_surface() |
| 6563 | ->layer_list() |
| 6564 | .size()); |
| 6565 | |
| 6566 | // We should check the backface visibility of child as it has a rotation |
| 6567 | // transform and for grand_child as it is in a 3d rendering context and not |
| 6568 | // the root of it. |
| 6569 | EXPECT_FALSE(root->should_check_backface_visibility()); |
| 6570 | EXPECT_TRUE(child->should_check_backface_visibility()); |
| 6571 | EXPECT_TRUE(grand_child->should_check_backface_visibility()); |
| 6572 | // grand_child is in an existing 3d rendering context, so it should not use |
| 6573 | // local transform for backface visibility. |
| 6574 | EXPECT_TRUE(root->use_local_transform_for_backface_visibility()); |
| 6575 | EXPECT_TRUE(child->use_local_transform_for_backface_visibility()); |
| 6576 | EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility()); |
ajuma | aa0d386 | 2015-11-09 22:24:46 | [diff] [blame] | 6577 | } |
| 6578 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6579 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 6580 | // Checks that the simple case (being clipped by a scroll parent that would |
| 6581 | // have been processed before you anyhow) results in the right clips. |
| 6582 | // |
| 6583 | // + root |
| 6584 | // + scroll_parent_border |
| 6585 | // | + scroll_parent_clip |
| 6586 | // | + scroll_parent |
| 6587 | // + scroll_child |
| 6588 | // |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6589 | LayerImpl* root = root_layer(); |
| 6590 | LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>(); |
| 6591 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6592 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6593 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6594 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6595 | scroll_parent->SetDrawsContent(true); |
| 6596 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6597 | scroll_parent_clip->SetMasksToBounds(true); |
| 6598 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6599 | scroll_child->SetScrollParent(scroll_parent); |
| 6600 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6601 | scroll_children->insert(scroll_child); |
| 6602 | scroll_parent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6603 | |
| 6604 | gfx::Transform identity_transform; |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6605 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6606 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6607 | true); |
| 6608 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6609 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6610 | true, false, false); |
| 6611 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6612 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6613 | true, false, false); |
| 6614 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6615 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6616 | true, false, false); |
| 6617 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6618 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6619 | false); |
| 6620 | |
enne | 085b48a | 2015-08-18 17:54:48 | [diff] [blame] | 6621 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6622 | |
| 6623 | EXPECT_TRUE(root->render_surface()); |
| 6624 | |
| 6625 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 6626 | scroll_child->clip_rect().ToString()); |
| 6627 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6628 | } |
| 6629 | |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6630 | TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) { |
| 6631 | // Tests the computation of draw transform for the scroll child when its |
| 6632 | // target is different from its scroll parent's target. |
| 6633 | LayerImpl* root = root_layer(); |
| 6634 | LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>(); |
| 6635 | LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target); |
| 6636 | LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target); |
| 6637 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target); |
| 6638 | |
| 6639 | scroll_parent->SetDrawsContent(true); |
| 6640 | scroll_child->SetDrawsContent(true); |
| 6641 | |
| 6642 | scroll_child->SetScrollParent(scroll_parent); |
| 6643 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6644 | scroll_children->insert(scroll_child); |
| 6645 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6646 | |
| 6647 | gfx::Transform identity_transform; |
| 6648 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6649 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6650 | true); |
| 6651 | SetLayerPropertiesForTesting(scroll_child_target, identity_transform, |
| 6652 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6653 | true, false, true); |
| 6654 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6655 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6656 | false); |
| 6657 | SetLayerPropertiesForTesting(scroll_parent_target, identity_transform, |
| 6658 | gfx::Point3F(), gfx::PointF(10, 10), |
| 6659 | gfx::Size(50, 50), true, false, true); |
| 6660 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6661 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6662 | true, false, false); |
| 6663 | scroll_parent_target->SetMasksToBounds(true); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6664 | |
jaydasika | 2489a44 | 2016-01-29 02:26:00 | [diff] [blame] | 6665 | float device_scale_factor = 1.5f; |
| 6666 | LayerImplList render_surface_layer_list_impl; |
| 6667 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
| 6668 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6669 | root, root->bounds(), identity_transform, &render_surface_layer_list_impl, |
| 6670 | root->layer_tree_impl()->current_render_surface_list_id()); |
| 6671 | inputs.device_scale_factor = device_scale_factor; |
| 6672 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6673 | |
| 6674 | EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40)); |
| 6675 | EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75)); |
| 6676 | gfx::Transform scale; |
| 6677 | scale.Scale(1.5f, 1.5f); |
| 6678 | EXPECT_EQ(scroll_child->DrawTransform(), scale); |
jaydasika | 8ccff3d | 2016-01-20 19:51:30 | [diff] [blame] | 6679 | } |
| 6680 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6681 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6682 | LayerImpl* root = root_layer(); |
| 6683 | root->SetDrawsContent(true); |
| 6684 | LayerImpl* parent = AddChildToRoot<LayerImpl>(); |
| 6685 | parent->SetDrawsContent(true); |
| 6686 | LayerImpl* child = AddChild<LayerImpl>(parent); |
| 6687 | child->SetDrawsContent(true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6688 | |
| 6689 | gfx::Transform identity_transform; |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6690 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6691 | gfx::PointF(), gfx::Size(50, 50), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6692 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6693 | SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(), |
| 6694 | gfx::PointF(), gfx::Size(30, 30), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6695 | true); |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6696 | SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(), |
| 6697 | gfx::PointF(), gfx::Size(20, 20), true, true, |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6698 | true); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6699 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6700 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6701 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6702 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6703 | |
| 6704 | gfx::Transform singular_transform; |
| 6705 | singular_transform.Scale3d( |
| 6706 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 6707 | |
| 6708 | child->SetTransform(singular_transform); |
| 6709 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6710 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6711 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6712 | EXPECT_EQ(2u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6713 | |
| 6714 | // Ensure that the entire subtree under a layer with singular transform does |
| 6715 | // not get rendered. |
| 6716 | parent->SetTransform(singular_transform); |
| 6717 | child->SetTransform(identity_transform); |
| 6718 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6719 | ExecuteCalculateDrawProperties(root); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6720 | |
enne | ca33fed | 2015-07-27 18:22:19 | [diff] [blame] | 6721 | EXPECT_EQ(1u, render_surface_layer_list_impl()->size()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 6722 | } |
| 6723 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6724 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 6725 | // Checks that clipping by a scroll parent that follows you in paint order |
| 6726 | // still results in correct clipping. |
| 6727 | // |
| 6728 | // + root |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6729 | // + scroll_parent_border |
| 6730 | // + scroll_parent_clip |
| 6731 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6732 | // + scroll_child |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6733 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6734 | LayerImpl* root = root_layer(); |
| 6735 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6736 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6737 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6738 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6739 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6740 | scroll_parent->SetDrawsContent(true); |
| 6741 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6742 | |
| 6743 | scroll_parent_clip->SetMasksToBounds(true); |
| 6744 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6745 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6746 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6747 | scroll_children->insert(scroll_child); |
| 6748 | scroll_parent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6749 | |
| 6750 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6751 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6752 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6753 | true); |
| 6754 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6755 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6756 | true, false, false); |
| 6757 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6758 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6759 | true, false, false); |
| 6760 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6761 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6762 | true, false, false); |
| 6763 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6764 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6765 | false); |
| 6766 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6767 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6768 | |
| 6769 | EXPECT_TRUE(root->render_surface()); |
| 6770 | |
| 6771 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 6772 | scroll_child->clip_rect().ToString()); |
| 6773 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6774 | } |
| 6775 | |
| 6776 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 6777 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 6778 | // you in paint order still results in correct clipping. |
| 6779 | // |
| 6780 | // + root |
| 6781 | // + scroll_child |
| 6782 | // + scroll_parent_border |
| 6783 | // | + scroll_parent_clip |
| 6784 | // | + scroll_parent |
| 6785 | // + scroll_grandparent_border |
| 6786 | // + scroll_grandparent_clip |
| 6787 | // + scroll_grandparent |
| 6788 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6789 | LayerImpl* root = root_layer(); |
| 6790 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6791 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6792 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6793 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6794 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6795 | LayerImpl* scroll_grandparent_clip = |
| 6796 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6797 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6798 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6799 | scroll_parent->SetDrawsContent(true); |
| 6800 | scroll_grandparent->SetDrawsContent(true); |
| 6801 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6802 | |
| 6803 | scroll_parent_clip->SetMasksToBounds(true); |
| 6804 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6805 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6806 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6807 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6808 | scroll_children->insert(scroll_child); |
| 6809 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6810 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6811 | scroll_parent_border->SetScrollParent(scroll_grandparent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6812 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6813 | scroll_children->insert(scroll_parent_border); |
| 6814 | scroll_grandparent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6815 | |
| 6816 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6817 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6818 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6819 | true); |
| 6820 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6821 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6822 | true, false, false); |
| 6823 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6824 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6825 | true, false, false); |
| 6826 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6827 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6828 | true, false, false); |
| 6829 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6830 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6831 | true, false, false); |
| 6832 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6833 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6834 | true, false, false); |
| 6835 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6836 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6837 | true, false, false); |
| 6838 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6839 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6840 | false); |
| 6841 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6842 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6843 | |
| 6844 | EXPECT_TRUE(root->render_surface()); |
| 6845 | |
| 6846 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 6847 | scroll_child->clip_rect().ToString()); |
| 6848 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6849 | |
| 6850 | // Despite the fact that we visited the above layers out of order to get the |
| 6851 | // correct clip, the layer lists should be unaffected. |
| 6852 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6853 | EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0)); |
| 6854 | EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1)); |
| 6855 | EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2)); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 6859 | // 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] | 6860 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6861 | // + root |
| 6862 | // + scroll_child |
| 6863 | // + scroll_parent_border |
| 6864 | // + scroll_parent_clip |
| 6865 | // + scroll_parent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6866 | // + render_surface2 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6867 | // + scroll_grandparent_border |
| 6868 | // + scroll_grandparent_clip |
| 6869 | // + scroll_grandparent |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6870 | // + render_surface1 |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6871 | // |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6872 | LayerImpl* root = root_layer(); |
| 6873 | root->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6874 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6875 | LayerImpl* scroll_child = AddChild<LayerImpl>(root); |
| 6876 | scroll_child->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6877 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6878 | LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root); |
| 6879 | LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border); |
| 6880 | LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip); |
| 6881 | LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent); |
| 6882 | LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root); |
| 6883 | LayerImpl* scroll_grandparent_clip = |
| 6884 | AddChild<LayerImpl>(scroll_grandparent_border); |
| 6885 | LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip); |
| 6886 | LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6887 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6888 | scroll_parent->SetDrawsContent(true); |
| 6889 | render_surface1->SetDrawsContent(true); |
| 6890 | scroll_grandparent->SetDrawsContent(true); |
| 6891 | render_surface2->SetDrawsContent(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6892 | |
| 6893 | scroll_parent_clip->SetMasksToBounds(true); |
| 6894 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 6895 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6896 | scroll_child->SetScrollParent(scroll_parent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6897 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 6898 | scroll_children->insert(scroll_child); |
| 6899 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 6900 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6901 | scroll_parent_border->SetScrollParent(scroll_grandparent); |
ajuma | 9af2e92b | 2015-06-29 22:26:38 | [diff] [blame] | 6902 | scroll_children.reset(new std::set<LayerImpl*>); |
| 6903 | scroll_children->insert(scroll_parent_border); |
| 6904 | scroll_grandparent->SetScrollChildren(scroll_children.release()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6905 | |
| 6906 | gfx::Transform identity_transform; |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6907 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 6908 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6909 | true); |
| 6910 | SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform, |
| 6911 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6912 | true, false, false); |
| 6913 | SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform, |
| 6914 | gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20), |
| 6915 | true, false, false); |
| 6916 | SetLayerPropertiesForTesting(scroll_grandparent, identity_transform, |
| 6917 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6918 | true, false, false); |
| 6919 | SetLayerPropertiesForTesting(render_surface1, identity_transform, |
| 6920 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6921 | true, false, true); |
| 6922 | SetLayerPropertiesForTesting(scroll_parent_border, identity_transform, |
| 6923 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 6924 | true, false, false); |
| 6925 | SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform, |
| 6926 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6927 | true, false, false); |
| 6928 | SetLayerPropertiesForTesting(scroll_parent, identity_transform, |
| 6929 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6930 | true, false, false); |
| 6931 | SetLayerPropertiesForTesting(render_surface2, identity_transform, |
| 6932 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 6933 | true, false, true); |
| 6934 | SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(), |
| 6935 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6936 | false); |
| 6937 | |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6938 | ExecuteCalculateDrawProperties(root); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6939 | |
| 6940 | EXPECT_TRUE(root->render_surface()); |
| 6941 | |
| 6942 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 6943 | scroll_child->clip_rect().ToString()); |
| 6944 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 6945 | |
| 6946 | // Despite the fact that we had to process the layers out of order to get the |
| 6947 | // right clip, our render_surface_layer_list's order should be unaffected. |
enne | 03b0e9a | 2015-06-19 00:08:02 | [diff] [blame] | 6948 | EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); |
| 6949 | EXPECT_EQ(root, render_surface_layer_list_impl()->at(0)); |
| 6950 | EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1)); |
| 6951 | EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2)); |
| 6952 | EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface()); |
| 6953 | EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface()); |
| 6954 | EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 6955 | } |
| 6956 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6957 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 6958 | // Ensures that when we have a render surface between a fixed position layer |
| 6959 | // and its container, we compute the fixed position layer's draw transform |
| 6960 | // with respect to that intervening render surface, not with respect to its |
| 6961 | // container's render target. |
| 6962 | // |
| 6963 | // + root |
| 6964 | // + render_surface |
| 6965 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6966 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6967 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6968 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6969 | scoped_refptr<LayerWithForcedDrawsContent> render_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6970 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6971 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6972 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6973 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6974 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6975 | |
| 6976 | root->AddChild(render_surface); |
| 6977 | render_surface->AddChild(fixed); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6978 | fixed->AddChild(child); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6979 | |
| 6980 | root->SetIsContainerForFixedPositionLayers(true); |
| 6981 | render_surface->SetForceRenderSurface(true); |
| 6982 | |
| 6983 | LayerPositionConstraint constraint; |
| 6984 | constraint.set_is_fixed_position(true); |
| 6985 | fixed->SetPositionConstraint(constraint); |
| 6986 | |
| 6987 | SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(), |
| 6988 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 6989 | SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(), |
| 6990 | gfx::Point3F(), gfx::PointF(7.f, 9.f), |
| 6991 | gfx::Size(50, 50), true, false); |
| 6992 | SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(), |
| 6993 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 6994 | false); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 6995 | SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(), |
| 6996 | gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, |
| 6997 | false); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 6998 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 6999 | host()->SetRootLayer(root); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7000 | |
| 7001 | ExecuteCalculateDrawProperties(root.get()); |
| 7002 | |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7003 | TransformTree& tree = host()->property_trees()->transform_tree; |
| 7004 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7005 | gfx::Transform expected_fixed_draw_transform; |
| 7006 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7007 | EXPECT_EQ(expected_fixed_draw_transform, |
| 7008 | DrawTransformFromPropertyTrees(fixed.get(), tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7009 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7010 | gfx::Transform expected_fixed_screen_space_transform; |
| 7011 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
| 7012 | EXPECT_EQ(expected_fixed_screen_space_transform, |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7013 | ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7014 | |
| 7015 | gfx::Transform expected_child_draw_transform; |
| 7016 | expected_child_draw_transform.Translate(11.f, 17.f); |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7017 | EXPECT_EQ(expected_child_draw_transform, |
| 7018 | DrawTransformFromPropertyTrees(child.get(), tree)); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7019 | |
| 7020 | gfx::Transform expected_child_screen_space_transform; |
| 7021 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
| 7022 | EXPECT_EQ(expected_child_screen_space_transform, |
enne | f690353 | 2015-08-18 05:10:15 | [diff] [blame] | 7023 | ScreenSpaceTransformFromPropertyTrees(child.get(), tree)); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7024 | } |
| 7025 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7026 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7027 | // This test verifies that a scrolling layer that gets snapped to |
| 7028 | // integer coordinates doesn't move a fixed position child. |
| 7029 | // |
| 7030 | // + root |
| 7031 | // + container |
| 7032 | // + scroller |
| 7033 | // + fixed |
| 7034 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7035 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7036 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7037 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7038 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7039 | &task_graph_runner); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7040 | host_impl.CreatePendingTree(); |
| 7041 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7042 | scoped_ptr<LayerImpl> container = |
| 7043 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7044 | LayerImpl* container_layer = container.get(); |
| 7045 | scoped_ptr<LayerImpl> scroller = |
| 7046 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7047 | LayerImpl* scroll_layer = scroller.get(); |
| 7048 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7049 | LayerImpl* fixed_layer = fixed.get(); |
| 7050 | |
| 7051 | container->SetIsContainerForFixedPositionLayers(true); |
| 7052 | |
| 7053 | LayerPositionConstraint constraint; |
| 7054 | constraint.set_is_fixed_position(true); |
| 7055 | fixed->SetPositionConstraint(constraint); |
| 7056 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7057 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7058 | |
| 7059 | gfx::Transform identity_transform; |
| 7060 | gfx::Transform container_transform; |
| 7061 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7062 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7063 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7064 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7065 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7066 | true); |
| 7067 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7068 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7069 | true, false, false); |
| 7070 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7071 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7072 | true, false, false); |
| 7073 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7074 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7075 | false); |
| 7076 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7077 | root->SetDrawsContent(true); |
| 7078 | container->SetDrawsContent(true); |
| 7079 | scroller->SetDrawsContent(true); |
| 7080 | fixed->SetDrawsContent(true); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7081 | scroller->AddChild(std::move(fixed)); |
| 7082 | container->AddChild(std::move(scroller)); |
| 7083 | root->AddChild(std::move(container)); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7084 | |
| 7085 | // Rounded to integers already. |
| 7086 | { |
| 7087 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7088 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7089 | |
| 7090 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7091 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7092 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7093 | root.get(), root->bounds(), &render_surface_layer_list, |
| 7094 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7095 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7096 | |
| 7097 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7098 | container_layer->draw_properties().screen_space_transform, |
| 7099 | fixed_layer->draw_properties().screen_space_transform); |
| 7100 | EXPECT_VECTOR_EQ( |
| 7101 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7102 | container_offset); |
| 7103 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7104 | .screen_space_transform.To2dTranslation(), |
| 7105 | container_offset - scroll_delta); |
| 7106 | } |
| 7107 | |
| 7108 | // Scroll delta requiring rounding. |
| 7109 | { |
| 7110 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7111 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7112 | |
| 7113 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7114 | |
| 7115 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7116 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7117 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7118 | root.get(), root->bounds(), &render_surface_layer_list, |
| 7119 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7120 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7121 | |
| 7122 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7123 | container_layer->draw_properties().screen_space_transform, |
| 7124 | fixed_layer->draw_properties().screen_space_transform); |
| 7125 | EXPECT_VECTOR_EQ( |
| 7126 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7127 | container_offset); |
| 7128 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7129 | .screen_space_transform.To2dTranslation(), |
| 7130 | container_offset - rounded_scroll_delta); |
| 7131 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7132 | |
| 7133 | // Scale is applied earlier in the tree. |
| 7134 | { |
| 7135 | gfx::Transform scaled_container_transform = container_transform; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7136 | scaled_container_transform.Scale3d(2.0, 2.0, 1.0); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7137 | container_layer->SetTransform(scaled_container_transform); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7138 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 7139 | root->layer_tree_impl() |
| 7140 | ->property_trees() |
| 7141 | ->transform_tree.set_source_to_parent_updates_allowed(true); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7142 | |
| 7143 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7144 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7145 | |
| 7146 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7147 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7148 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7149 | root.get(), root->bounds(), &render_surface_layer_list, |
| 7150 | root->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7151 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7152 | |
| 7153 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7154 | container_layer->draw_properties().screen_space_transform, |
| 7155 | fixed_layer->draw_properties().screen_space_transform); |
| 7156 | EXPECT_VECTOR_EQ( |
| 7157 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7158 | container_offset); |
| 7159 | |
| 7160 | container_layer->SetTransform(container_transform); |
| 7161 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7162 | } |
| 7163 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7164 | TEST_F(LayerTreeHostCommonTest, |
| 7165 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7166 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7167 | // from main doesn't move a fixed position child. |
| 7168 | // |
| 7169 | // + root |
| 7170 | // + container |
| 7171 | // + scroller |
| 7172 | // + fixed |
| 7173 | // |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7174 | FakeImplTaskRunnerProvider task_runner_provider; |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7175 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7176 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7177 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7178 | &task_graph_runner); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7179 | host_impl.CreatePendingTree(); |
| 7180 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7181 | scoped_ptr<LayerImpl> container = |
| 7182 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7183 | LayerImpl* container_layer = container.get(); |
| 7184 | scoped_ptr<LayerImpl> scroller = |
| 7185 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7186 | LayerImpl* scroll_layer = scroller.get(); |
| 7187 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7188 | LayerImpl* fixed_layer = fixed.get(); |
| 7189 | |
| 7190 | container->SetIsContainerForFixedPositionLayers(true); |
| 7191 | |
| 7192 | LayerPositionConstraint constraint; |
| 7193 | constraint.set_is_fixed_position(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 7194 | container->SetDrawsContent(true); |
| 7195 | fixed->SetDrawsContent(true); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7196 | fixed->SetPositionConstraint(constraint); |
| 7197 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 7198 | scroller->SetDrawsContent(true); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7199 | scroller->SetScrollClipLayer(container->id()); |
| 7200 | |
| 7201 | gfx::Transform identity_transform; |
| 7202 | gfx::Transform container_transform; |
| 7203 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7204 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7205 | |
| 7206 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7207 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7208 | true); |
| 7209 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7210 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7211 | true, false, false); |
| 7212 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7213 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7214 | gfx::Size(30, 30), true, false, false); |
| 7215 | |
| 7216 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7217 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7218 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7219 | // Blink only uses the integer part of the scroll_offset for fixed |
| 7220 | // position layer. |
| 7221 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7222 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7223 | false, false); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 7224 | scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 7225 | scroll_layer->SetScrollDelta(scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 7226 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7227 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7228 | scroller->AddChild(std::move(fixed)); |
| 7229 | container->AddChild(std::move(scroller)); |
| 7230 | root->AddChild(std::move(container)); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7231 | |
| 7232 | LayerImplList render_surface_layer_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7233 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7234 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7235 | root.get(), root->bounds(), &render_surface_layer_list, |
| 7236 | root->layer_tree_impl()->current_render_surface_list_id()); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7237 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7238 | |
| 7239 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7240 | container_layer->draw_properties().screen_space_transform, |
| 7241 | fixed_layer->draw_properties().screen_space_transform); |
| 7242 | EXPECT_VECTOR_EQ( |
| 7243 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7244 | container_offset); |
| 7245 | |
| 7246 | gfx::ScrollOffset effective_scroll_offset = |
| 7247 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7248 | gfx::Vector2d rounded_effective_scroll_offset = |
| 7249 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7250 | EXPECT_VECTOR_EQ( |
| 7251 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7252 | container_offset - rounded_effective_scroll_offset); |
| 7253 | } |
| 7254 | |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7255 | TEST_F(LayerTreeHostCommonTest, |
| 7256 | ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 7257 | // This test verifies that a scrolling layer whose screen space transform is |
| 7258 | // animating doesn't get snapped to integer coordinates. |
| 7259 | // |
| 7260 | // + root |
| 7261 | // + animated layer |
| 7262 | // + surface |
| 7263 | // + container |
| 7264 | // + scroller |
| 7265 | // |
| 7266 | LayerImpl* root = root_layer(); |
| 7267 | LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>(); |
| 7268 | LayerImpl* surface = AddChild<LayerImpl>(animated_layer); |
| 7269 | LayerImpl* container = AddChild<LayerImpl>(surface); |
| 7270 | LayerImpl* scroller = AddChild<LayerImpl>(container); |
| 7271 | scroller->SetScrollClipLayer(container->id()); |
| 7272 | scroller->SetDrawsContent(true); |
| 7273 | |
| 7274 | gfx::Transform identity_transform; |
| 7275 | gfx::Transform start_scale; |
| 7276 | start_scale.Scale(1.5f, 1.5f); |
| 7277 | SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), |
| 7278 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7279 | true); |
| 7280 | SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(), |
| 7281 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7282 | false); |
| 7283 | SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(), |
| 7284 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7285 | true); |
| 7286 | SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(), |
| 7287 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7288 | false); |
| 7289 | SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(), |
| 7290 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 7291 | false); |
| 7292 | |
| 7293 | gfx::Transform end_scale; |
| 7294 | end_scale.Scale(2.f, 2.f); |
| 7295 | TransformOperations start_operations; |
| 7296 | start_operations.AppendMatrix(start_scale); |
| 7297 | TransformOperations end_operations; |
| 7298 | end_operations.AppendMatrix(end_scale); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7299 | if (layer_settings().use_compositor_animation_timelines) { |
| 7300 | AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(), |
| 7301 | 1.0, start_operations, |
| 7302 | end_operations); |
| 7303 | } else { |
| 7304 | AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations, |
| 7305 | end_operations); |
| 7306 | } |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7307 | gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 7308 | scroller->SetScrollDelta(scroll_delta); |
| 7309 | |
| 7310 | ExecuteCalculateDrawProperties(root); |
| 7311 | |
| 7312 | gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
| 7313 | EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 7314 | scroller->DrawTransform().To2dTranslation()); |
ajuma | 5e8e40d | 2015-07-31 01:50:50 | [diff] [blame] | 7315 | } |
| 7316 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7317 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7318 | public: |
| 7319 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7320 | LayerTreeImpl* tree_impl, |
| 7321 | int id) { |
| 7322 | return make_scoped_ptr( |
| 7323 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7324 | } |
| 7325 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7326 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7327 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7328 | private: |
| 7329 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7330 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7331 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7332 | SetDrawsContent(true); |
| 7333 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7334 | }; |
| 7335 | |
| 7336 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7337 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7338 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7339 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7340 | LayerTreeSettings settings = host()->settings(); |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7341 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7342 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7343 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7344 | gfx::Transform identity_matrix; |
| 7345 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7346 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7347 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7348 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7349 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7350 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7351 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7352 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7353 | |
| 7354 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7355 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7356 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7357 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7358 | child->AddChild(std::move(grand_child)); |
| 7359 | parent->AddChild(std::move(child)); |
| 7360 | grand_parent->AddChild(std::move(parent)); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7361 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7362 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 7363 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7364 | true, false, true); |
| 7365 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7366 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7367 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7368 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7369 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7370 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7371 | |
| 7372 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7373 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7374 | false); |
| 7375 | |
| 7376 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7377 | |
| 7378 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7379 | EXPECT_EQ(0.f, |
| 7380 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7381 | EXPECT_EQ(0.f, |
| 7382 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7383 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7384 | EXPECT_EQ( |
| 7385 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7386 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7387 | EXPECT_EQ(0.f, |
| 7388 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7389 | EXPECT_EQ(0.f, |
| 7390 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7391 | EXPECT_EQ(0.f, |
| 7392 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7393 | EXPECT_EQ( |
| 7394 | 0.f, |
| 7395 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7396 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7397 | TransformOperations translation; |
| 7398 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7399 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7400 | scoped_refptr<AnimationTimeline> timeline; |
| 7401 | if (layer_settings().use_compositor_animation_timelines) { |
| 7402 | timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 7403 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 7404 | |
| 7405 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7406 | TransformOperations(), translation); |
| 7407 | } else { |
| 7408 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), |
| 7409 | translation); |
| 7410 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7411 | |
| 7412 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7413 | EXPECT_EQ(0.f, |
| 7414 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7415 | EXPECT_EQ(0.f, |
| 7416 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7417 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7418 | EXPECT_EQ( |
| 7419 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7420 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7421 | EXPECT_EQ(0.f, |
| 7422 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7423 | EXPECT_EQ(0.f, |
| 7424 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7425 | EXPECT_EQ(0.f, |
| 7426 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7427 | EXPECT_EQ( |
| 7428 | 0.f, |
| 7429 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7430 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7431 | TransformOperations scale; |
| 7432 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7433 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7434 | if (layer_settings().use_compositor_animation_timelines) { |
| 7435 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7436 | TransformOperations(), scale); |
| 7437 | } else { |
| 7438 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 7439 | } |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7440 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7441 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7442 | |
| 7443 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7444 | EXPECT_EQ(0.f, |
| 7445 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7446 | EXPECT_EQ(0.f, |
| 7447 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7448 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7449 | EXPECT_EQ( |
| 7450 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7451 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7452 | EXPECT_EQ(0.f, |
| 7453 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7454 | EXPECT_EQ(0.f, |
| 7455 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7456 | EXPECT_EQ(1.f, |
| 7457 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7458 | EXPECT_EQ( |
| 7459 | 1.f, |
| 7460 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7461 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7462 | if (layer_settings().use_compositor_animation_timelines) { |
| 7463 | AddAnimatedTransformToLayerWithPlayer(grand_parent->id(), timeline, 1.0, |
| 7464 | TransformOperations(), scale); |
| 7465 | } else { |
| 7466 | AddAnimatedTransformToLayer(grand_parent.get(), 1.0, TransformOperations(), |
| 7467 | scale); |
| 7468 | } |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7469 | grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7470 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7471 | |
| 7472 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7473 | EXPECT_EQ(5.f, |
| 7474 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7475 | EXPECT_EQ(5.f, |
| 7476 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7477 | // We don't support combining animated scales from two nodes; 0.f means |
| 7478 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7479 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7480 | EXPECT_EQ( |
| 7481 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7482 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7483 | EXPECT_EQ(1.f, |
| 7484 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7485 | EXPECT_EQ(1.f, |
| 7486 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7487 | EXPECT_EQ(0.f, |
| 7488 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7489 | EXPECT_EQ( |
| 7490 | 0.f, |
| 7491 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7492 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7493 | if (layer_settings().use_compositor_animation_timelines) { |
| 7494 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7495 | TransformOperations(), scale); |
| 7496 | } else { |
| 7497 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7498 | } |
ajuma | caaa9b3 | 2015-08-04 15:55:29 | [diff] [blame] | 7499 | parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7500 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7501 | |
| 7502 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7503 | EXPECT_EQ(5.f, |
| 7504 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7505 | EXPECT_EQ(0.f, |
| 7506 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7507 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7508 | EXPECT_EQ( |
| 7509 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7510 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7511 | EXPECT_EQ(1.f, |
| 7512 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7513 | EXPECT_EQ(0.f, |
| 7514 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7515 | EXPECT_EQ(0.f, |
| 7516 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7517 | EXPECT_EQ( |
| 7518 | 0.f, |
| 7519 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7520 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7521 | if (layer_settings().use_compositor_animation_timelines) { |
| 7522 | AbortAnimationsOnLayerWithPlayer(grand_parent->id(), timeline, |
| 7523 | Animation::TRANSFORM); |
| 7524 | AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline, |
| 7525 | Animation::TRANSFORM); |
| 7526 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7527 | Animation::TRANSFORM); |
| 7528 | } else { |
| 7529 | grand_parent->layer_animation_controller()->AbortAnimations( |
| 7530 | Animation::TRANSFORM); |
| 7531 | parent_raw->layer_animation_controller()->AbortAnimations( |
| 7532 | Animation::TRANSFORM); |
| 7533 | child_raw->layer_animation_controller()->AbortAnimations( |
| 7534 | Animation::TRANSFORM); |
| 7535 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7536 | |
| 7537 | TransformOperations perspective; |
| 7538 | perspective.AppendPerspective(10.f); |
| 7539 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7540 | if (layer_settings().use_compositor_animation_timelines) { |
| 7541 | AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0, |
| 7542 | TransformOperations(), perspective); |
| 7543 | } else { |
| 7544 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), |
| 7545 | perspective); |
| 7546 | } |
ajuma | b4a846f2 | 2015-08-24 19:13:44 | [diff] [blame] | 7547 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7548 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7549 | |
| 7550 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7551 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7552 | EXPECT_EQ(0.f, |
| 7553 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7554 | EXPECT_EQ(0.f, |
| 7555 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7556 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7557 | EXPECT_EQ( |
| 7558 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7559 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7560 | EXPECT_EQ(0.f, |
| 7561 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7562 | EXPECT_EQ(0.f, |
| 7563 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7564 | EXPECT_EQ(0.f, |
| 7565 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7566 | EXPECT_EQ( |
| 7567 | 0.f, |
| 7568 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7569 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7570 | if (layer_settings().use_compositor_animation_timelines) { |
| 7571 | AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline, |
| 7572 | Animation::TRANSFORM); |
| 7573 | } else { |
| 7574 | child_raw->layer_animation_controller()->AbortAnimations( |
| 7575 | Animation::TRANSFORM); |
| 7576 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7577 | gfx::Transform scale_matrix; |
| 7578 | scale_matrix.Scale(1.f, 2.f); |
| 7579 | grand_parent->SetTransform(scale_matrix); |
| 7580 | parent_raw->SetTransform(scale_matrix); |
miletus | 843080c | 2015-06-11 22:11:01 | [diff] [blame] | 7581 | grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7582 | |
| 7583 | if (layer_settings().use_compositor_animation_timelines) { |
| 7584 | AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0, |
| 7585 | TransformOperations(), scale); |
| 7586 | } else { |
| 7587 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7588 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7589 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7590 | |
| 7591 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 7592 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7593 | EXPECT_EQ(0.f, |
| 7594 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7595 | EXPECT_EQ(10.f, |
| 7596 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7597 | EXPECT_EQ(10.f, |
| 7598 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 7599 | EXPECT_EQ( |
| 7600 | 10.f, |
| 7601 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7602 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7603 | EXPECT_EQ(0.f, |
| 7604 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7605 | EXPECT_EQ(2.f, |
| 7606 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7607 | EXPECT_EQ(2.f, |
| 7608 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7609 | EXPECT_EQ( |
| 7610 | 2.f, |
| 7611 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7612 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7613 | gfx::Transform perspective_matrix; |
| 7614 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 7615 | child_raw->SetTransform(perspective_matrix); |
miletus | 843080c | 2015-06-11 22:11:01 | [diff] [blame] | 7616 | grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7617 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7618 | |
| 7619 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7620 | EXPECT_EQ(0.f, |
| 7621 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7622 | EXPECT_EQ(10.f, |
| 7623 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7624 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7625 | EXPECT_EQ( |
| 7626 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7627 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7628 | EXPECT_EQ(0.f, |
| 7629 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7630 | EXPECT_EQ(2.f, |
| 7631 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7632 | EXPECT_EQ(0.f, |
| 7633 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7634 | EXPECT_EQ( |
| 7635 | 0.f, |
| 7636 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7637 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7638 | parent_raw->SetTransform(perspective_matrix); |
miletus | 843080c | 2015-06-11 22:11:01 | [diff] [blame] | 7639 | grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7640 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7641 | |
| 7642 | // |parent| and |child| have transforms that are neither translations nor |
| 7643 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7644 | EXPECT_EQ(0.f, |
| 7645 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7646 | EXPECT_EQ(0.f, |
| 7647 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7648 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7649 | EXPECT_EQ( |
| 7650 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7651 | |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7652 | EXPECT_EQ(0.f, |
| 7653 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7654 | EXPECT_EQ(0.f, |
| 7655 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7656 | EXPECT_EQ(0.f, |
| 7657 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7658 | EXPECT_EQ( |
| 7659 | 0.f, |
| 7660 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
| 7661 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7662 | parent_raw->SetTransform(identity_matrix); |
| 7663 | child_raw->SetTransform(identity_matrix); |
| 7664 | grand_parent->SetTransform(perspective_matrix); |
miletus | 843080c | 2015-06-11 22:11:01 | [diff] [blame] | 7665 | grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7666 | |
| 7667 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7668 | |
| 7669 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7670 | EXPECT_EQ(0.f, |
| 7671 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7672 | EXPECT_EQ(0.f, |
| 7673 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7674 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7675 | EXPECT_EQ( |
| 7676 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
ajuma | 052892e | 2015-08-21 14:39:03 | [diff] [blame] | 7677 | |
| 7678 | EXPECT_EQ(0.f, |
| 7679 | grand_parent->draw_properties().starting_animation_contents_scale); |
| 7680 | EXPECT_EQ(0.f, |
| 7681 | parent_raw->draw_properties().starting_animation_contents_scale); |
| 7682 | EXPECT_EQ(0.f, |
| 7683 | child_raw->draw_properties().starting_animation_contents_scale); |
| 7684 | EXPECT_EQ( |
| 7685 | 0.f, |
| 7686 | grand_child_raw->draw_properties().starting_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7687 | } |
| 7688 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7689 | static int membership_id(LayerImpl* layer) { |
| 7690 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 7691 | } |
| 7692 | |
| 7693 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 7694 | std::set<LayerImpl*>* drawn_layers) { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 7695 | for (LayerIterator it = LayerIterator::Begin(rsll), |
| 7696 | end = LayerIterator::End(rsll); |
| 7697 | it != end; ++it) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7698 | LayerImpl* layer = *it; |
| 7699 | if (it.represents_itself()) |
| 7700 | drawn_layers->insert(layer); |
| 7701 | |
| 7702 | if (!it.represents_contributing_render_surface()) |
| 7703 | continue; |
| 7704 | |
| 7705 | if (layer->mask_layer()) |
| 7706 | drawn_layers->insert(layer->mask_layer()); |
| 7707 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 7708 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7713 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7714 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7715 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7716 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7717 | &task_graph_runner); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7718 | gfx::Transform identity_matrix; |
| 7719 | |
| 7720 | scoped_ptr<LayerImpl> grand_parent = |
| 7721 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 7722 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 7723 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 7724 | scoped_ptr<LayerImpl> grand_child1 = |
| 7725 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 7726 | scoped_ptr<LayerImpl> grand_child2 = |
| 7727 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 7728 | |
| 7729 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 7730 | LayerImpl* parent_raw = parent.get(); |
| 7731 | LayerImpl* child_raw = child.get(); |
| 7732 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 7733 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 7734 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7735 | child->AddChild(std::move(grand_child1)); |
| 7736 | child->AddChild(std::move(grand_child2)); |
| 7737 | parent->AddChild(std::move(child)); |
| 7738 | grand_parent->AddChild(std::move(parent)); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7739 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7740 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 7741 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7742 | true, false, true); |
| 7743 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7744 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7745 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7746 | |
| 7747 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7748 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7749 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7750 | |
| 7751 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 7752 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7753 | true, false, false); |
| 7754 | |
| 7755 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 7756 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7757 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7758 | |
| 7759 | // Start with nothing being drawn. |
| 7760 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7761 | int member_id = render_surface_layer_list_count(); |
| 7762 | |
| 7763 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7764 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7765 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7766 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7767 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7768 | |
| 7769 | std::set<LayerImpl*> expected; |
| 7770 | std::set<LayerImpl*> actual; |
| 7771 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7772 | EXPECT_EQ(expected, actual); |
| 7773 | |
| 7774 | // If we force render surface, but none of the layers are in the layer list, |
| 7775 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7776 | grand_child1_raw->SetHasRenderSurface(true); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7777 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7778 | |
| 7779 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7780 | member_id = render_surface_layer_list_count(); |
| 7781 | |
| 7782 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7783 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7784 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7785 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7786 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7787 | |
| 7788 | expected.clear(); |
| 7789 | actual.clear(); |
| 7790 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7791 | EXPECT_EQ(expected, actual); |
| 7792 | |
| 7793 | // However, if we say that this layer also draws content, it will appear in |
| 7794 | // RSLL. |
| 7795 | grand_child1_raw->SetDrawsContent(true); |
| 7796 | |
| 7797 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7798 | member_id = render_surface_layer_list_count(); |
| 7799 | |
| 7800 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7801 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7802 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7803 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 7804 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7805 | |
| 7806 | expected.clear(); |
| 7807 | expected.insert(grand_child1_raw); |
| 7808 | |
| 7809 | actual.clear(); |
| 7810 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7811 | EXPECT_EQ(expected, actual); |
| 7812 | |
| 7813 | // Now child is forced to have a render surface, and one if its children draws |
| 7814 | // content. |
| 7815 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7816 | grand_child1_raw->SetHasRenderSurface(false); |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 7817 | grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7818 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7819 | grand_child2_raw->SetDrawsContent(true); |
| 7820 | |
| 7821 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7822 | member_id = render_surface_layer_list_count(); |
| 7823 | |
| 7824 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7825 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7826 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7827 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7828 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7829 | |
| 7830 | expected.clear(); |
| 7831 | expected.insert(grand_child2_raw); |
| 7832 | |
| 7833 | actual.clear(); |
| 7834 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7835 | EXPECT_EQ(expected, actual); |
| 7836 | |
| 7837 | // Add a mask layer to child. |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7838 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7839 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7840 | |
| 7841 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7842 | member_id = render_surface_layer_list_count(); |
| 7843 | |
| 7844 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7845 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7846 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7847 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7848 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7849 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7850 | |
| 7851 | expected.clear(); |
| 7852 | expected.insert(grand_child2_raw); |
| 7853 | expected.insert(child_raw->mask_layer()); |
| 7854 | |
| 7855 | expected.clear(); |
| 7856 | expected.insert(grand_child2_raw); |
| 7857 | expected.insert(child_raw->mask_layer()); |
| 7858 | |
| 7859 | actual.clear(); |
| 7860 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7861 | EXPECT_EQ(expected, actual); |
| 7862 | |
| 7863 | // Add replica mask layer. |
| 7864 | scoped_ptr<LayerImpl> replica_layer = |
| 7865 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 7866 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7867 | child_raw->SetReplicaLayer(std::move(replica_layer)); |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 7868 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7869 | |
| 7870 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7871 | member_id = render_surface_layer_list_count(); |
| 7872 | |
| 7873 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7874 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7875 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7876 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7877 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 7878 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7879 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7880 | |
| 7881 | expected.clear(); |
| 7882 | expected.insert(grand_child2_raw); |
| 7883 | expected.insert(child_raw->mask_layer()); |
| 7884 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 7885 | |
| 7886 | actual.clear(); |
| 7887 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7888 | EXPECT_EQ(expected, actual); |
| 7889 | |
| 7890 | child_raw->TakeReplicaLayer(); |
| 7891 | |
| 7892 | // With nothing drawing, we should have no layers. |
| 7893 | grand_child2_raw->SetDrawsContent(false); |
| 7894 | |
| 7895 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7896 | member_id = render_surface_layer_list_count(); |
| 7897 | |
| 7898 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7899 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7900 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 7901 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 7902 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7903 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7904 | |
| 7905 | expected.clear(); |
| 7906 | actual.clear(); |
| 7907 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7908 | EXPECT_EQ(expected, actual); |
| 7909 | |
| 7910 | // Child itself draws means that we should have the child and the mask in the |
| 7911 | // list. |
| 7912 | child_raw->SetDrawsContent(true); |
| 7913 | |
| 7914 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7915 | member_id = render_surface_layer_list_count(); |
| 7916 | |
| 7917 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 7918 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 7919 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 7920 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 7921 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 7922 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 7923 | |
| 7924 | expected.clear(); |
| 7925 | expected.insert(child_raw); |
| 7926 | expected.insert(child_raw->mask_layer()); |
| 7927 | actual.clear(); |
| 7928 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7929 | EXPECT_EQ(expected, actual); |
| 7930 | |
| 7931 | child_raw->TakeMaskLayer(); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 7932 | child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 7933 | |
| 7934 | // Now everyone's a member! |
| 7935 | grand_parent_raw->SetDrawsContent(true); |
| 7936 | parent_raw->SetDrawsContent(true); |
| 7937 | child_raw->SetDrawsContent(true); |
| 7938 | grand_child1_raw->SetDrawsContent(true); |
| 7939 | grand_child2_raw->SetDrawsContent(true); |
| 7940 | |
| 7941 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 7942 | member_id = render_surface_layer_list_count(); |
| 7943 | |
| 7944 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 7945 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 7946 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 7947 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 7948 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 7949 | |
| 7950 | expected.clear(); |
| 7951 | expected.insert(grand_parent_raw); |
| 7952 | expected.insert(parent_raw); |
| 7953 | expected.insert(child_raw); |
| 7954 | expected.insert(grand_child1_raw); |
| 7955 | expected.insert(grand_child2_raw); |
| 7956 | |
| 7957 | actual.clear(); |
| 7958 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 7959 | EXPECT_EQ(expected, actual); |
| 7960 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7961 | |
| 7962 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7963 | FakeImplTaskRunnerProvider task_runner_provider; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7964 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 7965 | TestTaskGraphRunner task_graph_runner; |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 7966 | LayerTreeSettings settings = host()->settings(); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 7967 | settings.layer_transforms_should_scale_layer_contents = true; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 7968 | FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, |
| 7969 | &shared_bitmap_manager, &task_graph_runner); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7970 | |
| 7971 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7972 | LayerImpl* root_layer = root.get(); |
| 7973 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 7974 | LayerImpl* child1_layer = child1.get(); |
| 7975 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 7976 | LayerImpl* child2_layer = child2.get(); |
| 7977 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 7978 | root->AddChild(std::move(child1)); |
| 7979 | root->AddChild(std::move(child2)); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 7980 | root->SetForceRenderSurface(true); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7981 | root->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7982 | |
| 7983 | gfx::Transform identity_matrix, scale_transform_child1, |
| 7984 | scale_transform_child2; |
| 7985 | scale_transform_child1.Scale(2, 3); |
| 7986 | scale_transform_child2.Scale(4, 5); |
| 7987 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7988 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 7989 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 7990 | true); |
| 7991 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7992 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 7993 | true, false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7994 | |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 7995 | child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4)); |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 7996 | child1_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 7997 | |
| 7998 | scoped_ptr<LayerImpl> replica_layer = |
| 7999 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 8000 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8001 | child1_layer->SetReplicaLayer(std::move(replica_layer)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8002 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8003 | |
| 8004 | ExecuteCalculateDrawProperties(root_layer); |
| 8005 | |
| 8006 | TransformOperations scale; |
| 8007 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8008 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8009 | if (layer_settings().use_compositor_animation_timelines) { |
| 8010 | scoped_refptr<AnimationTimeline> timeline = |
| 8011 | AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
| 8012 | host_impl.animation_host()->AddAnimationTimeline(timeline); |
| 8013 | |
| 8014 | AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0, |
| 8015 | TransformOperations(), scale); |
| 8016 | } else { |
| 8017 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), |
| 8018 | scale); |
| 8019 | } |
| 8020 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8021 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8022 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1), |
| 8023 | true, false, false); |
| 8024 | child2_layer->SetDrawsContent(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8025 | |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8026 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8027 | ExecuteCalculateDrawProperties(root_layer); |
| 8028 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8029 | EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale()); |
| 8030 | EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale()); |
| 8031 | EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
| 8032 | EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8033 | |
| 8034 | EXPECT_FLOAT_EQ( |
| 8035 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8036 | EXPECT_FLOAT_EQ( |
| 8037 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8038 | EXPECT_FLOAT_EQ(0.f, |
| 8039 | child1_layer->mask_layer() |
| 8040 | ->draw_properties() |
| 8041 | .maximum_animation_contents_scale); |
| 8042 | EXPECT_FLOAT_EQ(0.f, |
| 8043 | child1_layer->replica_layer() |
| 8044 | ->mask_layer() |
| 8045 | ->draw_properties() |
| 8046 | .maximum_animation_contents_scale); |
| 8047 | EXPECT_FLOAT_EQ( |
| 8048 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8049 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8050 | // Changing page-scale would affect ideal_contents_scale and |
| 8051 | // maximum_animation_contents_scale. |
| 8052 | |
| 8053 | float page_scale_factor = 3.f; |
| 8054 | float device_scale_factor = 1.0f; |
| 8055 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8056 | gfx::Size device_viewport_size = |
| 8057 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8058 | root_layer->bounds().height() * device_scale_factor); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8059 | root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8060 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8061 | root_layer, device_viewport_size, &render_surface_layer_list, |
| 8062 | root_layer->layer_tree_impl()->current_render_surface_list_id()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8063 | |
| 8064 | inputs.page_scale_factor = page_scale_factor; |
| 8065 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8066 | inputs.page_scale_layer = root_layer; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8067 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8068 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8069 | EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale()); |
| 8070 | EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale()); |
| 8071 | EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8072 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8073 | 9.f, |
| 8074 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 8075 | EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8076 | |
| 8077 | EXPECT_FLOAT_EQ( |
| 8078 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8079 | EXPECT_FLOAT_EQ( |
| 8080 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8081 | EXPECT_FLOAT_EQ(0.f, |
| 8082 | child1_layer->mask_layer() |
| 8083 | ->draw_properties() |
| 8084 | .maximum_animation_contents_scale); |
| 8085 | EXPECT_FLOAT_EQ(0.f, |
| 8086 | child1_layer->replica_layer() |
| 8087 | ->mask_layer() |
| 8088 | ->draw_properties() |
| 8089 | .maximum_animation_contents_scale); |
| 8090 | EXPECT_FLOAT_EQ( |
| 8091 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8092 | |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8093 | // Changing device-scale would affect ideal_contents_scale and |
| 8094 | // maximum_animation_contents_scale. |
| 8095 | |
| 8096 | device_scale_factor = 4.0f; |
| 8097 | inputs.device_scale_factor = device_scale_factor; |
| 8098 | inputs.can_adjust_raster_scales = true; |
jaydasika | 0d98ba9 | 2015-11-17 05:17:28 | [diff] [blame] | 8099 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8100 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8101 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8102 | EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale()); |
| 8103 | EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale()); |
| 8104 | EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8105 | EXPECT_FLOAT_EQ( |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 8106 | 36.f, |
| 8107 | child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale()); |
| 8108 | EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale()); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8109 | |
| 8110 | EXPECT_FLOAT_EQ( |
| 8111 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8112 | EXPECT_FLOAT_EQ( |
| 8113 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8114 | EXPECT_FLOAT_EQ(0.f, |
| 8115 | child1_layer->mask_layer() |
| 8116 | ->draw_properties() |
| 8117 | .maximum_animation_contents_scale); |
| 8118 | EXPECT_FLOAT_EQ(0.f, |
| 8119 | child1_layer->replica_layer() |
| 8120 | ->mask_layer() |
| 8121 | ->draw_properties() |
| 8122 | .maximum_animation_contents_scale); |
| 8123 | EXPECT_FLOAT_EQ( |
| 8124 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8125 | } |
| 8126 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8127 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8128 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8129 | SetLayerPropertiesForTesting(root.get(), |
| 8130 | gfx::Transform(), |
| 8131 | gfx::Point3F(), |
| 8132 | gfx::PointF(), |
| 8133 | gfx::Size(768 / 2, 3000), |
| 8134 | true, |
| 8135 | false); |
| 8136 | root->SetIsDrawable(true); |
| 8137 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8138 | scoped_refptr<Layer> clip = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8139 | SetLayerPropertiesForTesting(clip.get(), |
| 8140 | gfx::Transform(), |
| 8141 | gfx::Point3F(), |
| 8142 | gfx::PointF(), |
| 8143 | gfx::Size(768 / 2, 10000), |
| 8144 | true, |
| 8145 | false); |
| 8146 | clip->SetMasksToBounds(true); |
| 8147 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8148 | scoped_refptr<Layer> content = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8149 | SetLayerPropertiesForTesting(content.get(), |
| 8150 | gfx::Transform(), |
| 8151 | gfx::Point3F(), |
| 8152 | gfx::PointF(), |
| 8153 | gfx::Size(768 / 2, 10000), |
| 8154 | true, |
| 8155 | false); |
| 8156 | content->SetIsDrawable(true); |
| 8157 | content->SetForceRenderSurface(true); |
| 8158 | |
| 8159 | root->AddChild(clip); |
| 8160 | clip->AddChild(content); |
| 8161 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8162 | host()->SetRootLayer(root); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8163 | |
| 8164 | gfx::Size device_viewport_size(768, 582); |
enne | 1e1008c | 2015-08-21 00:45:46 | [diff] [blame] | 8165 | LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(), |
| 8166 | device_viewport_size); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8167 | inputs.device_scale_factor = 2.f; |
| 8168 | inputs.page_scale_factor = 1.f; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8169 | inputs.page_scale_layer = NULL; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8170 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8171 | |
| 8172 | // Layers in the root render surface have their visible content rect clipped |
| 8173 | // by the viewport. |
weiliangc | 2d58b2c | 2015-07-29 00:42:43 | [diff] [blame] | 8174 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), |
| 8175 | root->visible_rect_from_property_trees()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8176 | |
| 8177 | // Layers drawing to a child render surface should still have their visible |
| 8178 | // content rect clipped by the viewport. |
weiliangc | 2d58b2c | 2015-07-29 00:42:43 | [diff] [blame] | 8179 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), |
| 8180 | content->visible_rect_from_property_trees()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8181 | } |
| 8182 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8183 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8184 | FakeImplTaskRunnerProvider task_runner_provider; |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8185 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8186 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 8187 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 8188 | &task_graph_runner); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8189 | |
| 8190 | // Set two layers: the root layer clips it's child, |
| 8191 | // the child draws its content. |
| 8192 | |
| 8193 | gfx::Size root_size = gfx::Size(300, 500); |
| 8194 | |
| 8195 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8196 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8197 | |
| 8198 | // Device viewport accomidated the root and the top controls. |
| 8199 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8200 | gfx::Transform identity_matrix; |
| 8201 | |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 8202 | host_impl.SetViewportSize(device_viewport_size); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8203 | host_impl.active_tree()->SetRootLayer( |
| 8204 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8205 | |
| 8206 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8207 | SetLayerPropertiesForTesting(root, |
| 8208 | identity_matrix, |
| 8209 | gfx::Point3F(), |
| 8210 | gfx::PointF(), |
| 8211 | root_size, |
| 8212 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8213 | false, |
| 8214 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8215 | root->SetMasksToBounds(true); |
| 8216 | |
| 8217 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8218 | |
| 8219 | LayerImpl* sublayer = root->child_at(0); |
| 8220 | SetLayerPropertiesForTesting(sublayer, |
| 8221 | identity_matrix, |
| 8222 | gfx::Point3F(), |
| 8223 | gfx::PointF(), |
| 8224 | sublayer_size, |
| 8225 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8226 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8227 | false); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8228 | sublayer->SetDrawsContent(true); |
| 8229 | |
| 8230 | LayerImplList layer_impl_list; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8231 | root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8232 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 8233 | root, device_viewport_size, &layer_impl_list, |
| 8234 | root->layer_tree_impl()->current_render_surface_list_id()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8235 | |
| 8236 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8237 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8238 | |
| 8239 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8240 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8241 | |
| 8242 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8243 | root_size.height() + 50); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 8244 | EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8245 | } |
| 8246 | |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 8247 | TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { |
| 8248 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8249 | scoped_refptr<Layer> inner_viewport_container_layer = |
| 8250 | Layer::Create(layer_settings()); |
| 8251 | scoped_refptr<Layer> inner_viewport_scroll_layer = |
| 8252 | Layer::Create(layer_settings()); |
| 8253 | scoped_refptr<Layer> outer_viewport_container_layer = |
| 8254 | Layer::Create(layer_settings()); |
| 8255 | scoped_refptr<Layer> outer_viewport_scroll_layer = |
| 8256 | Layer::Create(layer_settings()); |
| 8257 | |
| 8258 | root->AddChild(inner_viewport_container_layer); |
| 8259 | inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
| 8260 | inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
| 8261 | outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
| 8262 | |
| 8263 | inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8264 | inner_viewport_container_layer->id()); |
| 8265 | outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8266 | outer_viewport_container_layer->id()); |
| 8267 | |
| 8268 | inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8269 | outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8270 | |
| 8271 | host()->SetRootLayer(root); |
| 8272 | host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, |
| 8273 | outer_viewport_scroll_layer); |
| 8274 | |
| 8275 | scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings()); |
| 8276 | scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings()); |
| 8277 | |
| 8278 | inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8279 | outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8280 | |
| 8281 | LayerPositionConstraint fixed_to_right; |
| 8282 | fixed_to_right.set_is_fixed_position(true); |
| 8283 | fixed_to_right.set_is_fixed_to_right_edge(true); |
| 8284 | |
| 8285 | fixed_to_inner->SetPositionConstraint(fixed_to_right); |
| 8286 | fixed_to_outer->SetPositionConstraint(fixed_to_right); |
| 8287 | |
| 8288 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8289 | |
| 8290 | TransformTree& transform_tree = host()->property_trees()->transform_tree; |
| 8291 | EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8292 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8293 | |
| 8294 | LayerPositionConstraint fixed_to_left; |
| 8295 | fixed_to_left.set_is_fixed_position(true); |
| 8296 | fixed_to_inner->SetPositionConstraint(fixed_to_left); |
| 8297 | |
| 8298 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8299 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8300 | EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8301 | |
| 8302 | fixed_to_outer->SetPositionConstraint(fixed_to_left); |
| 8303 | |
| 8304 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8305 | EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta()); |
| 8306 | EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta()); |
| 8307 | } |
| 8308 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8309 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8310 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8311 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8312 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8313 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8314 | |
| 8315 | root->AddChild(animated); |
| 8316 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8317 | host()->SetRootLayer(root); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8318 | |
| 8319 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8320 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8321 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8322 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8323 | |
| 8324 | root->SetMasksToBounds(true); |
| 8325 | root->SetForceRenderSurface(true); |
| 8326 | animated->SetOpacity(0.f); |
| 8327 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8328 | if (layer_settings().use_compositor_animation_timelines) { |
| 8329 | AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f, |
| 8330 | 1.f, false); |
| 8331 | } else { |
| 8332 | AddOpacityTransitionToController(animated->layer_animation_controller(), |
| 8333 | 10.0, 0.f, 1.f, false); |
| 8334 | } |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8335 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8336 | |
| 8337 | EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); |
| 8338 | } |
| 8339 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8340 | TEST_F(LayerTreeHostCommonTest, |
| 8341 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
| 8342 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8343 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8344 | scoped_refptr<Layer> clip = Layer::Create(layer_settings()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8345 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8346 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8347 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8348 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8349 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8350 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8351 | |
| 8352 | root->AddChild(clip); |
| 8353 | clip->AddChild(animated); |
| 8354 | animated->AddChild(surface); |
| 8355 | surface->AddChild(descendant_of_animation); |
| 8356 | |
| 8357 | clip->SetMasksToBounds(true); |
| 8358 | surface->SetForceRenderSurface(true); |
| 8359 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8360 | host()->SetRootLayer(root); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8361 | |
| 8362 | gfx::Transform uninvertible_matrix; |
| 8363 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8364 | |
| 8365 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8366 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8367 | SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 8368 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8369 | SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix, |
| 8370 | gfx::Point3F(), gfx::PointF(), |
| 8371 | gfx::Size(120, 120), true, false); |
| 8372 | SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 8373 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8374 | SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix, |
| 8375 | gfx::Point3F(), gfx::PointF(), |
| 8376 | gfx::Size(200, 200), true, false); |
| 8377 | |
| 8378 | TransformOperations start_transform_operations; |
| 8379 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8380 | TransformOperations end_transform_operations; |
| 8381 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8382 | if (layer_settings().use_compositor_animation_timelines) { |
| 8383 | AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0, |
| 8384 | start_transform_operations, |
| 8385 | end_transform_operations); |
| 8386 | } else { |
| 8387 | AddAnimatedTransformToLayer(animated.get(), 10.0, |
| 8388 | start_transform_operations, |
| 8389 | end_transform_operations); |
| 8390 | } |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8391 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8392 | |
| 8393 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8394 | // clipped target space, so is treated as fully visible. |
| 8395 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees()); |
| 8396 | |
| 8397 | // The singular transform on |animated| is flattened when inherited by |
| 8398 | // |surface|, and this happens to make it invertible. |
| 8399 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees()); |
| 8400 | EXPECT_EQ(gfx::Rect(2, 2), |
| 8401 | descendant_of_animation->visible_rect_from_property_trees()); |
| 8402 | |
| 8403 | gfx::Transform zero_matrix; |
| 8404 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8405 | SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(), |
| 8406 | gfx::PointF(), gfx::Size(120, 120), true, false); |
| 8407 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8408 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8409 | |
| 8410 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8411 | // treated as having an empty visible rect. |
| 8412 | EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees()); |
| 8413 | |
| 8414 | // This time, flattening does not make |animated|'s transform invertible. This |
| 8415 | // means the clip cannot be projected into |surface|'s space, so we treat |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 8416 | // |surface| and layers that draw into it as having empty visible rect. |
| 8417 | EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees()); |
| 8418 | EXPECT_EQ(gfx::Rect(), |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8419 | descendant_of_animation->visible_rect_from_property_trees()); |
| 8420 | } |
| 8421 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8422 | // Verify that having an animated filter (but no current filter, as these |
| 8423 | // are mutually exclusive) correctly creates a render surface. |
| 8424 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8425 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8426 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 8427 | scoped_refptr<Layer> grandchild = Layer::Create(layer_settings()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8428 | root->AddChild(child); |
| 8429 | child->AddChild(grandchild); |
| 8430 | |
| 8431 | gfx::Transform identity_transform; |
| 8432 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8433 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8434 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8435 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8436 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8437 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8438 | true, false); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8439 | host()->SetRootLayer(root); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8440 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8441 | if (layer_settings().use_compositor_animation_timelines) { |
| 8442 | AddAnimatedFilterToLayerWithPlayer(child->id(), timeline(), 10.0, 0.1f, |
| 8443 | 0.2f); |
| 8444 | } else { |
| 8445 | AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); |
| 8446 | } |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8447 | ExecuteCalculateDrawProperties(root.get()); |
| 8448 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8449 | EXPECT_TRUE(root->has_render_surface()); |
| 8450 | EXPECT_TRUE(child->has_render_surface()); |
| 8451 | EXPECT_FALSE(grandchild->has_render_surface()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8452 | |
| 8453 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8454 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8455 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8456 | |
| 8457 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8458 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8459 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8460 | } |
| 8461 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8462 | // Verify that having a filter animation with a delayed start time creates a |
| 8463 | // render surface. |
| 8464 | TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) { |
| 8465 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8466 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 8467 | scoped_refptr<Layer> grandchild = Layer::Create(layer_settings()); |
| 8468 | root->AddChild(child); |
| 8469 | child->AddChild(grandchild); |
| 8470 | |
| 8471 | gfx::Transform identity_transform; |
| 8472 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8473 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8474 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8475 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8476 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8477 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8478 | true, false); |
| 8479 | host()->SetRootLayer(root); |
| 8480 | |
| 8481 | scoped_ptr<KeyframedFilterAnimationCurve> curve( |
| 8482 | KeyframedFilterAnimationCurve::Create()); |
| 8483 | FilterOperations start_filters; |
| 8484 | start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f)); |
| 8485 | FilterOperations end_filters; |
| 8486 | end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f)); |
| 8487 | curve->AddKeyframe( |
| 8488 | FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); |
| 8489 | curve->AddKeyframe(FilterKeyframe::Create( |
| 8490 | base::TimeDelta::FromMilliseconds(100), end_filters, nullptr)); |
| 8491 | scoped_ptr<Animation> animation = |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 8492 | Animation::Create(std::move(curve), 0, 1, Animation::FILTER); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8493 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 8494 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8495 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8496 | if (layer_settings().use_compositor_animation_timelines) { |
| 8497 | AddAnimationToLayerWithPlayer(child->id(), timeline(), |
| 8498 | std::move(animation)); |
| 8499 | } else { |
| 8500 | child->layer_animation_controller()->AddAnimation(std::move(animation)); |
| 8501 | } |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8502 | ExecuteCalculateDrawProperties(root.get()); |
| 8503 | |
enne | c133299 | 2015-08-24 19:45:09 | [diff] [blame] | 8504 | EXPECT_TRUE(root->has_render_surface()); |
| 8505 | EXPECT_TRUE(child->has_render_surface()); |
| 8506 | EXPECT_FALSE(grandchild->has_render_surface()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8507 | |
| 8508 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8509 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8510 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8511 | |
| 8512 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8513 | EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation()); |
| 8514 | EXPECT_FALSE(child->FilterIsAnimating()); |
| 8515 | EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation()); |
| 8516 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8517 | EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation()); |
| 8518 | } |
| 8519 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8520 | // Ensures that the property tree code accounts for offsets between fixed |
| 8521 | // position layers and their respective containers. |
| 8522 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8523 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8524 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8525 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8526 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8527 | |
| 8528 | root->AddChild(child); |
| 8529 | child->AddChild(grandchild); |
| 8530 | |
| 8531 | gfx::Transform identity_transform; |
| 8532 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8533 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8534 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8535 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8536 | false); |
| 8537 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8538 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8539 | gfx::Size(50, 50), true, false); |
| 8540 | |
| 8541 | root->SetMasksToBounds(true); |
| 8542 | root->SetIsContainerForFixedPositionLayers(true); |
| 8543 | LayerPositionConstraint constraint; |
| 8544 | constraint.set_is_fixed_position(true); |
| 8545 | grandchild->SetPositionConstraint(constraint); |
| 8546 | |
| 8547 | root->SetIsContainerForFixedPositionLayers(true); |
| 8548 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8549 | host()->SetRootLayer(root); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8550 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8551 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8552 | |
| 8553 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8554 | grandchild->visible_rect_from_property_trees()); |
| 8555 | } |
| 8556 | |
ajuma | 0178b52 | 2015-07-02 21:08:41 | [diff] [blame] | 8557 | // Ensures that the property tree code accounts for offsets between fixed |
| 8558 | // position containers and their transform tree parents, when a fixed position |
| 8559 | // layer's container is its layer tree parent, but this parent doesn't have its |
| 8560 | // own transform tree node. |
| 8561 | TEST_F(LayerTreeHostCommonTest, |
| 8562 | PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) { |
| 8563 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8564 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 8565 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
| 8566 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
| 8567 | |
| 8568 | root->AddChild(child); |
| 8569 | child->AddChild(grandchild); |
| 8570 | |
| 8571 | gfx::Transform identity_transform; |
| 8572 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8573 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8574 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8575 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8576 | false); |
| 8577 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8578 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8579 | gfx::Size(50, 50), true, false); |
| 8580 | |
| 8581 | root->SetMasksToBounds(true); |
| 8582 | child->SetIsContainerForFixedPositionLayers(true); |
| 8583 | LayerPositionConstraint constraint; |
| 8584 | constraint.set_is_fixed_position(true); |
| 8585 | grandchild->SetPositionConstraint(constraint); |
| 8586 | |
| 8587 | root->SetIsContainerForFixedPositionLayers(true); |
| 8588 | |
| 8589 | host()->SetRootLayer(root); |
| 8590 | |
| 8591 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8592 | |
| 8593 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8594 | grandchild->visible_rect_from_property_trees()); |
| 8595 | } |
| 8596 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8597 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8598 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8599 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8600 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8601 | // test ensures that happens. |
| 8602 | |
| 8603 | gfx::Transform rotate; |
| 8604 | rotate.Rotate(5); |
| 8605 | gfx::Transform identity; |
| 8606 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8607 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8608 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8609 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8610 | false); |
| 8611 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8612 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8613 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8614 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8615 | false); |
| 8616 | frame_clip->SetMasksToBounds(true); |
| 8617 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8618 | scoped_refptr<Layer> rotated = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8619 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8620 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8621 | gfx::Size(2500, 500), true, false); |
| 8622 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8623 | scoped_refptr<Layer> surface = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8624 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8625 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8626 | false); |
| 8627 | surface->SetOpacity(0.5); |
| 8628 | |
| 8629 | scoped_refptr<LayerWithForcedDrawsContent> container = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8630 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8631 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8632 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8633 | |
| 8634 | scoped_refptr<LayerWithForcedDrawsContent> box = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8635 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8636 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8637 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8638 | |
| 8639 | root->AddChild(frame_clip); |
| 8640 | frame_clip->AddChild(rotated); |
| 8641 | rotated->AddChild(surface); |
| 8642 | surface->AddChild(container); |
| 8643 | surface->AddChild(box); |
| 8644 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8645 | host()->SetRootLayer(root); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8646 | |
| 8647 | ExecuteCalculateDrawProperties(root.get()); |
| 8648 | } |
| 8649 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8650 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
| 8651 | gfx::Transform identity; |
| 8652 | gfx::Transform translate_z; |
| 8653 | translate_z.Translate3d(0, 0, 10); |
| 8654 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8655 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8656 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8657 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8658 | root->SetIsContainerForFixedPositionLayers(true); |
| 8659 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8660 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8661 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 8662 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8663 | false); |
| 8664 | frame_clip->SetMasksToBounds(true); |
| 8665 | |
| 8666 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8667 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8668 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8669 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8670 | false); |
| 8671 | |
| 8672 | LayerPositionConstraint constraint; |
| 8673 | constraint.set_is_fixed_position(true); |
| 8674 | fixed->SetPositionConstraint(constraint); |
| 8675 | |
| 8676 | root->AddChild(frame_clip); |
| 8677 | frame_clip->AddChild(fixed); |
| 8678 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8679 | host()->SetRootLayer(root); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8680 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8681 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8682 | |
| 8683 | gfx::Rect expected(0, 0, 100, 100); |
| 8684 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 8685 | } |
| 8686 | |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8687 | TEST_F(LayerTreeHostCommonTest, |
| 8688 | PropertyTreesAccountForScrollCompensationAdjustment) { |
| 8689 | gfx::Transform identity; |
| 8690 | gfx::Transform translate_z; |
| 8691 | translate_z.Translate3d(0, 0, 10); |
| 8692 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8693 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8694 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8695 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8696 | root->SetIsContainerForFixedPositionLayers(true); |
| 8697 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8698 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8699 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 8700 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8701 | false); |
| 8702 | frame_clip->SetMasksToBounds(true); |
| 8703 | |
| 8704 | scoped_refptr<LayerWithForcedDrawsContent> scroller = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8705 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8706 | SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), |
| 8707 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8708 | false); |
| 8709 | |
| 8710 | scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f)); |
| 8711 | scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7)); |
| 8712 | scroller->SetScrollClipLayerId(frame_clip->id()); |
| 8713 | |
| 8714 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8715 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8716 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8717 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8718 | |
| 8719 | LayerPositionConstraint constraint; |
| 8720 | constraint.set_is_fixed_position(true); |
| 8721 | fixed->SetPositionConstraint(constraint); |
| 8722 | |
| 8723 | scoped_refptr<LayerWithForcedDrawsContent> fixed_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8724 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8725 | SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(), |
| 8726 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8727 | |
| 8728 | fixed_child->SetPositionConstraint(constraint); |
| 8729 | |
| 8730 | root->AddChild(frame_clip); |
| 8731 | frame_clip->AddChild(scroller); |
| 8732 | scroller->AddChild(fixed); |
| 8733 | fixed->AddChild(fixed_child); |
| 8734 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8735 | host()->SetRootLayer(root); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8736 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8737 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 8738 | |
| 8739 | gfx::Rect expected(0, 0, 50, 50); |
| 8740 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 8741 | |
| 8742 | expected = gfx::Rect(0, 0, 10, 10); |
| 8743 | EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees()); |
| 8744 | } |
| 8745 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8746 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
| 8747 | gfx::Transform identity; |
| 8748 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8749 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8750 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8751 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8752 | root->SetIsContainerForFixedPositionLayers(true); |
| 8753 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8754 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8755 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8756 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8757 | false); |
| 8758 | frame_clip->SetMasksToBounds(true); |
| 8759 | |
| 8760 | scoped_refptr<LayerWithForcedDrawsContent> scroller = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8761 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8762 | SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), |
| 8763 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8764 | false); |
| 8765 | |
| 8766 | scroller->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 8767 | scroller->SetScrollClipLayerId(frame_clip->id()); |
| 8768 | |
| 8769 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8770 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8771 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8772 | gfx::PointF(100, 100), gfx::Size(50, 50), true, |
| 8773 | false); |
| 8774 | |
| 8775 | LayerPositionConstraint constraint; |
| 8776 | constraint.set_is_fixed_position(true); |
| 8777 | fixed->SetPositionConstraint(constraint); |
| 8778 | fixed->SetForceRenderSurface(true); |
| 8779 | fixed->SetMasksToBounds(true); |
| 8780 | |
| 8781 | root->AddChild(frame_clip); |
| 8782 | frame_clip->AddChild(scroller); |
| 8783 | scroller->AddChild(fixed); |
| 8784 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8785 | host()->SetRootLayer(root); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8786 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8787 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 8788 | |
| 8789 | gfx::Rect expected(0, 0, 50, 50); |
| 8790 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 8791 | } |
| 8792 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8793 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
| 8794 | gfx::Transform identity; |
| 8795 | gfx::Transform translate; |
| 8796 | gfx::Transform rotate; |
| 8797 | |
| 8798 | translate.Translate(10, 10); |
| 8799 | rotate.Rotate(45); |
| 8800 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8801 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8802 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8803 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8804 | root->SetIsContainerForFixedPositionLayers(true); |
| 8805 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8806 | host()->SetRootLayer(root); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8807 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8808 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8809 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8810 | |
| 8811 | root->SetTransform(translate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8812 | EXPECT_FALSE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8813 | |
| 8814 | root->SetTransform(rotate); |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8815 | EXPECT_TRUE(host()->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 8816 | } |
| 8817 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8818 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8819 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8820 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8821 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8822 | root->AddChild(child); |
| 8823 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8824 | host()->SetRootLayer(root); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8825 | |
| 8826 | gfx::Transform identity_matrix; |
| 8827 | gfx::Transform scale_matrix; |
| 8828 | scale_matrix.Scale(2.f, 2.f); |
| 8829 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8830 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8831 | SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(), |
| 8832 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8833 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8834 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8835 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees()); |
| 8836 | |
| 8837 | child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f)); |
| 8838 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8839 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 8840 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees()); |
| 8841 | } |
| 8842 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8843 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8844 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8845 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8846 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8847 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8848 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8849 | |
| 8850 | root->AddChild(scroll_child); |
| 8851 | root->AddChild(scroll_parent); |
| 8852 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 8853 | scroll_parent->SetScrollClipLayerId(root->id()); |
| 8854 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8855 | host()->SetRootLayer(root); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8856 | |
| 8857 | gfx::Transform identity_transform; |
| 8858 | gfx::Transform scale; |
| 8859 | scale.Scale(2.f, 2.f); |
| 8860 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8861 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8862 | SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(), |
| 8863 | gfx::PointF(), gfx::Size(40, 40), true, false); |
| 8864 | SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, |
| 8865 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 8866 | true, false); |
| 8867 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8868 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8869 | EXPECT_EQ(gfx::Rect(25, 25), |
| 8870 | scroll_child->visible_rect_from_property_trees()); |
| 8871 | |
| 8872 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
| 8873 | scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8874 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 8875 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), |
| 8876 | scroll_child->visible_rect_from_property_trees()); |
| 8877 | } |
| 8878 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8879 | static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 8880 | } |
| 8881 | |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 8882 | TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) { |
| 8883 | // If the layer has a node in effect_tree, the return value of |
| 8884 | // num_copy_requests_in_target_subtree() must be equal to the actual number |
| 8885 | // of copy requests in the sub-layer_tree; Otherwise, the number is expected |
| 8886 | // to be the value of its nearest ancestor that owns an effect node and |
| 8887 | // greater than or equal to the actual number of copy requests in the |
| 8888 | // sub-layer_tree. |
| 8889 | |
| 8890 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8891 | scoped_refptr<Layer> child1 = Layer::Create(layer_settings()); |
| 8892 | scoped_refptr<Layer> child2 = Layer::Create(layer_settings()); |
| 8893 | scoped_refptr<Layer> grandchild = Layer::Create(layer_settings()); |
| 8894 | scoped_refptr<Layer> greatgrandchild = Layer::Create(layer_settings()); |
| 8895 | |
| 8896 | root->AddChild(child1); |
| 8897 | root->AddChild(child2); |
| 8898 | child1->AddChild(grandchild); |
| 8899 | grandchild->AddChild(greatgrandchild); |
| 8900 | host()->SetRootLayer(root); |
| 8901 | |
| 8902 | child1->RequestCopyOfOutput( |
| 8903 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8904 | greatgrandchild->RequestCopyOfOutput( |
| 8905 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
| 8906 | child2->SetOpacity(0.f); |
| 8907 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8908 | |
| 8909 | EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2); |
| 8910 | EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2); |
| 8911 | EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0); |
| 8912 | EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2); |
| 8913 | EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1); |
| 8914 | } |
| 8915 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8916 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
| 8917 | gfx::Transform identity; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8918 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 8919 | FakeContentLayerClient client; |
| 8920 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8921 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8922 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8923 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8924 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 8925 | scoped_refptr<FakePictureLayer> greatgrandchild( |
| 8926 | FakePictureLayer::Create(layer_settings(), &client)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8927 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8928 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8929 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 8930 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8931 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 8932 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8933 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 8934 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8935 | |
| 8936 | root->AddChild(child); |
| 8937 | child->AddChild(grandchild); |
| 8938 | grandchild->AddChild(greatgrandchild); |
| 8939 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 8940 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8941 | |
| 8942 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8943 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8944 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
| 8945 | |
| 8946 | // Now we will reset the visible rect from property trees for the grandchild, |
| 8947 | // and we will configure |child| in several ways that should force the subtree |
| 8948 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 8949 | // remain empty. |
| 8950 | grandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
| 8951 | gfx::Transform singular; |
| 8952 | singular.matrix().set(0, 0, 0); |
| 8953 | |
| 8954 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8955 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8956 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 8957 | child->SetTransform(identity); |
| 8958 | |
| 8959 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8960 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8961 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 8962 | child->SetHideLayerAndSubtree(false); |
| 8963 | |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8964 | gfx::Transform zero_z_scale; |
| 8965 | zero_z_scale.Scale3d(1, 1, 0); |
| 8966 | child->SetTransform(zero_z_scale); |
| 8967 | |
| 8968 | // Add a transform animation with a start delay. Now, even though |child| has |
| 8969 | // a singular transform, the subtree should still get processed. |
| 8970 | int animation_id = 0; |
| 8971 | scoped_ptr<Animation> animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 8972 | scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8973 | animation_id, 1, Animation::TRANSFORM); |
| 8974 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 8975 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8976 | if (layer_settings().use_compositor_animation_timelines) { |
| 8977 | AddAnimationToLayerWithPlayer(child->id(), timeline(), |
| 8978 | std::move(animation)); |
| 8979 | } else { |
| 8980 | child->AddAnimation(std::move(animation)); |
| 8981 | } |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8982 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8983 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
| 8984 | grandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
| 8985 | |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 8986 | if (layer_settings().use_compositor_animation_timelines) { |
| 8987 | RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(), |
| 8988 | animation_id); |
| 8989 | } else { |
| 8990 | child->RemoveAnimation(animation_id); |
| 8991 | } |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 8992 | child->SetTransform(identity); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8993 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8994 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 8995 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 8996 | |
| 8997 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 8998 | // |greatgrandchild| in several ways that should force the subtree to be |
| 8999 | // processed anyhow. |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9000 | grandchild->RequestCopyOfOutput( |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9001 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9002 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9003 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9004 | greatgrandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9005 | |
| 9006 | // Add an opacity animation with a start delay. |
| 9007 | animation_id = 1; |
| 9008 | animation = Animation::Create( |
danakj | a5a05ba0 | 2015-11-20 20:14:21 | [diff] [blame] | 9009 | scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9010 | animation_id, 1, Animation::OPACITY); |
| 9011 | animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 9012 | animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
loyso | 968163c9 | 2016-01-04 23:18:48 | [diff] [blame] | 9013 | if (layer_settings().use_compositor_animation_timelines) { |
| 9014 | AddAnimationToLayerWithExistingPlayer(child->id(), timeline(), |
| 9015 | std::move(animation)); |
| 9016 | } else { |
| 9017 | child->AddAnimation(std::move(animation)); |
| 9018 | } |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 9019 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9020 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9021 | } |
| 9022 | |
| 9023 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) { |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 9024 | FakeImplTaskRunnerProvider task_runner_provider; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9025 | TestSharedBitmapManager shared_bitmap_manager; |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 9026 | TestTaskGraphRunner task_graph_runner; |
khushalsagar | b64b360d | 2015-10-21 19:25:16 | [diff] [blame] | 9027 | FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, |
danakj | cf61058 | 2015-06-16 22:48:56 | [diff] [blame] | 9028 | &task_graph_runner); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9029 | |
| 9030 | gfx::Transform identity; |
| 9031 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9032 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); |
| 9033 | scoped_ptr<LayerImpl> grandchild = |
| 9034 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9035 | |
danakj | 4e95f763 | 2015-06-05 19:46:25 | [diff] [blame] | 9036 | scoped_ptr<FakePictureLayerImpl> greatgrandchild( |
| 9037 | FakePictureLayerImpl::Create(host_impl.active_tree(), 4)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9038 | |
| 9039 | child->SetDrawsContent(true); |
| 9040 | grandchild->SetDrawsContent(true); |
| 9041 | greatgrandchild->SetDrawsContent(true); |
| 9042 | |
| 9043 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9044 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9045 | true); |
| 9046 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9047 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9048 | false); |
| 9049 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 9050 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9051 | false); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9052 | |
| 9053 | LayerImpl* child_ptr = child.get(); |
| 9054 | LayerImpl* grandchild_ptr = grandchild.get(); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9055 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 9056 | child->AddChild(std::move(grandchild)); |
| 9057 | root->AddChild(std::move(child)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9058 | |
| 9059 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9060 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9061 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9062 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9063 | |
| 9064 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9065 | // and we will configure |child| in several ways that should force the subtree |
| 9066 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9067 | // remain empty. |
| 9068 | grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9069 | gfx::Transform singular; |
| 9070 | singular.matrix().set(0, 0, 0); |
| 9071 | |
| 9072 | child_ptr->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9073 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9074 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9075 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9076 | child_ptr->SetTransform(identity); |
| 9077 | |
| 9078 | child_ptr->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9079 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9080 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9081 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9082 | child_ptr->SetHideLayerAndSubtree(false); |
| 9083 | |
| 9084 | child_ptr->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9085 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9086 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9087 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9088 | |
| 9089 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9090 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9091 | // processed anyhow. |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 9092 | std::vector<scoped_ptr<CopyOutputRequest>> requests; |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9093 | requests.push_back(CopyOutputRequest::CreateEmptyRequest()); |
| 9094 | |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9095 | grandchild_ptr->PassCopyRequests(&requests); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9096 | root.get()->layer_tree_impl()->property_trees()->needs_rebuild = true; |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9097 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9098 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9099 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9100 | } |
| 9101 | |
| 9102 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
| 9103 | gfx::Transform identity; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9104 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 9105 | FakeContentLayerClient client; |
| 9106 | client.set_bounds(root->bounds()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9107 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9108 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9109 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9110 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9111 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9112 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9113 | root->AddChild(child); |
| 9114 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9115 | host()->SetRootLayer(root); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9116 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9117 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9118 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees()); |
| 9119 | child->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9120 | |
| 9121 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9122 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9123 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9124 | child->SetHideLayerAndSubtree(false); |
| 9125 | |
| 9126 | child->SetBounds(gfx::Size()); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9127 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9128 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9129 | child->SetBounds(gfx::Size(10, 10)); |
| 9130 | |
| 9131 | gfx::Transform rotate; |
| 9132 | child->SetDoubleSided(false); |
| 9133 | rotate.RotateAboutXAxis(180.f); |
| 9134 | child->SetTransform(rotate); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9135 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9136 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9137 | child->SetDoubleSided(true); |
| 9138 | child->SetTransform(identity); |
| 9139 | |
| 9140 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9141 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9142 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9143 | } |
| 9144 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9145 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9146 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9147 | // PreCalculateMetaInformation happens when its required. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9148 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9149 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 9150 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9151 | |
| 9152 | root->AddChild(parent); |
| 9153 | parent->AddChild(child); |
| 9154 | |
| 9155 | child->SetClipParent(root.get()); |
| 9156 | |
| 9157 | gfx::Transform identity; |
| 9158 | |
| 9159 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9160 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9161 | SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(), |
| 9162 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9163 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9164 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9165 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9166 | host()->SetRootLayer(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9167 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9168 | child->RequestCopyOfOutput( |
| 9169 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 9170 | |
| 9171 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9172 | EXPECT_EQ(parent->num_unclipped_descendants(), 1u); |
| 9173 | |
| 9174 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
| 9175 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9176 | EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9177 | } |
| 9178 | |
| 9179 | TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) { |
| 9180 | // Ensure that the treewalk in LayertreeHostCommon:: |
| 9181 | // PreCalculateMetaInformation updates input handlers correctly. |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9182 | LayerImpl* root = root_layer(); |
| 9183 | LayerImpl* child = AddChild<LayerImpl>(root); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9184 | |
| 9185 | gfx::Transform identity; |
| 9186 | |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9187 | SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(), |
| 9188 | gfx::Size(100, 100), true, false, true); |
| 9189 | SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(), |
| 9190 | gfx::Size(100, 100), true, false, false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9191 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9192 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9193 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9194 | child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9195 | ExecuteCalculateDrawProperties(root); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9196 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), true); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9197 | |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9198 | child->SetTouchEventHandlerRegion(gfx::Rect()); |
enne | cf94ff0c | 2015-08-18 22:58:05 | [diff] [blame] | 9199 | ExecuteCalculateDrawProperties(root); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9200 | EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9201 | } |
| 9202 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9203 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
| 9204 | gfx::Transform identity; |
| 9205 | gfx::Transform translate_z; |
| 9206 | translate_z.Translate3d(0, 0, 10); |
| 9207 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9208 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9209 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9210 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9211 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9212 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9213 | SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(), |
| 9214 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9215 | |
| 9216 | root->AddChild(child); |
| 9217 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9218 | host()->SetRootLayer(root); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9219 | |
| 9220 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9221 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9222 | |
| 9223 | child->RemoveFromParent(); |
| 9224 | |
| 9225 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9226 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9227 | } |
| 9228 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 9229 | TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) { |
| 9230 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9231 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 9232 | |
| 9233 | root->AddChild(child); |
| 9234 | gfx::Transform identity; |
| 9235 | |
| 9236 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9237 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9238 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9239 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9240 | |
enne | a7b43c3 | 2015-06-18 20:01:33 | [diff] [blame] | 9241 | host()->SetRootLayer(root); |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 9242 | |
| 9243 | EXPECT_FALSE(root->layer_or_descendant_is_drawn()); |
| 9244 | EXPECT_FALSE(root->visited()); |
| 9245 | EXPECT_FALSE(root->sorted_for_recursion()); |
| 9246 | EXPECT_FALSE(child->layer_or_descendant_is_drawn()); |
| 9247 | EXPECT_FALSE(child->visited()); |
| 9248 | EXPECT_FALSE(child->sorted_for_recursion()); |
| 9249 | |
| 9250 | root->set_layer_or_descendant_is_drawn(true); |
| 9251 | root->set_visited(true); |
| 9252 | root->set_sorted_for_recursion(true); |
| 9253 | child->set_layer_or_descendant_is_drawn(true); |
| 9254 | child->set_visited(true); |
| 9255 | child->set_sorted_for_recursion(true); |
| 9256 | |
| 9257 | LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get()); |
| 9258 | |
| 9259 | EXPECT_FALSE(root->layer_or_descendant_is_drawn()); |
| 9260 | EXPECT_FALSE(root->visited()); |
| 9261 | EXPECT_FALSE(root->sorted_for_recursion()); |
| 9262 | EXPECT_FALSE(child->layer_or_descendant_is_drawn()); |
| 9263 | EXPECT_FALSE(child->visited()); |
| 9264 | EXPECT_FALSE(child->sorted_for_recursion()); |
| 9265 | } |
| 9266 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9267 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { |
| 9268 | // Ensure that a Clip Node is added when a render surface applies clip. |
| 9269 | LayerImpl* root = root_layer(); |
| 9270 | LayerImpl* significant_transform = AddChildToRoot<LayerImpl>(); |
| 9271 | LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform); |
| 9272 | LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree); |
| 9273 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9274 | |
| 9275 | const gfx::Transform identity_matrix; |
| 9276 | // This transform should be a significant one so that a transform node is |
| 9277 | // formed for it. |
| 9278 | gfx::Transform transform1; |
| 9279 | transform1.RotateAboutYAxis(45); |
| 9280 | transform1.RotateAboutXAxis(30); |
| 9281 | // This transform should be a 3d transform as we want the render surface |
| 9282 | // to flatten the transform |
| 9283 | gfx::Transform transform2; |
| 9284 | transform2.Translate3d(10, 10, 10); |
| 9285 | |
| 9286 | layer_clips_subtree->SetMasksToBounds(true); |
| 9287 | test_layer->SetDrawsContent(true); |
| 9288 | |
| 9289 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9290 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9291 | SetLayerPropertiesForTesting(significant_transform, transform1, |
| 9292 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9293 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9294 | SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix, |
| 9295 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9296 | true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9297 | SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9298 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9299 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9300 | gfx::PointF(), gfx::Size(30, 30), true, false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9301 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9302 | root->SetForceRenderSurface(true); |
| 9303 | significant_transform->SetForceRenderSurface(false); |
| 9304 | layer_clips_subtree->SetForceRenderSurface(true); |
| 9305 | render_surface->SetForceRenderSurface(true); |
| 9306 | test_layer->SetForceRenderSurface(false); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9307 | ExecuteCalculateDrawProperties(root); |
| 9308 | |
| 9309 | TransformTree transform_tree = |
| 9310 | root->layer_tree_impl()->property_trees()->transform_tree; |
| 9311 | TransformNode* transform_node = |
| 9312 | transform_tree.Node(significant_transform->transform_tree_index()); |
| 9313 | EXPECT_EQ(transform_node->owner_id, significant_transform->id()); |
| 9314 | |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9315 | EXPECT_TRUE(root->has_render_surface()); |
| 9316 | EXPECT_FALSE(significant_transform->has_render_surface()); |
| 9317 | EXPECT_TRUE(layer_clips_subtree->has_render_surface()); |
| 9318 | EXPECT_TRUE(render_surface->has_render_surface()); |
| 9319 | EXPECT_FALSE(test_layer->has_render_surface()); |
| 9320 | |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9321 | ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; |
| 9322 | ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9323 | EXPECT_FALSE(clip_node->data.applies_local_clip); |
weiliangc | c154ce2 | 2015-12-09 03:39:26 | [diff] [blame] | 9324 | EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_rect_from_property_trees()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9325 | } |
| 9326 | |
| 9327 | TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) { |
| 9328 | // Ensure that when parent clip node's transform is an ancestor of current |
| 9329 | // clip node's target, clip is 'projected' from parent space to current |
| 9330 | // target space and visible rects are calculated correctly. |
| 9331 | LayerImpl* root = root_layer(); |
| 9332 | LayerImpl* clip_layer = AddChild<LayerImpl>(root); |
| 9333 | LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer); |
| 9334 | LayerImpl* test_layer = AddChild<LayerImpl>(target_layer); |
| 9335 | |
| 9336 | const gfx::Transform identity_matrix; |
| 9337 | gfx::Transform transform; |
| 9338 | transform.RotateAboutYAxis(45); |
| 9339 | clip_layer->SetMasksToBounds(true); |
| 9340 | target_layer->SetMasksToBounds(true); |
| 9341 | test_layer->SetDrawsContent(true); |
| 9342 | |
| 9343 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9344 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9345 | true); |
| 9346 | SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(), |
| 9347 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9348 | false); |
| 9349 | SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(), |
| 9350 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9351 | true); |
| 9352 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9353 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9354 | false); |
| 9355 | ExecuteCalculateDrawProperties(root); |
| 9356 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 9357 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees()); |
jaydasika | 67d7989e | 2015-08-06 21:55:34 | [diff] [blame] | 9358 | } |
| 9359 | |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9360 | TEST_F(LayerTreeHostCommonTest, |
| 9361 | RenderSurfaceWithUnclippedDescendantsClipsSubtree) { |
| 9362 | // Ensure clip rect is calculated correctly when render surface has unclipped |
| 9363 | // descendants. |
| 9364 | LayerImpl* root = root_layer(); |
| 9365 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9366 | LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent); |
| 9367 | LayerImpl* render_surface = |
| 9368 | AddChild<LayerImpl>(between_clip_parent_and_child); |
| 9369 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9370 | |
| 9371 | const gfx::Transform identity_matrix; |
| 9372 | gfx::Transform transform; |
| 9373 | transform.Translate(2.0, 2.0); |
| 9374 | |
| 9375 | test_layer->SetDrawsContent(true); |
| 9376 | render_surface->SetClipParent(clip_parent); |
jaydasika | e9d0970 | 2015-09-15 01:26:41 | [diff] [blame] | 9377 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9378 | clip_children->insert(render_surface); |
| 9379 | clip_parent->SetClipChildren(clip_children.release()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9380 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9381 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9382 | true); |
| 9383 | SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(), |
| 9384 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9385 | false); |
| 9386 | SetLayerPropertiesForTesting(between_clip_parent_and_child, transform, |
| 9387 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 9388 | true, false, false); |
| 9389 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9390 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9391 | true); |
| 9392 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9393 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9394 | false); |
| 9395 | |
| 9396 | ExecuteCalculateDrawProperties(root); |
| 9397 | |
jaydasika | e9d0970 | 2015-09-15 01:26:41 | [diff] [blame] | 9398 | EXPECT_EQ(gfx::Rect(30, 30), test_layer->clip_rect()); |
jaydasika | 7d5c1ed | 2015-08-14 14:27:02 | [diff] [blame] | 9399 | } |
| 9400 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9401 | TEST_F(LayerTreeHostCommonTest, |
ajuma | 01734dd0 | 2015-10-07 01:22:08 | [diff] [blame] | 9402 | RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) { |
| 9403 | // Ensure that the visible layer rect of a descendant of a surface with |
| 9404 | // unclipped descendants is computed correctly, when the surface doesn't apply |
| 9405 | // a clip. |
| 9406 | LayerImpl* root = root_layer(); |
| 9407 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9408 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9409 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9410 | LayerImpl* child = AddChild<LayerImpl>(render_surface); |
| 9411 | |
| 9412 | const gfx::Transform identity_matrix; |
| 9413 | |
| 9414 | clip_child->SetDrawsContent(true); |
| 9415 | child->SetDrawsContent(true); |
| 9416 | clip_child->SetClipParent(clip_parent); |
| 9417 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9418 | clip_children->insert(clip_child); |
| 9419 | clip_parent->SetClipChildren(clip_children.release()); |
| 9420 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9421 | gfx::PointF(), gfx::Size(30, 10), true, false, |
| 9422 | true); |
| 9423 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9424 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9425 | false); |
| 9426 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9427 | gfx::PointF(), gfx::Size(10, 15), true, false, |
| 9428 | true); |
| 9429 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9430 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9431 | false); |
| 9432 | SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(), |
| 9433 | gfx::PointF(), gfx::Size(40, 40), true, false, |
| 9434 | false); |
| 9435 | |
| 9436 | ExecuteCalculateDrawProperties(root); |
| 9437 | EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect()); |
| 9438 | } |
| 9439 | |
| 9440 | TEST_F(LayerTreeHostCommonTest, |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9441 | RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) { |
| 9442 | LayerImpl* root = root_layer(); |
| 9443 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9444 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9445 | LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface); |
| 9446 | LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1); |
| 9447 | LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child); |
| 9448 | |
| 9449 | const gfx::Transform identity_matrix; |
| 9450 | root->SetMasksToBounds(true); |
| 9451 | render_surface->SetMasksToBounds(true); |
| 9452 | render_surface->SetDrawsContent(true); |
| 9453 | clip_child->SetDrawsContent(true); |
| 9454 | test_layer1->SetDrawsContent(true); |
| 9455 | test_layer2->SetDrawsContent(true); |
| 9456 | clip_child->SetClipParent(clip_parent); |
| 9457 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9458 | clip_children->insert(clip_child); |
| 9459 | clip_parent->SetClipChildren(clip_children.release()); |
| 9460 | |
| 9461 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9462 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9463 | true); |
| 9464 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9465 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9466 | false); |
| 9467 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9468 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9469 | true); |
| 9470 | SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(), |
| 9471 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9472 | false); |
| 9473 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9474 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9475 | false); |
| 9476 | SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(), |
| 9477 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9478 | false); |
| 9479 | |
| 9480 | ExecuteCalculateDrawProperties(root); |
| 9481 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->visible_layer_rect()); |
| 9482 | EXPECT_EQ(gfx::Rect(50, 50), test_layer1->visible_layer_rect()); |
| 9483 | EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect()); |
| 9484 | EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect()); |
| 9485 | } |
| 9486 | |
ajuma | e2b7a5c | 2015-09-30 21:41:42 | [diff] [blame] | 9487 | TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) { |
| 9488 | LayerImpl* root = root_layer(); |
| 9489 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9490 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9491 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9492 | |
| 9493 | const gfx::Transform identity_matrix; |
| 9494 | clip_parent->SetDrawsContent(true); |
| 9495 | render_surface->SetMasksToBounds(true); |
| 9496 | render_surface->SetDrawsContent(true); |
| 9497 | clip_child->SetDrawsContent(true); |
| 9498 | |
| 9499 | clip_child->SetClipParent(clip_parent); |
| 9500 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9501 | clip_children->insert(clip_child); |
| 9502 | clip_parent->SetClipChildren(clip_children.release()); |
| 9503 | |
| 9504 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9505 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9506 | true); |
| 9507 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9508 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9509 | false); |
| 9510 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9511 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9512 | true); |
| 9513 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9514 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9515 | false); |
| 9516 | |
| 9517 | ExecuteCalculateDrawProperties(root); |
| 9518 | |
| 9519 | // The clip child should inherit its clip parent's clipping state, not its |
| 9520 | // tree parent's clipping state. |
| 9521 | EXPECT_FALSE(clip_parent->is_clipped()); |
| 9522 | EXPECT_TRUE(render_surface->is_clipped()); |
| 9523 | EXPECT_FALSE(clip_child->is_clipped()); |
| 9524 | } |
| 9525 | |
jaydasika | 77a4a07 | 2015-10-20 21:47:27 | [diff] [blame] | 9526 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) { |
| 9527 | // Tests the value of render surface content rect when we have multiple types |
| 9528 | // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and |
| 9529 | // clipped surfaces. |
| 9530 | LayerImpl* root = root_layer(); |
| 9531 | LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>(); |
| 9532 | LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface); |
| 9533 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9534 | LayerImpl* unclipped_desc_surface2 = |
| 9535 | AddChild<LayerImpl>(unclipped_desc_surface); |
| 9536 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2); |
| 9537 | LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child); |
| 9538 | |
| 9539 | unclipped_surface->SetDrawsContent(true); |
| 9540 | unclipped_desc_surface->SetDrawsContent(true); |
| 9541 | unclipped_desc_surface2->SetDrawsContent(true); |
| 9542 | clipped_surface->SetDrawsContent(true); |
| 9543 | clip_child->SetClipParent(clip_parent); |
| 9544 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9545 | clip_children->insert(clip_child); |
| 9546 | clip_parent->SetClipChildren(clip_children.release()); |
| 9547 | |
| 9548 | gfx::Transform identity_matrix; |
| 9549 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9550 | gfx::PointF(), gfx::Size(80, 80), true, false, |
| 9551 | true); |
| 9552 | SetLayerPropertiesForTesting(unclipped_surface, identity_matrix, |
| 9553 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 9554 | true, false, true); |
| 9555 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9556 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9557 | false); |
| 9558 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9559 | gfx::Point3F(), gfx::PointF(), |
| 9560 | gfx::Size(100, 100), true, false, true); |
| 9561 | SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix, |
| 9562 | gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60), |
| 9563 | true, false, true); |
| 9564 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9565 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9566 | false); |
| 9567 | SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(), |
| 9568 | gfx::PointF(), gfx::Size(70, 70), true, false, |
| 9569 | true); |
| 9570 | clip_parent->SetMasksToBounds(true); |
| 9571 | unclipped_surface->SetMasksToBounds(true); |
| 9572 | unclipped_desc_surface->SetMasksToBounds(true); |
| 9573 | |
| 9574 | ExecuteCalculateDrawProperties(root); |
| 9575 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9576 | unclipped_surface->render_surface()->content_rect()); |
| 9577 | EXPECT_EQ(gfx::Rect(100, 100), |
| 9578 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9579 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9580 | unclipped_desc_surface2->render_surface()->content_rect()); |
| 9581 | EXPECT_EQ(gfx::Rect(50, 50), |
| 9582 | clipped_surface->render_surface()->content_rect()); |
| 9583 | } |
| 9584 | |
| 9585 | TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) { |
| 9586 | // Tests the value of render surface content rect when we have a layer that |
| 9587 | // clips between the clip parent's target and clip child's target. |
| 9588 | LayerImpl* root = root_layer(); |
| 9589 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9590 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9591 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9592 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9593 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9594 | |
| 9595 | clip_child->SetDrawsContent(true); |
| 9596 | unclipped_desc_surface->SetDrawsContent(true); |
| 9597 | clip_child->SetClipParent(clip_parent); |
| 9598 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9599 | clip_children->insert(clip_child); |
| 9600 | clip_parent->SetClipChildren(clip_children.release()); |
| 9601 | |
| 9602 | gfx::Transform identity_matrix; |
| 9603 | gfx::Transform translate; |
| 9604 | translate.Translate(10, 10); |
| 9605 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9606 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9607 | true); |
| 9608 | SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(), |
| 9609 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9610 | true); |
| 9611 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9612 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9613 | false); |
| 9614 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9615 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9616 | false); |
| 9617 | SetLayerPropertiesForTesting(unclipped_desc_surface, translate, |
| 9618 | gfx::Point3F(), gfx::PointF(), |
| 9619 | gfx::Size(100, 100), true, false, true); |
| 9620 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9621 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9622 | false); |
| 9623 | surface->SetMasksToBounds(true); |
| 9624 | clip_layer->SetMasksToBounds(true); |
| 9625 | |
| 9626 | ExecuteCalculateDrawProperties(root); |
| 9627 | |
| 9628 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9629 | unclipped_desc_surface->render_surface()->content_rect()); |
| 9630 | } |
| 9631 | |
jaydasika | 2c8c287 | 2015-10-21 23:28:21 | [diff] [blame] | 9632 | TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) { |
| 9633 | LayerImpl* root = root_layer(); |
| 9634 | LayerImpl* surface = AddChildToRoot<LayerImpl>(); |
| 9635 | LayerImpl* clip_layer = AddChild<LayerImpl>(surface); |
| 9636 | LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer); |
| 9637 | LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent); |
| 9638 | LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface); |
| 9639 | |
| 9640 | clip_child->SetDrawsContent(true); |
| 9641 | unclipped_desc_surface->SetDrawsContent(true); |
| 9642 | clip_child->SetClipParent(clip_parent); |
| 9643 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9644 | clip_children->insert(clip_child); |
| 9645 | clip_parent->SetClipChildren(clip_children.release()); |
| 9646 | |
| 9647 | gfx::Transform identity_matrix; |
| 9648 | gfx::Transform scale; |
| 9649 | scale.Scale(2, 2); |
| 9650 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9651 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9652 | true); |
| 9653 | SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(), |
| 9654 | gfx::Size(100, 100), true, false, true); |
| 9655 | SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(), |
| 9656 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9657 | false); |
| 9658 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9659 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9660 | false); |
| 9661 | SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix, |
| 9662 | gfx::Point3F(), gfx::PointF(), |
| 9663 | gfx::Size(100, 100), true, false, true); |
| 9664 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9665 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9666 | false); |
| 9667 | surface->SetMasksToBounds(true); |
| 9668 | clip_layer->SetMasksToBounds(true); |
| 9669 | |
| 9670 | ExecuteCalculateDrawProperties(root); |
| 9671 | |
| 9672 | EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect()); |
| 9673 | } |
| 9674 | |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9675 | TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) { |
| 9676 | LayerImpl* root = root_layer(); |
| 9677 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9678 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9679 | |
| 9680 | const gfx::Transform identity_matrix; |
| 9681 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9682 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9683 | true); |
| 9684 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9685 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9686 | true); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9687 | gfx::Transform translation; |
| 9688 | translation.Translate(10, 10); |
| 9689 | SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(), |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9690 | gfx::PointF(), gfx::Size(20, 20), true, false, |
| 9691 | false); |
| 9692 | |
| 9693 | render_surface->SetMasksToBounds(true); |
| 9694 | test_layer->SetDrawsContent(true); |
| 9695 | test_layer->SetOpacity(0); |
dtapuska | ee0b698 | 2016-01-29 15:14:48 | [diff] [blame] | 9696 | test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20)); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9697 | |
| 9698 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9699 | EXPECT_EQ(translation, test_layer->ScreenSpaceTransform()); |
jaydasika | 60f8586 | 2015-10-01 20:36:14 | [diff] [blame] | 9700 | } |
| 9701 | |
jaydasika | e4910fa2 | 2015-10-09 00:52:09 | [diff] [blame] | 9702 | TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) { |
| 9703 | LayerImpl* root = root_layer(); |
| 9704 | LayerImpl* clip_parent = AddChildToRoot<LayerImpl>(); |
| 9705 | LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent); |
| 9706 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface); |
| 9707 | |
| 9708 | const gfx::Transform identity_matrix; |
| 9709 | clip_parent->SetMasksToBounds(true); |
| 9710 | render_surface->SetMasksToBounds(true); |
| 9711 | render_surface->SetDrawsContent(true); |
| 9712 | clip_child->SetDrawsContent(true); |
| 9713 | clip_child->SetClipParent(clip_parent); |
| 9714 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9715 | clip_children->insert(clip_child); |
| 9716 | clip_parent->SetClipChildren(clip_children.release()); |
| 9717 | |
| 9718 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9719 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9720 | true); |
| 9721 | SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(), |
| 9722 | gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true, |
| 9723 | false, false); |
| 9724 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9725 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9726 | true); |
| 9727 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9728 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9729 | false); |
| 9730 | |
| 9731 | ExecuteCalculateDrawProperties(root); |
| 9732 | EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect()); |
| 9733 | } |
| 9734 | |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9735 | TEST_F(LayerTreeHostCommonTest, |
| 9736 | LayerClipRectLargerThanClippingRenderSurfaceRect) { |
| 9737 | LayerImpl* root = root_layer(); |
| 9738 | LayerImpl* render_surface = AddChild<LayerImpl>(root); |
| 9739 | LayerImpl* test_layer = AddChild<LayerImpl>(render_surface); |
| 9740 | const gfx::Transform identity_matrix; |
| 9741 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9742 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9743 | true); |
| 9744 | SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(), |
| 9745 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9746 | true); |
| 9747 | SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(), |
| 9748 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 9749 | false); |
| 9750 | root->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9751 | root->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9752 | render_surface->SetMasksToBounds(true); |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9753 | render_surface->SetDrawsContent(true); |
jaydasika | 571dd2cf | 2015-09-25 20:55:42 | [diff] [blame] | 9754 | test_layer->SetMasksToBounds(true); |
| 9755 | test_layer->SetDrawsContent(true); |
| 9756 | ExecuteCalculateDrawProperties(root); |
| 9757 | |
| 9758 | EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect()); |
| 9759 | EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect()); |
| 9760 | EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect()); |
| 9761 | } |
| 9762 | |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9763 | TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) { |
| 9764 | // Tests that subtree is hidden is updated. |
| 9765 | LayerImpl* root = root_layer(); |
| 9766 | LayerImpl* hidden = AddChild<LayerImpl>(root); |
| 9767 | LayerImpl* test = AddChild<LayerImpl>(hidden); |
| 9768 | |
| 9769 | const gfx::Transform identity_matrix; |
| 9770 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9771 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9772 | true); |
| 9773 | SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(), |
| 9774 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9775 | false, true); |
| 9776 | SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(), |
| 9777 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9778 | true); |
| 9779 | |
| 9780 | hidden->SetHideLayerAndSubtree(true); |
| 9781 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9782 | EXPECT_TRUE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9783 | |
| 9784 | hidden->SetHideLayerAndSubtree(false); |
| 9785 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9786 | ExecuteCalculateDrawProperties(root); |
jaydasika | 8665451 | 2016-01-27 17:05:07 | [diff] [blame] | 9787 | EXPECT_FALSE(test->IsHidden()); |
jaydasika | b5504ca | 2015-12-18 23:41:55 | [diff] [blame] | 9788 | } |
| 9789 | |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9790 | TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) { |
| 9791 | LayerImpl* root = root_layer(); |
| 9792 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9793 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9794 | LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2); |
| 9795 | |
| 9796 | const gfx::Transform identity_matrix; |
| 9797 | clip_child->SetClipParent(root); |
| 9798 | scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>); |
| 9799 | clip_children->insert(clip_child); |
| 9800 | root->SetClipChildren(clip_children.release()); |
| 9801 | root->SetMasksToBounds(true); |
| 9802 | render_surface1->SetDrawsContent(true); |
| 9803 | render_surface2->SetDrawsContent(true); |
| 9804 | |
| 9805 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9806 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9807 | true); |
| 9808 | SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(), |
| 9809 | gfx::PointF(10, 10), gfx::Size(30, 30), true, |
| 9810 | false, true); |
| 9811 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9812 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9813 | true); |
| 9814 | SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(), |
| 9815 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9816 | false); |
| 9817 | ExecuteCalculateDrawProperties(root); |
| 9818 | |
| 9819 | EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect()); |
jaydasika | daf0af0 | 2016-01-06 15:33:37 | [diff] [blame] | 9820 | // A clip node is created for every render surface and for layers that have |
| 9821 | // local clip. So, here it should be craeted for every layer. |
| 9822 | EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u); |
jaydasika | c013728 | 2015-10-01 15:50:30 | [diff] [blame] | 9823 | } |
| 9824 | |
jaydasika | 224bca0 | 2015-12-18 02:37:09 | [diff] [blame] | 9825 | TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) { |
| 9826 | // Tests that the mask layer gets its owning layer's screen space transform. |
| 9827 | LayerImpl* root = root_layer(); |
| 9828 | LayerImpl* child = AddChild<LayerImpl>(root); |
| 9829 | |
| 9830 | const gfx::Transform identity_matrix; |
| 9831 | gfx::Transform transform; |
| 9832 | transform.Translate(10, 10); |
| 9833 | |
| 9834 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9835 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9836 | true); |
| 9837 | SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(), |
| 9838 | gfx::Size(30, 30), true, false, false); |
| 9839 | root->SetDrawsContent(true); |
| 9840 | child->SetDrawsContent(false); |
| 9841 | child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100)); |
| 9842 | ExecuteCalculateDrawProperties(root); |
| 9843 | |
| 9844 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9845 | child->mask_layer()->ScreenSpaceTransform()); |
| 9846 | transform.Translate(10, 10); |
| 9847 | child->SetTransform(transform); |
| 9848 | child->SetDrawsContent(true); |
| 9849 | root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 9850 | ExecuteCalculateDrawProperties(root); |
| 9851 | EXPECT_TRANSFORMATION_MATRIX_EQ(transform, |
| 9852 | child->mask_layer()->ScreenSpaceTransform()); |
| 9853 | } |
| 9854 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9855 | TEST_F(LayerTreeHostCommonTest, LargeTransformTest) { |
| 9856 | LayerImpl* root = root_layer(); |
| 9857 | LayerImpl* render_surface1 = AddChild<LayerImpl>(root); |
| 9858 | LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1); |
| 9859 | |
| 9860 | const gfx::Transform identity_matrix; |
| 9861 | render_surface1->SetDrawsContent(true); |
| 9862 | render_surface2->SetDrawsContent(true); |
jaydasika | 445176f | 2015-11-04 20:14:03 | [diff] [blame] | 9863 | render_surface2->SetMasksToBounds(true); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9864 | |
| 9865 | gfx::Transform large_transform; |
| 9866 | large_transform.Scale(99999999999999999999.f, 99999999999999999999.f); |
| 9867 | large_transform.Scale(9999999999999999999.f, 9999999999999999999.f); |
| 9868 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0))); |
| 9869 | EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1))); |
| 9870 | |
| 9871 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 9872 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9873 | true); |
| 9874 | SetLayerPropertiesForTesting(render_surface1, large_transform, gfx::Point3F(), |
| 9875 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9876 | true); |
| 9877 | SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(), |
| 9878 | gfx::PointF(), gfx::Size(30, 30), true, false, |
| 9879 | true); |
| 9880 | |
| 9881 | ExecuteCalculateDrawProperties(root); |
| 9882 | |
jaydasika | 8640f9f | 2015-11-10 01:34:36 | [diff] [blame] | 9883 | bool is_inf_or_nan = |
| 9884 | std::isinf( |
| 9885 | render_surface2->render_surface()->draw_transform().matrix().get( |
| 9886 | 0, 0)) || |
| 9887 | std::isnan( |
| 9888 | render_surface2->render_surface()->draw_transform().matrix().get(0, |
| 9889 | 0)); |
| 9890 | EXPECT_TRUE(is_inf_or_nan); |
| 9891 | is_inf_or_nan = |
| 9892 | std::isinf( |
| 9893 | render_surface2->render_surface()->draw_transform().matrix().get( |
| 9894 | 1, 1)) || |
| 9895 | std::isnan( |
| 9896 | render_surface2->render_surface()->draw_transform().matrix().get(1, |
| 9897 | 1)); |
| 9898 | EXPECT_TRUE(is_inf_or_nan); |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 9899 | EXPECT_EQ(gfx::RectF(), |
| 9900 | render_surface2->render_surface()->DrawableContentRect()); |
| 9901 | |
| 9902 | std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); |
| 9903 | bool root_in_rsll = |
| 9904 | std::find(rsll->begin(), rsll->end(), root) != rsll->end(); |
| 9905 | EXPECT_TRUE(root_in_rsll); |
| 9906 | bool render_surface2_in_rsll = |
| 9907 | std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end(); |
| 9908 | EXPECT_FALSE(render_surface2_in_rsll); |
| 9909 | } |
| 9910 | |
khushalsagar | 3769421 | 2016-01-15 20:46:48 | [diff] [blame] | 9911 | TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
| 9912 | LayerTreeHostCommon::ScrollUpdateInfo scroll; |
| 9913 | scroll.layer_id = 2; |
| 9914 | scroll.scroll_delta = gfx::Vector2d(5, 10); |
| 9915 | |
| 9916 | proto::ScrollUpdateInfo proto; |
| 9917 | scroll.ToProtobuf(&proto); |
| 9918 | LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
| 9919 | new_scroll.FromProtobuf(proto); |
| 9920 | |
| 9921 | EXPECT_EQ(scroll, new_scroll); |
| 9922 | } |
| 9923 | |
| 9924 | TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { |
| 9925 | ScrollAndScaleSet scroll_and_scale_set; |
| 9926 | |
| 9927 | LayerTreeHostCommon::ScrollUpdateInfo scroll1; |
| 9928 | scroll1.layer_id = 1; |
| 9929 | scroll1.scroll_delta = gfx::Vector2d(5, 10); |
| 9930 | LayerTreeHostCommon::ScrollUpdateInfo scroll2; |
| 9931 | scroll2.layer_id = 2; |
| 9932 | scroll2.scroll_delta = gfx::Vector2d(1, 5); |
| 9933 | scroll_and_scale_set.scrolls.push_back(scroll1); |
| 9934 | scroll_and_scale_set.scrolls.push_back(scroll2); |
| 9935 | |
| 9936 | scroll_and_scale_set.page_scale_delta = 0.3f; |
| 9937 | scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); |
| 9938 | scroll_and_scale_set.top_controls_delta = 0.9f; |
| 9939 | |
| 9940 | proto::ScrollAndScaleSet proto; |
| 9941 | scroll_and_scale_set.ToProtobuf(&proto); |
| 9942 | ScrollAndScaleSet new_scroll_and_scale_set; |
| 9943 | new_scroll_and_scale_set.FromProtobuf(proto); |
| 9944 | |
| 9945 | EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
| 9946 | } |
| 9947 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9948 | TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9949 | // Test the behavior of scroll tree builder |
| 9950 | // Topology: |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 9951 | // +root1(1)[inner_viewport_container_layer] |
| 9952 | // +-page_scale_layer |
| 9953 | // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling & |
| 9954 | // scrollable, inner_viewport_scroll_layer] |
| 9955 | // +------child6(6)[kScrollbarScrolling] |
| 9956 | // +--------grand_child10(10)[kScrollbarScrolling] |
| 9957 | // +----parent3(3) |
| 9958 | // +------child7(7)[scrollable] |
| 9959 | // +------child8(8)[scroll_parent=7] |
| 9960 | // +--------grand_child11(11)[scrollable] |
| 9961 | // +----parent4(4) |
| 9962 | // +------child9(9) |
| 9963 | // +--------grand_child12(12) |
| 9964 | // +----parent5(5)[contains_non_fast_scrollable_region] |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9965 | // |
| 9966 | // Expected scroll tree topology: |
| 9967 | // +property_tree_root---owner:-1 |
| 9968 | // +--root---owner:1, id:1 |
| 9969 | // +----node---owner:2, id:2 |
| 9970 | // +------node---owner:6, id:3 |
| 9971 | // +----node---owner:7, id:4 |
| 9972 | // +------node---owner:11, id:5 |
| 9973 | // +----node---owner:5, id:6 |
| 9974 | // |
| 9975 | // Extra check: |
| 9976 | // scroll_tree_index() of: |
| 9977 | // grand_child10:3 |
| 9978 | // parent3:1 |
| 9979 | // child8:4 |
| 9980 | // parent4:1 |
| 9981 | // child9:1 |
| 9982 | // grand_child12:1 |
| 9983 | scoped_refptr<Layer> root1 = Layer::Create(layer_settings()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 9984 | scoped_refptr<Layer> page_scale_layer = Layer::Create(layer_settings()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 9985 | scoped_refptr<Layer> parent2 = Layer::Create(layer_settings()); |
| 9986 | scoped_refptr<Layer> parent3 = Layer::Create(layer_settings()); |
| 9987 | scoped_refptr<Layer> parent4 = Layer::Create(layer_settings()); |
| 9988 | scoped_refptr<Layer> parent5 = Layer::Create(layer_settings()); |
| 9989 | scoped_refptr<Layer> child6 = Layer::Create(layer_settings()); |
| 9990 | scoped_refptr<Layer> child7 = Layer::Create(layer_settings()); |
| 9991 | scoped_refptr<Layer> child8 = Layer::Create(layer_settings()); |
| 9992 | scoped_refptr<Layer> child9 = Layer::Create(layer_settings()); |
| 9993 | scoped_refptr<Layer> grand_child10 = Layer::Create(layer_settings()); |
| 9994 | scoped_refptr<Layer> grand_child11 = Layer::Create(layer_settings()); |
| 9995 | scoped_refptr<Layer> grand_child12 = Layer::Create(layer_settings()); |
| 9996 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 9997 | root1->AddChild(page_scale_layer); |
| 9998 | page_scale_layer->AddChild(parent2); |
| 9999 | page_scale_layer->AddChild(parent3); |
| 10000 | page_scale_layer->AddChild(parent4); |
| 10001 | page_scale_layer->AddChild(parent5); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10002 | parent2->AddChild(child6); |
| 10003 | parent3->AddChild(child7); |
| 10004 | parent3->AddChild(child8); |
| 10005 | parent4->AddChild(child9); |
| 10006 | child6->AddChild(grand_child10); |
| 10007 | child8->AddChild(grand_child11); |
| 10008 | child9->AddChild(grand_child12); |
| 10009 | host()->SetRootLayer(root1); |
| 10010 | |
| 10011 | parent2->AddMainThreadScrollingReasons( |
| 10012 | MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10013 | parent2->AddMainThreadScrollingReasons( |
| 10014 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10015 | parent2->SetScrollClipLayerId(root1->id()); |
| 10016 | child6->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10017 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10018 | grand_child10->AddMainThreadScrollingReasons( |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10019 | MainThreadScrollingReason::kScrollbarScrolling); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10020 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10021 | child7->SetScrollClipLayerId(parent3->id()); |
| 10022 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10023 | child8->SetScrollParent(child7.get()); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10024 | grand_child11->SetScrollClipLayerId(parent3->id()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10025 | |
| 10026 | parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10027 | parent5->SetBounds(gfx::Size(10, 10)); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10028 | |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10029 | host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10030 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 10031 | |
| 10032 | const int kInvalidPropertyTreeNodeId = -1; |
| 10033 | const int kRootPropertyTreeNodeId = 0; |
| 10034 | |
| 10035 | // Property tree root |
| 10036 | ScrollTree scroll_tree = host()->property_trees()->scroll_tree; |
| 10037 | ScrollTree expected_scroll_tree; |
| 10038 | ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 10039 | property_tree_root->id = kRootPropertyTreeNodeId; |
| 10040 | property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 10041 | property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
| 10042 | property_tree_root->data.scrollable = false; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10043 | property_tree_root->data.main_thread_scrolling_reasons = |
| 10044 | MainThreadScrollingReason::kNotScrollingOnMain; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10045 | property_tree_root->data.contains_non_fast_scrollable_region = false; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10046 | |
| 10047 | // The node owned by root1 |
| 10048 | ScrollNode scroll_root1; |
| 10049 | scroll_root1.id = 1; |
| 10050 | scroll_root1.owner_id = root1->id(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10051 | expected_scroll_tree.Insert(scroll_root1, 0); |
| 10052 | |
| 10053 | // The node owned by parent2 |
| 10054 | ScrollNode scroll_parent2; |
| 10055 | scroll_parent2.id = 2; |
| 10056 | scroll_parent2.owner_id = parent2->id(); |
| 10057 | scroll_parent2.data.scrollable = true; |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10058 | scroll_parent2.data.main_thread_scrolling_reasons = |
| 10059 | parent2->main_thread_scrolling_reasons(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10060 | scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds(); |
| 10061 | scroll_parent2.data.bounds = parent2->bounds(); |
| 10062 | scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true; |
| 10063 | scroll_parent2.data.is_inner_viewport_scroll_layer = true; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10064 | expected_scroll_tree.Insert(scroll_parent2, 1); |
| 10065 | |
| 10066 | // The node owned by child6 |
| 10067 | ScrollNode scroll_child6; |
| 10068 | scroll_child6.id = 3; |
| 10069 | scroll_child6.owner_id = child6->id(); |
sunxd | 29f17bf | 2016-02-03 02:47:48 | [diff] [blame] | 10070 | scroll_child6.data.main_thread_scrolling_reasons = |
| 10071 | child6->main_thread_scrolling_reasons(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10072 | expected_scroll_tree.Insert(scroll_child6, 2); |
| 10073 | |
| 10074 | // The node owned by child7, child7 also owns a transform node |
| 10075 | ScrollNode scroll_child7; |
| 10076 | scroll_child7.id = 4; |
| 10077 | scroll_child7.owner_id = child7->id(); |
| 10078 | scroll_child7.data.scrollable = true; |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10079 | scroll_parent2.data.scroll_clip_layer_bounds = parent3->bounds(); |
| 10080 | scroll_parent2.data.bounds = child7->bounds(); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10081 | expected_scroll_tree.Insert(scroll_child7, 1); |
| 10082 | |
| 10083 | // The node owned by grand_child11, grand_child11 also owns a transform node |
| 10084 | ScrollNode scroll_grand_child11; |
| 10085 | scroll_grand_child11.id = 5; |
| 10086 | scroll_grand_child11.owner_id = grand_child11->id(); |
| 10087 | scroll_grand_child11.data.scrollable = true; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10088 | expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 10089 | |
| 10090 | // The node owned by parent5 |
| 10091 | ScrollNode scroll_parent5; |
| 10092 | scroll_parent5.id = 8; |
| 10093 | scroll_parent5.owner_id = parent5->id(); |
| 10094 | scroll_parent5.data.contains_non_fast_scrollable_region = true; |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10095 | scroll_parent5.data.bounds = gfx::Size(10, 10); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10096 | expected_scroll_tree.Insert(scroll_parent5, 1); |
| 10097 | |
| 10098 | expected_scroll_tree.set_needs_update(false); |
| 10099 | |
| 10100 | EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 10101 | |
| 10102 | // Check other layers' scroll_tree_index |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame^] | 10103 | EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index()); |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 10104 | EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10105 | EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10106 | EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10107 | EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10108 | EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10109 | EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10110 | } |
| 10111 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10112 | } // namespace |
| 10113 | } // namespace cc |